SignalUtils.FirImpulse Method

Overload List

#SignatureDescription
1void FirImpulse(TVec H, Double[] W, TFilterType FilterType, Double FS)Design a FIR filter with rectangular window.
2void FirImpulse(TVec H, Double[] W, Double WindowParam, TFilterType FilterType, TSignalWindowType WindowType, Double Gain, Double FS)Windowed-sinc FIR impulse response of a preset length.

Overload 1: void FirImpulse(TVec H, Double[] W, TFilterType FilterType, Double FS)

Design a FIR filter with rectangular window.

#NameTypeDescription
1HTVecsource TVec
2WDouble[]
3FilterTypeTFilterType
4FSDoublescalar

Result: stored in self (calling object)

Remarks:

Compute a FIR impulse response filter (no window applied) and place the result in H. The transition regions are defined with the W array. There must be at least one (lowpass, highpass) and at most two (bandpass, bandstop) transition regions (2 or 4 elements). Filter type is defined with TFilterType. The length of the filter H.Length must be preset. Filters of even length (odd order), must have a stop band next to the nyquist (FS/2) frequency. 20*Log10(Ripple) is also the required attenuation of the stop band in decibel. FS is the sampling frequency.

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 h = new Vector(0);
        Vector response = new Vector(0);
        Vector x = new Vector(0);

        double FS = 2;
        int n = 41;

//lowpass design with cutoff frequency
    SignalUtils.FirImpulse(h.Size(n), new double[1] {0.5}, TFilterType.ftLowpass,FS);
    SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
    x = MtxExpr.Ramp(response.Length, TMtxFloatPrecision.mvDouble, 0, 1.0/response.Length);
    MtxVecTee.DrawIt(x,response,"Lowpass with cutoff at 0.5",false);

    //lowpass design with transition band
        SignalUtils.FirImpulse(h.Size(n), new double[2] {0.3,0.5}, TFilterType.ftLowpass,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response,"Lowpass with transition band: 0.3-0.5",false);

    //Highpass design with cutoff frequency
        SignalUtils.FirImpulse(h.Size(n), new double[1] {0.5}, TFilterType.ftHighpass,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response,"Highpass with cutoff at 0.5",false);

    //Highpass design with transition band
        SignalUtils.FirImpulse(h.Size(n), new double[2] {0.3,0.5}, TFilterType.ftHighpass,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response,"Highpass with transition band: 0.3-0.5",false);

    //Bandpass design with transition bands
        SignalUtils.FirImpulse(h.Size(n), new double[4] {0.3,0.4,0.5,0.6}, TFilterType.ftBandpass,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response,"Bandpass with transitoin band: 0.3-0.4, 0.5-0.6",false);

    //Bandstop design with transition bands
        SignalUtils.FirImpulse(h.Size(n), new double[4] {0.3,0.4,0.5,0.6}, TFilterType.ftBandstop,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response,"Bandstop with transition bands: 0.3-0.4, 0.5-0.6",false);

    //Hilbert III
        SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftHilbertIII,FS);
        SignalUtils.FrequencyResponse(h,null,response,8,false,TSignalWindowType.wtRectangular,0);
        MtxVecTee.DrawIt(x,response,"Hilbert III",false);

    //Hilbert IV
        n++;  //n must be even
        SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftHilbertIV,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response,"Hilbert IV", false);

    //Differentiator III
        n--; // n must be odd
        SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftDifferentiatorIII,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response, "Differentiator III",false);

    //Differentiator IV
        n++;  //n must be even
        SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftDifferentiatorIV,FS);
        SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0);
        MtxVecTee.DrawIt(x,response, "Differentiator IV", false);
    }

Overload 2: void FirImpulse(TVec H, Double[] W, Double WindowParam, TFilterType FilterType, TSignalWindowType WindowType, Double Gain, Double FS)

Windowed-sinc FIR impulse response of a preset length.

#NameTypeDescription
1HTVecsource TVec
2WDouble[]
3WindowParamDoublescalar
4FilterTypeTFilterType
5WindowTypeTSignalWindowType
6GainDoublescalar
7FSDoublescalar

Result: stored in self (calling object)

Remarks:

Fills H (length preset by the caller) with the linear-phase windowed-sinc FIR taps for the given FilterType, then multiplies by the chosen window and by Gain. The ideal kernel about the centre alpha=(N-1)/2 is, e.g. for a lowpass with normalised cutoff omega_c = (W[0]+W[1])/ FS,

h[n] = (sinbig(pi omega_c (n-alpha)big))/(pi (n-alpha)), h[alpha] = omega_c

with highpass, bandpass and bandstop using the matching spectral complements, and the Hilbert/differentiator types using their odd-symmetric kernels. WindowType selects the taper (WindowParam carries its parameter, e.g. the Kaiser beta); wtRectangular leaves the raw sinc. H.FloatPrecision sets the working precision. Domain: H.Length must be at least 4 (an exception is raised otherwise); W must supply 1-2 band edges for lowpass/highpass and 2-4 for bandpass/bandstop; integrator types are rejected. FS is the sampling frequency (default 2, so cutoffs are in cycles per Nyquist). Finite input yields finite taps.

See Also: SignalUtils.FirFilter, SignalUtils.FirImpulse, SignalUtils.KaiserImpulse, OptimalFir.RemezImpulse, SignalUtils.FractionalKaiserImpulse, SignalUtils.FractionalFirImpulse