Fundamentals / Numerical mathematics / Approximation and quadrature

Fourier projection and sampled frequencies

Recover periodic modes by projection and identify signals which become indistinguishable on a uniform sample grid.

From first principles

Recover a Fourier coefficient by orthogonality

For a square-integrable signal of period \(2\pi\), represent its main oscillations by harmonics \(e^{ikx}\). To choose the best coefficients in the integrated squared-error sense, set each residual inner product with an included harmonic to zero. Integration of a complex exponential gives the orthogonality relation

\[\frac{1}{2\pi}\int_0^{2\pi}e^{ikx}e^{-imx}\,dx=\begin{cases}1,&k=m,\\0,&k\ne m.\end{cases}\]

Consequently projection onto mode \(m\) gives

\[c_m=(2\pi)^{-1}\int f(x)e^{-imx}\,dx.\]

On a uniform grid \(x_j=2\pi j/N\), replacing this integral by the sample mean defines the normalized discrete coefficient,

\[\widehat c_m=\frac1N\sum_{j=0}^{N-1} f(x_j)e^{-imx_j}.\]

The finite geometric series now vanishes unless two frequency labels differ by a multiple of \(N\). Such labels have identical sampled values, so the sampled coefficients can combine several underlying continuous frequencies. A physical sampling rate and restrictions on the input bandwidth are needed to associate a discrete coefficient with a unique physical harmonic.

One-cycle and seven-cycle cosines pass through exactly the same nine samples on a uniform grid. Between sampled nodes the oscillations differ.Open full-size diagram
Two different functions can supply exactly the same input data At x = j/8 the two sampled phases are 2πj/8 and 2πj − 2πj/8. Their cosines coincide at every grid point. A reconstruction using only these samples cannot choose the underlying frequency. Take one more sample at x = 1/16 and predict which two values the competing models give.

Derivation and applications

Predict spectral leakage for a tone between Fourier bins

A frequency may lie well below the sampling limit and still distribute energy across many discrete Fourier bins. Consider \(N\) equally spaced samples of a single complex tone of unit amplitude with \(\nu\) cycles across the record. Using a rectangular measurement window, \(x_j=e^{2\pi i\nu j/N}\) for \(j=0,\ldots,N-1\). Under the normalization giving unit amplitude for a tone exactly on its bin, the coefficient in bin \(k\) is

\[X_k=\frac1N\sum_{j=0}^{N-1}e^{2\pi i(\nu-k)j/N}.\]

Set \(\delta=\nu-k\). If \(\delta\) is not a multiple of \(N\), sum the geometric progression and factor a phase out of both numerator and denominator. This gives

\[X_k=e^{i\pi\delta(N-1)/N}\frac{\sin(\pi\delta)}{N\sin(\pi\delta/N)} .\]

At a bin-centred frequency the corresponding limiting coefficient is one and all other bins vanish. At a fractional bin the tails are a consequence of observing a finite record. The total squared spectral weight remains fixed by orthogonality of the discrete basis,

\[\sum_{k=0}^{N-1}|X_k|^2=\frac1N\sum_{j=0}^{N-1}|x_j|^2=1.\]

Amplitudes in selected bins can therefore be smaller without any loss of input energy. The formula assumes a complex tone. A real cosine contains two complex tones at opposite frequencies, whose coefficients must be added with phase before comparing amplitudes near overlapping lobes.

Worked example

Quantify a half-bin mismatch

Take \(N=8\) and \(\nu=2.5\) cycles. Bins 2 and 3 each have magnitude \(1/[8\sin(\pi/16)]=0.641\). Together they contain \(2(0.641)^2\simeq0.821\) of the tone’s spectral energy. The remaining fraction is distributed among the other six bins even though the input contains only a single frequency.

Second application

Distinguish grid spacing from intrinsic frequency content

A recorder sampling at \(800\,\mathrm{Hz}\) takes 80 samples of a \(125\,\mathrm{Hz}\) complex tone. Its bin spacing is \(10\,\mathrm{Hz}\), placing the tone halfway between bins 12 and 13; each magnitude is

\[1/[80\sin(\pi/160)]=0.637.\]

Extending the actual record to 160 samples gives \(5\,\mathrm{Hz}\) spacing and exactly 25 cycles. The normalized magnitude in bin 25 becomes one when the tone remains coherent across the longer measurement.

Orthogonality on a period

For a square-integrable \(2\pi\)-periodic signal define \(\langle f,g\rangle=(2\pi)^{-1}\int_0^{2\pi} f(x)\overline{g(x)}\,dx\). The exponentials \(e^{ikx}\) are orthonormal for integer \(k\). Integrating their product gives one when the frequencies coincide and zero otherwise because a nonconstant exponential completes an integer number of cycles. Minimising the squared mean discrepancy over modes \(|k|\leq m\) therefore gives

