Scientific Computing · Signal Processing
FIR Design by Windowing and the Gibbs Ripple
Why truncating an ideal impulse response produces passband ripple, how window shape trades transition width against stopband rejection, and what the design formulas predict.
An ideal lowpass filter has a frequency response that is one across the passband and zero elsewhere, with a discontinuity at the cutoff. Its impulse response is the inverse transform of that rectangle: a sinc function, $h[n] = \sin(\omega_c n)/(\pi n)$, with nonzero values extending infinitely in both directions and decaying as $1/n$. Any implementation must truncate it, and truncation is the whole difficulty of finite impulse response design. The truncated response is not an approximation in some smooth sense; it is the ideal response multiplied by a rectangle, and the multiplication introduces a specific, predictable error.
Truncation is multiplication, and multiplication is convolution
The impulse response of a finite filter is the ideal response multiplied by a window $w[n]$ that is one for $|n| \le M$ and zero outside. In the frequency domain, that multiplication becomes a convolution with the window’s own transform, which for a rectangular window is the Dirichlet kernel:
$$W(\omega) = \frac{\sin(\omega (2M+1)/2)}{\sin(\omega/2)}$$
The Dirichlet kernel is a narrow main lobe of width roughly $4\pi/(2M+1)$ surrounded by sidelobes whose peaks decay slowly, with the first sidelobe at about $-13$ dB relative to the main lobe. Convolving the ideal rectangle with this kernel rounds the discontinuity into a transition of finite width and, crucially, leaves the sidelobe structure superimposed on both the passband and the stopband.
The passband is no longer flat. Near the cutoff it oscillates around unity with peaks exceeding it, and the first overshoot is about 9 percent, the Gibbs phenomenon. The stopband is no longer zero; it oscillates around zero with peaks at roughly $-21$ dB. Both amplitudes are independent of $M$. Increasing the filter length narrows the transition band but does not reduce the overshoot, because the overshoot amplitude is a property of the kernel’s shape and only its width scales with $M$. This is the observation that makes naive truncation unsatisfactory and motivates every window in the catalogue.
import numpy as np
def lowpass_impulse(n_taps, fc, fs):
n = np.arange(n_taps)
m = n - (n_taps - 1) / 2 # symmetric about the midpoint
h = 2 * fc / fs * np.sinc(2 * fc / fs * m) # ideal lowpass, normalized sinc
return h * np.hamming(n_taps)
h = lowpass_impulse(65, 1000, 8000)
h /= h.sum() # Hamming's mean value of 0.54 would scale the DC gain
print(round(h.sum(), 12), np.allclose(h, h[::-1])) # 1.0 and True
The sinc call above uses the normalized definition $\sin(\pi x)/(\pi x)$, which is why the argument carries the $2 f_c/f_s$ factor; the convention differs between libraries and is a common source of a factor-of-two error in cutoff frequency. The explicit normalization by the coefficient sum is not cosmetic: multiplying by a window changes the DC gain, and a spectrum computed from unnormalized coefficients is off by the window’s coherent gain.
Windows are a taper, and the taper is a trade
A window multiplies the ideal response by a function that decays toward the ends instead of dropping to zero abruptly. The taper reduces the discontinuity in the time domain, which reduces the sidelobe level in the frequency domain. The cost is a wider main lobe, because the effective aperture of the window is smaller than its physical length.
The catalogue is best understood along that single axis. The rectangular window has the narrowest main lobe, about $4\pi/N$ wide between first nulls, with first sidelobes at $-13$ dB and slow rolloff at 6 dB per octave. Hann, a raised cosine, gives $-31$ dB sidelobes with a main lobe twice as wide. Hamming, a raised cosine with a nonzero pedestal, gives about $-43$ dB near sidelobes but a flat far-field floor, because the pedestal leaves a small discontinuity. Blackman, a three-term cosine, gives about $-58$ dB with a main lobe three times as wide. The Kaiser window parameterizes the whole family with a single shape parameter $\beta$, and its design formulas relate $\beta$ to the required stopband attenuation and $N$ to the required transition width.
The Kaiser estimate for the length required to meet a stopband specification $A$ in decibels with transition width $\Delta\omega$ in radians per sample is approximately $N \approx (A - 8)/(2.285 \Delta\omega)$. A 60 dB stopband with a transition occupying a tenth of the Nyquist band, so $\Delta\omega \approx 0.1\pi$, therefore needs on the order of seventy taps; the same transition with 100 dB needs about a hundred and thirty. Because the length is proportional to $A - 8$, going from 60 dB to 120 dB roughly doubles the tap count, while halving the transition width also doubles it. Attenuation and transition width cost about the same per unit of improvement, which is why specifications are usually written with the widest acceptable transition band and the lowest acceptable attenuation.
The symmetry constraint is not optional
Linear phase requires the impulse response to be symmetric, $h[n] = h[N-1-n]$ for odd length, or antisymmetric for the odd-symmetric types used in differentiators and Hilbert transformers. Symmetry is what makes the phase response exactly linear and the group delay exactly $(N-1)/2$ samples, a constant across frequency. A filter with linear phase delays every frequency component by the same amount, so it does not disperse a pulse; a filter with nonlinear phase delays different components differently, and the shape of a transient is changed even if its magnitude spectrum is preserved.
All the standard windows are symmetric, so a design built by multiplying a symmetric ideal response by a symmetric window retains linear phase. This is the main reason windowing remains in use despite its inefficiency. The alternative design methods, least-squares and equiripple, can also produce linear phase but require an optimizer and produce coefficients that are harder to predict from a formula. Parks-McClellan equiripple design, in particular, achieves the specified stopband with the fewest taps in the minimax sense, and its passband and stopband ripples are equal in the weighted sense rather than decaying with distance from the cutoff. For a fixed length, an equiripple design beats a windowed design on both metrics simultaneously; the windowed design is preferred when the coefficients must be computable analytically or when a decaying ripple profile is desirable.
Filter length, group delay, and cost
The filter’s group delay is half its length in samples. A hundred-tap linear-phase filter delays the signal by about fifty samples, which at a rate of one megahertz is fifty microseconds. That delay is constant with frequency, so it does not distort the waveform, but it does matter in a closed loop: a delay inside a feedback path reduces phase margin, and a filter placed in a control loop must be accounted for in the loop’s stability analysis.
The arithmetic cost of a direct-form FIR filter is $N$ multiply-accumulates per output sample. For long filters the cost can be reduced by exploiting symmetry, halving the multiplies by pre-adding pairs of samples, and by implementing the filter as a block convolution in the frequency domain. The latter is worthwhile when the impulse response exceeds roughly 64 taps: an overlap-save or overlap-add scheme with a radix-2 transform costs $O(\log N)$ per output rather than $O(N)$, and the crossover is determined by the transform overhead. The same transform machinery that computes a spectrum serves as a convolution engine, as What the Discrete Fourier Transform Computes describes.
The fixed-point implementation has a further concern that the design formulas ignore. The sum of $N$ products, each of magnitude up to the largest coefficient times the largest input, requires accumulator width of at least the coefficient width plus the input width plus $\log_2 N$ guard bits to avoid overflow. A hundred-tap filter with 16-bit coefficients and 16-bit data needs a 39-bit accumulator; truncating to 32 bits loses low-order bits and can produce a limit cycle in a recursive structure, though not in a direct-form FIR. Coefficient quantization is a separate issue: rounding the ideal coefficients to a fixed grid perturbs the frequency response, and the perturbation is largest for filters with a narrow transition band, where the coefficients are small and the response is sensitive to their precise values.
Applying a filter without the startup transient
A causal filter applied to a finite record has a transient at the start, because the filter’s state is initialized to zero and the output before the record is not defined. For a record of $L$ samples and a filter of length $N$, roughly $N$ output samples at the beginning are contaminated. The standard remedy is to pad the record with a reflection of its first samples, run the filter, and discard the padding; the reflection creates a smooth continuation rather than a step, so the transient is smaller, though not zero.
The transient is not the only phase problem. A single causal pass has the linear phase delay described above, which shifts features in time by half the filter length. If the application needs the output aligned with the input, the delay must be compensated by removing the first $(N-1)/2$ output samples and appending an equivalent number of samples at the end, or by using a symmetric two-pass structure. The latter is the subject of Zero-Phase Filtering by Forward-Backward Passes, and it has its own cost in effective magnitude response.
Window design also interacts with spectral analysis of the filtered result. A filter with a 60 dB stopband attenuates out-of-band content by that factor, but it does not remove the content; it reduces it to a level that may still exceed the quantization floor of the data. The residual appears at the filter’s stopband level across the whole out-of-band region, including frequencies that will later alias if the data is resampled. Filtering before decimation must therefore meet the stopband requirement at the input rate, and the transition band must fit between the passband edge and the new Nyquist frequency, which is often the binding constraint on the design.
References
- Some Windows with Very Good Sidelobe Behavior — A. H. Nuttall, IEEE Transactions on Acoustics, Speech, and Signal Processing, 1981
- Discrete-Time Signal Processing — A. V. Oppenheim and R. W. Schafer, Pearson
- On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform — F. J. Harris, Proceedings of the IEEE, vol. 66, 1978