Design of FIR filters

Designs linear-phase FIR filters by the window method, covering the four linear-phase types, window trade-offs, length estimation from a specification, and FIR versus IIR.

Drafted with Aria, reviewed by the AiCanCode.org team. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

FIR filters are the default choice for cleaning up sampled sensor data — removing mains hum, band-limiting before decimation, smoothing ECG or vibration records — because they are always stable and can have exactly linear phase, so pulse shapes are not distorted. Designing one means choosing a length and coefficients that meet a passband/stopband specification at an acceptable computing cost.

Key ideas

Structure. An FIR filter of length N (order N − 1) computes y[n] = Σ from k=0 to N−1 of h[k] x[n − k]. Its impulse response is the coefficient list, it has no feedback, all its poles are at z = 0, and it is therefore always stable.

Linear phase. If the coefficients are symmetric, h[n] = h[N − 1 − n], or antisymmetric, h[n] = −h[N − 1 − n], the phase is linear: every frequency is delayed by the same (N − 1)/2 samples, so the waveform shape in the passband is preserved.

  • Type I: symmetric, N odd — any filter type (low-, high-, band-pass, band-stop).
  • Type II: symmetric, N even — H(e^(jπ)) = 0, so no high-pass or band-stop.
  • Type III: antisymmetric, N odd — zeros at ω = 0 and π; differentiators and Hilbert transformers only (band-pass).
  • Type IV: antisymmetric, N even — zero at ω = 0; high-pass, differentiators.
  • Zeros of a linear-phase filter occur in reciprocal pairs (z0 and 1/z0).

Window method

  1. Specify the ideal response, e.g. a low-pass with cut-off ωc (rad/sample).
  2. Its impulse response hd[n] = sin(ωc n)/(πn) is infinitely long and non-causal.
  3. Truncate to N samples centred on n = 0 by multiplying by a window w[n], then delay by (N − 1)/2 to make it causal: h[n] = hd[n − (N − 1)/2]·w[n].
  • Truncation causes ripples near the band edge (Gibbs phenomenon). With a rectangular window, the peak ripple stays fixed (about 9 %, giving only ~21 dB stopband attenuation) however large N is; increasing N only narrows the transition band.
  • Tapered windows lower the sidelobes (more attenuation) at the cost of a wider transition band for the same N. The window chooses the attenuation; N chooses the transition width.

