OptimalFir.RemezImpulse Method

Overload List

#SignatureDescription
1Boolean RemezImpulse(TVec H, Double[] W, TFilterType FilterType, Double Gain, Double FS)Design an optimal equiripple FIR filter with Parks-McClellan algorithm.
2Boolean RemezImpulse(TVec H, Double[] W, Double Ripple, TFilterType FilterType, Double Gain, Double FS, Boolean EnsureOdd)Design an optimal equiripple FIR filter with Parks-McClellan algorithm.

Overload 1: Boolean RemezImpulse(TVec H, Double[] W, TFilterType FilterType, Double Gain, Double FS)

Design an optimal equiripple FIR filter with Parks-McClellan algorithm.

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

Returns: Boolean

Remarks:

Required length of the filter must be preset by setting H.Length. H vector holds the impulse response on exit.

Examples
using Dew.Math;
    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);

    //Assumed sampling frequency = 2
        double FS = 2;
        double TransBW = 0.02; //transition bandwidth in Hz.
        double Ripple = 0.001;
//Lowpass filter
    OptimalFir.RemezImpulse(H,new double[2] {0.3,0.3+TransBW},Ripple, TFilterType.ftLowpass,1,FS,false);
//Highpass filter
    OptimalFir.RemezImpulse(H,new double[2] {0.3,0.3+TransBW},Ripple, TFilterType.ftHighpass,1,FS,false);
//Bandpass filter
    OptimalFir.RemezImpulse(H,new double[4] {0.3,0.3+TransBW, 0.5-TransBW,0.5},Ripple, TFilterType.ftBandpass,1,FS,false);
//Bandstop filter
    OptimalFir.RemezImpulse(H,new double[4] {0.3,0.3+TransBW, 0.5-TransBW,0.5},Ripple, TFilterType.ftBandstop, 1,FS,false);


//  Type III Hilbert transformer
    OptimalFir.RemezImpulse(H,new double[2] {TransBW,1-TransBW},Ripple, TFilterType.ftHilbertIII,1,FS,false);

//  Type IV Hilbert transformer
    OptimalFir.RemezImpulse(H,new double[2] {TransBW,1},Ripple, TFilterType.ftHilbertIV,1,FS,false);

//  Type III linear phase differentiator filter
    SignalUtils.KaiserImpulse(H,new double[2] {1-TransBW,1},Ripple, TFilterType.ftDifferentiatorIII,1,FS,false);
    H.Scale(FS);  //Scale by sampling frequency

//  Type IV linear phase differentiator filter
    SignalUtils.KaiserImpulse( H,new double[2] {1-TransBW,1},Ripple, TFilterType.ftDifferentiatorIV,1,FS,false);
    H.Scale(FS);  //Scale by sampling frequency

//  Type III differentiator filter
    OptimalFir.RemezImpulse(H,new double[2] {0,1-TransBW},Ripple, TFilterType.ftDifferentiatorIII,1,FS,false);
    H.Scale(FS);  //Scale by sampling frequency

//  Type IV differentiator filter
    OptimalFir.RemezImpulse( H,new double[2] {0,1-TransBW},Ripple, TFilterType.ftDifferentiatorIV,1,FS,false);
    H.Scale(FS);  //Scale by sampling frequency

// Type III 2x differentiator filter (remez)
    OptimalFir.RemezImpulse(H,new double[2] {0,1-TransBW},Ripple, TFilterType.ftDoubleDifferentiatorIII,1,FS,false);
    H.Scale(FS*FS);  //Scale by sampling frequency

// Type IV 2x differentiator filter (remez)
    OptimalFir.RemezImpulse(H,new double[2] {0,1-TransBW},Ripple, TFilterType.ftDoubleDifferentiatorIV,1,FS,false);
    H.Scale(FS*FS);  //Scale by sampling frequency

// Type III integrator  filter (remez).';
    OptimalFir.RemezImpulse(H,new double[2] {TransBW,1-TransBW},Ripple, TFilterType.ftIntegratorIII,1,FS,false);
    H.Scale(1/FS);  //Scale by sampling frequency

// Type IV integrator  filter (remez).';
    OptimalFir.RemezImpulse(H,new double[2] {TransBW,1},Ripple, TFilterType.ftIntegratorIV,1,FS,false);
    H.Scale(1/FS);  //Scale by sampling frequency

//  Type III 2x integrator  filter (remez).';
    OptimalFir.RemezImpulse(H,new double[2] {TransBW,1-TransBW},Ripple, TFilterType.ftDoubleIntegratorIII,1,FS,false);
    H.Scale(Math.Sqrt(1/FS));  //Scale by sampling frequency

//  Type IV 2x integrator  filter (remez).';
    OptimalFir.RemezImpulse(H,new double[2] {TransBW,1},Ripple, TFilterType.ftDoubleIntegratorIV,1,FS,false);
    H.Scale(Math.Sqrt(1/FS));  //Scale by sampling frequency

    SignalUtils.FrequencyResponse(H,null,Response,16,false,TSignalWindowType.wtRectangular,0);
    MtxVecTee.DrawIt(Response,"",false);
See Also: SignalUtils.KaiserImpulse, SignalUtils.SavGolayImpulse, OptimalFir.remez, SignalUtils.FirImpulse

Overload 2: Boolean RemezImpulse(TVec H, Double[] W, Double Ripple, TFilterType FilterType, Double Gain, Double FS, Boolean EnsureOdd)

Design an optimal equiripple FIR filter with Parks-McClellan algorithm.

#NameDescription
1HH vector holds the impulse response on exit.
2RippleThe required linear ripple of the passband and 20*Log10(Ripple) is the required attenuation of the stop band.
3FilterTypeParameter defines the filter type.
4GainSpecifies the gain of the passband.
5EnsureOddResulting filter length will be odd (not divisable by 2), if set to true. Default is true.
6FSThe sampling frequency used to normalize transition band edges defined in the W array. Default value for FS is 2.
7WArray which can hold only 2 (highpass/lowpass definition) or 4(bandpass/bandstop definition) parameters.

Returns: Boolean

Remarks:

The resulting impulse response is placed in H. Length of the filter is automatically estimated from the required Ripple and transition bandwidth. Function returns True, if the filter was succesfully designed. This does not guarantee that filter specifications have been meet.

This routine is a simplified version of Remez and can be used to design: Lowpass, bandpass, bandstop, highpass, differentiators and hilbert transformers.

Note:

RemezImpulse routine designes FIR filters about 10-20% shorter than the KaiserImpulse routine.

See Also: OptimalFir.remez