Prev Next linfir

Linear-phase FIR Filter Design
Syntax y = linfir(f1,f2,fs,Ntaps,filttype)
Syntax y = linfir(f1,f2,fs,Ntaps,filttype,wintype)
Syntax y = linfir(f1,f2,fs,Ntaps,filttype,wintype,winparam)
Include: include spt\linfir.oms
See Also pwlfir , pbfir , hilbert , rcfir , srrcfir

      f1       = INPUT, scalar, any numerical type. Represents
                 cutoff frequency in [Hz] for LOWPASS, HIGHPASS,
                 or, lower corner frequency in [Hz] for BANDPASS
                 and BANDSTOP types. 0<f1<f2<(fs/2). Coerced to
      f2       = INPUT, scalar, any numerical type. Represents
                 upper corner frequency in [Hz] for BANDPASS,
                 BANDSTOP types. 0<f1<f2<(fs/2). Coerced to DOUBLE.
      fs       = INPUT, scalar, any numerical type. Represents
                 sampling rate in [Samples/second]. Coerced to
      Ntaps    = INPUT, scalar, any numerical type. Filter
                 length in [taps]. Coerced to INTEGER.
      filttype = INPUT, CHAR. One of ["LOWPASS"|"HIGHPASS"|
      wintype  = INPUT, string. One of ["RECTANGULAR"|
      winparam = INPUT, scalar, any numerical type. Parameter
                 used by GAUSSIAN or KAISER window functions.
                 Coerced to DOUBLE.
   RETURN: Returns DOUBLE column vector representing FIR
           filter taps. If an error, returns value=0, and
           prints error message.


Linear-phase FIR filter design (per Stearns & David).

Creates a linear phase, windowed FIR filter of length 'Ntaps'. Function returns a column vector of type DOUBLE. 'Ntaps' may be of any numerical type and is coerced to INTEGER before local processing. 'Ntaps' must be >=3 or novalue is returned.

Filter cutoff frequencies are set with parameters 'f1', f2', and 'fs' all with dimension [Hz] (or, cycles per second). 'f1' specifies the cutoff frequency for LOWPASS and HIGHPASS filters, as well as the lower cutoff frequency for BANDPASS and BANDSTOP filters. 'f2' is only used for BANDPASS and BANDSTOP filters and specifies the upper cutoff frequency for those types. Parameter 'fs' is the system sampling frequency in [Samples/Second]. Both 'f1 and 'f2' must be strictly less than fs/2, and, f1<f2, or novalue is returned for the function. All three must be strictly positive or novalue is returned. All are coerced to DOUBLE before internal processing.

Filter types are specified by string parameter 'filttype' and may be one of :"LOWPASS", "HIGHPASS", "BANDPASS", or, "BANDSTOP". Case insensitive.

A window function may be applied to the resulting FIR filter. 'wintype' is a string specifying the window type to be applied. 'winparam' is the numerical parameter used with the GAUSSIAN and KAISER window functions. If you leave off 'wintype' and 'winparam', a "RECTANGULAR" window is assumed. For windows other than "GAUSSIAN" and "KAISER", 'winparam' may be omitted. Error handling is done by 'winddata()' function.

Create examples of all four possible filter with linfir().

Ntaps   = 63               # Number of taps
fs      = 10000d0          # Sampling rate [Samples/second]
f1      =  1500d0          # LOWPASS or HIGHPASS cutoff freq [Hz]
f2      =  3500d0          # Upper corner for BANDPASS or BANDSTOP [Hz]
wintype = "rectangular"    # Window function

hlp = linfir(f1, f2, fs, Ntaps, "LOWPASS",  wintype )
hhp = linfir(f1, f2, fs, Ntaps, "HIGHPASS", wintype )
hbp = linfir(f1, f2, fs, Ntaps, "BANDPASS", wintype )
hbs = linfir(f1, f2, fs, Ntaps, "BANDSTOP", wintype )

Plots of the resulting impulse and frequency responses are shown below.


Stearns & David