Typical window figures (approximate, as tabulated in most DSP textbooks — use your course's table):

  • Rectangular: main-lobe width 4π/N, minimum stopband attenuation ≈ 21 dB, transition ≈ 1.8π/N.
  • Hann (Hanning): 8π/N, ≈ 44 dB, ≈ 6.2π/N.
  • Hamming: 8π/N, ≈ 53 dB, ≈ 6.6π/N.
  • Blackman: 12π/N, ≈ 74 dB, ≈ 11π/N.
  • Kaiser: adjustable through its parameter β.

Other methods. Frequency sampling (specify H at N equally spaced frequencies and take the IDFT) and optimal equiripple design (Parks–McClellan), which gives the shortest filter for a given specification.

FIR versus IIR. FIR: always stable, exact linear phase possible, robust to coefficient quantisation, but needs many more coefficients (and delay) for a sharp transition. IIR: few coefficients, sharp transitions, but non-linear phase and stability must be checked.

Formulas

  • y[n] = Σ h[k] x[n − k] — FIR output.
  • hd[n] = sin(ωc n)/(πn), hd[0] = ωc/π — ideal low-pass impulse response.
  • h[n] = hd[n − (N − 1)/2] · w[n], n = 0 … N − 1 — windowed, causal design.
  • w[n] = 0.54 − 0.46 cos(2πn/(N − 1)) — Hamming window; 0.5 − 0.5 cos(2πn/(N − 1)) — Hann.
  • τg = (N − 1)/2 samples — group delay of a linear-phase FIR.
  • ωc = (ωp + ωs)/2 — cut-off used for the ideal response.
  • N ≈ (constant × π)/Δω, e.g. N ≈ 6.6π/Δω for Hamming — length from transition width.
  • ω = 2πf/fs — digital frequency.
  • H(e^(j0)) = Σ h[n] (DC gain); H(e^(jπ)) = Σ (−1)ⁿ h[n].

Symbols: N filter length (taps); h[n] coefficients (dimensionless); ωc, ωp, ωs cut-off, passband and stopband edges (rad/sample); Δω = ωs − ωp (rad/sample); f, fs (Hz); τg group delay (samples).

Worked examples

Example 1 (standard). Design a 7-tap low-pass FIR with ωc = π/2 using (a) a rectangular and (b) a Hamming window. Compare the DC gains.

  1. Ideal response: hd[n] = sin(πn/2)/(πn), hd[0] = 0.5. For n = ±1, ±2, ±3: 0.3183, 0, −0.1061.
  2. (a) Rectangular, delayed by 3: h = {−0.1061, 0, 0.3183, 0.5, 0.3183, 0, −0.1061} (symmetric ⇒ Type I, linear phase, delay 3 samples).
  3. DC gain = Σ h = 0.924; at ω = π: |Σ(−1)ⁿ h[n]| = 0.076.
  4. (b) Hamming for N = 7: w = {0.08, 0.31, 0.77, 1, 0.77, 0.31, 0.08}.
  5. h = {−0.0085, 0, 0.2451, 0.5, 0.2451, 0, −0.0085}; DC gain = 0.973, gain at ω = π = 0.027.
  6. Rectangular: DC gain 0.924, |H(e^(jπ))| = 0.076; Hamming: 0.973 and 0.027 — the window reduces ripple and improves attenuation, at the cost of a wider transition.

Example 2 (GATE level). A DAQ system samples at 8 kHz. Required: passband to 1 kHz, stopband from 1.5 kHz with at least 50 dB attenuation. Choose a window, the length, the cut-off and the delay.

  1. 50 dB needs a window with at least that attenuation: Hamming (≈ 53 dB) suffices; Hann (≈ 44 dB) does not.
  2. Transition width Δf = 1.5 − 1 = 0.5 kHz ⇒ Δω = 2π × 0.5/8 = 0.125π rad/sample.
  3. N ≈ 6.6π/Δω = 6.6/0.125 = 52.8 ⇒ take the next odd value, N = 53 (Type I).
  4. Cut-off ωc = 2π × 1.25/8 = 0.3125π rad/sample.
  5. Delay = (53 − 1)/2 = 26 samples = 26/8000 s = 3.25 ms.
  6. Hamming window, N = 53 taps, ωc = 0.3125π, delay 3.25 ms.

Common mistakes

  • Forgetting to shift hd[n] by (N − 1)/2 — the filter is then non-causal.
  • Expecting a longer rectangular window to remove the Gibbs overshoot. Only a different window lowers the ripple.
  • Using a Type II (even-length symmetric) filter for a high-pass design — it has a forced zero at ω = π.
  • Confusing "normalised frequency" conventions: f/fs, f/(fs/2) and ω = 2πf/fs all appear. State which you use.
  • Taking the cut-off at the passband edge instead of mid-transition.
  • Ignoring the delay: a 53-tap filter adds 26 samples of latency, which matters inside a control loop.

For GATE IN

Expect: identifying linear-phase types from coefficient symmetry and length, computing group delay, writing windowed coefficients for a small N, estimating N from a transition width and window table, choosing a window for a given attenuation, and comparing FIR with IIR. Practise hd[n] values for ωc = π/2, π/4 and DC/π gains as quick checks.

Quick check

  1. Group delay of a 31-tap linear-phase FIR?
  2. Which linear-phase type cannot realise a high-pass filter because H(e^(jπ)) = 0?
  3. hd[0] for an ideal low-pass with ωc = 0.3π?
  4. Does increasing N reduce the peak ripple with a rectangular window?
  5. Where are the poles of an FIR filter? Answers: 1. 15 samples. 2. Type II (symmetric, even length). 3. 0.3. 4. No — it only narrows the transition. 5. All at z = 0.

Try answering each one aloud before you open it.

  1. 1.What is an FIR filter and how does it differ from an IIR filter?Concept

    An FIR filter computes each output as a weighted sum of a finite number of present and past inputs, so its impulse response has finite length and it has no feedback. It is therefore always stable, and with symmetric or antisymmetric coefficients it has exactly linear phase. An IIR filter feeds back past outputs, so its impulse response never ends; it meets a sharp specification with far fewer coefficients but generally has non-linear phase and its stability must be checked.

  2. 2.Explain the concept of linear phase in FIR filters.Concept

    Linear phase in FIR filters means that the phase response of the filter is a linear function of frequency. This property ensures that all frequency components of the input signal are delayed by the same amount of time, preserving the wave shape of the signal. Linear phase is particularly important in applications like data communications and audio processing, where phase distortion can lead to signal degradation.

  3. 3.Why are window functions used in the design of FIR filters?Application

    Window functions are used in the design of FIR filters to control the trade-off between the main lobe width and the side lobe levels in the frequency response. By applying a window function to the ideal impulse response, we can reduce the side lobes, which decreases the ripple in the passband and stopband. Different window functions, such as Hamming, Hanning, and Blackman, offer different trade-offs between main lobe width and side lobe attenuation.

  4. 4.What happens if you increase the order of an FIR filter?Application

    Increasing the order of an FIR filter generally improves its ability to approximate the desired frequency response. A higher-order filter can have a sharper transition between the passband and stopband, and it can achieve better attenuation of unwanted frequencies. However, increasing the order also increases the computational complexity and the delay introduced by the filter, which may not be desirable in real-time applications.

  5. 5.How does the choice of window function affect the performance of an FIR filter?Application

    The choice of window function affects the trade-off between the width of the main lobe and the level of the side lobes in the frequency response of an FIR filter. For example, a Hamming window provides moderate side lobe attenuation and a relatively narrow main lobe, while a Blackman window offers higher side lobe attenuation at the cost of a wider main lobe. The choice depends on the specific requirements of the application, such as the need for sharp transitions or minimal ripple.

  6. 6.Explain the process of designing an FIR filter using the window method.Concept

    Designing an FIR filter using the window method involves several steps: 1) Define the desired frequency response of the filter. 2) Calculate the ideal impulse response by taking the inverse Fourier transform of the desired frequency response. 3) Choose an appropriate window function based on the application's requirements. 4) Multiply the ideal impulse response by the window function to obtain the final FIR filter coefficients. This process helps in controlling the trade-offs between main lobe width and side lobe levels.

  7. 7.What is the effect of using a rectangular window in FIR filter design?Application

    Using a rectangular window in FIR filter design results in a filter with a narrow main lobe but relatively high side lobes. This can lead to significant ripple in the passband and stopband, which may not be acceptable for applications requiring high precision. The rectangular window is the simplest window function, but it often requires a higher filter order to achieve the same level of performance as other window functions with better side lobe attenuation.

  8. 8.Estimate the number of coefficients needed for an FIR filter with a transition band of 0.1π rad/sample using a Hamming window.Numerical

    For the Hamming window the transition width is about 6.6π/N (textbook value), so N ≈ 6.6π/Δω = 6.6π/(0.1π) = 66. For a Type I linear-phase low-pass you would take the next odd length, N = 67, which gives about 53 dB stopband attenuation and a delay of 33 samples.

  9. 9.Design an 11-tap low-pass FIR filter with cut-off 0.25π rad/sample using a rectangular window. Give the coefficients.Numerical

    The ideal impulse response is hd[n] = sin(0.25πn)/(πn) with hd[0] = 0.25. For n = 0 to 5 this gives 0.25, 0.2251, 0.1592, 0.0750, 0 and −0.0450, symmetric for negative n. Shifting by 5 for causality: h = {−0.0450, 0, 0.0750, 0.1592, 0.2251, 0.25, 0.2251, 0.1592, 0.0750, 0, −0.0450}. It is a Type I linear-phase filter with a 5-sample delay; a rectangular window leaves about 9% Gibbs ripple, so a Hamming window would be used for better stopband attenuation.

  10. 10.What are the advantages and disadvantages of using FIR filters in digital signal processing?Application

    Advantages of FIR filters include inherent stability, linear phase response, and ease of implementation using fast algorithms like the FFT. They are also less sensitive to quantization errors compared to IIR filters. However, FIR filters typically require a higher order than IIR filters to achieve the same level of performance, which can lead to increased computational complexity and delay. This makes them less suitable for applications where real-time processing is critical and resources are limited.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?