Salta al contenuto
Note per Studenti Spectral Analysis of Audio - DFT, Windows and Spectrogram Report

Spectral Analysis of Audio - DFT, Windows and Spectrogram

In questa pagina 6

Spectral (Fourier) analysis is the main application of the DFT: given a signal x[n]x[n] one wants to know which frequencies it contains and with what amplitude. In theory one would need the DTFT of x[n]x[n] over all n∈Zn\in\mathbb Z; in practice only a finite stretch of LL samples is available and only the DFT (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 →) can be computed. The two approximations, windowing in time and sampling in frequency, produce artefacts that must be recognised: side lobes, loss of resolution, amplitude error. The reasoning is the same for images and audio; for signals whose frequency changes in time the STFT is used (last section).

1. The effect of the window

A complex exponential

Let x[n]=Aejω^0nx[n]=Ae^{j\hat\omega_0n}, n∈Zn\in\mathbb Z. Its DTFT is a periodic impulse train: X(ejω^)=2πA∑r∈Zδ(ω^−ω^0+2πr)X(e^{j\hat\omega})=2\pi A\sum_{r\in\mathbb Z}\delta(\hat\omega-\hat\omega_0+2\pi r). The position of the impulse gives ω^0\hat\omega_0 and its area AA. But if only LL samples are observed, the observed signal is

y[n]=x[n] wR[n],wR[n]=u[n]−u[n−L](rectangular window of length L).y[n]=x[n]\,w_R[n],\qquad w_R[n]=u[n]-u[n-L]\quad(\text{rectangular window of length }L).

Multiplication in time becomes periodic convolution in frequency and the impulse turns into a copy of the transform of the window:

Y(ejω^)=A WR(ej(ω^−ω^0)),WR(ejω^)=∑n=0L−1e−jω^n=e−jω^L−12 sin⁡(Lω^/2)sin⁡(ω^/2).Y(e^{j\hat\omega})=A\,W_R\big(e^{j(\hat\omega-\hat\omega_0)}\big),\qquad W_R(e^{j\hat\omega})=\sum_{n=0}^{L-1}e^{-j\hat\omega n}=e^{-j\hat\omega\frac{L-1}2}\,\frac{\sin(L\hat\omega/2)}{\sin(\hat\omega/2)}.

The last equality is the sum of a geometric series of ratio e−jω^e^{-j\hat\omega}. The ratio of sines is the Dirichlet kernel, a "periodic sinc".

Fact (spectrum of a sinusoid observed for LL samples). The peak of ∣Y∣\lvert Y\rvert is at ω^0\hat\omega_0 and equals L∣A∣L\lvert A\rvert; ∣WR∣\lvert W_R\rvert vanishes at ω^=2πr/L\hat\omega=2\pi r/L (r≠0r\neq0). The part between the two zeros ±2π/L\pm2\pi/L is the main lobe, of width 4π/L4\pi/L; the parts between successive zeros are the side lobes, of width 2π/L2\pi/L. The first side lobe is about 22%22\% of the main one, i.e. −13.3 dB-13.3\ \mathrm{dB}, whatever LL is.

Example. L=32L=32 and A=1A=1: peak 3232, zeros at multiples of 2π/32=0.1962\pi/32=0.196 rad, main lobe of width 4π/32=0.3934\pi/32=0.393 rad. The maximum of the first side lobe is ≈0.217⋅32≈6.9\approx0.217\cdot32\approx6.9.

Increasing LL narrows the main lobe (width ∝1/L\propto1/L) and approaches the ideal impulse, but the relative amplitude of the side lobes does not decrease.

Several components: resolution and leakage

If x[n]=A1ejω^1n+A2ejω^2nx[n]=A_1e^{j\hat\omega_1n}+A_2e^{j\hat\omega_2n}, by linearity Y=A1WR(ω^−ω^1)+A2WR(ω^−ω^2)Y=A_1W_R(\hat\omega-\hat\omega_1)+A_2W_R(\hat\omega-\hat\omega_2): the two copies of the kernel add up and interfere. Two problems follow.

  • Resolution: if ω^1\hat\omega_1 and ω^2\hat\omega_2 are too close, the two main lobes merge into a single peak and two lines are not recognised. Rule of thumb: two tones are separated if they are farther apart than about half the width of the main lobe, i.e. 2π/L2\pi/L for the rectangular window. The resolution depends only on the duration LL of the observation and on the window, not on zero-padding.
  • Leakage (spectral leakage): the energy of a tone escapes into the side lobes and can mask a weaker nearby tone, making the amplitude estimates wrong too.

