Compression Implementation

In the previous diagrams there was a stage where we effectively did detection of the envelope of the signal.

Envelope detection can work on either the peak amplitude of the waveform or on the RMS (Root Mean Square). We're going to be looking at the peak.

		octave:1 > piano = sndfile_load ('~/IADSPL/AudioFiles/pianoe2.wav') ;
		octave:2 > piano = abs (piano) ;
		octave:3 > clg ; plot (piano) ; hold on
		octave:4 > piano = piano (1:1000) ;
		octave:5 >
		octave:6 > smoothed_peak = 0 ; env = zeros (1, length (piano)) ; 
		octave:7 > for k = 1:length (piano),
		>  if (piano(k) > smoothed_peak),
		>     smoothed_peak = piano (k) ;
		>  else
		>     smoothed_peak = 0.999 * smoothed_peak ;
		>     endif
		> env (k) = smoothed_peak ;
		> endfor
		octave:6 > hold on
		octave:7 > plot (env)
		

back.png next.png