Remarks on DFT Notes
Total Page:16
File Type:pdf, Size:1020Kb
Remarks on DFT Notes The two parameters that we have control over in the DFT are the sampling interval ∆t and the total number of points N that determine the sampling period N∆t. The sampling interval ∆t determines the range of frequencies that 1 can be resolved (up to fNyquist = 2∆t ), while N determines the 1 details that can be resolves (∆f = N∆t ) Let's look at some examples to see how the choice of ∆t and N∆t affects the DFT. Example 1: What happens if the sample rate is too low? i.e. the signal contains frequencies that are larger than the Nyquist frequency. Aliasing Notes Consider a sine function f (t) = sin(2πft), with f = 4Hz,∆t = 0:2 s and N = 32. fNyquist = 1=(2 · 0:2s) = 2:5 Hz. Therefore, f > fNyquist Aliasing Notes Below is the power spectrum of the sine function. There is a peak at 1 Hz and 4 Hz, where the latter corresponds to the negative frequency −1 Hz. Aliasing Notes The frequency f = 4 Hz is 1:5 Hz above the Nyquist frequency (2:5 Hz). It gets folded back into the frequency range below the Nyquist frequency. This is called aliasing. ∗ Due to the symmetry YN=2−n = YN=2+n around the Nyquist frequency, it appears as a low frequency fNyquist − 1:5 Hz = 1 Hz. This is what we see in the power spectrum. Note: When sampling audio data, for example, a low pass filter is used to cut off frequencies beyond the audible spectrum of 20 KHz in order to avoid aliasing. The filter rolls off smoothly for a few kHz. Therefore, CD's audio are typically sampled at 2 · 22050 = 44100 Hz after the filter applied. Aliasing Notes Aliasing can be illustrated if we overplot a 1 Hz sinusoid onto the sampling points. On the ∆t = 0:2 sampling interval, 1 and 4 Hz frequencies are indistinguishable. DFT - comments I Notes When frequencies higher than 1=1∆t are present in a signal that undergoes DFT, aliasing occurs. Typically this leads to folding back of high frequency components to lower frequencies. When sampling a signal at a certain sampling rate 1=∆t it may be desirable to pass it through a low pass filter to get rid of frequencies above fNyquist. When going from frequency back to the time domain, often get non-zero imaginary components, while the real part is reconstructed correctly. Spectral/Frequency Leakage Notes Consider a triangular wave signal with period T = 3:2 s sampled at ∆t = 0:1 s. The total number of sampling points is N = 500. Therefore, the total sampling period is 50 s. Spectral/Frequency Leakage Notes Below is the computed Power spectrum jDFT (f (t))j2. Expect a a series of equally spaced sharp peaks at integer multiples of the f = 1=T = 0:3125 Hz. However, peaks are broad! Spectral/Frequency Leakage Notes Let's increase the sampling period to 51:2 s, which is an integer multiple of the period of the triangular wave. The total number of sampling points is now N = 512. Spectral/Frequency Leakage Notes Peaks in the power spectrum (below) are sharp and occupy only frequency bins at integer multiples of f . Spectral/Frequency Leakage Notes Reason: DFT yields frequency spectrum at discrete frequencies n N∆t , with n = 0 ::: N=2 − 1. If frequency components of signal do not match these discrete frequencies exactly, frequency amplitudes get smeared out. This is refereed to as \spectral leakage" or \frequency leakage". If the signal/function is periodic with frequency f = 1=T , we know that it contains only frequencies that are integer multiples of f . By choosing a sample period N∆t = mT , where m is an integer, we ensure that frequency bins can match f exactly, so leakage is avoided. Windowing Notes There is another way of mitigating the effects of spectral leakage in the power spectrum: Applying a window function to the signal. The Fourier transform of a finite sampling period can be considered as a product between the infinite signal and the window function: Windowing Notes Multiplication of two functions in the time domain corresponds to convolution of their Fourier transforms in the frequency domain (Convolution theorem works in both directions). The discrete Fourier transform of the rectangular window is just PN−1 −i2πmn=N m=0 e . However, in order to see the leakage of the absolute amplitudes, one looks at the square of the Fourier transform: 2 N−1 2 1 X 1 sin(πn) W = e−i2πmn=N = n N2 N2 sin(πn=N) m=0 This function has a main peak and side lobes. It is the side lobes that smear out the frequency spectrum and cause leakage. The goal is to find a different window function where the side lobes fall off faster as a function of the frequency bins. Windowing Notes There are plenty of window functions,but these are the most common ones: j − 1 N w = 1 − 2 ≡ \Bartlett window" j 1 2 N 1 2πj w = 1 − cos ≡ \Hann window" j 2 N 1 !2 j − 2 N wj = 1 − 1 ≡ \Welch window" 2 N Windowing Notes Numerical recipes (page 560) Windowing Notes Numerical recipes (page 561) Windowing Notes Example: Apply Hann window function to the triangular wave (N = 500), where period of the function is not commensurate with the sampling period. Windowing Notes Black points denote the power spectrum without the window function, red points correspond to the power spectrum of the product of triangular wave with the window function. Peaks are much sharper! DFT - comments II Notes If signal is periodic, the easiest way to avoid spectral leakage is to choose the sampling period to be an integer multiple of the period of the function. For non-periodic signals or if periodicity is unknown windowing can mitigate the effects of leakage. Choice of window function determines trade-off between narrowness of main peak and the decay of the sidelobes. Rectangular window has narrow main peak (good to determine comparable strength signals) but slow decay of sidelobes (bad for resolving nearby frequency components). Windowing can be useful when trying to resolve nearby frequencies that are masked/washed out by spectral leakage. Optimal Wiener filtering Notes Previously we considered simple deconvolution of a signal that is noise free. Recall the convolution theorem: F[u ⊗ r] = F[u]F[r] Therefore, if s = u ⊗ r, then F[s] u = F−1 F[r] However, in practice the measured signal s(t) is usually corrupted with noise, which makes this method unreliable. Optimal Wiener filtering Notes In general, a measured signal can be written as c(t) = [u(t) ⊗ r(t)] + n(t) (1) c(t) = s(t) + n(t); (2) where u(t) is the noise free, deconvoluted signal, r(t) the impulse response function and n(t) the noise term. Goal: Construct a filter φ(t) (or Φ(f )) to be applied to c(t) (or C(f )) in order to obtain an estimate of the uncorrupted signal u(t) (or U(f )). In particular we will estimate the true signal U(f ) as follows: C(f )Φ(f ) U~ (f ) = (3) R(f ) Optimal Wiener filtering Notes We demand U~ to be close to U in the mean square sense. Therefore we want to minimize the following integral: Z 1 Z 1 ju~(t) − u(t)j2dt = jU~ (f ) − U(f )j2df ; −∞ −∞ where we used Parseval's theorem. Substituting eqn.'s (2) and (3), we obtain Z 1 2 C(f )Φ(f ) S(f ) = − df ; −∞ R(f ) R(f ) Z 1 2 [S(f ) + N(f )]Φ(f ) S(f ) = − df ; −∞ R(f ) R(f ) Optimal Wiener filtering Notes Z 1 2 C(f )Φ(f ) S(f ) = − df ; −∞ R(f ) R(f ) Z 1 = jR(f )j−2 j[S(f ) + N(f )]Φ(f ) − S(f )j2 df ; −∞ Z 1 = jR(f )j−2 jS(f )[Φ(f ) − 1] + N(f )Φ(f )j2 df −∞ Z 1 = jR(f )j−2 jS(f )j2j1 − Φ(f )j2 + jN(f )j2jΦ(f )j2 df −∞ In the last step cross product between N and S integrated over the frequencies gives zero, since they are uncorrelated. Optimal Wiener filtering Notes In order to find Φ(f ) that minimizes the integral we differentiate the integrand and set it to zero: @ jS(f )j2j1 − Φ(f )j2 + jN(f )j2jΦ(f )j2 = 0 @Φ(f ) −2jS(f )j2j1 − Φ(f )j + 2jN(f )j2jΦ(f )j = 0 Therefore, Wiener Filter jS(f )j2 Φ(f ) = (4) jS(f )j2 + jN(f )j2 which we can use to estimate true signal: C(f )Φ(f ) U~ (f ) = R(f ) Optimal Wiener filtering Notes Still a little problem jS(f )j2 Φ(f ) = jS(f )j2 + jN(f )j2 The Wiener filter involves S, the smeared (convoluted signal) and the noise N. However, we only know the measured noisy signal C(f ) = S(f ) + N(f ) (or c(t) = s(t) + n(t)). How do we determine Φ(f )? We can estimate jS(f )j2 and jS(f )j2 + jN(f )j2 from the power spectrum of the measured signal c(t), since jC(f )j2 = jS(f )j2 + jN(f )j2. (This equation be proven via the Wiener-Khinchin theorem) Optimal Wiener filtering Notes Extrapolate noise spectrum to separate jS(f )j2 and jN(f )j2 (jN(f )j2 can be flat, tilted, smoothly varying - does not matter). Optimal Wiener filtering Notes Remarks: Quality of results second order in precision to which the optimal filter is determined.