electronics engineering
Course handbook · Fifth year
Digital Signal Processing
Digital signal processing: sampling, DFT and FFT, the Z transform, digital filter design and MATLAB exercises.
- 8Topics
- 0Solved exercises
- 29Formula sheet
Free handbook generated from the lessons of the site and updated often, every time a lesson or an exercise changes: the latest version is always at www.electronics-engineering.com/handbook/numerical-elaboration-of-signals. Links work in the PDF too.
1The DTFT and frequency response
Digital signal processing treats signals as sequences of numbers and transforms them with algorithms: filters, spectral analysis, sample-rate changes. The basis of everything is the frequency-domain description of discrete-time signals and systems. In this lesson we look at the discrete-time Fourier transform (DTFT), the proof that complex exponentials are eigenfunctions of linear systems, the frequency response of the moving average with its proof, and group delay with linear phase. Sampling, convolution and basic FIR and IIR filters are in the Signal Theory lessons; the z-transform and the DFT have lessons of their own.
The discrete-time Fourier transform
For a sequence
, the DTFT is
![Rendered by QuickLaTeX.com \[ X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n},\qquad x[n] = \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\omega})\,e^{j\omega n}\,d\omega \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-7198b0eb58f852edd369c75350e78208_l3.png)
The variable
is the normalised angular frequency, in radians per sample: a signal sampled at
with frequency
has
. The DTFT is periodic with period
, because
for every integer
: all the information lies in
, and
corresponds to half the sampling frequency. It is the z-transform evaluated on the unit circle,
.
The properties are those of the continuous Fourier transform: convolution becomes product, a delay of
samples multiplies by
, and Parseval’s theorem holds,
.
The frequency response
Theorem. If a linear time-invariant system with impulse response
receives the input
, the output is
![]()
Proof. By the convolution sum
![]()
∎
A complex exponential goes through the system remaining itself, multiplied by a complex number: it is an eigenfunction. The magnitude
says how much each frequency is amplified, the phase
how much it is shifted. For a real sinusoid, the sum of two conjugate exponentials, the output is the same sinusoid with amplitude multiplied by
and phase shifted by
.
The moving average
The simplest filter averages the last
samples:
.
Theorem. The frequency response of the moving average is
![]()
Proof. It is a geometric series with ratio
:
![Rendered by QuickLaTeX.com \[ H = \frac{1}{M}\sum_{k=0}^{M-1}e^{-j\omega k} = \frac{1}{M}\cdot\frac{1 - e^{-j\omega M}}{1 - e^{-j\omega}} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-bd701883f487a41415e94d9f89aa9f83_l3.png)
Factor
out of the numerator and
out of the denominator:
, and likewise the denominator. The ratio of the exponentials gives
and the ratio of the sines the rest. ∎

The gain is 1 at DC and vanishes for
: the moving average exactly cancels sinusoids that complete an integer number of periods in
samples. It is the same principle as mains rejection in integrating voltmeters (Electrical Measurements lesson on the digital voltmeter). As a low-pass filter, though, it is modest: the side lobes are high, the first around 22 % (−13 dB).
Linear phase and group delay
The phase of the moving average is
, a straight line: all frequencies are delayed by the same number of samples,
. In general the group delay is defined as
![]()
which measures the delay of the envelope of a narrowband signal around
. If the phase is linear,
is constant and the waveform passes without phase distortion, only delayed (Signal Theory lesson on distortionless transmission). It is a valuable property for audio, images and digital communications, where phase distortion deforms pulses and creates intersymbol interference. In the next lesson we will see that FIR filters with symmetric coefficients always have linear phase, while IIR filters in general do not.
A note on computation
The DTFT is a continuous function of
and cannot be computed as such. Samples of it are computed with the DFT, which for an
-point sequence gives
at the
frequencies
, and it is computed quickly with the FFT (lesson on the DFT and FFT). To plot a frequency response it is therefore enough to compute the FFT of the impulse response, padded with zeros to get denser points.
2FIR design with windows
The most direct way to design an FIR filter is to start from the ideal filter, compute its impulse response and shorten it. This is the window method: simple, robust and still widely used. In this lesson we derive the impulse response of the ideal low-pass filter, see why truncation creates Gibbs oscillations, compare the classic windows and the Kaiser window with its design formulas, and prove that an FIR filter with symmetric coefficients has linear phase.
The ideal low-pass filter
The ideal low-pass filter has gain 1 for
and 0 elsewhere, in the period
.
Theorem. Its impulse response is
![]()
Proof. With the inverse DTFT formula:
![Rendered by QuickLaTeX.com \[ h_d[n] = \frac{1}{2\pi}\int_{-\omega_c}^{\omega_c}e^{j\omega n}\,d\omega = \frac{1}{2\pi}\cdot\frac{e^{j\omega_c n} - e^{-j\omega_c n}}{jn} = \frac{\sin(\omega_c n)}{\pi n} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-efc698e8ff9546e2c285ba67c234ef58_l3.png)
and for
the integral is simply
. ∎
This response is infinite in both directions and non-causal: no real filter can implement it. So only
central samples are kept and everything is delayed by
, making the filter causal:
, where
is the window, zero outside
.
The Gibbs phenomenon
Multiplying by the window in time means convolving the ideal response with the window’s transform in frequency. For the rectangular window this transform is the kernel of the previous lesson, with a main lobe
wide and high side lobes. The convolution has two effects:
- a transition band roughly as wide as the main lobe, which narrows as
increases; - ripples in the passband and stopband, due to the side lobes. The highest is about 9 % of the jump, and it does not decrease as
grows: the ripples become denser but not smaller. This is the Gibbs phenomenon, the same as for truncated Fourier series.
For a filter with the rectangular window the maximum stopband attenuation therefore stays around 21 dB, whatever the length: too little for almost every application.
Windows
The solution is to use windows that taper smoothly to zero at the edges: the side lobes of their transform are much lower, at the price of a wider main lobe, i.e. a slower transition for the same
.
| Window | Main lobe width | Highest side lobe | Filter attenuation |
|---|---|---|---|
| rectangular | −13 dB | 21 dB | |
| Hann | −31 dB | 44 dB | |
| Hamming | −41 dB | 53 dB | |
| Blackman | −57 dB | 74 dB |
The Hamming window, for example, is
.

The Kaiser window
Fixed windows force a choice from a table. The Kaiser window has a parameter
that continuously adjusts the trade-off between main-lobe width and side-lobe height, and empirical design formulas. Given the required attenuation
in decibels (with
the tolerance, the same in passband and stopband) and the transition width
:
![Rendered by QuickLaTeX.com \[ \beta = \begin{cases} 0.1102\,(A - 8.7) & A \gt 50 \\ 0.5842\,(A - 21)^{0.4} + 0.07886\,(A - 21) & 21 \le A \le 50 \end{cases},\qquad N \approx \frac{A - 8}{2.285\,\Delta\omega} + 1 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-4d4ecf6e8a3acb5e5f97d88ed196501a_l3.png)
Example. Passband up to
, stopband from
with 50 dB. Then
and
taps. With the Hamming window, which guarantees the 50 dB, one would need
, i.e. about 67 taps: the Kaiser window saves a quarter. The cutoff is placed in the middle of the transition,
.
Linear phase
Theorem. If the coefficients of a length-
FIR filter are symmetric,
, then
![]()
with
real: the phase is linear and the group delay is
samples.
Proof. Let
be the centre. Factor out
:
. In the sum, the terms
and
have the same coefficient and opposite exponents,
, so together they give
, which is real. If
is odd the central term
remains, also real. So the sum is a real number
. ∎
can change sign, and then the phase jumps by
: it is still piecewise linear, and the group delay is constant. A filter designed with windows is symmetric by construction (the centred ideal response and the windows are even), so it always has linear phase. This is the main advantage of FIR filters over IIR ones, together with guaranteed stability: an FIR filter has no poles away from the origin.
3Optimal FIR filters
The window method is simple but wastes taps: the error is concentrated near the transition and elsewhere the filter does much better than needed. Optimal filters spread the error evenly and meet the same specifications with fewer taps. In this lesson we look at how specifications are written, the minimax criterion and the alternation theorem, order estimation, the four types of linear-phase FIR filters with the proof of their constraints, and the structure of the zeros.
Specifications
A real filter is specified with a tolerance mask: in the passband (
) the gain must lie between
and
; in the stopband (
) it must stay below
; in the transition band between the two nothing is required. In decibels, the passband ripple is
and the attenuation
.

The minimax criterion
For a symmetric FIR filter the response is
, with
a sum of cosines, i.e. a trigonometric polynomial in the coefficients (lesson on windows). Optimal design looks for the coefficients that minimise the maximum of the weighted error
![]()
over the specified bands, where
is the desired response (1 or 0) and the weight
is
in the passband and
in the stopband, so that both tolerances are met together.
The key result is the alternation theorem (Chebyshev): if
is a combination of
cosines, the minimax solution is unique, and it is characterised by the error reaching its maximum value, with alternating signs, at at least
frequencies. The optimal error is therefore equiripple: all the peaks have the same height. The Parks-McClellan algorithm, based on the Remez exchange, searches for exactly these alternation frequencies iteratively, and converges in a few iterations. It is the standard function of filter design programs.
Order estimation
For an equiripple low-pass filter a good empirical estimate of the length is
![Rendered by QuickLaTeX.com \[ N \approx \frac{-20\log_{10}\sqrt{\delta_p\delta_s} - 13}{14.6\,\Delta f} + 1,\qquad \Delta f = \frac{\omega_s - \omega_p}{2\pi} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-2146df5f1ea0479c417f7d8467453691_l3.png)
Example. With the specifications of the previous lesson (transition from
to
, so
),
(50 dB) and
:
, and
taps, against 50 for the Kaiser window. The gain is greater the more the tolerances of the two bands differ, because the window treats them as equal.
The length grows as
: halving the transition band doubles the taps, i.e. the multiplications per sample. It is the main price of FIR filters.
The four types of linear-phase FIR filters
The coefficients can be symmetric or antisymmetric (
), and the length even or odd. Four types arise, with different constraints.
Theorem. A symmetric FIR filter of even length (type II) always has
; an antisymmetric FIR filter (types III and IV) always has
, and if its length is odd (type III) also
.
Proof. *Type II.* From the lesson on windows
with
. If
is even,
is a half-integer and
is always an odd half-integer: at
every cosine is
. *Antisymmetric.* At
,
, and the terms
and
cancel in pairs (the central one, if present, is zero because it equals its own opposite). *Type III.* With
odd,
is an integer, the sum becomes
up to a factor
, and at
every sine is
. ∎
The practical consequences: a high-pass filter cannot be made with type II, which is forced to vanish at
; types III and IV, which vanish at DC, are suited to differentiators and Hilbert transformers, which shift all frequencies by 90°.
The zeros of a linear-phase FIR filter
The symmetry of the coefficients also shows in the
plane:
. So if
is a zero, so is
; and, since the coefficients are real, so are the conjugates. Zeros come in quadruples
, or in pairs if they lie on the unit circle or on the real axis. The zeros on the unit circle are the ones that create the dips in the stopband.
Beyond linear phase
If linear phase is not needed, a minimum-phase FIR filter with all its zeros inside the unit circle can be obtained by reflecting the outer ones: it has the same magnitude and a much shorter delay, useful in real-time systems and in control. There is also the frequency sampling method, which fixes the values of the response on a grid of frequencies, and least-squares methods, which minimise the energy of the error instead of its maximum: the ripples are not uniform but the average error is smaller.
4IIR filters and the bilinear transform
IIR filters have an infinite impulse response because they use feedback: the output also depends on past outputs. With few coefficients they achieve very steep transitions, but they give up linear phase and must be made stable. The classic way to design them is to start from an analogue prototype, one of the filters studied for decades for circuits, and transform it. In this lesson we look at the Butterworth filter with the order formula proved, the bilinear transform with the proof of its properties, frequency prewarping, impulse invariance and a complete numerical example.
Analogue prototypes
The Butterworth filter of order
has
![]()
It is maximally flat: at
the first
derivatives of the squared magnitude are zero, and the gain falls monotonically. At
it is
dB, and beyond it falls by
dB per decade. The poles lie on a semicircle of radius
in the left half-plane.
Theorem. To have at most
dB of attenuation up to
and at least
dB from
, the Butterworth order must be
![Rendered by QuickLaTeX.com \[ N \ge \frac{\log_{10}\left[(10^{A_s/10} - 1)/(10^{A_p/10} - 1)\right]}{2\log_{10}(\Omega_s/\Omega_p)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9e72721994f9cef85ce3d6b9b37366f7_l3.png)
Proof. The attenuation in dB is
. The two conditions give
and
. Dividing the second by the first,
disappears:
, and taking logarithms gives the formula. ∎
The Chebyshev type I filter accepts ripple in the passband, type II in the stopband, and the elliptic (or Cauer) filter in both: for the same order it has the steepest possible transition, but the most irregular phase.
The bilinear transform
To go from the analogue filter
to the digital one, substitute
![]()
where
is the sampling period. It is the trapezoidal rule applied to the integrator
, and it turns a rational function into another rational function of the same order.
Theorem. The bilinear transform maps the imaginary axis
onto the unit circle, with
![]()
and the left half-plane inside the unit circle. So a stable analogue filter becomes a stable digital filter.
Proof. Inverting the formula,
. For
numerator and denominator are complex conjugates,
, so
and
with
. For
the point
is closer to
than to
, so
and
: the poles end up inside the circle. ∎

There is no aliasing, because the whole
axis from 0 to infinity is “squeezed” into the interval from 0 to
. The price is frequency warping: the relation is not linear, and the characteristic frequencies of the prototype end up in the wrong place.
Prewarping
The remedy is to design the analogue prototype with prewarped frequencies: to get a digital cutoff at
, use
. The critical frequencies then fall exactly where they are needed; the shape of the response between one critical frequency and the next is slightly distorted, but for piecewise-constant filters (low-pass, high-pass, band-pass) it does not matter.
A complete example
We want a second-order Butterworth filter with digital cutoff
(for instance 1 kHz with 10 kHz sampling). With
prewarping gives
, and the prototype is
. Applying the substitution and setting
, with
:
![]()
The DC gain (
) is
, as it must be, and the gain at
(
) is zero, because the numerator
vanishes: the bilinear transform maps the prototype’s zero at infinity exactly to the Nyquist frequency. The poles have magnitude
: well inside the circle.
Impulse invariance
An alternative method samples the prototype’s impulse response:
. It preserves the shape of the time response and the linear relation between frequencies, but the digital frequency response is the sum of copies of the analogue one, so there is aliasing: it works well only for low-pass and band-pass filters strongly attenuated before the Nyquist frequency, and it is not used for high-pass filters.
FIR or IIR?
IIR filters reach steep transitions with a much lower order, hence fewer multiplications and less delay: they are the natural choice when phase does not matter, as in many audio filters, equalisers and control loops. FIR filters have exact linear phase, are always stable and tolerate finite precision better: they are preferred in digital communications, imaging and multirate systems. IIR filters are almost always implemented as a cascade of second-order sections, like the one in the example (lesson on structures).
5Filter structures and finite precision
Once the coefficients are computed, the filter must be implemented: in a DSP, a microcontroller, an FPGA. Mathematically all structures are equivalent, but with finite-precision numbers they behave very differently. In this lesson we look at the direct forms and the second-order section, the sensitivity of poles to coefficients with its proof, fixed-point arithmetic, round-off noise with the proof of its power formula, and limit cycles.
The direct forms
An IIR filter
corresponds to the difference equation
![Rendered by QuickLaTeX.com \[ y[n] = \sum_{k=0}^{M} b_k\,x[n-k] - \sum_{k=1}^{N} a_k\,y[n-k] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-07ef534769bf9ad2904ad47455250011_l3.png)
Direct form I implements it as it stands, with two delay lines, one for inputs and one for outputs. Direct form II swaps the order of the two parts (the system is linear, order does not matter) and shares a single delay line: it uses the minimum number of memory cells,
. The transposed form is obtained by reversing the direction of all branches and swapping input and output: it has the same transfer function and better numerical behaviour, because the additions happen right after the multiplications.

Why second-order sections are used
A high-order IIR filter implemented in direct form, with a single polynomial in the denominator, is dangerous: small errors in the coefficients move the poles a lot.
Theorem. Let
with distinct poles. The sensitivity of pole
to coefficient
is
![Rendered by QuickLaTeX.com \[ \frac{\partial p_i}{\partial a_k} = -\frac{p_i^{\,N-k}}{\prod_{j\ne i}(p_i - p_j)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-2c6bee16fa680227953d4127bb00da4b_l3.png)
Proof. Write the denominator as a polynomial in
:
, with roots
. For every pole
. Differentiating with respect to
, taking into account that
depends on
:
![]()
because
. Finally
gives
. ∎
The denominator is the product of the distances between the pole and all the others: if the poles are close together, as happens in selective filters, where they crowd near the unit circle around the passband, the sensitivity blows up. A rounding error on the coefficients can move a pole outside the circle and make the filter unstable. That is why an IIR filter is factored into a cascade of second-order sections (biquads), each with a single pair of poles: sensitivities stay small, each section can be checked on its own, and the order of the sections and the distribution of gain are chosen to reduce noise.
Fixed point
In inexpensive DSPs and in dedicated hardware numbers are in fixed point: for instance in Q15 format a 16-bit integer represents a value between
and
. There are two problems:
- overflow: a sum exceeding 1 wraps around to
, with an enormous error. It is prevented by scaling the signal at the input of each section, so that internal nodes do not exceed full scale, and the damage is limited by saturation arithmetic, which clamps the result at the maximum instead of letting it wrap; - quantisation: every product has twice the bits and must be rounded, introducing a small error at every step. DSPs accumulate sums in longer registers (40 bits or more) and round only once at the end.
Round-off noise
The rounding error with step
is modelled as white noise uniform between
and
, with power
(Signal Theory lesson on quantisation). But this noise does not leave the filter as it is: it goes through the part of the filter between the point where it arises and the output.
Theorem. White noise of power
entering a system with impulse response
produces at the output noise of power
![Rendered by QuickLaTeX.com \[ \sigma_y^2 = \sigma^2\sum_{n=0}^{\infty}h_e^2[n] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-df1d52c71eb6072e22b073fae74c908b_l3.png)
Proof. The output is
. Its power is
. For white noise
if
and 0 otherwise, so only the sum of the terms with
remains. ∎
Example. A first-order section
, with rounding at the summing node: the noise sees the whole filter,
, and
. With
, a pole close to the circle, the factor is about 50, i.e. 17 dB more noise than a single rounding: almost 3 bits lost. This is why very selective low-frequency filters, with poles near
, need more bits.
Limit cycles
In fixed-point IIR filters it can happen that, with zero input, the output does not go to zero but stays stuck at a constant value or a small oscillation: a limit cycle. Rounding causes it, by making the system non-linear: for instance with
, starting from 4 one gets
, and the output stays at 4 forever instead of decaying. Limit cycles are avoided by rounding towards zero (magnitude truncation) or with special structures; in audio filters they are heard as faint tones in silence. FIR filters have no feedback, so they have neither limit cycles nor stability problems: another reason to choose them when precision is scarce.
DSP architecture
Signal processors are built around the operation
: a multiply-accumulate unit (MAC) that performs a product and a sum in one cycle, separate memories for data and coefficients read in parallel, circular buffers handled in hardware for delay lines and zero-overhead loops. An
-tap FIR filter thus costs about
cycles per sample. Today the same principles are found in the SIMD instructions of general-purpose processors and in the DSP blocks of FPGAs.
6Multirate processing
Many systems work with different sampling rates at different points: an oversampled converter produces millions of samples per second that must be reduced, audio goes from 44.1 to 48 kHz, a digital radio extracts a narrow channel from a wide band. Multirate processing changes the sampling rate numerically. In this lesson we prove what happens to the spectrum when downsampling and upsampling, look at the filters needed, rational rate conversion, and the polyphase structure with the noble identities that make it all efficient.
Downsampling
Downsampling by an integer factor
means keeping one sample every
:
.
Theorem. The spectrum of the downsampled signal is
![Rendered by QuickLaTeX.com \[ Y(e^{j\omega}) = \frac{1}{M}\sum_{k=0}^{M-1}X\!\left(e^{j(\omega - 2\pi k)/M}\right) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-937c2e475c07116c99b500c4880f187e_l3.png)
Proof. Introduce the intermediate signal
, where
is 1 when
is a multiple of
and 0 otherwise. This comb can be written as an average of exponentials,
(the sum is
if
is a multiple of
and 0 otherwise, by the geometric series). Multiplying by
shifts the spectrum by
, so
. Finally
only removes zeros, and its transform is
. Substituting gives the formula. ∎
The spectrum is stretched
times and
shifted copies are added. If the original signal had components above
, the copies overlap: this is aliasing, and it can no longer be removed.

That is why, before downsampling, the signal is filtered with a low-pass filter at
: filter plus downsampler together are called a decimator.
Upsampling
Upsampling by a factor
means inserting
zeros between samples:
if
is a multiple of
, 0 otherwise. The spectrum is
, because only the terms
remain in the transform sum, with
. The spectrum is compressed
times, and
copies appear in the interval
: the images. A low-pass filter at
with gain
removes them and fills the zeros with interpolated values: this is the interpolator.
Rational rate conversion
To multiply the sampling rate by
, upsample by
, filter with a single low-pass filter with cutoff
, which removes the images and prevents aliasing at the same time, and downsample by
. Converting from CD audio (44.1 kHz) to professional audio (48 kHz) has ratio
: upsampling by 160 followed by downsampling by 147. Done literally it would be an enormous computation, at 7 MHz in the middle; polyphase structures make it practical.
The noble identities and the polyphase structure
The obvious flaw of the decimator is that the filter works at the high rate and then
samples out of
are thrown away: most multiplications are wasted.
Theorem (noble identity). Filtering with
and then downsampling by
is equivalent to downsampling by
and then filtering with
.
Proof.
has an impulse response that is non-zero only at multiples of
:
. The filter output at instant
is
, which is exactly the convolution of
with the downsampled signal
. ∎
Every FIR filter
can be split into
polyphase components, collecting the coefficients with index
:
![Rendered by QuickLaTeX.com \[ H(z) = \sum_{k=0}^{M-1}z^{-k}E_k(z^M) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-8004d7c95068cec48a949ec1c9b73ce0_l3.png)
Applying the noble identity to each branch, the downsampling moves before the filters
, which work at the low rate. The number of multiplications per output sample is still that of the filter, but the number per unit time drops by a factor
. The same holds, dually, for the interpolator. For the 160/147 conversion only the output samples that are needed are computed, each time using the right subset of coefficients.
Applications
- Oversampled converters. A sigma-delta converter samples at many megahertz with few bits and pushes the quantisation noise to high frequencies; a digital decimator filters it out and reduces the rate, gaining bits (Applied Electronics lesson on converters). The first stages often use CIC filters, cascades of integrators and differentiators that need no multiplications.
- Software-defined radio. A wide band is sampled, the desired channel is brought to baseband with a numerical oscillator and decimated down to the channel width.
- Filter banks. A signal is split into sub-bands, each downsampled and coded with the appropriate number of bits: this is the basis of audio compression (MP3, AAC) and of the polyphase banks of OFDM.
7Spectral analysis
Computing the spectrum of a measured signal looks easy: take a block of samples and compute the FFT. But the result depends on how the block was cut, and on a noisy signal it is surprisingly unreliable. In this lesson we look at spectral leakage with its proof, resolution and scalloping loss, why zero padding does not increase resolution, the periodogram and Welch’s method with the proof of the variance reduction, and the spectrogram.
The DFT of a finite block
When
samples are analysed the signal is observed through a rectangular window, and the DFT gives
samples of the DTFT of the windowed signal, at the frequencies
(the bins). With sampling frequency
the bins are
apart: with 1 kHz and 1000 samples, 1 Hz.
Theorem. For
,
, the DFT is
![Rendered by QuickLaTeX.com \[ X[k] = \sum_{n=0}^{N-1}e^{j(\omega_0 - 2\pi k/N)n} = e^{j(N-1)\Delta_k/2}\,\frac{\sin(N\Delta_k/2)}{\sin(\Delta_k/2)},\qquad \Delta_k = \omega_0 - \frac{2\pi k}{N} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-c874f079ccf56b0a66908a3e5ad22aa3_l3.png)
If
coincides with a bin,
, the DFT is
in bin
and zero in all the others; otherwise it is non-zero in every bin.
Proof. It is the same geometric series as the moving average (lesson on the DTFT), with ratio
. If
, for
one has
, a multiple of
: the sine in the numerator is zero while the one in the denominator is not. For
all the terms equal 1. If
falls between two bins,
is never a multiple of
and no term vanishes. ∎

This is spectral leakage: a pure sinusoid appears as a peak surrounded by a “skirt” spreading over the whole spectrum, falling off slowly (the side lobes of the rectangular window, the first at −13 dB). The physical reason is that the DFT treats the block as one period of a periodic signal: if the number of periods is not an integer, there is a jump at the junction, and a jump has a wide spectrum.
Resolution, dynamic range and scalloping loss
The consequences are managed with the windows of the FIR lesson, applied this time to the signal:
- resolution: two sinusoids can be told apart if they are farther apart than the main-lobe width, about
for the rectangular window and
for Hann and Hamming. Resolving close frequencies requires long blocks; - dynamic range: a weak sinusoid near a strong one stays hidden in the latter’s side lobes. Windows with low side lobes (Hann, Blackman, Kaiser) make it possible to see components 60-100 dB below;
- scalloping loss: if the frequency falls halfway between two bins, the measured peak is lower. With the rectangular window the value is
, i.e. −3.9 dB. Flat-top windows reduce it below 0.01 dB and are used to measure amplitudes accurately.
Zero padding does not increase resolution
Extending the block with zeros before the FFT (zero padding) produces a denser, smoother plot, but it does not separate two close sinusoids.
Theorem. The
-point DFT (
) of the zero-padded block gives samples of the same DTFT as the original block, at the frequencies
.
Proof.
, because the added samples are zero; and this is the DTFT of the original block evaluated at
. ∎
The sampled function is always the same, with the same main lobe: zero padding interpolates, useful to read the position of a peak better, but the information is that of the
measured samples.
The periodogram and Welch’s method
For a random signal, such as noise, what matters is the power spectral density (Signal Theory lesson on random processes). The immediate estimate is the periodogram
. It has a serious flaw: its standard deviation in each bin is of the order of the value itself, and it does not decrease as the block gets longer. More samples give more bins, but each one stays just as noisy: the estimated spectrum of white noise looks like dense grass instead of a flat line.
Welch’s method divides the signal into
segments (often overlapping by 50 %), applies a window to each, computes its periodogram and averages.
Theorem. If the
periodograms are independent and have the same variance
, their average has variance
.
Proof. It is the same result as the mean of
readings (Electrical Measurements lesson on uncertainty):
. ∎
The price is resolution: each segment is
times shorter. It is the fundamental trade-off of spectral analysis: resolution versus variance, for a given signal duration. Digital spectrum analysers do exactly this, averaging many FFTs.
The spectrogram
For signals that change over time, such as speech or music, the DFT is computed on successive windows and the results are placed side by side: this is the spectrogram (short-time Fourier transform, STFT). A long window gives good frequency resolution but blurs fast events; a short one the opposite. The product of the two resolutions cannot go below a limit, as in the uncertainty principle:
is at least of the order of 1. Wavelet transforms choose long windows for low frequencies and short ones for high frequencies, adapting to many natural signals.
The discrete Fourier transform (DFT): from the DTFT, inverse, properties and circular convolution proved
The discrete Fourier transform (DFT) is the transform a computer can actually compute: it takes
numbers and returns
numbers. Every digital spectrum analyser, every equaliser, every OFDM modem (Wi-Fi, 4G, 5G) and every fast filter uses it, almost always through the FFT algorithm. This in-depth study derives the DFT from the discrete-time Fourier transform (DTFT) and proves its formulas and properties: inverse transform, Parseval, circular shift, Hermitian symmetry, circular convolution and how to obtain linear convolution from it. The linked lessons explain the FFT algorithm and practical use in spectral analysis (leakage, windows, Welch’s method). The path follows the topics of Sandro Petrizzelli’s notes from which this page originated.
From the DTFT to the DFT
A sequence
has DTFT
![Rendered by QuickLaTeX.com \[ X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-3924c9aac433909bd41e8ca3b74ae732_l3.png)
a continuous function, periodic with period
in the normalised angular frequency
. A computer cannot store a continuous function: it takes
equally spaced samples of it,
,
. If
is nonzero only for
, these samples are
![Rendered by QuickLaTeX.com \[ X[k] = X(e^{j2\pi k/N}) = \sum_{n=0}^{N-1} x[n]\,W_N^{kn},\qquad W_N = e^{-j2\pi/N} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-0776dd0b3dff4ea6153deff3db7aee3a_l3.png)
This is the
-point DFT. The number
is an
-th root of unity:
, and its powers are
equally spaced points on the unit circle.

Theorem (sampling in frequency is repeating in time). If
is longer than
, the samples
of its DTFT coincide with the DFT of the sequence
,
: the parts of
beyond
overlap (time aliasing).
Proof. Split the DTFT sum into blocks of
samples,
with
:
. Since
, what remains is
, the DFT of
. ∎
It is the dual of the sampling theorem: sampling in time makes the spectrum periodic, sampling the spectrum makes the signal periodic. This is why the DFT always treats the block of
samples as if it were one period of a periodic signal: all the properties that follow are “circular”.
The inverse transform
Theorem.
.
Proof. A lemma is needed, the orthogonality of discrete exponentials:
if
is a multiple of
, otherwise 0. Indeed in the first case every term equals 1; in the second
and the geometric sum is
. Now substitute the definition:
![Rendered by QuickLaTeX.com \[ \frac{1}{N}\sum_{k=0}^{N-1}\Big(\sum_{m=0}^{N-1} x[m]W_N^{km}\Big)W_N^{-kn} = \frac{1}{N}\sum_{m=0}^{N-1} x[m]\sum_{k=0}^{N-1} W_N^{k(m - n)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-1eae07dd0e0acdf74616968470658ea9_l3.png)
The inner sum equals
only for
(with
between 0 and
,
is a multiple of
only if it is zero):
remains. ∎
In matrix form
with
, and the theorem says
: the matrix
is unitary. Parseval’s theorem follows immediately:
![Rendered by QuickLaTeX.com \[ \sum_{n=0}^{N-1}|x[n]|^2 = \frac{1}{N}\sum_{k=0}^{N-1}|X[k]|^2 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-1fdffcd952bacd263bf00d7c93e696cc_l3.png)
because a unitary matrix preserves the norm:
. Energy can be measured equally in time or in frequency.
The properties, proved
In all that follows indices are taken modulo
:
is the remainder of
divided by
.
Linearity.
: the definition is a sum.
Circular time shift.
.
Proof.
; with
, as
runs over
so does
(in another order), and
because
. The sum becomes
. ∎
The delay only changes the phase of the coefficients, not the magnitude. But it is a circular delay: samples leaving on the right re-enter on the left.

Frequency shift (modulation).
: same proof with the roles swapped. Multiplying by a complex exponential shifts the spectrum: it is the principle of frequency conversion in digital receivers.
Hermitian symmetry. If
is real,
.
Proof.
, because
. For real
, conjugation only changes the sign of the exponent:
. ∎
So real part and magnitude are symmetric about
, imaginary part and phase antisymmetric: for a real signal the coefficients from 0 to
are enough, and the “real” FFT does half the computation. The coefficient
(with even
) is the Nyquist frequency and is real.

Circular symmetry. If moreover
(even in the circular sense, i.e.
), the DFT is real; if it is odd, purely imaginary. It follows from the previous property: for even
,
.
Circular convolution
Theorem. The product of DFTs corresponds to circular convolution:
![Rendered by QuickLaTeX.com \[ Y[k] = X[k]H[k] \;\leftrightarrow\; y[n] = \sum_{m=0}^{N-1} x[m]\,h[(n - m)_N] = (x \circledast h)[n] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-faa3a5028b77240fadbccc845b68a93b_l3.png)
Proof. Compute the DFT of
and use the circular shift:
. ∎
Filtering a signal is instead a linear convolution,
, with length
if
and
have lengths
and
. Circular convolution on
points is the linear one “wrapped around”: samples beyond
are added at the start (the frequency-sampling theorem applied to
).
Example.
,
. The linear convolution is
. With an
point DFT the last 3 wraps onto
:
, a wrong result for a filter. With
there is no overlap and
is obtained again.

Practical rule: to filter with the FFT, pad
and
with zeros up to
. For long signals the signal is split into blocks and the overlap-add and overlap-save methods are used, which reassemble the blocks without errors; with large
the cost,
instead of
, is much lower than direct convolution.
Two DFTs to know by heart
Rectangular pulse of
samples on
points: with the geometric sum
![Rendered by QuickLaTeX.com \[ X[k] = \sum_{n=0}^{L-1} W_N^{kn} = \frac{1 - W_N^{kL}}{1 - W_N^k} = e^{-j\pi k(L - 1)/N}\,\frac{\sin(\pi kL/N)}{\sin(\pi k/N)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-aa9f0b84b1007c1d76c95322d808cbef_l3.png)
(factoring
in the numerator and
in the denominator). The magnitude is the Dirichlet kernel, the discrete version of the sinc: for
,
it is
. It is also the response of the rectangular window, the origin of spectral leakage.
Cosine on a bin.
: by orthogonality the DFT equals
at
and at
, zero elsewhere. If the frequency does not fall exactly on a bin the DFT has values at all
: this is spectral leakage, covered in the spectral analysis lesson.
Zero padding
Padding a block of
samples with zeros up to
does not add information: by the first theorem, the
-point DFT samples the same DTFT more densely (figure at the top, 8 and 16 points). It helps to read peak positions better and to reach a power of 2 for the FFT, but the ability to separate two close frequencies depends only on the duration
of the observed signal: about
.
Checking in Python
import numpy as np
def dft(x):
"""DFT from the definition: X[k] = sum x[n] e^{-j 2 pi k n / N}."""
N = len(x)
n = np.arange(N)
W = np.exp(-2j * np.pi * np.outer(n, n) / N) # Fourier matrix
return W @ x
def idft(X):
N = len(X)
n = np.arange(N)
return np.exp(2j * np.pi * np.outer(n, n) / N) @ X / N
rng = np.random.default_rng(1)
x = rng.standard_normal(8)
X = dft(x)
print("equal to np.fft.fft:", np.allclose(X, np.fft.fft(x)))
print("exact inverse:", np.allclose(idft(X), x))
print("Parseval:", np.isclose(np.sum(x**2), np.sum(abs(X)**2) / 8))
print("Hermitian symmetry X[N-k] = X*[k]:", np.allclose(X[1:][::-1], np.conj(X[1:])))
m = 3
print("circular shift:", np.allclose(dft(np.roll(x, m)), np.exp(-2j * np.pi * np.arange(8) * m / 8) * X))
# circular versus linear convolution
a, h = np.array([1.0, 2, 3]), np.array([1.0, 1])
lin = np.convolve(a, h)
circ3 = np.real(idft(dft(a) * dft(np.r_[h, 0])))
circ4 = np.real(idft(dft(np.r_[a, 0]) * dft(np.r_[h, 0, 0])))
print("linear:", lin, " circular N=3:", np.round(circ3, 6), " circular N=4:", np.round(circ4, 6))
# DFT of a rectangular pulse of L = 4 samples on N = 8 points: Dirichlet kernel
L, N = 4, 8
r = np.r_[np.ones(L), np.zeros(N - L)]
k = np.arange(1, N)
dirichlet = np.exp(-1j * np.pi * k * (L - 1) / N) * np.sin(np.pi * k * L / N) / np.sin(np.pi * k / N)
print("rectangle, Dirichlet formula:", np.allclose(dft(r)[1:], dirichlet), " |X| =", np.round(abs(dft(r)), 3))
# cosine falling exactly on bin 2
c = np.cos(2 * np.pi * 2 * np.arange(N) / N)
print("cosine on bin 2:", np.round(abs(dft(c)), 6))All checks print True; the 3-point circular convolution gives
and the 4-point one
, equal to the linear one; the magnitude of the rectangle and the cosine on bin 2 (value 4 at
and
) match the formulas. The DFT from the definition costs
multiplications: for
it does not matter, for
it does, and this is the reason for the FFT algorithm, explained in the linked lesson.
8Adaptive filters
The filters seen so far have fixed coefficients, computed once from the specifications. But often the signal and the disturbance change over time, or are not known in advance: the echo of a phone call depends on the room, a modem’s channel changes with the line, the noise of an engine with its speed. An adaptive filter updates its own coefficients at every sample to minimise an error. In this lesson we derive the Wiener filter with the orthogonality principle, the LMS algorithm as gradient descent with the proof of the convergence condition, the normalised version and the applications.
The problem
An FIR filter with coefficients
receives the vector of the last
input samples
and produces
. There is a desired signal
, and the error is
. We look for the coefficients that minimise the mean squared error
.
The Wiener filter
Expanding the square, with the input autocorrelation matrix
and the cross-correlation vector
:
![]()
It is a quadratic function of the coefficients, a “bowl” with a single minimum.
Theorem. The optimal coefficients satisfy the normal equations
, and at the optimum the error is uncorrelated with every input sample:
.
Proof. The gradient of
with respect to
is
. The minimum of a convex quadratic function (
is positive semidefinite) is where the gradient vanishes,
. Moreover
, which is zero at
. ∎
The second result is the orthogonality principle: the optimal error no longer contains anything that can be predicted from the input. The Wiener filter, however, requires knowing
and
and solving a linear system, and if the statistics change one has to start again.
The LMS algorithm
The idea of Widrow and Hoff (1960) is to go down the gradient one step at a time, using instead of the true gradient, which would require statistical averages, its instantaneous estimate. Replacing
and
with
and
, the estimated gradient is
, and the descent step becomes
![]()
with the step size
(the factor 2 is absorbed into
). Each coefficient is corrected in proportion to the error and to the input sample it multiplies. The cost is about
multiplications per sample: the same order as the filter.
Convergence
Theorem. With stationary inputs, independent from one step to the next, the LMS coefficients converge in the mean to the Wiener solution if and only if
![]()
where
is the largest eigenvalue of
.
Proof. Let
be the deviation from the optimum. Taking the mean of the update, with the independence assumption
, gives
, i.e., using
,
![]()
is symmetric,
with
orthogonal; in the coordinates
the components evolve separately as
. They tend to zero if and only if
for every
, i.e.
; the most restrictive condition is that of the largest eigenvalue. ∎
In practice the estimate
, easy to measure, is used:
. The convergence speed, instead, is set by the smallest eigenvalue: if the eigenvalues are very different (a very coloured input), LMS converges slowly along some directions. A large
converges quickly but leaves the coefficients “jittering” around the optimum (the misadjustment, an excess error); a small
is accurate but slow to track changes.
Normalised LMS
If the input power varies, a fixed
becomes too large or too small. NLMS divides the step by the current energy of the samples:
![]()
with a small
to avoid division by zero. It is the version used almost always, for instance in echo cancellers. More expensive algorithms such as RLS (recursive least squares) converge much faster at the price of
operations per sample, and the Kalman filter is their generalisation to systems described in state space.
Applications

- Noise cancellation. One microphone picks up voice plus noise, a second one picks up only the noise (the reference). The filter learns the transformation between the two noises and subtracts it: by the orthogonality principle the minimum error is exactly the voice, which is uncorrelated with the reference. Active noise-cancelling headphones use a variant of this.
- Echo cancellation. In speakerphones and video calls the loudspeaker leaks back into the microphone. The filter, with the far-end voice as reference, estimates the echo path in the room (hundreds of milliseconds, thousands of coefficients) and removes it.
- Equalisation. In a modem or a radio receiver, the filter compensates the channel distortion by learning from a known sequence, then keeps tracking using the receiver’s decisions.
- Identification. Placed in parallel with an unknown system, with the same input, the filter converges to its impulse response: it is used to measure acoustics, channels and processes.
∑Formula sheet
The DTFT and frequency response
The discrete-time Fourier transform
![Rendered by QuickLaTeX.com \[ X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n},\qquad x[n] = \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\omega})\,e^{j\omega n}\,d\omega \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-7198b0eb58f852edd369c75350e78208_l3.png)
The frequency response
![]()
![]()
The moving average
![]()
![Rendered by QuickLaTeX.com \[ H = \frac{1}{M}\sum_{k=0}^{M-1}e^{-j\omega k} = \frac{1}{M}\cdot\frac{1 - e^{-j\omega M}}{1 - e^{-j\omega}} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-bd701883f487a41415e94d9f89aa9f83_l3.png)
Linear phase and group delay
![]()
FIR design with windows
The ideal low-pass filter
![]()
![Rendered by QuickLaTeX.com \[ h_d[n] = \frac{1}{2\pi}\int_{-\omega_c}^{\omega_c}e^{j\omega n}\,d\omega = \frac{1}{2\pi}\cdot\frac{e^{j\omega_c n} - e^{-j\omega_c n}}{jn} = \frac{\sin(\omega_c n)}{\pi n} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-efc698e8ff9546e2c285ba67c234ef58_l3.png)
The Kaiser window
![Rendered by QuickLaTeX.com \[ \beta = \begin{cases} 0.1102\,(A - 8.7) & A \gt 50 \\ 0.5842\,(A - 21)^{0.4} + 0.07886\,(A - 21) & 21 \le A \le 50 \end{cases},\qquad N \approx \frac{A - 8}{2.285\,\Delta\omega} + 1 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-4d4ecf6e8a3acb5e5f97d88ed196501a_l3.png)
Linear phase
![]()
Optimal FIR filters
The minimax criterion
![]()
Order estimation
![Rendered by QuickLaTeX.com \[ N \approx \frac{-20\log_{10}\sqrt{\delta_p\delta_s} - 13}{14.6\,\Delta f} + 1,\qquad \Delta f = \frac{\omega_s - \omega_p}{2\pi} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-2146df5f1ea0479c417f7d8467453691_l3.png)
IIR filters and the bilinear transform
Analogue prototypes
![]()
![Rendered by QuickLaTeX.com \[ N \ge \frac{\log_{10}\left[(10^{A_s/10} - 1)/(10^{A_p/10} - 1)\right]}{2\log_{10}(\Omega_s/\Omega_p)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9e72721994f9cef85ce3d6b9b37366f7_l3.png)
The bilinear transform
![]()
![]()
A complete example
![]()
Filter structures and finite precision
The direct forms
![Rendered by QuickLaTeX.com \[ y[n] = \sum_{k=0}^{M} b_k\,x[n-k] - \sum_{k=1}^{N} a_k\,y[n-k] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-07ef534769bf9ad2904ad47455250011_l3.png)
Why second-order sections are used
![Rendered by QuickLaTeX.com \[ \frac{\partial p_i}{\partial a_k} = -\frac{p_i^{\,N-k}}{\prod_{j\ne i}(p_i - p_j)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-2c6bee16fa680227953d4127bb00da4b_l3.png)
![]()
Round-off noise
![Rendered by QuickLaTeX.com \[ \sigma_y^2 = \sigma^2\sum_{n=0}^{\infty}h_e^2[n] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-df1d52c71eb6072e22b073fae74c908b_l3.png)
Multirate processing
Downsampling
![Rendered by QuickLaTeX.com \[ Y(e^{j\omega}) = \frac{1}{M}\sum_{k=0}^{M-1}X\!\left(e^{j(\omega - 2\pi k)/M}\right) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-937c2e475c07116c99b500c4880f187e_l3.png)
The noble identities and the polyphase structure
![Rendered by QuickLaTeX.com \[ H(z) = \sum_{k=0}^{M-1}z^{-k}E_k(z^M) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-8004d7c95068cec48a949ec1c9b73ce0_l3.png)
Spectral analysis
The DFT of a finite block
![Rendered by QuickLaTeX.com \[ X[k] = \sum_{n=0}^{N-1}e^{j(\omega_0 - 2\pi k/N)n} = e^{j(N-1)\Delta_k/2}\,\frac{\sin(N\Delta_k/2)}{\sin(\Delta_k/2)},\qquad \Delta_k = \omega_0 - \frac{2\pi k}{N} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-c874f079ccf56b0a66908a3e5ad22aa3_l3.png)
Adaptive filters
The Wiener filter
![]()
The LMS algorithm
![]()
Convergence
![]()
![]()
Normalised LMS
![]()