Overload List
| # | Signature | Description |
|---|---|---|
| 1 | procedure FirImpulse(const H: TVec; W: TDoubleArray; FilterType: TFilterType; FS: Double); | Design a FIR filter with rectangular window. |
| 2 | procedure FirImpulse(const H: TVec; W: TDoubleArray; WindowParam: Double; FilterType: TFilterType; WindowType: TSignalWindowType; Gain: Double; FS: Double); | Windowed-sinc FIR impulse response of a preset length. |
Overload 1: procedure FirImpulse(const H: TVec; W: TDoubleArray; FilterType: TFilterType; FS: Double);
Design a FIR filter with rectangular window.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | H | TVec | |
| 2 | W | TDoubleArray | |
| 3 | FilterType | TFilterType | |
| 4 | FS | Double | scalar |
Result: stored in self (calling object)
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.
uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit;
procedure TForm1.Button1Click(Sender: TObject);
var FS: double;
n: integer;
H, Response, X: Vector;
begin
FS := 2; //sampling frequency
n := 41; // filter length
//lowpass design with cutoff frequency
FIRImpulse(H.Size(n), [0.5], ftLowpass,FS);
FrequencyResponse(H,nil,Response,8);
X := Ramp(Response.Length, mvDouble, 0, 1/Response.Length);
DrawIt(X,Response,'Lowpass with cutoff at 0.5');
//lowpass design with transition band
FIRImpulse(H.Size(n), [0.3,0.5], ftLowpass,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response,'Lowpass with transition band: 0.3-0.5');
//Highpass design with cutoff frequency
FIRImpulse(H.Size(n), [0.5], ftHighpass,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response,'Highpass with cutoff at 0.5');
//Highpass design with transition band
FIRImpulse(H.Size(n), [0.3,0.5], ftHighpass,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response,'Highpass with transition band: 0.3-0.5');
//Bandpass design with transition bands
FIRImpulse(H.Size(n), [0.3,0.4,0.5,0.6], ftBandpass,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response,'Bandpass with transitoin band: 0.3-0.4, 0.5-0.6');
//Bandstop design with transition bands
FIRImpulse(H.Size(n), [0.3,0.4,0.5,0.6], ftBandstop,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response,'Bandstop with transition bands: 0.3-0.4, 0.5-0.6');
//Hilbert III
FIRImpulse(H.Size(n), [0], ftHilbertIII,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response);
//Hilbert IV
Inc(n); //n must be even
FIRImpulse(H.Size(n), [0], ftHilbertIV,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response);
//Differentiator III
Dec(n); // n must be odd
FIRImpulse(H.Size(n), [0], ftDifferentiatorIII,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response);
//Differentiator IV
Inc(n); //n must be even
FIRImpulse(H.Size(n), [0], ftDifferentiatorIV,FS);
FrequencyResponse(H,nil,Response,8);
DrawIt(X,Response);
end;
Overload 2: procedure FirImpulse(const H: TVec; W: TDoubleArray; WindowParam: Double; FilterType: TFilterType; WindowType: TSignalWindowType; Gain: Double; FS: Double);
Windowed-sinc FIR impulse response of a preset length.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | H | TVec | |
| 2 | W | TDoubleArray | |
| 3 | WindowParam | Double | scalar |
| 4 | FilterType | TFilterType | |
| 5 | WindowType | TSignalWindowType | |
| 6 | Gain | Double | scalar |
| 7 | FS | Double | scalar |
Result: stored in self (calling object)
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.