FIR filters can be designed with a method called windowing. This method makes use of the relation between impulse response $h[n]$ and frequency response $H[f]$ through the Fourier transform:
$$ H[f] = \mathcal{F}\{ h[n]\} $$
In the windowing method, the following steps are applied to create FIR filter coefficients for a desired frequency response:
- 1: Define magnitude response in the frequency domain
- 2: Calculate impulse response (IR) with inverse Fourier transform
- 3: Truncate - or window - the IR
Ideal Lowpass Example¶
Frequency Response¶
The frequeny response of an ideal lowpass is defined as a boxcar window, centered at $f=0$. It is ideal, in the sense that pass-band and stop-band are perfectly flat and the slope is infinite:
$$ H[f] = \begin{cases} 1 & \text{if $|f| \leq f_c$ } \\ 0 & \text{otherwise} \end{cases} $$
The figure below shows the ideal lowpass for $f_c = 1000 \mathrm{Hz}$ at a sampling rate of $f_s = 48 \mathrm{kHz}$:
Impulse Response¶
In order to get the impulse response for the ideal filter above, we need to apply the inverse Fourier transform (IFFT). From the Fourier transform introduction we know that the Fourier transform of a boxcar window is a sinc function. This also applies to the IFFT.
Inserting $f_c$ this results in:
$$ \begin{eqnarray} \mathcal h[n] & = & {2 f_c} \frac{\sin (2 \pi n f_c)} {2 \pi n f_c}\\ & = & {\frac{1}{2 f_c} ~ \mathrm{sinc}(2 \pi n f_c)} \\ \end{eqnarray} $$
Truncation & Transform¶
The resulting impulse response $h[n]$ has $N=f_s$ samples. It can be directly applied by convolution with an input signal. However an FIR filter with the order $48000$ introduce a significant delay and a high processing cost.
To reduce the order, a window is applied in the time domain to truncate the IR. This example shows this for a boxcar window with $\hat{N}=40$ samples.
- The first plot below shows the impulse response $h[n]$ with the windowing function $w[n]$.
- The second plot shows the truncated IR $\hat{h}[n]$.
- The third plot shows the Fourier transform of $h[t]$ - this is the frequency response of our truncated filter.
Frequency Response in Detail¶
The figure below shows the frequency response of the low-pass filter obtained through the windowing method. The resulting shape can be explained as a convolution of the ideal boxcar with a sinc function - the Fourier transform of the window used to truncate the impulse response.
The previously ideal window is now affected by Gibb's phenomenon. This is the same effect that occurs when a signal is approximated through a Fourier series.
- We see an overshoot - the gain goes above $1.0$ in the pass-band.
- The pass-band ripples have a gain of 0.08.
- The stop-band ripples have a gain of 0.075.