- Principle
- Mathematical description
- Digitization considerations
- MATLAB
^{TM}implementation - C implementation considerations
- Conclusion

FIR bandpass filter

The method is to make an ideal filter in the frequency domain, and then translate it into the discrete time domain. However this will give an infinite impulse response. To compensate for this, a window function is multiplied onto the ideal impulse response.

In this appendix a rectangular window is chosen. This is done for simplicity as the window amplitude is either 1 or 0. In FIR filter design the order for the filter is denoted and it determines the length of the window. The type of FIR filter used here utilizes linear phase i.e. constant group delay.

An example of a FIR bandpass filter is shown in figure M.1. The filter has a center frequency ( ) of and a bandwith of 2 kHz. The order ( ) is 20.

Corresponding to the discrete-time notation of

with as the approximated impulse response of the filter, and with as the windowing function

(M.3) |

The product of (M.2) is in the frequency domain equal to the convolution

(M.4) |

Utilizing equation (7.52) with
and (5.146b) from [Oppenheim & Schafer, 1998, p. 472 and p. 297 respectively] with the amplitude function set to 1,
can be written as

(M.5) |

Transforming
to the time domain yields (by use of Euler rewriting)

Multiplying
with the window
in the time domain, to achieve the definition of
, and transforming to the Z-domain yields

(M.9) | |||

(M.10) |

due to the magnitude of being 1 in and zero otherwise. This is an approximation of the ideal bandpass filter of equation (M.1) and figure jtkr04:fig:fir02.

Using the basic attribute of
and transforming back to the time domain, will yield the filter output

(M.11) |

The above can be readily implemented in an algorithm, with the value of describing the order of the filter. The values of are reusable for each , calculated from the expression in (M.8).

- the sample rate ( ), in Hz.
- the center frequency of the passband ( ), in Hz.
- the passband width ( ), in Hz.
- the order of the filter ( ), must be an even number.
- the data to be processed ( ).

- Done once:
- Assign memory for coefficients ( ).
- Loop from 0 to , decide filter coefficients. One exception is , where L'Hospitals' rule must be used.
- Determine factor for gain adjustment.

- Done for each data chunk:
- Assign memory for output
- Handle first samples
- Loop for each sample(i):
- Loop for n = 0 to , summing coefficients .
- Adjust gain
- Move to output

The system datatype used for handling soundcard samples is set to integers, while the internal workings of the filter relies on float values. The solution is to use float values internally, and export values rounded to integers.

As C contains no built in ``length'' command, the length of the supplied samples must be specified. Furthermore, the data to be processed is supplied in chunks. This results in problems as the filter uses samples from the past. When crossing the boundary between chunks this must be addressed.

Jes Toft Kristensen 2005-12-13