25
Revision of sampled signals Windowing and Localization From Fourier Series to Analysis of Non-stationary Signals - VI prof. Miroslav Vlcek November 16, 2010 prof. Miroslav Vlcek Lecture 6

From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

From Fourier Series to Analysis ofNon-stationary Signals - VI

prof. Miroslav Vlcek

November 16, 2010

prof. Miroslav Vlcek Lecture 6

Page 2: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Contents

1 Revision of sampled signals

2 Windowing and Localization

prof. Miroslav Vlcek Lecture 6

Page 3: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Contents

1 Revision of sampled signals

2 Windowing and Localization

prof. Miroslav Vlcek Lecture 6

Page 4: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Sampling and Aliasing

Nyquist-Shannon Sampling Theorem (1927)

It is possible precisely to reconstruct a continuous-time signalfrom its samples.

1 when the signal is bandlimited;

2 when the sampling frequency is greater than twice thesignal bandwidth.

prof. Miroslav Vlcek Lecture 6

Page 5: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Aliasing in Audio

1 The initial sound is a numerically synthetized piano-tone at440Hz. The sampling frequency is of 44.1kHz (CD-quality).click to play

2 The harmonic frequencies at multiple of the fundamental tone(440Hz) are clearly visible.

0 500 1000 1500 2000 2500 3000 3500 4000 4500 50000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

frequency(Hz)

ampl

itude

prof. Miroslav Vlcek Lecture 6

Page 6: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Aliasing in Audio

1 The sound will be resampled at 2kHz, without precautionsagainst aliasing. The tone sounds rather strange. click to play

2 The aliasing is visible on the graphs as a ”warping” of thefrequencies against a ”mirror” at the Nyquist frequency (1kHz).

0 500 1000 1500 2000 2500 3000 3500 4000 4500 50000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

frequency(Hz)

ampl

itude

prof. Miroslav Vlcek Lecture 6

Page 7: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Aliasing in Audio

1 In order to avoid aliasing, the spectrum of the signal should bezero at frequencies higher than the Nyquist frequency beforeresampling. A low-pass filter is used to achieve this click to play

0 500 1000 1500 2000 2500 3000 3500 4000 4500 50000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

frequency(Hz)

ampl

itude

prof. Miroslav Vlcek Lecture 6

Page 8: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Aliasing and DFT

...for a digital signal processing with DFT there are limits:

1 The signal must be band-limited. This means there is afrequency above which the signal is zero.

2 Hence the maximum useable frequency in the DFT is fs/2 - theNyquist 1 frequency!

1Harry Nyquist 1889-1976prof. Miroslav Vlcek Lecture 6

Page 9: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Nonlocality of DFT

Example 1: Consider two different signals f (t) and g(t) definedon 0 ≤ t ≤ 1 with frequencies f1 = 96 [Hz] f1 = 235 [Hz] asfollows:

f (t) = 0.5 sin(2πf1t) + 0.5 sin(2πf2t)

g(t) =

