Salta al contenuto
Note per Studenti Digital Filtering of Audio Signals Report

Digital Filtering of Audio Signals

In questa pagina 6

Digital filtering is the core of audio processing: removing noise, isolating a band, changing the sampling rate. This note covers FIR filters and their design with windows, the IIR Butterworth filter, and multirate processing (decimation and interpolation). Sampling itself and aliasing are in Digital Representation of Audio and Image SignalsAnalog-to-digital conversion has three steps, sampling at Fs at least twice the signal bandwidth after an anti-aliasing low-pass filter, uniform quantization on L = 2^b levels, and binarization of each level into b bits, giving a nominal bit-rate R = Fs times b times the number of channels (speech 64 kbit/s, CD audio 1.411 Mbit/s); an image is a two-dimensional sampled signal with 8 bits per grey level or 24 bits per RGB pixel (12 in YCbCr 4:2:0), and quality is measured with MSE and PSNR.Digital Representation of Audio and Image Signals →; spectral analysis is in Spectral Analysis of Audio - DFT, Windows and SpectrogramObserving L samples of a signal means multiplying by a rectangular window, so a sinusoid shows up not as a line but as a Dirichlet kernel with main lobe 4 pi / L and first side lobe at -13.3 dB; closer tones merge (resolution depends only on L and the window), strong tones mask weak ones (leakage), the DFT samples the spectrum at 2 pi k / N so the amplitude is exact only if the tone falls on a bin (loss up to 3.9 dB), zero-padding refines the samples without improving resolution, tapered windows lower side lobes and widen the main lobe, and the short-time Fourier transform with its spectrogram follows signals whose frequency content changes in time at the cost of a time-frequency trade-off.Spectral Analysis of Audio - DFT, Windows and Spectrogram →.

In the course the sampling step is taken as T=1T=1: the signal is a sequence x[n]x[n], n∈Zn\in\mathbb Z, and frequencies are normalised (ω^\hat\omega, with ω^=2πf/Fs\hat\omega=2\pi f/F_s).

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)x(t) is the chain: input low-pass filter (LPF) →\to A/D converter →\to digital signal processing (DSP) →\to D/A converter →\to output LPF. Two assumptions: the input is band-limited (the task of the first LPF, which prevents aliasing) and FsF_s 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][-V_x,V_x] and the converter has BB bits, each sample is replaced by the nearest level x^=k q\hat x=k\,q with step

q=Vx2B−1,∣x−x^∣≤q2.q=\frac{V_x}{2^{B-1}},\qquad \lvert x-\hat x\rvert\le\frac q2 .

Example. B=16B=16 and Vx=1 VV_x=1\ \mathrm V: q=1/215 V≈30.5 μVq=1/2^{15}\ \mathrm V\approx30.5\ \mu\mathrm V and the maximum error is q/2≈15.3 μVq/2\approx15.3\ \mu\mathrm V. An 8-bit converter with the same range gives q=1/128=7.8 mVq=1/128=7.8\ \mathrm{mV}. The D/A converter holds the value constant until the next sample (zero-order hold, H0(f)=T sinc(fT) e−jπfTH_0(f)=T\,\mathrm{sinc}(fT)\,e^{-j\pi 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/G1/G and obtains x(t)+σ(t)/Gx(t)+\sigma(t)/G: the noise is amplified and accumulates; with G=0.5G=0.5 and independent noise of standard deviation 11 per leg, after N=10N=10 legs the noise standard deviation is 10⋅1/0.5≈6.3\sqrt{10}\cdot1/0.5\approx6.3. A digital repeater applies a threshold, x^=sgn[Gx+σ]\hat x=\mathrm{sgn}[Gx+\sigma], 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]x[n] into an output sequence y[n]y[n]: y[n]=T{x[n]}y[n]=T\{x[n]\}. In general y[n]y[n] depends on the whole input: past, present and future.

Two fundamental signals. The unit sample δ[n]=1\delta[n]=1 for n=0n=0 and 00 otherwise (the Kronecker delta, not the Dirac delta); the unit step u[n]=1u[n]=1 for n≥0n\ge0 and 00 for n<0n<0. Relations: δ[n]=u[n]−u[n−1]\delta[n]=u[n]-u[n-1], u[n]=∑k=−∞nδ[k]u[n]=\sum_{k=-\infty}^{n}\delta[k]. Above all every signal is a sum of shifted and weighted impulses:

x[n]=∑k=−∞∞x[k] δ[n−k],x[n]=\sum_{k=-\infty}^{\infty}x[k]\,\delta[n-k],

because δ[n−k]\delta[n-k] equals 11 only for n=kn=k. Example. x={2,4,6,4,2}x=\{2,4,6,4,2\} for n=0,…,4n=0,\dots,4 is 2δ[n]+4δ[n−1]+6δ[n−2]+4δ[n−3]+2δ[n−4]2\delta[n]+4\delta[n-1]+6\delta[n-2]+4\delta[n-3]+2\delta[n-4].

The moving average

Each output sample is the average of a sliding window of input samples. With three points "forward":

y[n]=13(x[n]+x[n+1]+x[n+2]).y[n]=\tfrac13\big(x[n]+x[n+1]+x[n+2]\big).

This is a difference equation: a complete description of the filter since it allows y[n]y[n] to be computed for every nn.

Worked example. With x={2,4,6,4,2}x=\{2,4,6,4,2\} for n=0,…,4n=0,\dots,4: y[0]=13(2+4+6)=4y[0]=\frac13(2+4+6)=4; y[1]=13(4+6+4)=143y[1]=\frac13(4+6+4)=\frac{14}3; y[−1]=13(0+2+4)=2y[-1]=\frac13(0+2+4)=2, y[−2]=13(0+0+2)=23y[-2]=\frac13(0+0+2)=\frac23; y[3]=13(4+2+0)=2y[3]=\frac13(4+2+0)=2, y[4]=23y[4]=\frac23; y[n]=0y[n]=0 outside −2≤n≤4-2\le n\le4. So y={23,2,4,143,4,2,23}y=\{\frac23,2,4,\frac{14}3,4,2,\frac23\} for n=−2,…,4n=-2,\dots,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=−2n=-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]=13(x[n]+x[n−1]+x[n−2]).y[n]=\tfrac13\big(x[n]+x[n-1]+x[n-2]\big).

It gives the same numbers {23,2,4,143,4,2,23}\{\frac23,2,4,\frac{14}3,4,2,\frac23\} but starting from n=0n=0: the support is shifted by two samples, the values are the same. The centred filter y[n]=13(x[n+1]+x[n]+x[n−1])y[n]=\frac13(x[n+1]+x[n]+x[n-1]) gives the same values starting from n=−1n=-1: it is symmetric, so it does not delay the signal.