\[c_k=\langle f,e^{ikx}\rangle.\]

The residual is orthogonal to every retained mode.

Orthogonality also splits energy. The squared norm of the original signal equals the sum of the retained squared coefficient magnitudes plus the remaining squared error. This identity gives the truncation error exactly for a finite trigonometric series. For a general square-integrable periodic signal the projections converge in the mean-square norm. That statement concerns an integral; a narrow region of large pointwise error can contribute little to it.

Background · Why does a noninteger cycle spread power over several bins?

Project \(e^{i\nu x}\) on the integer harmonic \(e^{ikx}\) over a single observed interval of length \(2\pi\). Integrating the exponential exactly gives

\[c_k=e^{i\pi(\nu-k)}\,\frac{\sin[\pi(\nu-k)]}{\pi(\nu-k)}.\]

For an integer \(\nu\), the limit at \(k=\nu\) is one and every other bin receives zero. A tone with \(\nu=3.5\) cycles has equal coefficient magnitudes \(2/\pi\) at bins 3 and 4. A longer record at the same sampling rate narrows the physical frequency interval between bins. Applying a taper changes the leakage shape because it changes the projection window. Adding zeros after the existing record samples that same windowed spectrum more densely, without extending the observed duration.

A resolvable frequency and an invisible one

Take \(f(x)=2+\cos(2x)+0.4\sin(5x)\). Projecting onto frequencies through three retains the constant and cosine. The remaining mean-square error is \(0.4^2/2=0.08\), so its root mean square is about 0.28284. Now sample at \(x_j=2\pi j/8\). At those points \(5x_j\) differs from \(-3x_j\) by \(2\pi j\). Thus the data are equally compatible with \(2+\cos(2x)-0.4\sin(3x)\). A discrete fit through frequency three can have zero sample residual yet disagree between nodes.

At \(x=\pi/8\), the two sine contributions are \(0.4\sin(5\pi/8)\) and \(-0.4\sin(3\pi/8)\). Their difference is about 0.7391. This unsampled point exposes the false low-frequency reconstruction. More generally the finite sum of \(e^{2\pi i(k-l)j/N}\) vanishes unless \(k-l\) is divisible by \(N\). This geometric-series argument explains frequency equivalence on the grid and also supplies the discrete orthogonality behind a Fourier transform.

Factor the discrete Fourier transform into short transforms

The discrete Fourier transform (DFT) maps \(N\) equally spaced samples \(x_n\) to \(X_k=\sum_{n=0}^{N-1}x_n W_N^{kn}\), with \(W_N=e^{-2\pi i/N}\). In this convention the forward transform has no normalization. The discrete Fourier coefficients are \(X_k/N\). Computing every sum directly uses order \(N^2\) operations. There is redundant work because the sample weights are powers of the same root of unity.

For even \(N\), separate \(n=2j\) and \(n=2j+1\). Since \(W_N^2=W_{N/2}\), the two partial sums are the length-\(N/2\) transforms \(E_k,O_k\) of the even and odd samples. Increasing \(k\) by \(N/2\) leaves both short transforms unchanged and reverses the sign of \(W_N^k\). A single product therefore supplies two entries:

\[X_k=E_k+W_N^kO_k,\]
\[X_{k+N/2}=E_k-W_N^kO_k,\qquad 0\leq k<N/2.\]

For the four samples \((1,2,3,4)\), the even subsequence \((1,3)\) gives \((4,-2)\), while the odd subsequence \((2,4)\) gives \((6,-2)\). The multipliers are 1 and \(-i\). Combining the two pairs produces \((10,-2+2i,-2,-2-2i)\) in frequency order. The zero-frequency term recovers the sum of the samples. Conjugate symmetry holds because the samples are real. The Nyquist entry is real as it must be.

For \(N=2^m\), repeat the split down to length one. Each of the \(m\) stages contains \(N/2\) paired combinations, often called butterflies. The work scales as \(N\log_2 N\). The FFT computes exactly the same mathematical transform as the direct formula, up to rounding. An aliased high frequency still occupies the same discrete bin. Padding an already sampled record can interpolate its displayed spectrum but cannot supply independent measurements at the missing times.

Practise on sheet 5 · Find the zeros in an eight-sample spectrum without eight long sums. Further reading · MIT · 2.161 Signal Processing, Continuous and Discrete · The Fast Fourier Transform · The radix-2 FFT with decimation in time.

Smoothness and endpoint matching

Integrating a Fourier coefficient by parts divides by its frequency. The boundary term vanishes for a smooth periodic continuation. Repeating the operation shows faster coefficient decay when successive derivatives also match at the endpoints and remain sufficiently regular. A mismatch when a finite record is periodically repeated creates a jump. Near a jump partial sums develop oscillations, and adding modes confines them to a narrower region while a peak overshoot persists.