To reduce interference one takes LL as large as possible (narrow main lobes) or changes the window.

Example (lab). x(t)=cos⁡(2πf1t)+10−3cos⁡(2πf2t)+cos⁡(2πf3t)x(t)=\cos(2\pi f_1t)+10^{-3}\cos(2\pi f_2t)+\cos(2\pi f_3t) with f1=1.5f_1=1.5, f2=2.5f_2=2.5, f3=3.5 kHzf_3=3.5\ \mathrm{kHz} and Fs=10 kHzF_s=10\ \mathrm{kHz}: the central tone is 20log⁡1010−3=−60 dB20\log_{10}10^{-3}=-60\ \mathrm{dB} with respect to the others. To see it the side lobes of the two strong tones must be under −60 dB-60\ \mathrm{dB} (with a margin, say −70 dB-70\ \mathrm{dB}): neither the rectangular window (−13 dB-13\ \mathrm{dB}) nor the Hamming window (−42 dB-42\ \mathrm{dB}) does.

2. Sampling in frequency

Computing the NN-point DFT of the observed signal gives the values Y[k]=Y(ej2πk/N)Y[k]=Y(e^{j2\pi k/N}), k=0,…,N−1k=0,\dots,N-1: samples of the DTFT at ω^k=2πk/N\hat\omega_k=2\pi k/N. A tone at an arbitrary ω^0\hat\omega_0 in general does not coincide with one of these points, and the samples can miss the vertex of the main lobe: the estimated amplitude is wrong.

Condition for a correct peak. With N=LN=L, the amplitude is read correctly only if ω^0=2πNk0\hat\omega_0=\frac{2\pi}{N}k_0 with k0k_0 an integer (the tone falls on a bin). Equivalent: the window contains an integer number k0k_0 of periods of the tone. Then the main lobe is sampled at the vertex and all the other samples fall on the zeros: the DFT is a single line.

The reason: for ω^0=2πk0/N\hat\omega_0=2\pi k_0/N the samples x[0]=1x[0]=1 and x[N]=ej2πk0=1x[N]=e^{j2\pi k_0}=1 coincide, so the periodic repetition of the observed stretch has no jump.

Example. L=N=32L=N=32, x[n]=ej2πk0n/32x[n]=e^{j2\pi k_0n/32}.

  • k0=4k_0=4 (on a bin): ∣X[k]∣=32\lvert X[k]\rvert=32 for k=4k=4 and 00 for all others.
  • k0=4.5k_0=4.5 (halfway between two bins): ∣X[4]∣=∣X[5]∣=20.38\lvert X[4]\rvert=\lvert X[5]\rvert=20.38, ∣X[3]∣=∣X[6]∣=6.82\lvert X[3]\rvert=\lvert X[6]\rvert=6.82 and many other non-zero values (leakage). The sampled peak is 20.3820.38 instead of 3232: a loss of −3.92 dB-3.92\ \mathrm{dB} (scalloping loss).
  • k0=4.25k_0=4.25: peak 28.8128.81 (−0.91 dB-0.91\ \mathrm{dB}).

Zero-padding

To sample the DTFT more densely the signal is completed with zeros and an N>LN>L point DFT is computed. The maximum is sampled closer to the vertex and the amplitude is better estimated. With L=32L=32, k0=4.5k_0=4.5:

NN 32 64 128 1024
sampled peak 20.3820.38 32.0032.00 32.0032.00 32.0032.00

With N=64N=64 the point ω^0=2π⋅9/64\hat\omega_0=2\pi\cdot9/64 is exactly a sample. Zero-padding adds no information: the samples are points of the same curve (the Dirichlet kernel), so it does not separate two tones that the window does not separate, but it allows the peak to be located better.

3. Tapered windows

The rectangular window has the narrowest main lobe (best resolution) but the highest side lobes. A tapered window falls gently to zero at the edges and has much lower side lobes, at the price of a wider main lobe: less leakage, less resolution.

