SignalUtils.IirInitBQ Method

void IirInitBQ(TVec sos, ref TIirState IIRState, Boolean ComplexData)

Initialize an IIR filter with second order sections.

#NameTypeDescription
1sosTVecsource TVec
2IIRStateTIirState (ref)
3ComplexDataBoolean

Result: stored in self (calling object)

Remarks:

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.

Examples
using Dew.Math;
using Dew.Math.Editors;
using Dew.Math.Units;
using Dew.Signal;
using Dew.Signal.Units;
using Dew.Math.Tee;
using Dew.Signal.Tee;

private void button1_Click(object sender, EventArgs e)
{
    Vector b = new Vector(0);
    Vector c = new Vector(0);
    Vector sos = new Vector(0);
    Vector Response1 = new Vector(0);
    Vector Response2 = new Vector(0);
    TIirState state = new TIirState();
    int n;
    int i;

    SignalUtils.Tone(b,300,6.0/300,0,1,false);

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

    IIRFilters.ChebyshevIFilter(6,0.2,new double[1] {0.6}, TFilterType.ftLowpass,false,sos,TIirFrequencyTransform.ftStateSpaceAnalog);
    SignalUtils.IirInit(sos,ref state,false);
    try
    {
        c.Copy(b);  //backup data
        SignalUtils.IirFilter(c,state);  //apply filter to the data
    }
    finally
    {
        SignalUtils.IirFree(ref state);   //free structure, if you dont require this IIR filter anymore
    }

    MtxVecTee.DrawIt(new TVec[2] {b,c}, new string[2] {"Original signal","Filtered signal"},"Time signals", false);
    SignalUtils.FrequencyResponse(c, null, Response1, 1, true, TSignalWindowType.wtHanning, 0);
    SignalUtils.FrequencyResponse(b, null, Response2, 1, true, TSignalWindowType.wtHanning, 0);
    MtxVecTee.DrawIt(new TVec[2] {Response1,Response2}, new string[2] {"Spectrum: original signal","Spectrum: filtered signal"}, "Frequency spectrum", false);
}
See Also: SignalUtils.SavGolayFilter, OptimalFir.RemezImpulse, SignalUtils.FirInit, SignalUtils.IirInit, SignalUtils.IirFree