Fundamentals / Numerical mathematics / Approximation and quadrature

Integrate a rapidly oscillating signal without resolving every crest

A lock-in detector measures the in-phase integral \(I(k)=\int_0^1 f(x)\cos(kx)\,dx\). The carrier frequency is known exactly from the instrument. The envelope is smooth and expensive to evaluate. Design a quadrature rule that spends those evaluations on the envelope, and find a case where even the improved method gives a deceptively small answer.

Predict a complete alias on a coarse scan

Let \(f(x)=1+x^2\) and \(k=16\pi\). Use eight uniform panels and include both endpoints with half weight in the trapezoidal rule. What does the instrument predict, and what is the true integral?

Work through the solution

The carrier completes exactly one full cycle per panel. Its values at every sampled point are therefore one, so the naive sum integrates only the envelope. It gives

\[1+1/3+1/(6\cdot8^2)=1.3359375.\]

Integrating the oscillatory expression by parts twice gives

\[I(k)=2\sin k/k+2\cos k/k^2-2\sin k/k^3.\]

At \(16\pi\) the true result is

\[2/(16\pi)^2=0.00079157.\]

The small true signal comes from cancellation of lobes with slightly unequal envelope weights. Nothing in the sampled carrier values reveals those lobes. A small residual between the trapezoidal estimates of a few adjacent sampled segments would be uninformative here.

Explore the related calculation with adjustable inputs. Change the parameters in the experiment on this same project page and compare its output with this part of the derivation.

Record which quantities are known before choosing a rule. If the underlying carrier were unknown and only sampled instrument voltages were available, this example would be an information problem: the samples are also consistent with an unmodulated envelope. Here the oscillator frequency and phase are controlled and available between sample positions. A numerical method can exploit that extra knowledge without evaluating the expensive part of the integrand any more frequently.

Integrate a linear envelope against the exact carrier

Approximate only the envelope on a panel of width \(h\) and midpoint \(m\) by \(a+bt\), where \(t=x-m\). Find \(a,b\) from endpoint samples and derive the exact panel integral of this approximation.

Work through the solution

Use \(a=(f_L+f_R)/2\), \(b=(f_R-f_L)/h\), and set \(d=kh/2\). Expand \(\cos[k(m+t)]\) into cosine and sine products. Odd integrands integrate to zero on the symmetric interval. The constant part gives \(2a\cos(km)\sin d/k\). The slope term gives \(-2b\sin(km)(\sin d-d\cos d)/k^2\), after an integration by parts of \(t\sin(kt)\). Add the two terms and sum over panels. This is a piecewise-linear member of the Filon family: interpolate a slowly varying amplitude and compute its oscillatory moments. It integrates every globally linear envelope exactly for every carrier frequency, up to roundoff.

Explore the related calculation with adjustable inputs. Change the parameters in the experiment on this same project page and compare its output with this part of the derivation.

The individual moment expressions require care when \(d\) is very small. In particular \(\sin d-d\cos d=d^3/3-d^5/30+\cdots\); evaluating it by direct subtraction near zero loses significant digits. In the limit \(k\to0\) the constant moment becomes \(h\), the odd contribution vanishes, and the rule reduces to an ordinary trapezoid for the envelope. For high frequency the same formula behaves quite differently from sampling the product. The analytic moments retain the signs and magnitudes of oscillatory contributions between the nodes.

Explain an apparently perfect zero and recover curvature

Return to eight complete periods on eight panels. The fitted linear rule now gives zero. Is this answer exact? What new measurement can recover the missing signal?

Work through the solution

Here \(d=\pi\) and \(\sin(km)=0\) on every panel. Both moment contributions vanish separately, regardless of the endpoint amplitudes. The constant and linear parts of each local envelope make no net contribution over a centred complete cosine period aligned this way. The exact quadratic curvature does contribute. Introduce one midpoint envelope measurement and fit a quadratic through the endpoints and midpoint; its exact oscillatory second moment recovers the polynomial test identically. On these aligned panels a simpler check is to compute the residual \(f(x)-p_1(x)=(x-x_L)(x-x_R)\). The integral of its quadratic term supplies exactly the signal discarded by the linear rule. The linear answer is far closer in absolute terms than the aliased trapezoid, yet its relative error for the small target is still one hundred percent.

Explore the related calculation with adjustable inputs. Change the parameters in the experiment on this same project page and compare its output with this part of the derivation.

Dimensional reasoning makes the restoration plausible. For a twice differentiable amplitude the pointwise error of linear interpolation on one panel is bounded by \(\max|f''|h^2/8\). Multiplying by \(|\cos|\le1\) and integrating across all panels yields a uniform absolute error bound of the same order on this unit interval. It says little about relative error when the exact integral is a small difference of much larger signed contributions. An acceptance criterion for a detector with a known noise floor should therefore include an absolute tolerance expressed in the actual output units.

Test resolution and report a useful tolerance

Vary the number of panels and sweep the carrier through adjacent frequencies in the live graph. Which measurements distinguish genuinely small coherent output from values produced by aliasing?

Work through the solution

Compute an independent reference by integrating the polynomial test analytically. Compare absolute errors on both sides of an integer number of cycles, including the exact alignment at eight cycles. The aliased trapezoid produces peaks when sampled phases line up. The Filon result follows the reference more closely once the envelope is resolved, with the special zero at the exactly aligned coarse case explained above. Repeat after doubling panel count and changing the start phase in an actual experiment. The true in-phase projection also changes with phase, so compare against the corresponding analytic reference for that phase instead of demanding agreement between physically different projections.

Explore the related calculation with adjustable inputs. Change the parameters in the experiment on this same project page and compare its output with this part of the derivation.

The graph displays integrals versus the number of carrier cycles, holding the number of envelope panels fixed over the sweep. Start with eight panels and include the neighbourhood of eight cycles. Then increase the panel count to sixteen. Read the signed reference and the two calculated estimates at the selected frequency. A rapidly oscillating but known carrier is a structural clue: a rule using its exact moments and an independently tested envelope approximation can avoid catastrophic sampling aliases.

L. N. G. Filon's original paper on quadrature for trigonometric integrals.

Notebook practice · Integrating an infinite endpoint with a finite table of samples