Compromise (leakage versus resolution). Lower side lobes are paid with a wider main lobe; no window improves both. Several windows and lengths are tried and the spectra compared.

With a symmetric w[n]w[n] of length LL (n=0,…,L−1n=0,\dots,L-1):

window formula main lobe width (zero to zero) max side lobe
rectangular 11 4π/L4\pi/L −13.3 dB-13.3\ \mathrm{dB}
triangular (Bartlett) 1−∣n−L−12∣(L−1)/21-\frac{\lvert n-\frac{L-1}2\rvert}{(L-1)/2} 8π/L8\pi/L −26.5 dB-26.5\ \mathrm{dB}
Hann 0.5−0.5cos⁡2πnL−10.5-0.5\cos\frac{2\pi n}{L-1} 8π/L8\pi/L −31.5 dB-31.5\ \mathrm{dB}
Hamming 0.54−0.46cos⁡2πnL−10.54-0.46\cos\frac{2\pi n}{L-1} 8π/L8\pi/L −42.4 dB-42.4\ \mathrm{dB} (course material: −42.7-42.7)
Blackman 0.42−0.5cos⁡2πnL−1+0.08cos⁡4πnL−10.42-0.5\cos\frac{2\pi n}{L-1}+0.08\cos\frac{4\pi n}{L-1} 12π/L12\pi/L −58 dB-58\ \mathrm{dB} (course material: −57-57)

Side-lobe levels depend little on LL; the widths are 4, 8, 8, 8, 124,\ 8,\ 8,\ 8,\ 12 times π/L\pi/L. Hann is a "raised cosine" at 100%; Hamming has a pedestal (0.540.54) that lowers the first side lobe but leaves far lobes decaying less; Blackman adds a corrective term. For the adjustable Kaiser window see Digital Filtering of Audio SignalsA causal FIR filter of order M computes y[n] = sum b_k x[n-k], a weighted moving average whose impulse response is the coefficient sequence; FIR filters are designed by truncating the Fourier series of the ideal response with a window (rectangular gives Gibbs overshoot of 9 percent and 21 dB, tapered windows lower the side lobes and widen the transition, Kaiser adjusts it), while the IIR Butterworth filter has squared modulus 1/(1+(W/W0)^(2N)) and is fixed by order N and cut-off; multirate processing changes the sampling rate by expansion (insert L-1 zeros, then low-pass with cut-off pi/L and gain L) and decimation (low-pass with cut-off pi/M, then keep one sample in M).Digital Filtering of Audio Signals →.

The transforms of cosine windows come from the Dirichlet kernel: 0.5−0.5cos⁡(ω^1n)0.5-0.5\cos(\hat\omega_1n) with ω^1=2π/(L−1)\hat\omega_1=2\pi/(L-1) is a sum of three terms, and in centred form W(ω^)=0.5 D(ω^)+0.25 [D(ω^−ω^1)+D(ω^+ω^1)]W(\hat\omega)=0.5\,D(\hat\omega)+0.25\,\big[D(\hat\omega-\hat\omega_1)+D(\hat\omega+\hat\omega_1)\big] where D(ω^)=sin⁡(Lω^/2)/sin⁡(ω^/2)D(\hat\omega)=\sin(L\hat\omega/2)/\sin(\hat\omega/2). The side lobes of the three terms partly cancel, hence the low side lobes.

Example (lab, weak tone at −60 dB-60\ \mathrm{dB}). With L=217L=217 samples (from the design formula L≥AdB−814.36 ΔfFs+1L\ge\frac{A_{dB}-8}{14.36\,\Delta f}F_s+1 with AdB=70A_{dB}=70, Δf=0.2 kHz\Delta f=0.2\ \mathrm{kHz}, Fs=10 kHzF_s=10\ \mathrm{kHz}, giving 216.9216.9) and a Kaiser window with β=0.1102(70−8.7)=6.755\beta=0.1102(70-8.7)=6.755, the tone at 2.5 kHz2.5\ \mathrm{kHz} emerges at −60.9 dB-60.9\ \mathrm{dB} above a leakage of −67.4 dB-67.4\ \mathrm{dB}. With the rectangular and the Hamming window of the same length the maximum around 2.5 kHz2.5\ \mathrm{kHz} is at −32.5 dB-32.5\ \mathrm{dB} and −48.7 dB-48.7\ \mathrm{dB}, well above the −60 dB-60\ \mathrm{dB} tone: it is leakage of the strong tones and the weak tone cannot be told apart.