{

sin(2πf1t) for 0 ≤ t < 0.5

sin(2πf2t) for 0 ≤ t < 0.5

and using the sampling frequency f0 = 1000 [Hz] producesample vectors f and g and compute the DFT of each sampledsignal.

prof. Miroslav Vlcek Lecture 6

Page 10: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Nonlocality of DFT

Two different signals f (t) and g(t) are constructed withMATLAB commands

t1=(0:1/f0:0.499);t2= (0.5:1/f0:1);t=[t1 t2];f=0.5*sin(2*pi*96*t)+0.5*sin(2*pi*235*t);g1=[sin(2*pi*96*t1) zeros(1,501)];g2=[zeros(1,500) sin(2*pi*235*t2)];g=g1+g2;

prof. Miroslav Vlcek Lecture 6

Page 11: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Magnitue of DFT for f (t) and g(t)

0 0.2 0.4 0.6 0.8 1−1

−0.5

0

0.5

1Signal f(x)

0 100 200 300 400 5000

50

100

150

200

250Frequency content of f(t)

frequency (Hz) provided f0=1/N

0 0.2 0.4 0.6 0.8 1−1

−0.5

0

0.5

1Signal g(t)

0 100 200 300 400 5000

50

100

150

200

250

300Frequency content of g(t)

frequency (Hz) provided f0=1/N

prof. Miroslav Vlcek Lecture 6

Page 12: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Nonlocality of DFT

• It is obvious that each signal contains dominant frequenciesclose to 96 [Hz] 235 [Hz] and the magnitudes are fairly similar.

• But the signals f (t) and g(t) are quite different in the timedomain !

• The example illustrates one of the shortcomings of traditionalFourier transform: nonlocality or global nature of the basisvectors WN or its constituting analog waveforms ej2πkt/T ,

prof. Miroslav Vlcek Lecture 6

Page 13: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Detail of signal g(t)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1

−0.5

0

0.5

1Signal g(x)

0 50 100 150 200 250 300 350 400 450 5000

50

100

150

200

250

300Frequency content of g(t)

frequency (Hz)

prof. Miroslav Vlcek Lecture 6

Page 14: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Nonlocality of DFT

• Discontinuities are particularly troublesome.

• The signal g(t) consists of two sinusoids only, but the excitationof several Gk in frequency domain gives the impression that theentire signal is higher oscillatory.

• We would like to have possibility to localize the frequencyanalysis to smaller portions for the signal.

• These requirements led to development of windowed Fouriertransform or short time Fourier transform - STFT.

prof. Miroslav Vlcek Lecture 6

Page 15: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Windowing

Consider a sampled signal x ∈ CN , indexed from 0 to N − 1. We wishto analyze the frequencies present in x, but only within a certain timerange. We choose integers m ≥ 0 and M such that m + M ≤ N anddefine a vector w ∈ CN as

w(k) =

{

1 for m ≤ k ≤ m + M − 10 otherwise

Define a vector y with components

y(k) = w(k)x(k) for 0 ≤ k ≤ N − 1.

We use notation y = wx and refer to the vector w as the window.

prof. Miroslav Vlcek Lecture 6

Page 16: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Windowing

Consider a sampled signal x ∈ CN , indexed from 0 to N − 1. We wishto analyze the frequencies present in x, but only within a certain timerange. We choose integers m ≥ 0 and M such that m + M ≤ N anddefine a vector w ∈ CN as

w(k) =

{

1 for m ≤ k ≤ m + M − 10 otherwise

Define a vector y with components

y(k) = w(k)x(k) for 0 ≤ k ≤ N − 1.

We use notation y = wx and refer to the vector w as the window.

prof. Miroslav Vlcek Lecture 6

Page 17: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Windowing

Proposition Let x and w be vectors in CN with discrete Fouriertransforms X and W, respectively. Let y = wx have DFT Y. Then

Y =1N

X ∗ W,

where ∗ is circular convolution in CN .An N-point circular convolution of N-periodic vectors X and W is alsodefined as follows

Y (n) =1N

N−1∑

m=0

X(m)W ((n − m) mod N).

prof. Miroslav Vlcek Lecture 6

Page 18: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Windowing

• In processing of a non-stationary signal we want to assume thesignal is short-time stationary and perform a Fourier transformon these small blocks.

• Solution: multiple the signal by a window function that is zerooutside some defined range.

• The rectangular window is defined as:

w(n) =

{

1 for 0 ≤ n < N

0 otherwise

• Use command wr=recwin(N) to produce the N-pointrectangular window.

prof. Miroslav Vlcek Lecture 6

Page 19: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Windowing

• The most common in speech analysis is the Hamming window:

w(n) =

{

0.54 + 0.46 cos(2π nN−1 ) for 0 ≤ n < N

0 otherwise

• Use command wh = hamming(N) to produce the N-pointHamming window.

• Another type of window is the Blackman window:

w(n) =

{

0.42 + 0.5 cos(2π nN−1 ) + 0.08 cos(4π n

N−1 ) for 0 ≤ n < N

0 otherwise

• Use command wb = blackman(N) to produce the N-pointBlackman window.

prof. Miroslav Vlcek Lecture 6

Page 20: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

Windowing result

0 100 200 300−1

−0.5

0

0.5

1rectangular windowed sine wave

discrete time0 100 200 300

−1

−0.5

0

0.5

1Hamming windowed sine wave

discrete time

0 100 200 3000

10

20

30

40

50

60

70FFT of rectangular windowed sine wave

frequency0 100 200 300

0

5

10

15

20

25

30

35FFT of Hamming windowed sine wave

frequency

prof. Miroslav Vlcek Lecture 6

Page 21: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

MATLAB project Windowing

Consider signal f (t) = sin(2πf1t) + 0.4 sin(2πf2t) defined on0 ≤ t ≤ 1 with frequencies f1 = 137 [Hz] and f1 = 147 [Hz]:

1 Use MATLAB to sample f (t) at 1000 points tk = k/f0 withsampling frequency f0 = 1000 [Hz]f0=1000; % sampling frequencyf1=137; % 1. frequencyf2=137; % 2. frequencyt=[0:999]/f0;f=sin(2*pi*f1*t)+0.4*sin(2*pi*f2*t); %sampledsignal

2 Compute the DFT of the signal with F=fft(f); or resp.F=fft(f,N);. See the help!

3 Display the magnitude of the Fourier transform withplot(abs(F(1:501))

prof. Miroslav Vlcek Lecture 6

Page 22: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

MATLAB project Windowing

4 Construct a rectangular windowed version of f (n) of length1000 with commandsfwa=f;fwa(201:1000)=0.0;

5 Compute the DFT and display the magnitude of the first501 components.

6 Can you distinguish the two constituent frequencies? Becareful - is it really obvious that the second frequency isnot a side lobe leakage?

prof. Miroslav Vlcek Lecture 6

Page 23: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

MATLAB project Windowing

7 Construct a windowed version of f (n) of length 200 withcommandfwb= f(1:200);

8 Compute the DFT and display the magnitude of the first101 components.

9 Can you distinguish the two constituent frequencies?Compare the plot of the DFT of fwa.

10 Repeat the parts 4-9 using other window lengths such as300, 100 or 50. How short can the time window be and stillallow resolution of the two constituent frequencies?

11 Does it matter whether we treat the windowed signal as avector of length 1000 as in part 4 or shorter vector as inpart 7? Does the side lobe energy confuse the results?

prof. Miroslav Vlcek Lecture 6

Page 24: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

MATLAB project Windowing

12 Repeat the previous parts 1-10, but use a triangularwindow

13 You can construct a window vector w of length 201 asw=zeros(1,201);w(1:101)=[0:1:100]/100;w(102:201)=[99:-1;0]/100;

14 Then construct a windowed signal of the length 1000 asfwc=zeros(size(f));fwc(1:201)=f(1:201).*w;

15 Try varying the window length. What is the shortestwindow that allows you to distinguish the two frequencies?

16 Repeat the previous parts 1-10 for the Hamming window.

prof. Miroslav Vlcek Lecture 6

Page 25: From Fourier Series to Analysis of Non-stationary …euler.fd.cvut.cz/predmety/mathtools/files/lecture_06.pdfRevision of sampled signals Windowing and Localization From Fourier Series

Revision of sampled signalsWindowing and Localization

MATLAB project Windowing-Questions

17 Submit the answers for the several questions raised inparts 1-16 as a written Report on Window Functions - dueNovember 23, 2010.

prof. Miroslav Vlcek Lecture 6