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

Initialize an IIR filter with second order sections.

Pascal
procedure IirInitBQ(const Sos: TVec; var IirState: TIirState; ComplexData: boolean);

Initialize an IIR filter by initializing the IirState variable. Set ComplexData to True, if the data stream to be filtered will be complex. The Sos (real) vector variable contains second order sections as produced by the ZeroPoleToSOS function: 

(B00, B10, B20, A00, A10, A20), (B01, B11, B21, A01, A11, A21), (.... ),... 

B - numerator sections array A - denumarator sections array 

Using second order sections to compute an IIR filter results in higher numerical accuracy and greater filter stability at a slightly higher cost on performance.

Lowpass filter a sine signal with Chebyshev type I filter. Sampling frequency is 2Hz, cutoff frequency is 0.6 Hz. Passband ripple is 0.2 dB and filter order is 6. 

 

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

  procedure TForm42.Button1Click(Sender: TObject);
  var b,c,Response,Response1,sos: Vector;
      State: TIirState;
      n,i: integer;
  begin
      Tone(b,300,6/300,0,1);

  //   Alternative: try gaussian noise
  //    b := RandGauss(300);

      c.Size(b);
      ChebyshevIFilter(6,0.2,[0.6],ftLowpass,false,sos); //design filter
      FillChar(State,SizeOf(State),0);
      IirInitBQ(sos,State);  //initialize filtering structure
      try
          c.Copy(b); //make backup of data
          IirFilter(c,State); //apply filter to data

          DrawIt([b,c],['Original signal','Filtered signal']);
          FrequencyResponse(b,nil,Response,8,True,wtHanning);
          FrequencyResponse(c,nil,Response1,8,True,wtHanning);
          DrawIt([Response,Response1],['Orig. signal','Filtered']);
      finally
          IirFree(State);
      end;
  end;

 

  #include "MtxExpr.hpp"
  #include "MtxVecEdit.hpp"
  #include "MtxVecTee.hpp"
  #include "SignalUtils.hpp"
  #include "IIRFilters.hpp"
  #include <string.h>

  void __fastcall TForm1::BitBtn1Click(TObject *Sender)
  {
      sVector b,c, Response1, Response, sos;
      TIirState State;
      TToneState ToneState;
      int i,n;

      b.Size(300);
      ToneInit(6.0/300,0.0,1.0,ToneState,false);
      Tone(b,ToneState);  //generate data

    //   Alternative: try gaussian noise
    //   b.RandGauss();

      ChebyshevIFilter(6,0.2,OPENARRAY(double,(0.6)),ftLowpass,false,sos);
      memset(&State,0,sizeof(State));
      IirInit(sos,State);
      try
      {
              c.Copy(b);  //backup data
              IirFilter(c,State);  //apply filter to the data

          DrawIt(OPENARRAY(TVec*,(b,c)),OPENARRAY(AnsiString,("Original signal","Filtered Signal")));
          FrequencyResponse(b,NULL,Response,8,True,wtHanning);
          FrequencyResponse(c,NULL,Response1,8,True,wtHanning);
          DrawIt(OPENARRAY(TVec*,(Response,Response1)),OPENARRAY(AnsiString,("Spectrum: original signal","Spectrum: filtered signal")));
      }
      __finally
      {
        IirFree(State);
      }
  }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!