4. Real sinusoids and two close tones

A real sinusoid x[n]=Acos⁡(ω^0n)=A2ejω^0n+A2e−jω^0nx[n]=A\cos(\hat\omega_0n)=\frac A2e^{j\hat\omega_0n}+\frac A2e^{-j\hat\omega_0n} is the sum of two exponentials at opposite frequencies. Everything above holds for each; it suffices to estimate the one in 0≤ω^0≤π0\le\hat\omega_0\le\pi because the other is its mirror. With a rectangular window and a tone on a bin: ∣X[k0]∣=∣X[N−k0]∣=AL/2\lvert X[k_0]\rvert=\lvert X[N-k_0]\rvert=AL/2, so A=2∣X[k0]∣/LA=2\lvert X[k_0]\rvert/L. With a generic window the peak is A2∑nw[n]\frac A2\sum_nw[n] and A=2∣X∣/∑nw[n]A=2\lvert X\rvert/\sum_nw[n] (coherent gain). Example. A=3A=3, L=N=32L=N=32, ω^0=2π⋅5/32\hat\omega_0=2\pi\cdot5/32: ∣X[5]∣=∣X[27]∣=48\lvert X[5]\rvert=\lvert X[27]\rvert=48 and A=2⋅48/32=3A=2\cdot48/32=3. With a Hann window (∑w≈16\sum w\approx16) about A2⋅16=24\frac A2\cdot16=24 would be read.

Example: two close tones. One observes LL samples of x[n]=cos⁡(0.2πn)+1.5cos⁡(0.227πn)x[n]=\cos(0.2\pi n)+1.5\cos(0.227\pi n) with a Hann window centred at ns=2000n_s=2000. The separation is 0.027π0.027\pi. The Hann main lobe has width 8π/L8\pi/L, half-width 4π/L4\pi/L:

  • L=75L=75: 4π/75=0.053π>0.027π4\pi/75=0.053\pi>0.027\pi, the lobes merge: a single peak, at 0.217π0.217\pi, of height 39.639.6.
  • L=301L=301: 4π/301=0.0133π<0.027π4\pi/301=0.0133\pi<0.027\pi: two separate peaks, at 0.200π0.200\pi (height 74.974.9) and 0.227π0.227\pi (height 112.4112.4).

If two tones are closer than the resolution, the result also depends on the relative phase with which the two lobes add: the same L=75L=75 with another window position may give a single peak or two false humps at 0.183π0.183\pi and 0.236π0.236\pi. Below the resolution one cannot say whether there are one or two tones.

In practice. (1) Fix the wanted resolution Δω^\Delta\hat\omega and choose L≥c⋅2π/Δω^L\ge c\cdot2\pi/\Delta\hat\omega with cc about 11 for rectangular, 22 for Hann/Hamming, 33 for Blackman. (2) Choose the window from the needed dynamic range: if a strong tone can hide one −60 dB-60\ \mathrm{dB} down, side lobes under −60 dB-60\ \mathrm{dB} are needed (Blackman, Kaiser). (3) Choose N≥LN\ge L (a power of two, zero-padding) to read peaks better. (4) Correct the amplitude with the coherent gain ∑w[n]\sum w[n] and remember the loss of up to 3.9 dB3.9\ \mathrm{dB} if the tone is not on a bin.

5. Short-time Fourier transform and spectrogram

The DFT gives the global spectrum of a finite signal: it says which frequencies are present but not when. An audio signal, a voice, a moving whistle have a frequency content that changes in time. Computing one enormous DFT over the whole signal would require waiting for all the samples and a huge computation, unacceptable for real-time processing. The solution is to view the long signal as the concatenation of many short signals and compute many short DFTs: the short-time Fourier transform (STFT), whose graphical representation is the spectrogram.

