Dynamic range compression - Need pseudo algorithm for normalizing a signal
from your posted waveform, i am assuming that this is a unipolar signal.  that is

$$ x[n] \ge 0 $$

in audio, it would be the same, except that we would be working on $|x[n]|$ instead.

so first you want a sliding maximum of your signal, where the window length is $L$.

$$ x_1[n] = \max_{0 \le i &lt; L} \Big| x[n-i] \Big|  $$

since your input signal $x[n]$ appears to be unipolar, you can leave off the absolute value operation.

then you want to apply a low-pass filter (LPF) to that sliding max.  you want the gain of the LPF at DC (0 Hz) to be 1 (or 0 dB gain).  a simple first-order LPF is

$$ \begin{align}
 x_2[n] &amp;= (1-p) \cdot x_1[n] + p \cdot x_2[n-1] \\ 
\\
        &amp;= x_1[n] + p \cdot (x_2[n-1] - x_1[n]) \\ 
\\
        &amp;= x_2[n-1] + (1-p) \cdot (x_1[n] - x_2[n-1]) \\ 
\end{align} $$

$p$ is the pole value of the LPF and 

$$ 0 &lt; 1-p \ll 1 $$

so

$x_2[n]$ will be an envelope for your input signal $x[n]$ and will be delayed by about half of the max window length plus about 4 times the "time constant" of the LPF:

$$d = \frac{L}{2} - \frac{4}{\log(p)} \quad \quad \text{samples}$$.

so, to normalize, you want to invert (compute the reciprocal of) the envelope $x_2[n]$ and multiply your input signal by that inverted envelope.  the inverted envelope is

$$ x_3[n] = \frac{A}{x_2[n] + \epsilon} $$

$A$ is the normalized amplitude you want (it can be $A=1$ or $A=$ any other positive number that you like).  $\epsilon$ is a tiny number, much smaller than most of your non-zero $x[n]$ that you need to add to the denominator to keep from dividing by zero (which is a bad thing).

but you should line up the signal and the delayed inverted envelope, so your normalized output is also delayed by $d$ samples (defined above):

$$ y[n] = x_3[n] \cdot x[n-d] $$

the most computationally expensive operation is the sliding max.  we were just talking about this sliding max in the music-dsp mailing list.  i will dig up C code for it and post that in a following answer.