SignalUtils.FirFilter Method

Overload List

#SignatureDescription
1void FirFilter(TCplx Src, ref TCplx Dst, ref TFirState FIRState)Filter data with a FIR filter.
2void FirFilter(TVec Src, TVec Dst, ref TFirState FIRState)Filter data with a FIR filter.
3void FirFilter(TVec Data, TVec FirTaps, Int32 UpSample, Int32 DownSample)Filter Data with a FIR filter and place the result back in the Data.
4void FirFilter(Double Src, ref Double Dst, ref TFirState FIRState)Filter data with a FIR filter.

Overload 1: void FirFilter(TCplx Src, ref TCplx Dst, ref TFirState FIRState)

Filter data with a FIR filter.

#NameTypeDescription
1SrcTCplxscalar
2DstTCplx (ref)output
3FIRStateTFirState (ref)

Result: stored in self (calling object)

Remarks:

Filter real TCplx sample and place the filtered result in Dst sample.

Overload 2: void FirFilter(TVec Src, TVec Dst, ref TFirState FIRState)

Filter data with a FIR filter.

#NameTypeDescription
1SrcTVecsource TVec
2DstTVecsource TVec
3FIRStateTFirState (ref)

Result: stored in self (calling object)

Remarks:

Filter data in Src and place the result in Dst. FirState must be initialized with a call to FirInit. This version of FirFilter routine can filter streaming blocks of data.

Overload 3: void FirFilter(TVec Data, TVec FirTaps, Int32 UpSample, Int32 DownSample)

Filter Data with a FIR filter and place the result back in the Data.

#NameTypeDescription
1DataTVecsource TVec
2FirTapsTVecsource TVec
3UpSampleInt32
4DownSampleInt32

Result: stored in self (calling object)

Remarks:

This version of FirFilter can not be used to filter streaming data. The routine compensates for group delay and returns filtered data delayed by 0 (odd FIR length) or 0.5 samples (even FIR length).

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 h = new Vector(0);
        Vector Response1 = new Vector(0);
        Vector Response2 = new Vector(0);
        TFirState state = new TFirState();
        int n;
        int i;
        double FS = 2;

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

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

        c.Size(b);
        OptimalFir.RemezImpulse(h, new double[2] { 0.5, 0.7 }, 0.001, TFilterType.ftLowpass, 1, FS,false);
        SignalUtils.FirInit(h,ref state,1,0,1,0);
        try
        {
    //Alternative 1, FIR streaming
        n = 10;
        int bLength = b.Length; //to prevente reevaluaton inside "for"
        for (i = 0; i < (bLength/n); i++)
        {
            b.SetSubRange(i*n,n);
            c.SetSubRange(i*n,n);
            SignalUtils.FirFilter(b,c,ref state);
        }
        }
        finally
        {
            c.SetFullRange();
            b.SetFullRange();
            SignalUtils.FirFree(ref state);
        }

//Alternative 2 single block filter (does not require TFirState)
//                c.Copy(b);
//                SignalUtils.FirFilter(c,h,1,1);

//Alternative 3 single block
//                c.Copy(b);
//                SignalUtils.FirFilter(b,c,state);

    MtxVecTee.DrawIt(new TVec[2] {b,c}, new string[2] {"Original signal","Filtered signal"},"Time signals", false);
    SignalUtils.FrequencyResponse(b, null, Response1, 1, true, TSignalWindowType.wtHanning, 0);
    SignalUtils.FrequencyResponse(c, 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.FirInit, SignalUtils.FirFilter

Overload 4: void FirFilter(Double Src, ref Double Dst, ref TFirState FIRState)

Filter data with a FIR filter.

#NameTypeDescription
1SrcDoublescalar
2DstDouble (ref)output
3FIRStateTFirState (ref)

Result: stored in self (calling object)

Remarks:

Filter real Src sample and place the filtered result in Dst sample.