Definition (STFT). Let x[n]x[n] be a long sequence and w[n]w[n] an analysis window (for instance Hann), non-zero only for n=0,…,L−1n=0,\dots,L-1, with LL much smaller than the length of xx. For each analysis instant ℓ\ell: X[k,ℓ]=∑n=0L−1w[n] x[ℓ+n] e−j2πkn/N,k=0,1,…,N−1,N≥L.X[k,\ell]=\sum_{n=0}^{L-1}w[n]\,x[\ell+n]\,e^{-j2\pi kn/N},\qquad k=0,1,\dots,N-1,\quad N\ge L.

Two steps: windowing (w[n]x[ℓ+n]w[n]x[\ell+n] extracts the stretch of length LL starting at ℓ\ell, a frame, and weights it) and a short DFT of NN points (zero-padded if N>LN>L) giving the local spectrum. The parameter kk is the frequency: ω^k=2πk/N\hat\omega_k=2\pi k/N, i.e. fk=kFs/Nf_k=kF_s/N. The parameter ℓ\ell is the time; it moves in jumps of RR samples (hop size), ℓ=mR\ell=mR with 1≤R<L1\le R<L. If R<LR<L the frames overlap; the common choice is R=L/2R=L/2 (50% overlap). The number of frames for a signal of length DD is ⌊(D−L)/R⌋+1\lfloor(D-L)/R\rfloor+1.

Example. D=10 000D=10\,000 samples, L=301L=301, R=30R=30 and N=1024N=1024: ⌊(10000−301)/30⌋+1=324\lfloor(10000-301)/30\rfloor+1=324 frames; for a real signal the bins k=0,…,512k=0,\dots,512 (N/2+1=513N/2+1=513 values) suffice by conjugate symmetry. With L=75L=75 and R=8R=8: 12411241 frames.

Spectrogram. X[k,ℓ]X[k,\ell] is a function of two variables. It is shown as an image: horizontal axis time (ℓ=mR\ell=mR), vertical axis frequency (ω^k\hat\omega_k in rad/sample, ω^/π∈[0,1]\hat\omega/\pi\in[0,1], or Hz), grey level (or colour) proportional to ∣X[k,ℓ]∣\lvert X[k,\ell]\rvert, to 20log⁡10∣X[k,ℓ]∣20\log_{10}\lvert X[k,\ell]\rvert (dB scale, which also shows weak components) or to ∣X∣2\lvert X\rvert^2 (power density). A bright horizontal line is a stable tone; an inclined line a rising or falling frequency; a vertical dash an impulse (flat spectrum). Example (lab). scipy.signal.spectrogram with a Hamming window of 256256 samples, nfft=256 and noverlap=128: R=128R=128, frequency resolution Fs/256F_s/256 and for a 10 00010\,000-sample signal ⌊(10000−256)/128⌋+1=77\lfloor(10000-256)/128\rfloor+1=77 frames and 129129 bins.

The time-frequency trade-off

The most important choice is the window length LL, which acts in two opposite ways.

Frequency resolution. Each spectral line appears in the spectrogram as the main lobe of the window transform, whose width is inversely proportional to LL: Δω^≃c 2πL\Delta\hat\omega\simeq c\,\dfrac{2\pi}{L}, with cc depending on the window (main lobe 4π/L4\pi/L rectangular, 8π/L8\pi/L Hann and Hamming, 12π/L12\pi/L Blackman). Frequencies closer than about the half-width of the lobe merge. To separate close lines a long window is needed. A window shorter than a period of the signal gives no information on its periodicity.

Time resolution. The frame [ℓ,ℓ+L−1][\ell,\ell+L-1] sees a stretch of length LL: a sudden change (for instance a frequency that starts abruptly) appears blurred over an interval comparable to LL. To locate changes precisely a short window is needed.

Time-frequency trade-off. The window must be short to follow changes in time and long to resolve close frequencies: the two requirements are opposite and cannot be satisfied together. For an unknown signal spectrograms with different lengths are computed: what is evident in one may be hidden in another.

