You are here: Symbol Reference > SignalUtils Namespace > Functions > SignalUtils.EnvelopeDetector Function
DSP Master VCL
ContentsIndex
PreviousUpNext
SignalUtils.EnvelopeDetector Function

Fast envelope detector.

Pascal
procedure EnvelopeDetector(const Src: TVec; const Dst: TVec; FrameSize: integer);

A simple and fast envelope detector using moving average filter. FrameSize defines the length of the moving average (low pass filter) and the downsampling factor. The result is placed in Dst. Dst.Length = Src.Length div FrameSize. Src.Length must be divisable by FrameSize. This routine is 10 to 100x times faster then a decimator based envelope detector. Its drawback is higher noise due to some aliasing. Envelope detection is used to find the frequency of events with "long" periods. 

For example: sampling frequency is 11kHz. The audio card is recording hammer impacts which occur once every five seconds. Because the duration of the hammer impact is very short, the 0.2 Hz frequency will not show up in the frequency spectrum of the signal, regardless of the frequency resolution, especially because the audio card filters out everything below 20 Hz. By selecting FrameSize = 2000 the sampling frequency will be reduced by 2000x, by averaging together groups of rectified samples. The frequency spectrum of the filtered signal will show a clear peak at 0.2 Hz.

A simple test of the function: 

 

  uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit;

  procedure TForm1.Button1Click(Sender: TObject);
  var b,c,Response,x: Vector;
      FS: double;
  begin
      FS := 2;

      b := Sin(Ramp(3000, mvDouble, 0,2*Pi*0.02/FS))*Sin(Ramp(3000, mvDouble, 0,2*Pi*0.2/FS));
      EnvelopeDetector(b,c,10); //reduce sampling frequency by 10x

      FrequencyResponse(b,nil,Response,8,true,wtHanning);
      x := Ramp(Response.Length, mvDouble, 0,1.0/Response.Length);
      DrawIt(x,Response,'Original frequency spectrum');

      FrequencyResponse(c,nil,Response,8,true,wtHanning);
      x := Ramp(Response.Length, mvDouble, 0,0.1/Response.Length);
      DrawIt(x,Response,'Envelope - frequency spectrum');
  end;

 

  #include "MtxExpr.hpp"
  #include "MtxVecEdit.hpp"
  #include "MtxVecTee.hpp"
  #include "SignalUtils.hpp"

  void __fastcall TForm1::BitBtn1Click(TObject *Sender)
  {
      sVector b,c,Response,x;
      double FS = 2;

      b = Sin(Ramp(3000, mvDouble,0,2*PI*0.02/FS))*Sin(Ramp(3000, mvDouble,0,2*PI*0.2/FS));
      EnvelopeDetector(b,c,10); //reduce sampling frequency by 10x

      FrequencyResponse(b,NULL,Response,8,true,wtHanning);
      x = Ramp(Response.Length, mvDouble, 0,1.0/Response.Length);
      DrawIt(x,Response,"Original frequency spectrum",false);

      FrequencyResponse(c,NULL,Response,8,true,wtHanning);
      x = Ramp(Response.Length, mvDouble, 0,0.1/Response.Length);

      //Shows frequency at 0.04Hz:
      DrawIt(x,Response,"Envelope - frequency spectrum",false);
  }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!