In the course the sampling step is taken as T=1: the signal is a sequence x[n], n∈Z, and frequencies are normalised (ω^, with ω^=2πf/Fs).
1. From the analog to the digital signal
A signal is the evolution of a physical quantity with respect to an independent variable (time for a sound, space for a photograph) that carries information. It is processed for two purposes: analysis (understanding or extracting the information: filtering, removing noise, recognising structures) and synthesis (building a signal that contains certain information: synthetic music, telephony and radio signals).
The basic scheme to process an analog signal x(t) is the chain: input low-pass filter (LPF) → A/D converter → digital signal processing (DSP) → D/A converter → output LPF. Two assumptions: the input is band-limited (the task of the first LPF, which prevents aliasing) and Fs is at least twice the bandwidth. The A/D converter is an ideal sampler followed by a uniform quantizer: if the signal lies in [−Vx,Vx] and the converter has B bits, each sample is replaced by the nearest level x^=kq with step
q=2B−1Vx,∣x−x^∣≤2q.
Example.B=16 and Vx=1V: q=1/215V≈30.5μV and the maximum error is q/2≈15.3μV. An 8-bit converter with the same range gives q=1/128=7.8mV. The D/A converter holds the value constant until the next sample (zero-order hold, H0(f)=Tsinc(fT)e−jπfT) and the final LPF smooths the steps.
Why digital: (1) precision, which depends only on the number of bits; (2) reliability: a working digital system always performs the same operations and gives the same result; no thermal drift or noise; (3) adaptivity: to change the behaviour of a filter one changes numbers in memory, not components. In transmission, an analog repeater can only re-amplify by 1/G and obtains x(t)+σ(t)/G: the noise is amplified and accumulates; with G=0.5 and independent noise of standard deviation 1 per leg, after N=10 legs the noise standard deviation is 10⋅1/0.5≈6.3. A digital repeater applies a threshold, x^=sgn[Gx+σ], and regenerates the clean signal: as long as the noise does not flip the sign, the error is cancelled at every leg.
2. Discrete-time systems and FIR filters
Definition (discrete-time system). A process that transforms an input sequence x[n] into an output sequence y[n]: y[n]=T{x[n]}. In general y[n] depends on the whole input: past, present and future.
Two fundamental signals. The unit sampleδ[n]=1 for n=0 and 0 otherwise (the Kronecker delta, not the Dirac delta); the unit stepu[n]=1 for n≥0 and 0 for n<0. Relations: δ[n]=u[n]−u[n−1], u[n]=∑k=−∞nδ[k]. Above all every signal is a sum of shifted and weighted impulses:
x[n]=k=−∞∑∞x[k]δ[n−k],
because δ[n−k] equals 1 only for n=k. Example.x={2,4,6,4,2} for n=0,…,4 is 2δ[n]+4δ[n−1]+6δ[n−2]+4δ[n−3]+2δ[n−4].
The moving average
Each output sample is the average of a sliding window of input samples. With three points "forward":
y[n]=31(x[n]+x[n+1]+x[n+2]).
This is a difference equation: a complete description of the filter since it allows y[n] to be computed for every n.
Worked example. With x={2,4,6,4,2} for n=0,…,4: y[0]=31(2+4+6)=4; y[1]=31(4+6+4)=314; y[−1]=31(0+2+4)=2, y[−2]=31(0+0+2)=32; y[3]=31(4+2+0)=2, y[4]=32; y[n]=0 outside −2≤n≤4. So y={32,2,4,314,4,2,32} for n=−2,…,4. Both input and output have finite support: the output is two samples longer because the window begins to "see" the signal before the input starts and ends after it.
Causality. In this form the output begins (at n=−2) before the input: the filter uses the future of the input. A system that uses only present and past values is causal; one that uses future values is non-causal and cannot be implemented in real time. This is not a defect for a recorded signal (images, saved audio), where the future exists and is often convenient to use. The causal three-point average is
y[n]=31(x[n]+x[n−1]+x[n−2]).
It gives the same numbers {32,2,4,314,4,2,32} but starting from n=0: the support is shifted by two samples, the values are the same. The centred filter y[n]=31(x[n+1]+x[n]+x[n−1]) gives the same values starting from n=−1: it is symmetric, so it does not delay the signal.
Moving average of L points:y[n]=L1∑k=0L−1x[n−k]. The longer the window, the smoother the output and the longer the transient at the edges. Example. Input x[n]=1.02n+0.5cos(82πn+4π), 0≤n≤40: a slow exponential growth plus an oscillation of period 8 samples. The filter lets the slow part through almost intact and attenuates the oscillation: with L=3 the sinusoid amplitude drops from 0.5 to 0.5⋅0.805=0.402, with L=7 to 0.5⋅71=0.0714. The output also arrives late by 2M=2L−1 samples (1 for L=3, 3 for L=7).
The causal FIR filter
Definition (FIR filter, finite impulse response). A causal FIR filter of orderM is the system
y[n]=k=0∑Mbkx[n−k]=b0x[n]+b1x[n−1]+⋯+bMx[n−M].
It is a weighted moving average of L=M+1 samples, and L is the length of the filter. The numbers bk are the coefficients.
The three-point average is the case M=2, b0=b1=b2=31. Beware of the difference between orderM (number of delays) and lengthL=M+1 (number of coefficients): confusing them is the most frequent mistake.
Support of the output. If the input has support 0≤n≤N−1 (length N), the window of M+1 samples starts touching the signal at n=0 and stops at n=N−1+M: the output has length N+M. With N=5, M=2 one gets the 7 samples above.
Impulse response. With x=δ[n] in the equation, y[n]=∑kbkδ[n−k], which equals bn for n=0,…,M and 0 elsewhere:
h[n]={bn00≤n≤Motherwise
The impulse response of an FIR is the sequence of its coefficients: it lasts M+1 samples and then vanishes, hence "finite impulse response". IIR filters instead have an internal feedback and can respond forever (usually with a decay).
Two simple cases: a delayy[n]=x[n−n0] is an FIR with a single non-zero coefficient (for n0=3: {bk}={0,0,0,1}, h[n]=δ[n−3]); the running sum of 3 points with step input gives 1,2,3,3,3,…; the 5-point moving average on the step gives 0.2;0.4;0.6;0.8;1;1;….
Block diagrams. Three operations are needed: multiply by a constant, add, delay by one sample (the only element with memory). In the direct form the input runs through a chain of delays, each tap is multiplied by a bk and the products are summed. In the transposed formx[n] is sent in parallel to all multipliers and the delay chain collects the partial sums. The two forms have the same equation. FIR filters are feed-forward: no loops.
Example (cost of a cascade). Two moving averages h1={1,1,1,1} and h2={1,1,1} in cascade equal a single filter h={1,2,3,3,2,1}. As a single filter it takes 6 multiplications and 5 additions; as a cascade w[n]=∑k=03x[n−k], y[n]=∑k=02w[n−k] it takes only additions and no multiplications. In hardware a multiplier costs far more area and power than an adder.
3. FIR design with the window method
An ideal low-pass filter passes everything up to a cut-off frequency and blocks the rest: its impulse response is infinite and non-causal, so it cannot be realised. Designing an FIR filter means finding the coefficients h[0],…,h[N] of a causal finite-response filter whose frequency response approximates the ideal one within assigned tolerances. Only linear-phase filters are considered, so the design concerns the modulus only.
Low-pass specifications
ω^p: pass-band edge; for ∣ω^∣≤ω^p the signal passes practically unaltered.
ω^s: stop-band edge; for ω^s≤∣ω^∣≤π the signal is strongly suppressed. Between the two there is the transition band.
δp: pass-band error, 1−δp≤∣H(ejω^)∣≤1+δp.
δs: stop-band error, ∣H(ejω^)∣≤δs.
In decibels: pass-band ripple Rp=20log101−δp1+δp and stop-band attenuation As=−20log10δs.
Example.δp=δs=10−2.5=0.00316: As=50 dB, Rp=0.055 dB. With δp=0.05 and δs=0.01: Rp=0.87 dB and As=40 dB.
Type I linear-phase filter
A causal FIR of order N has N+1 coefficients; it has linear phase if h[n]=±h[N−n]. In type I (N even, symmetry +):
with p0=h[N/2] and pn=2h[N/2−n]. Hˉ is real and is the amplitude response; the phase is exactly −ω^N/2 (a delay of N/2 samples). Example.N=4, h={1,2,3,2,1}: p0=3, p1=4, p2=2, Hˉ(ω^)=3+4cosω^+2cos2ω^ and Hˉ(0)=9=∑h[n].
The goal: the Fourier series of the desired amplitude
One wants Hd(ejω^)=e−jω^N/2D(ω^), where D is the desired amplitude: real, non-negative and periodic with period 2π. Being periodic, it has a Fourier series:
An FIR response is a finite sum ∑n=0Nh[n]e−jω^n, the desired one an infinite sum: the design is choosing h[n] so that the finite sum approximates the infinite one. Three methods: windows (truncating the series), frequency sampling (h is the IDFT of samples of D), minimax (minimising the maximum weighted error).
The window method
For type I one works with the symmetric non-causal filter hˉ[n], −N/2≤n≤N/2, taking the central coefficients of the series:
and the causal filter is obtained by delaying by N/2 samples: h[n]=hˉ[n−2N], n=0,…,N. The delay does not change the modulus. Ideal low-pass: for D=1 in ∣ω^∣≤ω^0 and 0 elsewhere
Example.N=20, ω^0=π/3, rectangular window: h[10]=31=0.3333, h[10±1]=0.2757, h[10±2]=0.1378, h[10±3]=0, h[10±4]=−0.0689, h[10±5]=−0.0551, h[10±6]=0, h[10±7]=0.0394, h[10±8]=0.0345, h[10±9]=0, h[10±10]=−0.0276. The sum is 1.0048≈1 (the DC gain).
Optimality (theorem). Among all linear-phase FIR filters of order N=2r, the partial sum Hˉ(ω^)=∑n=−rrhd[n]e−jω^n minimises the mean squared error E2=2π1∫−ππ(D−Hˉ)2dω^. Proof. By Parseval E2=∑∣n∣≤r(hd[n]−hˉ[n])2+∑∣n∣>rhd[n]2; the last sum does not depend on hˉ, the first is non-negative and vanishes if and only if hˉ[n]=hd[n] for ∣n∣≤r. □ The truncation is optimal in the mean-square sense but not in the worst case.
Gibbs phenomenon. Multiplying by wR[n] in time is convolving in frequency:
with L=N+1 the length (the Dirichlet kernel). WR equals L at 0 and vanishes at ω^=L2πk, k=0. The part between the first two zeros ±L2π is the main lobe, of width L4π; the others are side lobes. The first side lobe is about 22% of the main one (−13.3 dB) whatever L is: increasing L narrows the lobes but does not lower them. Near a jump of D the alternating-sign side lobes enter and leave the jump and produce oscillations (Gibbs phenomenon). With ω^0=π/3 the maximum of Hˉ is 1.0706 for L=21, 1.0928 for L=61, 1.0908 for L=151, 1.0900 for L=401: the overshoot converges to about 9% of the jump. The error in pass-band and stop-band is about δp≃δs≃0.09, i.e. As≃21 dB, and does not depend on L; what depends on L is the transition width, about 0.9⋅L2π.
Other windows. To lower the side lobes a smoother window that falls gently towards the edges is used; the price is a wider main lobe, i.e. a wider transition. Non-causal expressions of odd length L=N+1, ∣n∣≤N/2:
window
w[n]
rectangular
1
triangular (Bartlett)
1−N/2∣n∣
Hann
21+21cosN2πn
Hamming
0.54+0.46cosN2πn
Blackman
0.42+0.5cosN2πn+0.08cosN4πn
Their spectra are combinations of shifted Dirichlet kernels, whose side lobes partially cancel. Typical values:
window
main lobe
max side lobe
transition band
minimum attenuation As
rectangular
2⋅L2π
−13.3 dB
0.9⋅L2π
21 dB
triangular
4⋅L2π
−26.5 dB
3⋅L2π
26 dB
Hann
4⋅L2π
−31.5 dB
3.1⋅L2π
44 dB
Hamming
4⋅L2π
−42.7 dB
3.3⋅L2π
54 dB
Blackman
6⋅L2π
−57 dB
5.5⋅L2π
74 dB
Three general facts for all fixed windows: (1) the transition width is inversely proportional to the length, 2πω^s−ω^p≃Lα, with α depending only on the window; (2) the errors are almost equal in the two bands, δp≃δs, and depend only on the window type, not on L; (3) neither depends on the cut-off ω^0=2ω^p+ω^s. So with fixed windows δp and δs cannot be chosen separately. These figures are rules of thumb.
Kaiser window. It has a parameter β that sets the attenuation:
w[n]=I0(β)I0(β1−(N2n)2),∣n∣≤2N,
with I0 the modified Bessel function of order zero. With β=0 it is the rectangular window (As=21 dB). Given As in dB and the transition band, the empirical formulas are
Example.As=50 dB, ω^s−ω^p=0.125π: β=0.5842⋅290.4+0.07886⋅29=4.534 and N≥14.36⋅0.062542=46.8, so N=48 (even, for type I).
Design procedure. (1) Compute the ideal hd[n] with cut-off ω^0=2ω^p+ω^s. (2) Choose the window from the required As and the order from the transition width: L=N+1≥αω^s−ω^p2π. (3) Compute hˉ[n]=hd[n]w[n] and delay to make it causal. (4) Compute H(ejω^) and verify the specifications; if not met, increase N or change window.
Complete example and comparison.Fs=8 kHz, pass-band up to fp=1 kHz, stop-band from fs=1.5 kHz, As=50 dB (δp=δs=0.00316): ω^p=0.25π, ω^s=0.375π, ω^0=0.3125π. Rectangular: no good, δ≃0.09 whatever N. Hamming: L≃3.3⋅0.125π2π=52.8, so N=52; numerical check: δs=0.00330 (As=49.6 dB), just out of specification; with N=54, δp=0.00258, δs=0.00220, the specification is met. Hann and Blackman need N=76 and N=74. Kaiser: β=4.55, N=48 (δp=0.00299, δs=0.00260). Minimax: N=42 (δp=δs=0.00279). The table is a rule of thumb, not a guarantee: step 4 is needed.
Minimax (Parks-McClellan). The maximum weighted error W(ω^)∣D(ω^)−Hˉ(ω^)∣ over the bands (transition excluded) is minimised. Alternation theorem:Hˉ=∑n=0rpncos(nω^) is optimal if and only if the weighted error has at least r+2alternations. The response is equiripple. With weights W=101 in the pass-band and 1 in the stop-band, δs is ten times smaller than δp. The order is estimated by
N≃14.62πω^s−ω^p−10log10(δpδs)−13,
inversely proportional to the transition width, independent of the cut-off. Example:δp=δs=0.00316 gives N≃40.5 (actual value 42).
method
what it controls
optimal?
errors
order
windows
h from hd and the window
no (rectangular is optimal in mean square)
almost equal, fixed by the window
higher
frequency sampling
H exact at the samples
no
not controlled between samples
depends on samples
minimax
maximum weighted error
yes, worst case
chosen with weight W, equiripple
the lowest
For the same specification, orders 54 (Hamming), 48 (Kaiser), 42 (minimax): the minimax filter is the shortest, therefore also with the smallest delay (N/2 samples).
4. The Butterworth IIR filter
For the bilinear transformation an analog low-pass prototype is needed. The all-pole analog filters have Ha(s)=Da(s)1 (all zeros at infinity): Butterworth and Chebyshev type 1; those with finite zeros are Chebyshev type 2 and elliptic.
filter
pass-band
stop-band
Butterworth
monotonic
monotonic
Chebyshev type 1
equiripple
monotonic
Chebyshev type 2
monotonic
equiripple
elliptic
equiripple
equiripple
Analog specifications.A1=δs (A is the stop-band attenuation) and 1+ε21=1−δp, so ε2=10Rp/10−1 and A=10Rs/20, with Rs=−20log10δs. The conditions are ∣Ha(jΩp)∣2≥1+ε21 and ∣Ha(jΩs)∣2≤A21. Example.Rp=0.1 dB and Rs=40 dB: ε2=0.02329 (ε=0.1526) and A=100.
Squared modulus. The Butterworth filter is defined by maximal flatness of the modulus at Ω=0. For a real filter the squared modulus is even in Ω: ∣Ha(jΩ)∣2=PN(Ω2)1 with PN(Ω2)=p0+p1Ω2+⋯+pNΩ2N. Three constraints: (1) unit DC gain, p0=1; (2) maximal flatness at 0: PN−1 must be an infinitesimal of maximal order, so p1=⋯=pN−1=0 and PN=1+pNΩ2N; (3) at the cut-off ∣Ha(jΩ0)∣2=21 (−3 dB, modulus 21≃0.707), so pN=Ω0−2N:
∣Ha(jΩ)∣2=1+(Ω0Ω)2N1.
It equals 1 at 0, 21 at Ω0 for every N, and decreases monotonically; for N→∞ it tends to the ideal rectangle. At Ω=2Ω0 (one octave above the cut-off) the attenuation is 10log10(1+22N)≃6N dB: 24 dB for N=4, 48 dB for N=8.
Transfer function. One looks for the stable rational Ha(s) with Ha(s)Ha(−s)=1+(jΩ0s)2N1. The poles are sk=Ω0ejπ(21+2N2k−1), k=1,…,2N: 2N poles on a circle of radius Ω0, half in the left half-plane, half in the right. For a causal stable system Ha(s) takes the N poles with Resk<0:
Ha(s)=∏k=1N(s−sk)Ω0N,
with the constant fixed by Ha(0)=1. Examples (Ω0=1).N=2: Ha(s)=s2+2s+11. N=3: poles −1 and −21±j23, Ha(s)=s3+2s2+2s+11. A Butterworth filter is completely specified by two parameters: N and Ω0.
Digital filter. With the bilinear transformation s=z+1z−1 the N zeros at infinity become a zero of multiplicity N at z=−1:
with A chosen so that H(1)=1. The poles are inside the unit circle. Substituting Ω=tan2ω^:
∣H(ejω^)∣2=1+(Ω0tan(ω^/2))2N1.
The digital −3 dB cut-off is ω^0=2arctanΩ0: for Ω0=1 it is ω^0=π/2.
Choosing the order from the specifications. Given ω^p,ω^s,Rp,Rs: Ωp=tan2ω^p, Ωs=tan2ω^s. Imposing equality in the two conditions: (Ω0Ωp)2N=ε2 and (Ω0Ωs)2N=A2−1. Dividing eliminates Ω0, (ΩpΩs)2N=ε2A2−1:
N≥2log10ΩpΩslog10ε2A2−1
rounded up. Then Ω0 lies between Ωpε−1/N and Ωs(A2−1)−1/(2N); since N was rounded up, one of the two conditions is met with margin.
Example.Fs=8 kHz, fp=1 kHz, fs=2 kHz, Rp=0.1 dB, Rs=40 dB. ω^p=4π, ω^s=2π, Ωp=tan8π=0.4142, Ωs=1, ε=0.1526, A=100: N≥2log10(1/0.4142)log10(9999/0.02329)=0.76565.6327=7.358, so N=8; the two values of Ω0 are 0.5623 and 0.5239.
Phase. Like all IIR filters the Butterworth filter has no linear phase: its group delay grows near the cut-off. For the specifications ω^p=0.25π, ω^s=0.375π, Rp=0.055 dB, As=50 dB the orders are 17 (Butterworth), 9 (Chebyshev 1), 6 (elliptic).
5. Multirate processing: decimation and interpolation
Audio, images and video use signals with different sampling rates: a CD has 44.1 kHz, a professional file 48 kHz. Processing that changes the sampling rate is called multirate. Three cases: interpolation (Fs′=LFs), decimation (Fs′=Fs/M), generic conversion (Fs′=MLFs with L,M coprime). The goals are to preserve in the output as much of the input information as possible and to do so at low computational cost.
Interpolation
The expander (upsampler) inserts L−1 zeros between two consecutive samples: v[n]=x[n/L] for n=0,±L,±2L,…, 0 elsewhere. Example.x={1,2,3}, L=3: v={1,0,0,2,0,0,3,0,0}. It is linear and time-invariant and loses no information.
Theorem (spectrum of the expander).V(ejω^)=X(ejLω^).
Proof.V(ω^)=∑nv[n]e−jω^n=∑kx[k]e−jω^kL, since only the terms n=kL are non-zero. This is X evaluated at Lω^. □
X has period 2π, so X(ejLω^) has period L2π: the input spectrum is compressed by a factor L and repeated L times in (−π,π): the original plus L−1images. Example.x[n]=cos(0.4πn), L=3: lines at 0.1333π (the original, compressed), 0.5333π and 0.8π (the two images).
An ideal low-pass filter with cut-off Lπ and gain L removes the L−1 images. The ideal filter has h[n]=sinc(Ln), which equals 1 at n=0 and vanishes at all other multiples of L, so y[kL]=x[k]: the correct interpolation property (the original samples are not modified, the new ones are inferred). The ideal sinc is not realisable; it is approximated with an FIR designed with windows (for instance Hamming; the window method preserves the zeros of hd at the multiples of L, hence the property).
Linear interpolation. With few resources, samples are joined by segments: the impulse response is a triangle
with frequency response H(ejω^)=L1(sin(ω^/2)sin(Lω^/2))2 (for L=2: 1+cosω^), gain L at DC. It is far from the ideal (a rectangle up to Lπ): for L=5 the normalised gain is 0.42 at 5π, and beyond 0.4π the maximum gain is still 0.0625, only −24 dB. So linear interpolation gives good results only if the signal occupies frequencies much lower than the maximum.
Multistage interpolation. If L=L1L2⋯LK it is better to interpolate in K stages: each filter has a wider transition band relative to its working frequency, hence fewer coefficients. The minimum cost is with the factors in increasing order (the smallest factor first). Example (a 2 kHz signal with useful band up to 800 Hz interpolated by L=24 to 48 kHz with 60 dB attenuation; multiplications per second): one stage 876000; 2×12: 378000; 12×2: 680000; 3×8: 366000; 8×3: 536000. In all cases multistage costs less than a single stage, and for each pair the small factor first costs less.
Decimation
The decimator keeps one sample out of M: y[n]=x[nM]. Example.x={1,…,7}, M=3: y={1,4,7}. It is linear but not time-invariant and in general loses information.
Theorem (spectrum of the decimator).Y(ejω^)=M1k=0∑M−1X(ejMω^−2πk).
Proof. Define u[n]=x[n]p[n] with p[n]=∑kδ[n−kM] (an impulse comb: 1 at multiples of M). Then u[n]=x[n] if M divides n and 0 otherwise, and y[m]=u[mM]. The DTFT of the comb is P(ω^)=M2π∑k=0M−1δ(ω^−M2πk), and the product in time is a convolution in frequency: U(ω^)=M1∑k=0M−1X(ω^−M2πk). Then Y(ω^)=∑mu[mM]e−jω^m=∑nu[n]e−jω^n/M=U(ω^/M). □
So Y is the sum of M versions of the spectrum of X, dilated by M and shifted by 2πk, divided by M. The replicas overlap if X occupies more than ∣ω^∣<Mπ: this is aliasing of decimation. Example.x[n]=cos(0.6πn) and M=2: y[n]=cos(1.2πn)=cos(0.8πn), because 1.2π≡−0.8π(mod2π). The frequency 0.6π>2π reappears falsely at 0.8π.
To limit aliasing the decimator is preceded by a low-pass filter with cut-off Mπ (in Hz 2MFs=2Fs′) and gain 1. For x[n]=cos(0.6πn), M=2, the prefilter removes the component: the output is practically zero instead of a false sinusoid. In multiple stages, M=M1⋯MK, the minimum cost is with the factors in decreasing order (the largest first). Example with Fs=48 kHz, M=24, useful band 800 Hz, 60 dB: one filter of order 437 costs 876000 multiplications/s; 12×2 costs 378000 against 680000 for 2×12; 8×3 costs 366000 against 536000 for 3×8.
Generic conversion Fs′=MLFs
It is a cascade of three blocks (the order matters: interpolate first, then decimate): an expander ↑L, a low-pass filter g working at Fs′′=LFs=MFs′, a decimator ↓M. The anti-image filter (cut-off Lπ) and the anti-aliasing filter (cut-off Mπ) are in cascade at the same rate and are replaced by one low-pass filter with gain L and cut-off
ω^c=min(Lπ,Mπ).
The input-output equation is y[n]=∑ix[i]g[nM−iL]. This is not a convolution: the system is linear but not time-invariant; it is periodically time-invariant (shifting the input by M samples shifts the output by L samples). Example (audio). From 44.1 kHz to 48 kHz: 4410048000=147160, so L=160, M=147, Fs′′=7056 kHz, cut-off 160π (22.05 kHz). Computing at 7 MHz would be prohibitive: the polyphase structure is used, which splits g into L subfilters gr[k]=g[kL+r] and computes only the output samples: LK multiplications per output sample instead of K for interpolation; for decimation, K multiplications every M input samples.
Typical mistakes
Confusing order M (delays) with length M+1 (coefficients).
Taking the window-design tables as a guarantee: verify H against the specifications.
Not rounding the Butterworth order up; confusing Ω0 with the digital frequency ω^0.
Inverting the order of the multirate blocks (decimating before interpolating loses information), or thinking the system is LTI.
Decimating without the anti-aliasing low-pass filter.
Versione ripasso
Chain. LPF, A/D, DSP, D/A, LPF; assumptions: band-limited input and Fs≥2B. A/D: uniform quantizer with q=Vx/2B−1, error at most q/2 (B=16, Vx=1 V: q≈30.5μV). D/A: zero-order hold. Digital wins on precision, reliability, adaptivity; digital repeaters regenerate with a threshold (analog noise Nσ/G).
FIR. Causal FIR of order M (length L=M+1): y[n]=∑k=0Mbkx[n−k]; h[n]=bn for 0≤n≤M. δ[n]=u[n]−u[n−1]; x[n]=∑kx[k]δ[n−k]. Three-point average on {2,4,6,4,2}: causal {32,2,4,314,4,2,32} from n=0; centred, same values from n=−1. Support: input N, output N+M. Non-causal = uses future samples: fine on recordings. L-point average y[n]=L1∑x[n−k]; delay 2L−1. Step: running sum 1,2,3,3,…; 5-point average 0.2,0.4,…,1. Direct and transposed forms, same equation; feed-forward. Cascade {1,1,1,1} and {1,1,1} equals {1,2,3,3,2,1}: 6 multiplications as one filter, none as a cascade.
Type I.N even, h[n]=h[N−n]: H=e−jω^N/2Hˉ, Hˉ=∑n=0N/2pncos(nω^), p0=h[N/2], pn=2h[N/2−n]. h={1,2,3,2,1}: Hˉ=3+4cosω^+2cos2ω^.
Window method.hˉ[n]=hd[n]w[n] for ∣n∣≤N/2, then h[n]=hˉ[n−N/2]. Ideal low-pass hd[n]=πnsin(ω^0n)=πω^0sincπω^0n, hd[0]=πω^0. N=20, ω^0=3π: h[10]=31, h[10±1]=0.2757, h[10±2]=0.1378, zeros at ±3,±6,±9; sum 1.0048.
Optimality: truncation minimises the mean square error (Parseval), not the maximum error.
Gibbs:Hˉ=2π1∫D(θ)WR(ω^−θ)dθ, Dirichlet kernel, main lobe L4π, first side lobe −13.3 dB (about 22%), independent of L; overshoot about 9%, As≃21 dB, independent of L; transition about 0.9L2π.
Three facts:2πω^s−ω^p≃Lα; δp≃δs depends on the window only; neither depends on the cut-off.
Kaiser:w=I0(β)I0(β1−(2n/N)2); β=0.1102(As−8.7) for As>50; 0.5842(As−21)0.4+0.07886(As−21) for 21<As≤50; N≥14.36ΔfAs−8 with Δf=2πω^s−ω^p. As=50, transition 0.125π: β≈4.55, N=48.
Procedure: cut-off 2ω^p+ω^s; window from As; order from the transition; hdw and delay; verify.
ExampleFs=8 kHz, fp=1, fs=1.5 kHz, 50 dB: rectangular fails (δ≃0.09); Hamming N=52 gives 49.6 dB (not enough), N=54 works; Hann 76, Blackman 74; Kaiser 48; minimax 42.
Frequency sampling:H[k]=e−jω^kN/2D(ω^k) at ω^k=L2πk, h=IDFT; exact at samples, uncontrolled between; error = time aliasing; a transition sample helps (D=0.5) at the cost of a wider transition.
Minimax: minimise maxW∣D−Hˉ∣; optimal iff ≥r+2 alternations; equiripple; weights set δs/δp. N≃14.6Δf−10log10(δpδs)−13 (40.5 vs actual 42). Same specification: orders 54, 48, 42.
Butterworth.∣Ha(jΩ)∣2=1+(Ω/Ω0)2N1: maximally flat, monotonic, 21 at Ω0 for every N; 2Ω0: 10log10(1+22N)≈6N dB. Construction: p0=1, PN=1+pNΩ2N, pN=Ω0−2N. Poles sk=Ω0ejπ(21+2N2k−1) (2N on a circle); Ha(s)=∏(s−sk)Ω0N with the N left poles. N=2: s2+2s+11; N=3: s3+2s2+2s+11.
Digital:H(z)=A∏(1−pkz−1)(1+z−1)N, pk=1−sk1+sk, A=2N∏(1−pk); ∣H∣2=1+(tan(ω^/2)/Ω0)2N1; cut-off 2arctanΩ0 (2π for Ω0=1).
No linear phase (IIR). Orders for the same specification: Butterworth 17, Chebyshev 1 9, elliptic 6. Families: Butterworth, Chebyshev 1 (all-pole), Chebyshev 2, elliptic.
Multirate. Expander: v[n]=x[n/L] at multiples of L; V(ω^)=X(Lω^); spectrum compressed and repeated (images); low-pass with cut-off Lπ and gain L. x={1,2,3}, L=3: {1,0,0,2,0,0,3,0,0}. cos(0.4πn), L=3: lines at 0.1333π, 0.5333π, 0.8π. Correct interpolation: h[n]=sincLn, y[kL]=x[k]; windowed FIR keeps the zeros. Linear: h[n]=1−L∣n∣, H=L1(sin(ω^/2)sin(Lω^/2))2; L=5: beyond 0.4π only −24 dB; good only for low-frequency signals. Multistage interpolation: small factors first (24: 876000 vs 3×8366000, 2×12378000, 12×2680000).
Decimator y[n]=x[nM] ({1..7}, M=3: {1,4,7}): Y=M1∑kX(Mω^−2πk) (impulse comb); aliasing beyond Mπ; cos(0.6πn), M=2 becomes cos(0.8πn); prefilter cut-off Mπ, gain 1. Multistage: large factors first (12×2378000 vs 680000; 8×3366000 vs 536000).
Rational ML: ↑L, one low-pass (gain L, cut-off min(Lπ,Mπ)), ↓M; y[n]=∑ix[i]g[nM−iL], not a convolution, periodically time-invariant. 44.1→48 kHz: L=160, M=147, cut-off 160π; polyphase: LK multiplications per output sample.
Typical mistakes: order vs length; tables as guarantees; Butterworth order not rounded up; Ω0 vs ω^0; wrong order of multirate blocks; decimating without a prefilter.
More reminders.
Analysis and synthesis: analysis extracts information (filtering, denoising), synthesis builds a signal that contains information (synthetic music, telephony, radio). A computer processes exactly only digital signals.
Impulse as a basis:x={2,4,6,4,2} equals 2δ[n]+4δ[n−1]+6δ[n−2]+4δ[n−3]+2δ[n−4]; a delay y[n]=x[n−3] has {bk}={0,0,0,1}, h[n]=δ[n−3].
Moving average, L=3 and 7: attenuation of the period-8 sinusoid 0.805 and 71 (amplitudes 0.402 and 0.0714), delay 1 and 3 samples.
Specifications example:δp=0.05, δs=0.01 give Rp=0.87 dB, As=40 dB.
Window method steps: (1) ideal hd with cut-off 2ω^p+ω^s; (2) window from As, order from L≥αω^s−ω^p2π; (3) hdw and delay; (4) verify H. Advantage: simple, keeps the zeros of hd; drawback: not optimal, δp≃δs.
Gibbs values:ω^0=3π: maximum 1.0706 (L=21), 1.0928 (61), 1.0908 (151), 1.0900 (401): about 9%.
Kaiser:β=0 is rectangular; β=0.5842⋅290.4+0.07886⋅29=4.534 for As=50.
Frequency sampling: exact at ω^k=L2πk; equals the ideal response folded with period L; transition sample D=0.5 lowers the oscillation.
Minimax: weights W=101 pass-band and 1 stop-band give δs=10δp; Remez solves a linear system of r+2 equations. The minimax filter is the shortest for the same specification (order 42 against 54 for Hamming), so it also has the least delay.
Butterworth family: all-pole (Butterworth, Chebyshev 1) against finite zeros (Chebyshev 2, elliptic); Butterworth monotonic in both bands; Chebyshev 1 equiripple in the pass-band; Chebyshev 2 equiripple in the stop-band; elliptic in both.