Example: two close tones and a transition. The test signal (length 10 00010\,000) is x[n]=cos⁡(0.2πn)+1.5cos⁡(0.227πn)x[n]=\cos(0.2\pi n)+1.5\cos(0.227\pi n) for 0≤n<50000\le n<5000; cos⁡(0.2πn)\cos(0.2\pi n) for 5000≤n<70005000\le n<7000; cos⁡(0.6πn)+cos⁡(0.7πn)\cos(0.6\pi n)+\cos(0.7\pi n) for 7000≤n<100007000\le n<10000. STFT with a Hann window, N=1024N=1024, at three instants:

instant nn true content L=301L=301 L=75L=75
20002000 tones at 0.2π0.2\pi and 0.227π0.227\pi two peaks: 0.200π0.200\pi (74.474.4) and 0.227π0.227\pi (112.2112.2) a single peak at 0.217π0.217\pi (39.339.3)
60006000 one tone at 0.2π0.2\pi a peak at 0.199π0.199\pi a peak at 0.199π0.199\pi (wide)
80008000 tones at 0.6π0.6\pi and 0.7π0.7\pi two peaks 0.600π0.600\pi, 0.699π0.699\pi two peaks 0.600π0.600\pi, 0.699π0.699\pi (wide)

The tones at 0.2π0.2\pi and 0.227π0.227\pi are 0.027π0.027\pi apart. With L=301L=301 the Hann half-width is 4π/301=0.0133π4\pi/301=0.0133\pi, so they are resolved; with L=75L=75 it is 4π/75=0.053π4\pi/75=0.053\pi, so they are merged. Those at 0.6π0.6\pi and 0.7π0.7\pi are 0.1π0.1\pi apart and are separated even with L=75L=75. For two tones at distance Δω^\Delta\hat\omega the condition on Hann is 4π/L<Δω^4\pi/L<\Delta\hat\omega: with Δω^=0.027π\Delta\hat\omega=0.027\pi one gets L>148L>148.

The cost in time. At n=7000n=7000 the tone at 0.6π0.6\pi appears suddenly. Measuring the amplitude of the line at 0.6π0.6\pi in the frames, the rise from 10% to 90% of the maximum takes ≈145\approx145 samples for L=301L=301 and ≈38\approx38 for L=75L=75: the long window blurs the transition by about L/2L/2 samples, the short one locates it well. A model: for a Hann window centred at tt, with u=(t−7000)/Lu=(t-7000)/L limited to [−12,12][-\tfrac12,\tfrac12], the line has relative amplitude 12+u+sin⁡2πu2π\tfrac12+u+\tfrac{\sin2\pi u}{2\pi} (the area of the window falling after the instant 70007000); at t=7000t=7000 it is 0.50.5. This is an example of the general principle: long window ⇒\Rightarrow frequency resolution ∝1/L\propto1/L and time blur ∝L\propto L; the product of the two uncertainties stays constant.

Choosing the parameters. Window LL: from the wanted resolution, L≥c⋅2π/Δω^L\ge c\cdot2\pi/\Delta\hat\omega (c≃2c\simeq2 for Hann/Hamming) and from the duration of the phenomena to follow (LL no longer than the event). Window shape: Hann or Hamming for a good balance; rectangular only if the narrowest lobe is needed and leakage does not matter. Hop RR: R=L/2R=L/2 by default; R≈0.1LR\approx0.1L for a smoother image (more frames). NN: a power of two, N≥LN\ge L; zero-padding to trace peaks better (it does not change the resolution).

Typical mistakes

  • Confusing zero-padding with an increase of resolution, or reading the amplitude of an off-bin tone without correction.
  • Believing that a longer window lowers the side lobes of the rectangular window: it only narrows the lobes.
  • Believing that zero-padding improves time or frequency resolution in the spectrogram: it only densifies the samples.
  • Using a single window length for a signal with both close tones and fast transitions.