Start a numerical study by refining the sample grid with a fixed retained bandwidth. Then hold that refined grid and enlarge the bandwidth. The first experiment probes whether the coefficient estimates are polluted by unresolved modes. The second probes how much physical detail a deliberately truncated representation omits. A single refinement that changes both quantities makes these explanations difficult to distinguish.

The special frequency at half the sample rate

With eight equally spaced samples the mode \(\cos(4x)\) gives \(1,-1,1,-1,\ldots\), whereas \(\sin(4x)\) gives zero at every point. A phase shift of a sinusoid at precisely this frequency therefore changes its observed amplitude and can hide the entire oscillation. This explains the special treatment of the highest coefficient in an even-length real Fourier transform. Ten samples over the same period distinguish both sine and cosine components at frequency four because their sample values are now linearly independent.

Average partial Fourier sums to obtain a positive kernel

Ordinary Fourier projection cuts sharply from a retained coefficient to a discarded one. Instead average the first \(m+1\) symmetric partial sums, counting the constant-only projection as the first. Mode \(k\) then appears in \(m+1-|k|\) of those sums for \(|k|\le m\). Its coefficient is multiplied by \(1-|k|/(m+1)\). This triangular weighting is called a Fejér mean. Its convolution kernel is the squared modulus of the finite geometric sum \(\sum_{j=0}^m e^{ijx}\), divided by \(m+1\). Expanding that squared modulus counts exactly the same number of pairs with each index difference \(k\).

The resulting kernel is nonnegative and has unit integral when measured with the normalised period measure \(dx/(2\pi)\). The reconstructed value is thus a weighted average of the true values. If a real continuous signal lies between zero and one everywhere, this averaged approximation remains in the same interval. For continuous periodic functions the averages converge uniformly: continuity makes nearby signal values uniformly close, while away from the origin the geometric-sum formula bounds the kernel by a constant divided by \(m+1\). Splitting the convolution into these two regions makes the approximation argument explicit.

Compare the reconstructed amplitudes at fixed bandwidth

Take \(f(x)=\cos x+2\cos(3x)\), retaining bandwidth through three. Ordinary projection reproduces this finite Fourier series exactly. Averaging the four partial sums of orders 0 through 3 retains the first cosine with weight \(3/4\) and the third with weight \(1/4\). The reconstruction is \(0.75\cos x+0.5\cos(3x)\). At zero it predicts 1.25 instead of three. Since the omitted amplitudes are 0.25 and 1.5, orthogonality gives squared mean error \((0.25^2+1.5^2)/2=1.15625\). The loss is substantial precisely because the real signal contains strong energy near the edge of the chosen band.

For a periodic piecewise-constant indicator, on the other hand, preservation of the interval between zero and one can be more important than full transmission of high modes. At an isolated jump separating two flat values, symmetry of the kernel assigns equal weight to sufficiently close points on either side of the jump. As the bandwidth grows, the averaged limit at a jump is the midpoint of its one-sided limits under these conditions. It cannot reproduce both sides at the mathematical point of discontinuity, regardless of the convention used to label that point in a data file.

These guarantees concern the continuous kernel and accurate coefficients. Aliased coefficients computed from an insufficient grid represent a different periodic function; applying triangular weights after such sampling cannot recover the missing distinctions between frequencies. Separate the choice of smoothing weights from the acquisition resolution when comparing a nonnegative reconstruction with actual measurements.

The smoothing window also supplies a direct frequency-response test. Feeding the averaging routine a unit cosine at frequency two with bandwidth three should return half its original amplitude. Feeding a constant should return the constant unchanged. Together these probes distinguish a correctly normalised triangular response from an accidental averaging operation that also attenuates the mean.

Make two different waves agree at every sample

Sample each continuous signal eight times per second at \(t=j/8\). At these instants the phases of the two components differ by \(2\pi j\). A discrete Fourier transform of those measurements cannot determine which continuous waveform produced them.

Make two different waves agree at every sample. Horizontal axis: Time (s). Vertical axis: Signal. Data follow the figure.
At t = 1/8 s both waves equal one, but between recorded times the ten-hertz signal executes an extra cycle. Increasing the acquisition rate with an appropriate analogue bandwidth is different from interpolating more display points.
Read values from the plot
Signal at selected values of Time (s).
Time (s)Two cycles per secondTen cycles per second
000
0.251.2246e−166.1232e−16
0.5−2.4493e−16−1.2246e−15
0.753.6739e−165.3897e−15
1−4.8986e−16−2.4493e−15

Download all 401 plotted samples (CSV)

Change parameters · Make two different waves agree at every sample

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Study the full derivation

Integrating cosine interpolants on nested grids · Function approximation and numerical integration

Chebyshev points turn polynomial interpolation into a cosine series. Derive the exact moments of each basis polynomial, explain aliasing and find a case where two consecutive quadrature grids confidently agree on the wrong answer.