Overload List
| # | Signature | Description |
|---|---|---|
| 1 | Boolean RemezImpulse(TVec H, Double[] W, TFilterType FilterType, Double Gain, Double FS) | Design an optimal equiripple FIR filter with Parks-McClellan algorithm. |
| 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. |
Overload 1: Boolean RemezImpulse(TVec H, Double[] W, TFilterType FilterType, Double Gain, Double FS)
Design an optimal equiripple FIR filter with Parks-McClellan algorithm.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | H | TVec | source TVec |
| 2 | W | Double[] | |
| 3 | FilterType | TFilterType | |
| 4 | Gain | Double | scalar |
| 5 | FS | Double | scalar |
Returns: Boolean
Required length of the filter must be preset by setting H.Length. H vector holds the impulse response on exit.
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);
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.
| # | Name | Description |
|---|---|---|
| 1 | H | H vector holds the impulse response on exit. |
| 2 | Ripple | The required linear ripple of the passband and 20*Log10(Ripple) is the required attenuation of the stop band. |
| 3 | FilterType | Parameter defines the filter type. |
| 4 | Gain | Specifies the gain of the passband. |
| 5 | EnsureOdd | Resulting filter length will be odd (not divisable by 2), if set to true. Default is true. |
| 6 | FS | The sampling frequency used to normalize transition band edges defined in the W array. Default value for FS is 2. |
| 7 | W | Array which can hold only 2 (highpass/lowpass definition) or 4(bandpass/bandstop definition) parameters. |
Returns: Boolean
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.