Versione ripasso

  • Windowing. Observing LL samples is multiplying by wR[n]=u[n]−u[n−L]w_R[n]=u[n]-u[n-L]. For x=Aejω^0nx=Ae^{j\hat\omega_0n}: Y=A WR(ej(ω^−ω^0))Y=A\,W_R(e^{j(\hat\omega-\hat\omega_0)}), WR=e−jω^L−12sin⁡(Lω^/2)sin⁡(ω^/2)W_R=e^{-j\hat\omega\frac{L-1}2}\frac{\sin(L\hat\omega/2)}{\sin(\hat\omega/2)} (Dirichlet kernel).
  • Lobes. Peak L∣A∣L\lvert A\rvert at ω^0\hat\omega_0. Zeros at 2πr/L2\pi r/L. Main lobe width 4π/L4\pi/L; side lobes 2π/L2\pi/L wide. First side lobe −13.3-13.3 dB regardless of LL. L=32L=32: main lobe 0.3930.393 rad. Growing LL narrows the lobe but does not lower the side lobes.
  • Resolution. Two tones separate if farther than about 2π/L2\pi/L (half the main lobe). Depends on LL and the window, not on zero-padding.
  • Leakage. Energy in the side lobes can mask a weaker nearby tone. Lab: a tone −60-60 dB down is invisible with rectangular (−13-13 dB) or Hamming (−42-42 dB).
  • Frequency sampling. The NN-point DFT samples the DTFT at 2πk/N2\pi k/N. With N=LN=L the peak is right only if the tone falls on a bin (integer number of periods).
  • Scalloping. L=N=32L=N=32: tone on a bin (k0=4k_0=4) gives 3232; between bins (k0=4.5k_0=4.5) 20.3820.38 in bins 4 and 5, loss −3.92-3.92 dB; k0=4.25k_0=4.25: 28.8128.81 (−0.91-0.91 dB).
  • Zero-padding. L=32L=32, k0=4.5k_0=4.5: peak 20.3820.38 for N=32N=32, 3232 for N=64,128,1024N=64,128,1024. Does not separate tones the window cannot, but locates the peak better.
  • Tapered windows. Fall to zero at the edges: lower side lobes, wider main lobe. Compromise leakage vs resolution. (Main lobe, max side lobe): rectangular 4π/L4\pi/L, −13.3-13.3 dB; triangular 8π/L8\pi/L, −26.5-26.5; Hann 8π/L8\pi/L, −31.5-31.5; Hamming 8π/L8\pi/L, −42.4-42.4; Blackman 12π/L12\pi/L, −58-58.
  • Formulas. Hann 0.5−0.5cos⁡2πnL−10.5-0.5\cos\frac{2\pi n}{L-1}; Hamming 0.54−0.46cos⁡2πnL−10.54-0.46\cos\frac{2\pi n}{L-1}; Blackman 0.42−0.5cos⁡2πnL−1+0.08cos⁡4πnL−10.42-0.5\cos\frac{2\pi n}{L-1}+0.08\cos\frac{4\pi n}{L-1}; Kaiser in Digital Filtering of Audio SignalsA causal FIR filter of order M computes y[n] = sum b_k x[n-k], a weighted moving average whose impulse response is the coefficient sequence; FIR filters are designed by truncating the Fourier series of the ideal response with a window (rectangular gives Gibbs overshoot of 9 percent and 21 dB, tapered windows lower the side lobes and widen the transition, Kaiser adjusts it), while the IIR Butterworth filter has squared modulus 1/(1+(W/W0)^(2N)) and is fixed by order N and cut-off; multirate processing changes the sampling rate by expansion (insert L-1 zeros, then low-pass with cut-off pi/L and gain L) and decimation (low-pass with cut-off pi/M, then keep one sample in M).Digital Filtering of Audio Signals →.
  • Why Hann has low lobes. Three Dirichlet kernels: 0.5D(ω^)+0.25[D(ω^−ω^1)+D(ω^+ω^1)]0.5D(\hat\omega)+0.25[D(\hat\omega-\hat\omega_1)+D(\hat\omega+\hat\omega_1)], ω^1=2πL−1\hat\omega_1=\frac{2\pi}{L-1}; side lobes partly cancel.
  • Close tones. cos⁡(0.2πn)+1.5cos⁡(0.227πn)\cos(0.2\pi n)+1.5\cos(0.227\pi n) with Hann: separation 0.027π0.027\pi. L=75L=75 (4π/75=0.053π4\pi/75=0.053\pi): one peak at 0.217π0.217\pi; L=301L=301 (0.0133π0.0133\pi): two peaks at 0.200π0.200\pi and 0.227π0.227\pi. Below the resolution the relative phase decides: one or two tones cannot be told.
  • Real sinusoid. Rectangular, on a bin: ∣X[k0]∣=AL/2\lvert X[k_0]\rvert=AL/2, A=2∣X[k0]∣/LA=2\lvert X[k_0]\rvert/L. Generic window: A=2∣X∣/∑w[n]A=2\lvert X\rvert/\sum w[n]. A=3A=3, L=N=32L=N=32: ∣X[5]∣=48\lvert X[5]\rvert=48; with Hann about 2424.
  • Procedure. LL from the resolution (c≈1c\approx1 rectangular, 22 Hann/Hamming, 33 Blackman, units of 2π/L2\pi/L); window from the dynamic range; N≥LN\ge L; correct amplitude with coherent gain (loss up to 3.93.9 dB off-bin).
  • Lab Kaiser. −60-60 dB tone: L≥AdB−814.36 ΔfFs+1=216.9⇒217L\ge\frac{A_{dB}-8}{14.36\,\Delta f}F_s+1=216.9\Rightarrow217, β=0.1102(70−8.7)=6.755\beta=0.1102(70-8.7)=6.755; tone at −60.9-60.9 dB above leakage −67.4-67.4 dB; rectangular and Hamming leave −32.5-32.5 and −48.7-48.7 dB.
  • STFT. X[k,ℓ]=∑n=0L−1w[n] x[ℓ+n] e−j2πkn/NX[k,\ell]=\sum_{n=0}^{L-1}w[n]\,x[\ell+n]\,e^{-j2\pi kn/N}, N≥LN\ge L, ℓ=mR\ell=mR, 1≤R<L1\le R<L (usually L/2L/2). fk=kFs/Nf_k=kF_s/N. Frames for length DD: ⌊(D−L)/R⌋+1\lfloor(D-L)/R\rfloor+1. D=10 000D=10\,000, L=301L=301, R=30R=30, N=1024N=1024: 324 frames, 513 bins; L=75L=75, R=8R=8: 1241 frames.
  • Spectrogram. Image with time horizontal, frequency vertical, level ∝∣X∣\propto\lvert X\rvert, 20log⁡10∣X∣20\log_{10}\lvert X\rvert or ∣X∣2\lvert X\rvert^2. Horizontal line = stable tone; inclined = changing frequency; vertical dash = impulse. Lab: Hamming 256, nfft=256, noverlap=128: R=128R=128, 77 frames, 129 bins.
  • Trade-off. Lobe ≈c 2π/L\approx c\,2\pi/L: long window = good frequency resolution but time blur about L/2L/2; short window = good localisation but merged lines. Try several lengths.
  • Test signal. cos⁡(0.2πn)+1.5cos⁡(0.227πn)\cos(0.2\pi n)+1.5\cos(0.227\pi n) for n<5000n<5000; cos⁡(0.2πn)\cos(0.2\pi n) to 70007000; cos⁡(0.6πn)+cos⁡(0.7πn)\cos(0.6\pi n)+\cos(0.7\pi n) to 10 00010\,000. At n=2000n=2000: L=301L=301 two peaks, L=75L=75 one peak at 0.217π0.217\pi; n=6000n=6000 and 80008000: both resolve (wider with L=75L=75).
  • Transition. The 0.6π0.6\pi tone starts at n=7000n=7000: 10%-90% rise ≈145\approx145 samples (L=301L=301) vs 3838 (L=75L=75). Model: relative amplitude 12+u+sin⁡2πu2π\frac12+u+\frac{\sin2\pi u}{2\pi}, u=t−7000Lu=\frac{t-7000}L; 0.50.5 at t=7000t=7000.
  • Threshold. Hann half-width 4π/L<0.027π⇒L>1484\pi/L<0.027\pi\Rightarrow L>148; tones 0.1π0.1\pi apart separate with L=75L=75.
  • Parameters. L≥c⋅2π/Δω^L\ge c\cdot2\pi/\Delta\hat\omega, not longer than the event; R=L/2R=L/2 (0.1L0.1L for smoother); NN power of two. Principle: frequency resolution ∝1/L\propto1/L, time blur ∝L\propto L.
  • Typical mistakes: zero-padding as extra resolution; off-bin amplitude uncorrected; longer window believed to lower the rectangular side lobes.

Teoria collegata