outline lecture, week 10 the discrete fourier transform ii · lecture, week 10 the discrete fourier...
TRANSCRIPT
Lecture, week 10The Discrete Fourier Transform II
Week 10, INF3190/4190
Andreas Austeng
Department of Informatics, University of Oslo
October 2019
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 1 / 21
Outline
Outline
1 Spectral smoothingSpectral smoothingDiscrete time windowsWindow resolution
2 Using the DFTLinear convolution of long sequencesBandlimited interpolation
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 2 / 21
Spectral smoothing
Outline
1 Spectral smoothingSpectral smoothingDiscrete time windowsWindow resolution
2 Using the DFTLinear convolution of long sequencesBandlimited interpolation
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 3 / 21
Spectral smoothing
Finite length data (I)
If we define a window w [n] =
(1, n 2 0, 1, . . . , N � 10 otherwise
and a periodic signal xp[n], n 2 �1 . . .1,then the product x [n] = xp[n] w [n]describes a time limited version of xp[n].Taking the DFT of x [n] might cause problems as:
I Spectral leakage (when N 6= kTs, k 2 N, Ts being the period of xp[n])I Smoothing
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 4 / 21
Spectral smoothing
Finite length data (II)
Effect of rectangularwindowing on the spectrumof a sinousoidal signal.x [n] = xp[n] w [n], i.e.X (e|!) = Xp(e|!) ⇤W (e|!).
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 5 / 21
Spectral smoothing
Finite length data (III)Different parts of the periodic signal xp[n] = 0.5 sin(2⇡F0n):
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
-5
0 100 200 300 400 500�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 11FsF0
-5
DFT)
DFT)
DFT)
-Fs2
-F0 0 F0 Fs2
0
14
12
Mag
nitu
de
N = 3FsF0
-Fs2
-F0 0 F0 Fs2
0
14
12
Mag
nitu
de
N = 11FsF0
-5
-Fs2
-F0 0 F0 Fs2
0
14
12
Mag
nitu
de
N = 11FsF0
-5
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 6 / 21
Spectral smoothing
Finite length data (IV)Different parts of the periodic signal xp[n] = 0.5 sin(2⇡F0n) + 0.5 sin(2⇡F1n):
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
-5
0 100 200 300 400 500�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 11FsF0
-5
DFT)
DFT)
DFT)
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 7 / 21
Spectral smoothing Spectral smoothing
The spectrum of a time limited window function
A window w [n] =
(1, n 2 0, 1, . . . , N � 10 otherwise
has the DTFT W (⌦) = sinN⌦/2sin⌦/2 e�|(N�1)⌦/2
> N = 14;> omega = l inspace(�pi , p i ,512) ;> W = ( s in (N*omega / 2 ) . / s in (omega / 2 ) ) . . .
. * exp(�j * (N�1)*omega / 2 ) ;> p l o t (omega , r e a l (W ) ) ;
> h = fvtool (ones (N , 1 ) /N , 1 , . . .' f requencyrange ' , ' [�pi , p i ) ' ) ;
> p r i n t �dpng WindowedSin
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 8 / 21
Spectral smoothing Discrete time windows
Response, typical windows; quality metrics
Quality metrics, windows;I Maks verdi; Peak value (P)I Maks sidelobe value, Peak Sidelobe Level (PSL)I -3dB width (W3), ⇠
p2/2 P
I -6dB width (W6), ⇠ 0.5P
I Width, 1st zero (WM )I Width to reach max-SL level (WS)
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 9 / 21
Spectral smoothing Discrete time windows
Some typicalwindows (I)
The different windowsgive compromisesbetween resolution andleakage
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 10 / 21
Spectral smoothing Discrete time windows
Some typical windows (II)
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 11 / 21
Spectral smoothing Discrete time windows
Finite length data – rectangular windowDifferent parts of the periodic signal xp[n] = 0.5 sin(2⇡F0n) + 0.5 sin(2⇡F1n):
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
eN = 3Fs
F0-5
0 100 200 300 400 500�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 11FsF0
-5
DFT)
DFT)
DFT)
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 12 / 21
Spectral smoothing Discrete time windows
Finite length data – Hamming windowDifferent parts of the periodic signal xp[n] = 0.5 sin(2⇡F0n) + 0.5 sin(2⇡F1n):
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
�20 0 20 40 60�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 3FsF0
-5
0 100 200 300 400 500�1.5
�1.0
�0.5
0.0
0.5
1.0
1.5
Am
plitud
e
N = 11FsF0
-5
DFT)
DFT)
DFT)
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
-Fs2
-F1-F0 0 F0F1 Fs2
0
14
12
Mag
nitu
de
FDFT {x[n]} = X[k]
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 13 / 21
Spectral smoothing Window resolution
Windows, resolution (I)How close can two frequencies be if we want to be able to separate them?
Frequency resolution: �f = WMFs, where WM is window dependent and gives distance to 1stzero, and Fs is the sampling frequency.
Eksempel:
Given:
x(t) = A1 cos 2⇡f0t + A2 cos 2⇡(f0 + �f )t
A1 = A2 = 1 f0 = 30 Hz Fs = 128 Hz
(a) What is the smallest resolvable �f using a Boxcar (rectangular) and Hanning (vonHann) window when:
i N = 256, Zero-padded to length 2048ii N = 512, Zero-padded to length 2048iii N = 256, Zero-padded to length 4096
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 14 / 21
Spectral smoothing Window resolution
Windows, resolution (II)Answer to "(a) What is the smallest resolvable �f using a Boxcar and Hanning, when"
i N = 256, Zero-padded to length 2048) Boxcar: �F = 2
NFs = 2
256 128Hz = 1Hz
) Hanning: �F = 4N
Fs = 4256 128Hz = 2Hz
ii N = 512, Zero-padded to length 2048) Boxcar: �F = 2
NFs = 2
512 128Hz = 0.5Hz
) Hanning: �F = 4N
Fs = 4512 128Hz = 1Hz
iii N = 256, Zero-padded to length 4096) Boxcar: �F = 2
NFs = 2
256 128Hz = 1Hz
) Hanning: �F = 4N
Fs = 4256 128Hz = 2Hz
Boxcar gives the best resolution, but has the highest sidelobes / spectral leakage.
The resolution improves when N is increased.
Zero-padding has no effect..
Hanning gives half the resolution, but has less leakage.
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 15 / 21
Spectral smoothing Window resolution
Windows,resolution (III)
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 16 / 21
Using the DFT
Outline
1 Spectral smoothingSpectral smoothingDiscrete time windowsWindow resolution
2 Using the DFTLinear convolution of long sequencesBandlimited interpolation
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 17 / 21
Using the DFT Linear convolution of long sequences
Convolution of long sequences
Given h[n] of length N1, and x [n] of length N2.1 Zero-pad h[n] and x [n] to length L � N1 + N2 � 1.2 Compute L-point DFT of h[n] and x [n].3 Perform multiplication: Y [k ] = H[k ] X [k ].4 Find inverse of Y [k ]! y [n] = h[n] ⇤ x [n].
Sometime, this is not practical:I Long sequences require much storage, large computational load, and long time (we
have to wait for last sample).Solution: Block-convolution. Two types:
I Overlap-addI Overlap-save
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 18 / 21
Using the DFT Linear convolution of long sequences
Overlap-add
1 Split x [n] into m sequences xi [n] oflength M.
2 Compute convolution of xi [n] and h[n](of length N1 + M � 1).
I May be done using DFTs3 Add all Xi [k ]
X [k ] =M�1Pi=0
Xi [k ]
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 19 / 21
Using the DFT Linear convolution of long sequences
Overlap-save
Let x [n] be the long sequence:1 Zero-pad x [n] with N � 1 zeros in front.2 Divide into k over-lapping segments
(N � 1 elements overlapp) of lengthM + N � 1 (larger than length of h[n]).
3 Zero-pad h[n] to length M + N � 1.4 Compute the circular convolution of
each part and cut overlapping region.
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 20 / 21
Using the DFT Bandlimited interpolation
Interpolation in frequency, from length N to N ⇥M
1 x [n]DFT! X [k ]
2 Zero-pad X [k ] til Xi [k ] as follows:
Xi [k ] =
({X [0], . . . ,X [N/2 � 1], . . . (M � 1)N ”zeros” . . .X [N/2], . . . ,X [N � 1] If N odd{X [0], . . . , 0.5X [N/2], . . . (M � 1)N � 1 ”zeros” . . . 0.5X [N/2], . . . ,X [N � 1] if N even
3 xi [n]DFT Xi [k ]
Equivalentto zero-pad x [n] between samples, perform DFT, LP-filter result, and IDFT.
AA, IN3190/4190 (Ifi/UiO) Lecture, week 10 Oct. 2019 21 / 21