Designing FIR Filters

Designing FIR Filters

We explore two strategies for designing an FIR filter. The first approach (the windowing method) defines the filter in the time domain. The second approach (the frequency sampling method) defines the filter in the frequency domain.

Windowing Method

The windowing method defines an FIR filter by approximating an ideal (potentially IIR) impulse response response $h_d[n]$. The ideal impulse response is then windowed by multiple it by a window function $w[n]$. Hence the resulting impulse response $$h[n] = h_d[n] w[n] \; .$$ with a DTFT defined by $$H(\omega) = H_d(\omega) \circledast W(\omega) \; ,$$ where $\circledast$ represents a circular convolution operation.

Note that we want our resulting filter to be casual. As a result, the window function $w[n]$ must be causal. In addition, we may need to shift the ideal frequency response $h_d[n]$ if it is acausal. If the impulse response is symmetric around zero, we would shift $h_d[n]$ so that it is symmetric around the center of the window $w[n]$. If $h_d[n]$ is already causal, no shift is necessary.

Example

Consider the ideal, desired DTFT frequency response $$H_d(\omega) = \frac{1}{1-(1/2)e^{-j\omega}} \; .$$ Use the windowing method (with a length $N=3$ rectangular window) to approximate the FIR filter coefficients $h[n]$ for a filter with frequency response $H_d(\omega)$.

Given the desired frequency response, the desired impulse response is $$h_d[n] = (1/2)^n u[n] \; .$$ The length $N=3$ rectangular window is defined by $$w[n] = u[n] - u[n-3]$$ Therefore, the estimated impulse response is $$h[n] = (1/2)^n u[n] (u[n] - u[n-3]) \; .$$ This can be written out a sum of impulses, $$h[n] = \delta[n] + (1/2) \delta[n-1] + (1/4) \delta[n-2] \; .$$ Therefore, the corresponding frequency response is $$H(\omega) = 1 + (1/2) e^{-j \omega} + (1/4) e^{-j 2 \omega} \; .$$ The figures below illustrate the differences between the ideal / desired filter and the approximate FIR filter. In the magnitude and phase response, the blue curve represents the desired response and the red curve represents the approximate response.

Frequency Sampling Method

The frequency sampling method defines an FIR filter by approximating an ideal / desired (potentially IIR) frequency magnitude response $|H_d(\omega)|$. The ideal frequency magnitude response is uniformly sampled with $N$ values, where $N$ is the desired length of the FIR filter. The resulting magnitude response is defined by $|H[k]|$.

The FIR filter coefficients can then be determined by computing the inverse discrete Fourier trasnform (DFT) of the sampled frequency components. However, to ensure that the resulting filter is both linear phase and causal, we make adjustments to the inverse DFT. Specifically, we define the filter coefficients according to: $$h[n] = \frac{1}{N} \left[ H[0] + 2 \sum_{k=1}^{(N-1)/2} (-1)^k H[k] \cos\left( \frac{2\pi}{N} \left( n + \frac{1}{2} \right) k \right) \right]$$ This will yield a result that is always symmetric around $(N-1)/2$.

Example

Consider the ideal, desired DTFT frequency magnitude response $$H_d(\omega) = |H_d(\omega)| = \left| \frac{1}{1-(1/2)e^{-j\omega}} \right| \; .$$ Use the frequency sampling method (with a length $N=5$ rectangular window) to approximate the FIR, linear phase filter coefficients $h[n]$ for a filter with frequency response $H_d(\omega)$.

Given the desired frequency response, the frequency sampled version is defined by $$ H[k] \approx 2 \delta[k] + (1.031)\delta[k-1] + (0.697)\delta[k-2] + (0.697)\delta[k-3] + (1.031)\delta[k-4] \;. $$ Plugging these values into the equation aboves yields the causal, linear phase impulse response defined by $$ h[n] \approx (0.153)\delta[n] + (0.302)\delta[n-1] + (1.091)\delta[n-2] + (0.302)\delta[n-3] + (0.153)\delta[n-4] $$ The figures below illustrate the differences between the ideal / desired filter and the approximate FIR filter. In the magnitude and phase response, the blue curve represents the desired response and the red curve represents the approximate response.