Moving average of LL points: y[n]=1L∑k=0L−1x[n−k]y[n]=\frac1L\sum_{k=0}^{L-1}x[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⁡(2πn8+π4)x[n]=1.02^n+0.5\cos(\frac{2\pi n}{8}+\frac\pi4), 0≤n≤400\le n\le40: 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=3L=3 the sinusoid amplitude drops from 0.50.5 to 0.5⋅0.805=0.4020.5\cdot0.805=0.402, with L=7L=7 to 0.5⋅17=0.07140.5\cdot\frac17=0.0714. The output also arrives late by M2=L−12\frac{M}2=\frac{L-1}2 samples (11 for L=3L=3, 33 for L=7L=7).

The causal FIR filter

Definition (FIR filter, finite impulse response). A causal FIR filter of order MM is the system y[n]=∑k=0Mbk x[n−k]=b0x[n]+b1x[n−1]+⋯+bMx[n−M].y[n]=\sum_{k=0}^{M}b_k\,x[n-k]=b_0x[n]+b_1x[n-1]+\dots+b_Mx[n-M]. It is a weighted moving average of L=M+1L=M+1 samples, and LL is the length of the filter. The numbers bkb_k are the coefficients.

The three-point average is the case M=2M=2, b0=b1=b2=13b_0=b_1=b_2=\frac13. Beware of the difference between order MM (number of delays) and length L=M+1L=M+1 (number of coefficients): confusing them is the most frequent mistake.

Support of the output. If the input has support 0≤n≤N−10\le n\le N-1 (length NN), the window of M+1M+1 samples starts touching the signal at n=0n=0 and stops at n=N−1+Mn=N-1+M: the output has length N+MN+M. With N=5N=5, M=2M=2 one gets the 77 samples above.

Impulse response. With x=δ[n]x=\delta[n] in the equation, y[n]=∑kbkδ[n−k]y[n]=\sum_kb_k\delta[n-k], which equals bnb_n for n=0,…,Mn=0,\dots,M and 00 elsewhere:

h[n]={bn0≤n≤M0otherwiseh[n]=\begin{cases}b_n&0\le n\le M\\0&\text{otherwise}\end{cases}

The impulse response of an FIR is the sequence of its coefficients: it lasts M+1M+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 delay y[n]=x[n−n0]y[n]=x[n-n_0] is an FIR with a single non-zero coefficient (for n0=3n_0=3: {bk}={0,0,0,1}\{b_k\}=\{0,0,0,1\}, h[n]=δ[n−3]h[n]=\delta[n-3]); the running sum of 3 points with step input gives 1,2,3,3,3,…1,2,3,3,3,\dots; the 5-point moving average on the step gives 0.2; 0.4; 0.6; 0.8; 1; 1;…0.2;\,0.4;\,0.6;\,0.8;\,1;\,1;\dots.

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 bkb_k and the products are summed. In the transposed form x[n]x[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}h_1=\{1,1,1,1\} and h2={1,1,1}h_2=\{1,1,1\} in cascade equal a single filter h={1,2,3,3,2,1}h=\{1,2,3,3,2,1\}. As a single filter it takes 66 multiplications and 55 additions; as a cascade w[n]=∑k=03x[n−k]w[n]=\sum_{k=0}^3x[n-k], y[n]=∑k=02w[n−k]y[n]=\sum_{k=0}^2w[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]h[0],\dots,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\hat\omega_p: pass-band edge; for ∣ω^∣≤ω^p|\hat\omega|\le\hat\omega_p the signal passes practically unaltered.
  • ω^s\hat\omega_s: stop-band edge; for ω^s≤∣ω^∣≤π\hat\omega_s\le|\hat\omega|\le\pi the signal is strongly suppressed. Between the two there is the transition band.
  • δp\delta_p: pass-band error, 1−δp≤∣H(ejω^)∣≤1+δp1-\delta_p\le|H(e^{j\hat\omega})|\le1+\delta_p.
  • δs\delta_s: stop-band error, ∣H(ejω^)∣≤δs|H(e^{j\hat\omega})|\le\delta_s.

In decibels: pass-band ripple Rp=20log⁡101+δp1−δpR_p=20\log_{10}\dfrac{1+\delta_p}{1-\delta_p} and stop-band attenuation As=−20log⁡10δsA_s=-20\log_{10}\delta_s.

Example. δp=δs=10−2.5=0.00316\delta_p=\delta_s=10^{-2.5}=0.00316: As=50A_s=50 dB, Rp=0.055R_p=0.055 dB. With δp=0.05\delta_p=0.05 and δs=0.01\delta_s=0.01: Rp=0.87R_p=0.87 dB and As=40A_s=40 dB.

Type I linear-phase filter

A causal FIR of order NN has N+1N+1 coefficients; it has linear phase if h[n]=±h[N−n]h[n]=\pm h[N-n]. In type I (NN even, symmetry ++):

H(ejω^)=e−jω^N/2 Hˉ(ω^),Hˉ(ω^)=∑n=0N/2pncos⁡(nω^),H(e^{j\hat\omega})=e^{-j\hat\omega N/2}\,\bar H(\hat\omega),\qquad \bar H(\hat\omega)=\sum_{n=0}^{N/2}p_n\cos(n\hat\omega),

with p0=h[N/2]p_0=h[N/2] and pn=2h[N/2−n]p_n=2h[N/2-n]. Hˉ\bar H is real and is the amplitude response; the phase is exactly −ω^N/2-\hat\omega N/2 (a delay of N/2N/2 samples). Example. N=4N=4, h={1,2,3,2,1}h=\{1,2,3,2,1\}: p0=3p_0=3, p1=4p_1=4, p2=2p_2=2, Hˉ(ω^)=3+4cos⁡ω^+2cos⁡2ω^\bar H(\hat\omega)=3+4\cos\hat\omega+2\cos2\hat\omega and Hˉ(0)=9=∑h[n]\bar H(0)=9=\sum h[n].

The goal: the Fourier series of the desired amplitude

One wants Hd(ejω^)=e−jω^N/2D(ω^)H_d(e^{j\hat\omega})=e^{-j\hat\omega N/2}D(\hat\omega), where DD is the desired amplitude: real, non-negative and periodic with period 2π2\pi. Being periodic, it has a Fourier series:

D(ω^)=∑n=−∞+∞hd[n] e−jω^n,hd[n]=12π∫−ππD(ω^) ejω^n dω^.D(\hat\omega)=\sum_{n=-\infty}^{+\infty}h_d[n]\,e^{-j\hat\omega n},\qquad h_d[n]=\frac1{2\pi}\int_{-\pi}^{\pi}D(\hat\omega)\,e^{j\hat\omega n}\,d\hat\omega .

An FIR response is a finite sum ∑n=0Nh[n]e−jω^n\sum_{n=0}^{N}h[n]e^{-j\hat\omega n}, the desired one an infinite sum: the design is choosing h[n]h[n] so that the finite sum approximates the infinite one. Three methods: windows (truncating the series), frequency sampling (hh is the IDFT of samples of DD), minimax (minimising the maximum weighted error).

The window method

For type I one works with the symmetric non-causal filter hˉ[n]\bar h[n], −N/2≤n≤N/2-N/2\le n\le N/2, taking the central coefficients of the series:

hˉ[n]=hd[n] wR[n],wR[n]={1,∣n∣≤N/20,elsewhere,\bar h[n]=h_d[n]\,w_R[n],\qquad w_R[n]=\begin{cases}1,&|n|\le N/2\\0,&\text{elsewhere,}\end{cases}

and the causal filter is obtained by delaying by N/2N/2 samples: h[n]=hˉ ⁣[n−N2]h[n]=\bar h\!\left[n-\tfrac N2\right], n=0,…,Nn=0,\dots,N. The delay does not change the modulus. Ideal low-pass: for D=1D=1 in ∣ω^∣≤ω^0|\hat\omega|\le\hat\omega_0 and 00 elsewhere

hd[n]=sin⁡(ω^0n)πn=ω^0πsinc⁡ ⁣(ω^0nπ),hd[0]=ω^0π.h_d[n]=\frac{\sin(\hat\omega_0 n)}{\pi n}=\frac{\hat\omega_0}{\pi}\operatorname{sinc}\!\Big(\frac{\hat\omega_0 n}{\pi}\Big),\qquad h_d[0]=\frac{\hat\omega_0}{\pi}.

Example. N=20N=20, ω^0=π/3\hat\omega_0=\pi/3, rectangular window: h[10]=13=0.3333h[10]=\frac13=0.3333, h[10±1]=0.2757h[10\pm1]=0.2757, h[10±2]=0.1378h[10\pm2]=0.1378, h[10±3]=0h[10\pm3]=0, h[10±4]=−0.0689h[10\pm4]=-0.0689, h[10±5]=−0.0551h[10\pm5]=-0.0551, h[10±6]=0h[10\pm6]=0, h[10±7]=0.0394h[10\pm7]=0.0394, h[10±8]=0.0345h[10\pm8]=0.0345, h[10±9]=0h[10\pm9]=0, h[10±10]=−0.0276h[10\pm10]=-0.0276. The sum is 1.0048≈11.0048\approx1 (the DC gain).

Optimality (theorem). Among all linear-phase FIR filters of order N=2rN=2r, the partial sum Hˉ(ω^)=∑n=−rrhd[n]e−jω^n\bar H(\hat\omega)=\sum_{n=-r}^{r}h_d[n]e^{-j\hat\omega n} minimises the mean squared error E2=12π∫−ππ(D−Hˉ)2dω^E^2=\frac1{2\pi}\int_{-\pi}^{\pi}\big(D-\bar H\big)^2d\hat\omega. Proof. By Parseval E2=∑∣n∣≤r(hd[n]−hˉ[n])2+∑∣n∣>rhd[n]2E^2=\sum_{|n|\le r}(h_d[n]-\bar h[n])^2+\sum_{|n|>r}h_d[n]^2; the last sum does not depend on hˉ\bar h, the first is non-negative and vanishes if and only if hˉ[n]=hd[n]\bar h[n]=h_d[n] for ∣n∣≤r|n|\le r. □\square The truncation is optimal in the mean-square sense but not in the worst case.

Gibbs phenomenon. Multiplying by wR[n]w_R[n] in time is convolving in frequency:

Hˉ(ω^)=12π∫−ππD(θ) WR(ω^−θ) dθ,WR(ω^)=sin⁡(Lω^/2)sin⁡(ω^/2),\bar H(\hat\omega)=\frac1{2\pi}\int_{-\pi}^{\pi}D(\theta)\,W_R(\hat\omega-\theta)\,d\theta,\qquad W_R(\hat\omega)=\frac{\sin(L\hat\omega/2)}{\sin(\hat\omega/2)},

with L=N+1L=N+1 the length (the Dirichlet kernel). WRW_R equals LL at 00 and vanishes at ω^=2πLk\hat\omega=\frac{2\pi}{L}k, k≠0k\ne0. The part between the first two zeros ±2πL\pm\frac{2\pi}L is the main lobe, of width 4πL\frac{4\pi}{L}; the others are side lobes. The first side lobe is about 22% of the main one (−13.3-13.3 dB) whatever LL is: increasing LL narrows the lobes but does not lower them. Near a jump of DD the alternating-sign side lobes enter and leave the jump and produce oscillations (Gibbs phenomenon). With ω^0=π/3\hat\omega_0=\pi/3 the maximum of Hˉ\bar H is 1.07061.0706 for L=21L=21, 1.09281.0928 for L=61L=61, 1.09081.0908 for L=151L=151, 1.09001.0900 for L=401L=401: the overshoot converges to about 9% of the jump. The error in pass-band and stop-band is about δp≃δs≃0.09\delta_p\simeq\delta_s\simeq0.09, i.e. As≃21A_s\simeq21 dB, and does not depend on LL; what depends on LL is the transition width, about 0.9⋅2πL0.9\cdot\frac{2\pi}{L}.

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+1L=N+1, ∣n∣≤N/2|n|\le N/2:

window w[n]w[n]
rectangular 11
triangular (Bartlett) 1−∣n∣N/21-\frac{\lvert n\rvert}{N/2}
Hann 12+12cos⁡2πnN\frac12+\frac12\cos\frac{2\pi n}{N}
Hamming 0.54+0.46cos⁡2πnN0.54+0.46\cos\frac{2\pi n}{N}
Blackman 0.42+0.5cos⁡2πnN+0.08cos⁡4πnN0.42+0.5\cos\frac{2\pi n}{N}+0.08\cos\frac{4\pi n}{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 AsA_s
rectangular 2⋅2πL2\cdot\frac{2\pi}L −13.3-13.3 dB 0.9⋅2πL0.9\cdot\frac{2\pi}L 21 dB
triangular 4⋅2πL4\cdot\frac{2\pi}L −26.5-26.5 dB 3⋅2πL3\cdot\frac{2\pi}L 26 dB
Hann 4⋅2πL4\cdot\frac{2\pi}L −31.5-31.5 dB 3.1⋅2πL3.1\cdot\frac{2\pi}L 44 dB
Hamming 4⋅2πL4\cdot\frac{2\pi}L −42.7-42.7 dB 3.3⋅2πL3.3\cdot\frac{2\pi}L 54 dB
Blackman 6⋅2πL6\cdot\frac{2\pi}L −57-57 dB 5.5⋅2πL5.5\cdot\frac{2\pi}L 74 dB

Three general facts for all fixed windows: (1) the transition width is inversely proportional to the length, ω^s−ω^p2π≃αL\dfrac{\hat\omega_s-\hat\omega_p}{2\pi}\simeq\dfrac{\alpha}{L}, with α\alpha depending only on the window; (2) the errors are almost equal in the two bands, δp≃δs\delta_p\simeq\delta_s, and depend only on the window type, not on LL; (3) neither depends on the cut-off ω^0=ω^p+ω^s2\hat\omega_0=\frac{\hat\omega_p+\hat\omega_s}2. So with fixed windows δp\delta_p and δs\delta_s cannot be chosen separately. These figures are rules of thumb.

Kaiser window. It has a parameter β\beta that sets the attenuation:

w[n]=I0 ⁣(β1−(2nN)2)I0(β),∣n∣≤N2,w[n]=\frac{I_0\!\Big(\beta\sqrt{1-\big(\frac{2n}{N}\big)^2}\Big)}{I_0(\beta)},\quad|n|\le\frac N2,

with I0I_0 the modified Bessel function of order zero. With β=0\beta=0 it is the rectangular window (As=21A_s=21 dB). Given AsA_s in dB and the transition band, the empirical formulas are

β={0.1102 (As−8.7),As>500.5842 (As−21)0.4+0.07886 (As−21),21<As≤500,As≤21N≥As−814.36 ω^s−ω^p2π.\beta=\begin{cases}0.1102\,(A_s-8.7),&A_s>50\\0.5842\,(A_s-21)^{0.4}+0.07886\,(A_s-21),&21<A_s\le50\\0,&A_s\le21\end{cases}\qquad N\ge\frac{A_s-8}{14.36\,\frac{\hat\omega_s-\hat\omega_p}{2\pi}} .

Example. As=50A_s=50 dB, ω^s−ω^p=0.125π\hat\omega_s-\hat\omega_p=0.125\pi: β=0.5842⋅290.4+0.07886⋅29=4.534\beta=0.5842\cdot29^{0.4}+0.07886\cdot29=4.534 and N≥4214.36⋅0.0625=46.8N\ge\frac{42}{14.36\cdot0.0625}=46.8, so N=48N=48 (even, for type I).

Design procedure. (1) Compute the ideal hd[n]h_d[n] with cut-off ω^0=ω^p+ω^s2\hat\omega_0=\frac{\hat\omega_p+\hat\omega_s}2. (2) Choose the window from the required AsA_s and the order from the transition width: L=N+1≥α 2πω^s−ω^pL=N+1\ge\alpha\,\frac{2\pi}{\hat\omega_s-\hat\omega_p}. (3) Compute hˉ[n]=hd[n] w[n]\bar h[n]=h_d[n]\,w[n] and delay to make it causal. (4) Compute H(ejω^)H(e^{j\hat\omega}) and verify the specifications; if not met, increase NN or change window.

Complete example and comparison. Fs=8F_s=8 kHz, pass-band up to fp=1f_p=1 kHz, stop-band from fs=1.5f_s=1.5 kHz, As=50A_s=50 dB (δp=δs=0.00316\delta_p=\delta_s=0.00316): ω^p=0.25π\hat\omega_p=0.25\pi, ω^s=0.375π\hat\omega_s=0.375\pi, ω^0=0.3125π\hat\omega_0=0.3125\pi. Rectangular: no good, δ≃0.09\delta\simeq0.09 whatever NN. Hamming: L≃3.3⋅2π0.125π=52.8L\simeq3.3\cdot\frac{2\pi}{0.125\pi}=52.8, so N=52N=52; numerical check: δs=0.00330\delta_s=0.00330 (As=49.6A_s=49.6 dB), just out of specification; with N=54N=54, δp=0.00258\delta_p=0.00258, δs=0.00220\delta_s=0.00220, the specification is met. Hann and Blackman need N=76N=76 and N=74N=74. Kaiser: β=4.55\beta=4.55, N=48N=48 (δp=0.00299\delta_p=0.00299, δs=0.00260\delta_s=0.00260). Minimax: N=42N=42 (δp=δs=0.00279\delta_p=\delta_s=0.00279). The table is a rule of thumb, not a guarantee: step 4 is needed.

Frequency sampling and minimax

Frequency sampling. The desired response is sampled at L=N+1L=N+1 equispaced points ω^k=2πLk\hat\omega_k=\frac{2\pi}{L}k and the impulse response is the IDFT (Discrete Fourier TransformHeuristic derivation of the discrete Fourier transform for N-periodic discrete-time signals: complex exponentials with period N, the finite basis of N modes obtained from the difference equation x(k)-x(k-N)=0, orthogonality, the coefficient formula and the definition of the DFT with its periodicity and matrix form.Discrete Fourier Transform →): H[k]=e−jω^kN/2D(ω^k)H[k]=e^{-j\hat\omega_k N/2}D(\hat\omega_k), h[n]=IDFT{H[k]}h[n]=\mathrm{IDFT}\{H[k]\}. The filter has exactly the desired response at the sample points, but nothing is controlled in between. It is equivalent to folding the ideal response with period LL: the time aliasing of the ideal impulse response is the error. A transition sample (for instance D=0.5D=0.5 at a sample in the transition band) lowers the oscillations at the price of a wider transition.

Minimax (Parks-McClellan). The maximum weighted error W(ω^) ∣D(ω^)−Hˉ(ω^)∣W(\hat\omega)\,|D(\hat\omega)-\bar H(\hat\omega)| over the bands (transition excluded) is minimised. Alternation theorem: Hˉ=∑n=0rpncos⁡(nω^)\bar H=\sum_{n=0}^{r}p_n\cos(n\hat\omega) is optimal if and only if the weighted error has at least r+2r+2 alternations. The response is equiripple. With weights W=110W=\frac1{10} in the pass-band and 11 in the stop-band, δs\delta_s is ten times smaller than δp\delta_p. The order is estimated by

N≃−10log⁡10(δpδs)−1314.6 ω^s−ω^p2π,N\simeq\frac{-10\log_{10}(\delta_p\delta_s)-13}{14.6\,\frac{\hat\omega_s-\hat\omega_p}{2\pi}} ,

inversely proportional to the transition width, independent of the cut-off. Example: δp=δs=0.00316\delta_p=\delta_s=0.00316 gives N≃40.5N\simeq40.5 (actual value 4242).

method what it controls optimal? errors order
windows hh from hdh_d and the window no (rectangular is optimal in mean square) almost equal, fixed by the window higher
frequency sampling HH exact at the samples no not controlled between samples depends on samples
minimax maximum weighted error yes, worst case chosen with weight WW, equiripple the lowest

For the same specification, orders 5454 (Hamming), 4848 (Kaiser), 4242 (minimax): the minimax filter is the shortest, therefore also with the smallest delay (N/2N/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)=1Da(s)H_a(s)=\frac1{D_a(s)} (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. 1A=δs\frac1A=\delta_s (AA is the stop-band attenuation) and 11+ε2=1−δp\frac1{\sqrt{1+\varepsilon^2}}=1-\delta_p, so ε2=10Rp/10−1\varepsilon^2=10^{R_p/10}-1 and A=10Rs/20A=10^{R_s/20}, with Rs=−20log⁡10δsR_s=-20\log_{10}\delta_s. The conditions are ∣Ha(jΩp)∣2≥11+ε2|H_a(j\Omega_p)|^2\ge\frac1{1+\varepsilon^2} and ∣Ha(jΩs)∣2≤1A2|H_a(j\Omega_s)|^2\le\frac1{A^2}. Example. Rp=0.1R_p=0.1 dB and Rs=40R_s=40 dB: ε2=0.02329\varepsilon^2=0.02329 (ε=0.1526\varepsilon=0.1526) and A=100A=100.

Squared modulus. The Butterworth filter is defined by maximal flatness of the modulus at Ω=0\Omega=0. For a real filter the squared modulus is even in Ω\Omega: ∣Ha(jΩ)∣2=1PN(Ω2)|H_a(j\Omega)|^2=\frac1{P_N(\Omega^2)} with PN(Ω2)=p0+p1Ω2+⋯+pNΩ2NP_N(\Omega^2)=p_0+p_1\Omega^2+\dots+p_N\Omega^{2N}. Three constraints: (1) unit DC gain, p0=1p_0=1; (2) maximal flatness at 00: PN−1P_N-1 must be an infinitesimal of maximal order, so p1=⋯=pN−1=0p_1=\dots=p_{N-1}=0 and PN=1+pNΩ2NP_N=1+p_N\Omega^{2N}; (3) at the cut-off ∣Ha(jΩ0)∣2=12|H_a(j\Omega_0)|^2=\frac12 (−3-3 dB, modulus 12≃0.707\frac1{\sqrt2}\simeq0.707), so pN=Ω0−2Np_N=\Omega_0^{-2N}:

∣Ha(jΩ)∣2=11+(ΩΩ0)2N.|H_a(j\Omega)|^2=\frac{1}{1+\big(\frac{\Omega}{\Omega_0}\big)^{2N}}.

It equals 11 at 00, 12\frac12 at Ω0\Omega_0 for every NN, and decreases monotonically; for N→∞N\to\infty it tends to the ideal rectangle. At Ω=2Ω0\Omega=2\Omega_0 (one octave above the cut-off) the attenuation is 10log⁡10(1+22N)≃6N10\log_{10}(1+2^{2N})\simeq6N dB: 2424 dB for N=4N=4, 4848 dB for N=8N=8.

Transfer function. One looks for the stable rational Ha(s)H_a(s) with Ha(s)Ha(−s)=11+(sjΩ0)2NH_a(s)H_a(-s)=\frac{1}{1+\big(\frac{s}{j\Omega_0}\big)^{2N}}. The poles are sk=Ω0ejπ(12+2k−12N)s_k=\Omega_0e^{j\pi\left(\frac12+\frac{2k-1}{2N}\right)}, k=1,…,2Nk=1,\dots,2N: 2N2N poles on a circle of radius Ω0\Omega_0, half in the left half-plane, half in the right. For a causal stable system Ha(s)H_a(s) takes the NN poles with Re⁡sk<0\operatorname{Re}s_k<0:

Ha(s)=Ω0N∏k=1N(s−sk),H_a(s)=\frac{\Omega_0^N}{\prod_{k=1}^N(s-s_k)},

with the constant fixed by Ha(0)=1H_a(0)=1. Examples (Ω0=1\Omega_0=1). N=2N=2: Ha(s)=1s2+2 s+1H_a(s)=\frac1{s^2+\sqrt2\,s+1}. N=3N=3: poles −1-1 and −12±j32-\frac12\pm j\frac{\sqrt3}2, Ha(s)=1s3+2s2+2s+1H_a(s)=\frac1{s^3+2s^2+2s+1}. A Butterworth filter is completely specified by two parameters: NN and Ω0\Omega_0.

Digital filter. With the bilinear transformation s=z−1z+1s=\frac{z-1}{z+1} the NN zeros at infinity become a zero of multiplicity NN at z=−1z=-1:

H(z)=A (1+z−1)N∏k=1N(1−pkz−1),pk=1+sk1−sk,A=∏k(1−pk)2N,H(z)=A\,\frac{(1+z^{-1})^N}{\prod_{k=1}^{N}(1-p_kz^{-1})},\qquad p_k=\frac{1+s_k}{1-s_k},\quad A=\frac{\prod_k(1-p_k)}{2^N},

with AA chosen so that H(1)=1H(1)=1. The poles are inside the unit circle. Substituting Ω=tan⁡ω^2\Omega=\tan\frac{\hat\omega}2:

∣H(ejω^)∣2=11+(tan⁡(ω^/2)Ω0)2N.|H(e^{j\hat\omega})|^2=\frac1{1+\Big(\dfrac{\tan(\hat\omega/2)}{\Omega_0}\Big)^{2N}} .

The digital −3-3 dB cut-off is ω^0=2arctan⁡Ω0\hat\omega_0=2\arctan\Omega_0: for Ω0=1\Omega_0=1 it is ω^0=π/2\hat\omega_0=\pi/2.

Choosing the order from the specifications. Given ω^p,ω^s,Rp,Rs\hat\omega_p,\hat\omega_s,R_p,R_s: Ωp=tan⁡ω^p2\Omega_p=\tan\frac{\hat\omega_p}2, Ωs=tan⁡ω^s2\Omega_s=\tan\frac{\hat\omega_s}2. Imposing equality in the two conditions: (ΩpΩ0)2N=ε2\big(\frac{\Omega_p}{\Omega_0}\big)^{2N}=\varepsilon^2 and (ΩsΩ0)2N=A2−1\big(\frac{\Omega_s}{\Omega_0}\big)^{2N}=A^2-1. Dividing eliminates Ω0\Omega_0, (ΩsΩp)2N=A2−1ε2\big(\frac{\Omega_s}{\Omega_p}\big)^{2N}=\frac{A^2-1}{\varepsilon^2}:

N ≥ log⁡10A2−1ε22log⁡10ΩsΩp\boxed{N\ \ge\ \frac{\log_{10}\dfrac{A^2-1}{\varepsilon^2}}{2\log_{10}\dfrac{\Omega_s}{\Omega_p}}}

rounded up. Then Ω0\Omega_0 lies between Ωp ε−1/N\Omega_p\,\varepsilon^{-1/N} and Ωs (A2−1)−1/(2N)\Omega_s\,(A^2-1)^{-1/(2N)}; since NN was rounded up, one of the two conditions is met with margin.

Example. Fs=8F_s=8 kHz, fp=1f_p=1 kHz, fs=2f_s=2 kHz, Rp=0.1R_p=0.1 dB, Rs=40R_s=40 dB. ω^p=π4\hat\omega_p=\frac\pi4, ω^s=π2\hat\omega_s=\frac\pi2, Ωp=tan⁡π8=0.4142\Omega_p=\tan\frac\pi8=0.4142, Ωs=1\Omega_s=1, ε=0.1526\varepsilon=0.1526, A=100A=100: N≥log⁡10(9999/0.02329)2log⁡10(1/0.4142)=5.63270.7656=7.358N\ge\frac{\log_{10}(9999/0.02329)}{2\log_{10}(1/0.4142)}=\frac{5.6327}{0.7656}=7.358, so N=8N=8; the two values of Ω0\Omega_0 are 0.56230.5623 and 0.52390.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π\hat\omega_p=0.25\pi, ω^s=0.375π\hat\omega_s=0.375\pi, Rp=0.055R_p=0.055 dB, As=50A_s=50 dB the orders are 1717 (Butterworth), 99 (Chebyshev 1), 66 (elliptic).

5. Multirate processing: decimation and interpolation

Audio, images and video use signals with different sampling rates: a CD has 44.144.1 kHz, a professional file 4848 kHz. Processing that changes the sampling rate is called multirate. Three cases: interpolation (Fs′=LFsF_s'=LF_s), decimation (Fs′=Fs/MF_s'=F_s/M), generic conversion (Fs′=LMFsF_s'=\frac LMF_s with L,ML,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−1L-1 zeros between two consecutive samples: v[n]=x[n/L]v[n]=x[n/L] for n=0,±L,±2L,…n=0,\pm L,\pm2L,\dots, 00 elsewhere. Example. x={1,2,3}x=\{1,2,3\}, L=3L=3: v={1,0,0,2,0,0,3,0,0}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ω^)V(e^{j\hat\omega})=X(e^{jL\hat\omega}).

Proof. V(ω^)=∑nv[n]e−jω^n=∑kx[k] e−jω^kLV(\hat\omega)=\sum_nv[n]e^{-j\hat\omega n}=\sum_kx[k]\,e^{-j\hat\omega kL}, since only the terms n=kLn=kL are non-zero. This is XX evaluated at Lω^L\hat\omega. □\square

XX has period 2π2\pi, so X(ejLω^)X(e^{jL\hat\omega}) has period 2πL\frac{2\pi}L: the input spectrum is compressed by a factor LL and repeated LL times in (−π,π)(-\pi,\pi): the original plus L−1L-1 images. Example. x[n]=cos⁡(0.4πn)x[n]=\cos(0.4\pi n), L=3L=3: lines at 0.1333π0.1333\pi (the original, compressed), 0.5333π0.5333\pi and 0.8π0.8\pi (the two images).

An ideal low-pass filter with cut-off πL\frac\pi L and gain LL removes the L−1L-1 images. The ideal filter has h[n]=sinc⁡ ⁣(nL)h[n]=\operatorname{sinc}\!\big(\frac nL\big), which equals 11 at n=0n=0 and vanishes at all other multiples of LL, so y[kL]=x[k]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 hdh_d at the multiples of LL, hence the property).

Linear interpolation. With few resources, samples are joined by segments: the impulse response is a triangle

h[n]={1−∣n∣L,∣n∣<L0,elsewhereL=2: h={12, 1, 12},L=3: {13,23,1,23,13},h[n]=\begin{cases}1-\frac{|n|}{L},&|n|<L\\0,&\text{elsewhere}\end{cases}\qquad L=2:\ h=\big\{\tfrac12,\,1,\,\tfrac12\big\},\quad L=3:\ \big\{\tfrac13,\tfrac23,1,\tfrac23,\tfrac13\big\},

with frequency response H(ejω^)=1L(sin⁡(Lω^/2)sin⁡(ω^/2))2H(e^{j\hat\omega})=\frac1L\Big(\frac{\sin(L\hat\omega/2)}{\sin(\hat\omega/2)}\Big)^2 (for L=2L=2: 1+cos⁡ω^1+\cos\hat\omega), gain LL at DC. It is far from the ideal (a rectangle up to πL\frac\pi L): for L=5L=5 the normalised gain is 0.420.42 at π5\frac\pi5, and beyond 0.4π0.4\pi the maximum gain is still 0.06250.0625, only −24-24 dB. So linear interpolation gives good results only if the signal occupies frequencies much lower than the maximum.

Multistage interpolation. If L=L1L2⋯LKL=L_1L_2\cdots L_K it is better to interpolate in KK 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=24L=24 to 48 kHz with 60 dB attenuation; multiplications per second): one stage 876 000876\,000; 2×122\times12: 378 000378\,000; 12×212\times2: 680 000680\,000; 3×83\times8: 366 000366\,000; 8×38\times3: 536 000536\,000. 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 MM: y[n]=x[nM]y[n]=x[nM]. Example. x={1,…,7}x=\{1,\dots,7\}, M=3M=3: y={1,4,7}y=\{1,4,7\}. It is linear but not time-invariant and in general loses information.

Theorem (spectrum of the decimator). Y(ejω^)=1M∑k=0M−1X ⁣(ejω^−2πkM)Y(e^{j\hat\omega})=\dfrac1M\displaystyle\sum_{k=0}^{M-1}X\!\Big(e^{j\frac{\hat\omega-2\pi k}M}\Big).

Proof. Define u[n]=x[n] p[n]u[n]=x[n]\,p[n] with p[n]=∑kδ[n−kM]p[n]=\sum_{k}\delta[n-kM] (an impulse comb: 11 at multiples of MM). Then u[n]=x[n]u[n]=x[n] if MM divides nn and 00 otherwise, and y[m]=u[mM]y[m]=u[mM]. The DTFT of the comb is P(ω^)=2πM∑k=0M−1δ(ω^−2πkM)P(\hat\omega)=\frac{2\pi}{M}\sum_{k=0}^{M-1}\delta(\hat\omega-\frac{2\pi k}{M}), and the product in time is a convolution in frequency: U(ω^)=1M∑k=0M−1X(ω^−2πkM)U(\hat\omega)=\frac1M\sum_{k=0}^{M-1}X(\hat\omega-\frac{2\pi k}M). Then Y(ω^)=∑mu[mM]e−jω^m=∑nu[n]e−jω^n/M=U(ω^/M)Y(\hat\omega)=\sum_mu[mM]e^{-j\hat\omega m}=\sum_nu[n]e^{-j\hat\omega n/M}=U(\hat\omega/M). □\square

So YY is the sum of MM versions of the spectrum of XX, dilated by MM and shifted by 2πk2\pi k, divided by MM. The replicas overlap if XX occupies more than ∣ω^∣<πM|\hat\omega|<\frac\pi M: this is aliasing of decimation. Example. x[n]=cos⁡(0.6πn)x[n]=\cos(0.6\pi n) and M=2M=2: y[n]=cos⁡(1.2πn)=cos⁡(0.8πn)y[n]=\cos(1.2\pi n)=\cos(0.8\pi n), because 1.2π≡−0.8π(mod2π)1.2\pi\equiv-0.8\pi\pmod{2\pi}. The frequency 0.6π>π20.6\pi>\frac\pi2 reappears falsely at 0.8π0.8\pi.

To limit aliasing the decimator is preceded by a low-pass filter with cut-off πM\frac\pi M (in Hz Fs2M=Fs′2\frac{F_s}{2M}=\frac{F_s'}2) and gain 11. For x[n]=cos⁡(0.6πn)x[n]=\cos(0.6\pi n), M=2M=2, the prefilter removes the component: the output is practically zero instead of a false sinusoid. In multiple stages, M=M1⋯MKM=M_1\cdots M_K, the minimum cost is with the factors in decreasing order (the largest first). Example with Fs=48F_s=48 kHz, M=24M=24, useful band 800800 Hz, 6060 dB: one filter of order 437437 costs 876 000876\,000 multiplications/s; 12×212\times2 costs 378 000378\,000 against 680 000680\,000 for 2×122\times12; 8×38\times3 costs 366 000366\,000 against 536 000536\,000 for 3×83\times8.

Generic conversion Fs′=LMFsF_s'=\frac LMF_s

It is a cascade of three blocks (the order matters: interpolate first, then decimate): an expander ↑L\uparrow L, a low-pass filter gg working at Fs′′=LFs=MFs′F_s''=LF_s=MF_s', a decimator ↓M\downarrow M. The anti-image filter (cut-off πL\frac\pi L) and the anti-aliasing filter (cut-off πM\frac\pi M) are in cascade at the same rate and are replaced by one low-pass filter with gain LL and cut-off

ω^c=min⁡(πL,πM).\hat\omega_c=\min\Big(\frac\pi L,\frac\pi M\Big).

The input-output equation is y[n]=∑ix[i] g[nM−iL]y[n]=\sum_{i}x[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 MM samples shifts the output by LL samples). Example (audio). From 44.144.1 kHz to 4848 kHz: 4800044100=160147\frac{48000}{44100}=\frac{160}{147}, so L=160L=160, M=147M=147, Fs′′=7056F_s''=7056 kHz, cut-off π160\frac\pi{160} (22.0522.05 kHz). Computing at 77 MHz would be prohibitive: the polyphase structure is used, which splits gg into LL subfilters gr[k]=g[kL+r]g_r[k]=g[kL+r] and computes only the output samples: KL\frac KL multiplications per output sample instead of KK for interpolation; for decimation, KK multiplications every MM input samples.

Typical mistakes

  • Confusing order MM (delays) with length M+1M+1 (coefficients).
  • Taking the window-design tables as a guarantee: verify HH against the specifications.
  • Not rounding the Butterworth order up; confusing Ω0\Omega_0 with the digital frequency ω^0\hat\omega_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≥2BF_s\ge2B. A/D: uniform quantizer with q=Vx/2B−1q=V_x/2^{B-1}, error at most q/2q/2 (B=16B=16, Vx=1V_x=1 V: q≈30.5 μq\approx30.5\ \muV). D/A: zero-order hold. Digital wins on precision, reliability, adaptivity; digital repeaters regenerate with a threshold (analog noise Nσ/G\sqrt N\sigma/G).

FIR. Causal FIR of order MM (length L=M+1L=M+1): y[n]=∑k=0Mbkx[n−k]y[n]=\sum_{k=0}^{M}b_kx[n-k]; h[n]=bnh[n]=b_n for 0≤n≤M0\le n\le M. δ[n]=u[n]−u[n−1]\delta[n]=u[n]-u[n-1]; x[n]=∑kx[k]δ[n−k]x[n]=\sum_kx[k]\delta[n-k]. Three-point average on {2,4,6,4,2}\{2,4,6,4,2\}: causal {23,2,4,143,4,2,23}\{\frac23,2,4,\frac{14}3,4,2,\frac23\} from n=0n=0; centred, same values from n=−1n=-1. Support: input NN, output N+MN+M. Non-causal = uses future samples: fine on recordings. LL-point average y[n]=1L∑x[n−k]y[n]=\frac1L\sum x[n-k]; delay L−12\frac{L-1}2. Step: running sum 1,2,3,3,…1,2,3,3,\dots; 5-point average 0.2,0.4,…,10.2,0.4,\dots,1. Direct and transposed forms, same equation; feed-forward. Cascade {1,1,1,1}\{1,1,1,1\} and {1,1,1}\{1,1,1\} equals {1,2,3,3,2,1}\{1,2,3,3,2,1\}: 6 multiplications as one filter, none as a cascade.

Specifications. ω^p\hat\omega_p, ω^s\hat\omega_s, δp\delta_p, δs\delta_s; Rp=20log⁡101+δp1−δpR_p=20\log_{10}\frac{1+\delta_p}{1-\delta_p}, As=−20log⁡10δsA_s=-20\log_{10}\delta_s. δ=10−2.5\delta=10^{-2.5}: As=50A_s=50 dB, Rp=0.055R_p=0.055 dB.

Type I. NN even, h[n]=h[N−n]h[n]=h[N-n]: H=e−jω^N/2HˉH=e^{-j\hat\omega N/2}\bar H, Hˉ=∑n=0N/2pncos⁡(nω^)\bar H=\sum_{n=0}^{N/2}p_n\cos(n\hat\omega), p0=h[N/2]p_0=h[N/2], pn=2h[N/2−n]p_n=2h[N/2-n]. h={1,2,3,2,1}h=\{1,2,3,2,1\}: Hˉ=3+4cos⁡ω^+2cos⁡2ω^\bar H=3+4\cos\hat\omega+2\cos2\hat\omega.

Window method. hˉ[n]=hd[n]w[n]\bar h[n]=h_d[n]w[n] for ∣n∣≤N/2|n|\le N/2, then h[n]=hˉ[n−N/2]h[n]=\bar h[n-N/2]. Ideal low-pass hd[n]=sin⁡(ω^0n)πn=ω^0πsinc⁡ω^0nπh_d[n]=\frac{\sin(\hat\omega_0n)}{\pi n}=\frac{\hat\omega_0}\pi\operatorname{sinc}\frac{\hat\omega_0n}\pi, hd[0]=ω^0πh_d[0]=\frac{\hat\omega_0}\pi. N=20N=20, ω^0=π3\hat\omega_0=\frac\pi3: h[10]=13h[10]=\frac13, h[10±1]=0.2757h[10\pm1]=0.2757, h[10±2]=0.1378h[10\pm2]=0.1378, zeros at ±3,±6,±9\pm3,\pm6,\pm9; sum 1.00481.0048.

  • Optimality: truncation minimises the mean square error (Parseval), not the maximum error.
  • Gibbs: Hˉ=12π∫D(θ)WR(ω^−θ)dθ\bar H=\frac1{2\pi}\int D(\theta)W_R(\hat\omega-\theta)d\theta, Dirichlet kernel, main lobe 4πL\frac{4\pi}L, first side lobe −13.3-13.3 dB (about 22%), independent of LL; overshoot about 9%, As≃21A_s\simeq21 dB, independent of LL; transition about 0.92πL0.9\frac{2\pi}L.
  • Windows: rectangular 11; triangular 1−∣n∣N/21-\frac{|n|}{N/2}; Hann 12+12cos⁡2πnN\frac12+\frac12\cos\frac{2\pi n}N; Hamming 0.54+0.46cos⁡2πnN0.54+0.46\cos\frac{2\pi n}N; Blackman 0.42+0.5cos⁡2πnN+0.08cos⁡4πnN0.42+0.5\cos\frac{2\pi n}N+0.08\cos\frac{4\pi n}N. Main lobe (units 2πL\frac{2\pi}L): 2, 4, 4, 4, 6. Transition: 0.9, 3, 3.1, 3.3, 5.5. AsA_s: 21, 26, 44, 54, 74 dB. Side lobes: −13.3,−26.5,−31.5,−42.7,−57-13.3,-26.5,-31.5,-42.7,-57 dB.
  • Three facts: ω^s−ω^p2π≃αL\frac{\hat\omega_s-\hat\omega_p}{2\pi}\simeq\frac\alpha L; δp≃δs\delta_p\simeq\delta_s depends on the window only; neither depends on the cut-off.
  • Kaiser: w=I0(β1−(2n/N)2)I0(β)w=\frac{I_0(\beta\sqrt{1-(2n/N)^2})}{I_0(\beta)}; β=0.1102(As−8.7)\beta=0.1102(A_s-8.7) for As>50A_s>50; 0.5842(As−21)0.4+0.07886(As−21)0.5842(A_s-21)^{0.4}+0.07886(A_s-21) for 21<As≤5021<A_s\le50; N≥As−814.36 ΔfN\ge\frac{A_s-8}{14.36\,\Delta f} with Δf=ω^s−ω^p2π\Delta f=\frac{\hat\omega_s-\hat\omega_p}{2\pi}. As=50A_s=50, transition 0.125π0.125\pi: β≈4.55\beta\approx4.55, N=48N=48.
  • Procedure: cut-off ω^p+ω^s2\frac{\hat\omega_p+\hat\omega_s}2; window from AsA_s; order from the transition; hd wh_d\,w and delay; verify.
  • Example Fs=8F_s=8 kHz, fp=1f_p=1, fs=1.5f_s=1.5 kHz, 50 dB: rectangular fails (δ≃0.09\delta\simeq0.09); Hamming N=52N=52 gives 49.6 dB (not enough), N=54N=54 works; Hann 76, Blackman 74; Kaiser 48; minimax 42.
  • Frequency sampling: H[k]=e−jω^kN/2D(ω^k)H[k]=e^{-j\hat\omega_kN/2}D(\hat\omega_k) at ω^k=2πkL\hat\omega_k=\frac{2\pi k}L, h=IDFTh=\mathrm{IDFT}; exact at samples, uncontrolled between; error = time aliasing; a transition sample helps (D=0.5D=0.5) at the cost of a wider transition.
  • Minimax: minimise max⁡W∣D−Hˉ∣\max W|D-\bar H|; optimal iff ≥r+2\ge r+2 alternations; equiripple; weights set δs/δp\delta_s/\delta_p. N≃−10log⁡10(δpδs)−1314.6 ΔfN\simeq\frac{-10\log_{10}(\delta_p\delta_s)-13}{14.6\,\Delta f} (40.540.5 vs actual 4242). Same specification: orders 54, 48, 42.

Butterworth. ∣Ha(jΩ)∣2=11+(Ω/Ω0)2N|H_a(j\Omega)|^2=\frac1{1+(\Omega/\Omega_0)^{2N}}: maximally flat, monotonic, 12\frac1{\sqrt2} at Ω0\Omega_0 for every NN; 2Ω02\Omega_0: 10log⁡10(1+22N)≈6N10\log_{10}(1+2^{2N})\approx6N dB. Construction: p0=1p_0=1, PN=1+pNΩ2NP_N=1+p_N\Omega^{2N}, pN=Ω0−2Np_N=\Omega_0^{-2N}. Poles sk=Ω0ejπ(12+2k−12N)s_k=\Omega_0e^{j\pi(\frac12+\frac{2k-1}{2N})} (2N2N on a circle); Ha(s)=Ω0N∏(s−sk)H_a(s)=\frac{\Omega_0^N}{\prod(s-s_k)} with the NN left poles. N=2N=2: 1s2+2s+1\frac1{s^2+\sqrt2s+1}; N=3N=3: 1s3+2s2+2s+1\frac1{s^3+2s^2+2s+1}.

  • Digital: H(z)=A(1+z−1)N∏(1−pkz−1)H(z)=A\frac{(1+z^{-1})^N}{\prod(1-p_kz^{-1})}, pk=1+sk1−skp_k=\frac{1+s_k}{1-s_k}, A=∏(1−pk)2NA=\frac{\prod(1-p_k)}{2^N}; ∣H∣2=11+(tan⁡(ω^/2)/Ω0)2N|H|^2=\frac1{1+(\tan(\hat\omega/2)/\Omega_0)^{2N}}; cut-off 2arctan⁡Ω02\arctan\Omega_0 (π2\frac\pi2 for Ω0=1\Omega_0=1).
  • Order: ε2=10Rp/10−1\varepsilon^2=10^{R_p/10}-1, A=10Rs/20A=10^{R_s/20}, Ω=tan⁡ω^2\Omega=\tan\frac{\hat\omega}2; N≥log⁡10A2−1ε22log⁡10ΩsΩpN\ge\frac{\log_{10}\frac{A^2-1}{\varepsilon^2}}{2\log_{10}\frac{\Omega_s}{\Omega_p}} rounded up; Ω0∈[Ωpε−1/N,Ωs(A2−1)−1/2N]\Omega_0\in[\Omega_p\varepsilon^{-1/N},\Omega_s(A^2-1)^{-1/2N}]. Fs=8F_s=8 kHz, 1 and 2 kHz, 0.1 dB, 40 dB: N≥7.358⇒8N\ge7.358\Rightarrow8, Ω0∈[0.5239,0.5623]\Omega_0\in[0.5239,0.5623].
  • 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]v[n]=x[n/L] at multiples of LL; V(ω^)=X(Lω^)V(\hat\omega)=X(L\hat\omega); spectrum compressed and repeated (images); low-pass with cut-off πL\frac\pi L and gain LL. x={1,2,3}x=\{1,2,3\}, L=3L=3: {1,0,0,2,0,0,3,0,0}\{1,0,0,2,0,0,3,0,0\}. cos⁡(0.4πn)\cos(0.4\pi n), L=3L=3: lines at 0.1333π0.1333\pi, 0.5333π0.5333\pi, 0.8π0.8\pi. Correct interpolation: h[n]=sinc⁡nLh[n]=\operatorname{sinc}\frac nL, y[kL]=x[k]y[kL]=x[k]; windowed FIR keeps the zeros. Linear: h[n]=1−∣n∣Lh[n]=1-\frac{|n|}L, H=1L(sin⁡(Lω^/2)sin⁡(ω^/2))2H=\frac1L(\frac{\sin(L\hat\omega/2)}{\sin(\hat\omega/2)})^2; L=5L=5: beyond 0.4π0.4\pi only −24-24 dB; good only for low-frequency signals. Multistage interpolation: small factors first (2424: 876 000876\,000 vs 3×83\times8 366 000366\,000, 2×122\times12 378 000378\,000, 12×212\times2 680 000680\,000).

  • Decimator y[n]=x[nM]y[n]=x[nM] ({1..7}\{1..7\}, M=3M=3: {1,4,7}\{1,4,7\}): Y=1M∑kX(ω^−2πkM)Y=\frac1M\sum_kX(\frac{\hat\omega-2\pi k}M) (impulse comb); aliasing beyond πM\frac\pi M; cos⁡(0.6πn)\cos(0.6\pi n), M=2M=2 becomes cos⁡(0.8πn)\cos(0.8\pi n); prefilter cut-off πM\frac\pi M, gain 1. Multistage: large factors first (12×212\times2 378 000378\,000 vs 680 000680\,000; 8×38\times3 366 000366\,000 vs 536 000536\,000).
  • Rational LM\frac LM: ↑L\uparrow L, one low-pass (gain LL, cut-off min⁡(πL,πM)\min(\frac\pi L,\frac\pi M)), ↓M\downarrow M; y[n]=∑ix[i]g[nM−iL]y[n]=\sum_ix[i]g[nM-iL], not a convolution, periodically time-invariant. 44.1→4844.1\to48 kHz: L=160L=160, M=147M=147, cut-off π160\frac\pi{160}; polyphase: KL\frac KL multiplications per output sample.

Typical mistakes: order vs length; tables as guarantees; Butterworth order not rounded up; Ω0\Omega_0 vs ω^0\hat\omega_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}x=\{2,4,6,4,2\} equals 2δ[n]+4δ[n−1]+6δ[n−2]+4δ[n−3]+2δ[n−4]2\delta[n]+4\delta[n-1]+6\delta[n-2]+4\delta[n-3]+2\delta[n-4]; a delay y[n]=x[n−3]y[n]=x[n-3] has {bk}={0,0,0,1}\{b_k\}=\{0,0,0,1\}, h[n]=δ[n−3]h[n]=\delta[n-3].
  • Moving average, L=3L=3 and 77: attenuation of the period-8 sinusoid 0.8050.805 and 17\frac17 (amplitudes 0.4020.402 and 0.07140.0714), delay 11 and 33 samples.
  • Specifications example: δp=0.05\delta_p=0.05, δs=0.01\delta_s=0.01 give Rp=0.87R_p=0.87 dB, As=40A_s=40 dB.
  • Window method steps: (1) ideal hdh_d with cut-off ω^p+ω^s2\frac{\hat\omega_p+\hat\omega_s}2; (2) window from AsA_s, order from L≥α2πω^s−ω^pL\ge\alpha\frac{2\pi}{\hat\omega_s-\hat\omega_p}; (3) hdwh_dw and delay; (4) verify HH. Advantage: simple, keeps the zeros of hdh_d; drawback: not optimal, δp≃δs\delta_p\simeq\delta_s.
  • Gibbs values: ω^0=π3\hat\omega_0=\frac\pi3: maximum 1.07061.0706 (L=21L=21), 1.09281.0928 (6161), 1.09081.0908 (151151), 1.09001.0900 (401401): about 9%.
  • Kaiser: β=0\beta=0 is rectangular; β=0.5842⋅290.4+0.07886⋅29=4.534\beta=0.5842\cdot29^{0.4}+0.07886\cdot29=4.534 for As=50A_s=50.
  • Frequency sampling: exact at ω^k=2πkL\hat\omega_k=\frac{2\pi k}L; equals the ideal response folded with period LL; transition sample D=0.5D=0.5 lowers the oscillation.
  • Minimax: weights W=110W=\frac1{10} pass-band and 11 stop-band give δs=δp10\delta_s=\frac{\delta_p}{10}; Remez solves a linear system of r+2r+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.
  • Butterworth specs: Rp=0.1R_p=0.1 dB, Rs=40R_s=40 dB: ε2=0.02329\varepsilon^2=0.02329 (ε=0.1526\varepsilon=0.1526), A=100A=100. Conditions ∣Ha(jΩp)∣2≥11+ε2|H_a(j\Omega_p)|^2\ge\frac1{1+\varepsilon^2}, ∣Ha(jΩs)∣2≤1A2|H_a(j\Omega_s)|^2\le\frac1{A^2}.
  • Why flatness: near Ω=0\Omega=0, 3Ω23\Omega^2 dominates 5Ω85\Omega^8, so zeroing low-order coefficients keeps ∣Ha∣2|H_a|^2 near 1 longest.
  • Multirate cases: Fs′=LFsF_s'=LF_s (interpolation), Fs/MF_s/M (decimation), LMFs\frac LMF_s (conversion, L,ML,M coprime); Fs′′=LFs=MFs′F_s''=LF_s=MF_s'. Fs=2F_s=2, Fs′=3F_s'=3: Fs′′=6F_s''=6; 44.1→4844.1\to48 kHz: 160147\frac{160}{147}, Fs′′=7056F_s''=7056 kHz.
  • Comb for decimation: p[n]=∑kδ[n−kM]p[n]=\sum_k\delta[n-kM], DTFT 2πM∑kδ(ω^−2πkM)\frac{2\pi}M\sum_k\delta(\hat\omega-\frac{2\pi k}M); product in time is convolution in frequency; Y(ω^)=U(ω^/M)Y(\hat\omega)=U(\hat\omega/M).
  • Rational conversion, L=2L=2, M=3M=3: y[n]=∑ix[i]g[3n−2i]y[n]=\sum_ix[i]g[3n-2i]; each output uses a different phase of gg (the phase nM mod LnM\bmod L repeats every LL outputs).
  • Mistake: believing a rational converter is LTI; it is only periodically time-invariant, with period mcm⁡(T,T′)\operatorname{mcm}(T,T').

Teoria collegata