EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal...

29
Note Set #22 Using the DFT for Spectral Analysis of Signals Reading Assignment: Sect. 7.4 of Proakis & Manolakis Ch. 6 of Porat’s Book EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29

Transcript of EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal...

Page 1: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Note Set #22• Using the DFT for Spectral Analysis of Signals• Reading Assignment: Sect. 7.4 of Proakis & Manolakis

Ch. 6 of Porat’s Book

EEO 401 Digital Signal Processing

Prof. Mark Fowler

1/29

Page 2: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Goal of Practical Spectral AnalysisGoal: Given a discrete-time signal x[n], use DFT (via FFT)

to analyze its spectral content – in particular, to detect the presence of sinusoids and estimate their frequency.

Challenges: 1. Available signal may be short (e.g., a radar signal

may only be “on” for a very short time).2. If the signal is long, then the spectral content may

change with time (e.g., music spectrum changes with time) – so spectrum may be considered to be constant only a block-by-block basis where the blocks are short.

Both of these drive the need to apply the DFT to a short signal record Challenge = Resolution & Accuracy

2/29

Page 3: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Example Application (Electronic Warfare) Intercept T seconds of a Radar Pulse Train p(t), Compute DFT, detect &

estimate peaks to identify type of radar.

“Underlying” Pulse Train is Periodic Fourier Series

n

tffjnn

pcectp )(2)(

tp(t)

PRI

fp = 1/PRIFS

Since DFT shows samples of the DTFT of the finite duration signal we can study what the DFT gives us by looking at what the DTFT of a finite-duration signal looks like!!

f

)( fPF

fcfp

FTDTFT

of InfiniteDuration

Signal

)(fT P

fcfp

DFT Shows Samples of This DTFT

DFT

Signal Samples

0

N-1

DTFTof FiniteDuration

Signal3/29

Page 4: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Effect of Windowing

Porat Sections 6.1 and 6.2

4/29

Page 5: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Basic Viewpoint of Signal Data We are given a finite # of signal samples, and want to use them to see the spectrum of the infinite-duration signal….How well can we do that?

otherwise ,0

10],[][

Nnnynx

Infinite Duration SignalFinite Duration Signal Available for Processing

Better Math Model – Rectangular Window-Based Model:

otherwise ,0

10,1][ where],[][][

Nnnwnwnynx rr

Math Model for having a finite # of samples:

5/29

Page 6: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Implication of Window-Based Model Since the available data x[n] is related to the unavailable signal y[n] through multiplication we can use the Multiplication Theorem for DTFT (Eq. (2.103) in Porat) to find out what we get!Thus, the DTFT of the signal data is related to the DTFT of the infinite-duration signal by:

dWY

WYX

r

r

)()(21

)(*21)(

ff

fff

where the DTFT of the rect. window is:

)2/sin()2/sin(

2

2

111)(

2)1(

2/2/2/

2/2/2/

1

0

f

/][/][

Ne

jeee

jeee

eeeW

Nj

jjj

NjNjNj

j

NjN

n

njr

Use Euler!

)2/sin()2/sin(),(

NND

Use Geometric Sum

6/29

Page 7: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

The “Dirichlet Kernel” D(,N)• Looks like “sinc”, except periodic• Mainlobe Gets Narrower as N• Sidelobes “Get Lower” as N• Height of Mainlobe = N Looks more like delta as N

-3 -2 -1 0 1 2 3-5

0

5

10

15

/

-3 -2 -1 0 1 2 3-20

0

20

40

60

/

N=41

N=11

D(

,41)

D(

,11)

Nearest Zero@ =2/N

Largest Sidelobe–13 dB w.r.t. ML peak

(For Any N)

Mainlobe Width = 4/N

7/29

Page 8: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Impact of Window

-3 -2 - 0 2 3-0.5

0

0.5

1

1.5

Digital Frequency (rad/sample)

-10

0

10

20

0

10

20

0

0.5

1

1.5

-3 -2 - 0 2 3

-3 -2 - 0 2 3

-3 -2 - 0 2 3

)(f Y

)2/(fr W

)2/()( fr

f WY

)(* ff rWY

To Compute @ /2Shift Window DTFT by /2Form ProductIntegrate - to

Mainlobe EffectSmoothes Edges

Sidelobe Effect“Leakage”

8/29

Page 9: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Impact of Window (pt. 2)

Recall: F()*( – ) = F( – ) so…. f f f

f f1 1 2 2

1( ) ( )21 ( ) ( )

2

rN

r r

X Y W

AW A W

Consider a signal consisting of two complex sinusoids:

Elsewhere Repeats,),()()(

][

2211f

2121

AAY

eAeAny njnj

-3 -2 - 0 2 3-0.5

0

0.5

1

1.5

Digital Frequency (rad/sample)

)(f Y

-3 -2 - 0 2 3

)(fr iW

Sidelobe Leakage (“SL Interference”)Large Sidelobes Obscure Small Sinusoid

9/29

Page 10: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Impact of Window (pt. 3)Consider a signal consisting of two complex sinusoids closely spaced in frequency and similar in amplitude:

-3 -2 - 0 2 3

)(fr iW

-3 -2 - 0 2 3-0.5

0

0.5

1

1.5

Digital Frequency (rad/sample)

)(f Y

-3 -2 - 0 2 3

)(f X

Mainlobe SmearingWide Mainlobe “Smears” Sinusoids Together

10/29

Page 11: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

ADC

x[0]x[1]x[2]

x[N-1]

DFT processing

XN[0]XN[1]XN [2]

XN [N-1]

Inside “Computer”

)(tx][nx

CTFTfX )(

2/Fs2/Fsf

DTFTFullX )(

Look here to see aliased view of CTFT

Aliasing

DTFTTruncatedX N )(

“Smearing” DFTComputedkX N ][

NS-21 CTFT-DTFT-DFT Connections – Summary

11/29

Page 12: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Errors in a Computed DFT

CTFT

DTFT

DTFTN

DFT

Aliasing Error – control through Fs choice (i.e. through proper sampling)

“Smearing” Error – control through N choice “window” choice

This is the only thing we can compute from data… and it has all these “errors” in it!! The theory covered here allows an engineer to understand how to control the amount of those errors!!!

“Grid” Error – control through N choice “zero padding”

NS-21 CTFT-DTFT-DFT Connections – Summary

12/29

Page 13: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Let’s imagine we have the following CT Signal: 0)()( bfortuetx bt

)(tx

…1

t

Suppose that 2000b

0 1 2 3 4 5 6 70

0.2

0.4

0.6

0.8

1

n

x[n]

Suppose we sample this signal at Fs = 30 kHz Suppose we take 8 samples….

NS-21 CTFT-DTFT-DFT Connections – Example

13/29

Page 14: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Now put these 8 samples into our computer and compute the DFT without ZP:

ADC

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

Inside “Computer”

memory array

sensor)(tx ][nx

memory array

X[N-1]

)(tx

…1

t0 1 2 3 4 5 6 7

0

0.2

0.4

0.6

0.8

1

n

x[n]

Let’s simulate doing this by using MATLAB!!

14/29

Page 15: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

2000( ) ( )tx t e u t Fs = 30 kHz 1 / sT F

Fs=30000; T=1/Fs;n=0:7;t_n=n*T;b=2000*pi;x=exp(-b*t_n);subplot(2,1,1); stem(n,x); xlabel('n');ylabel('x[n]')

%%%% Now we have 8 signal samples of this signal%%% Now we compute the DFT of it using the fft command%%% ....and we use fftshift to put the results between -pi and pi

X_dft=fftshift(fft(x));

%%% Now plot magnitude of DFTN = length(X_dft);delta_f = Fs/N;f=(-(N/2):((N/2)-1))*delta_f;subplot(2,1,2); stem(f,abs(X_dft)); xlabel('f (Hz)');ylabel('|DFT|')

We have three choices:(a) Against index k values

(Rarely a good choice)(b) Against DT freq Omega (rad/sample) between -pi and pi

(Use if you only care about “DT world”)(c) Against CT frequency f (Hz) between -Fs/2 and Fs/2

(Use when you care about “link to CT world”)

See Next Slide…

15/29

Page 16: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Creation of Frequency Vector for DFT PlottingWhen computing the DFT (using fft) you get N numbers that tell the values the DFT coefficients have. But you need to know what frequencies they are at…

We’ll assume that you are using fftshift, which moves the DFT coefficients around so they lie in the frequency range - to

To plot versus f in Hz:• For N DFT points… the frequency spacing between them is • With fftshift, the frequencies start at –Fs/2• Thus the command that makes these frequency points is

f = ( (-N/2):( (N/2) -1 ) )*Fs/N

sF N

To plot versus in rad/sample:• For N DFT points… the frequency spacing between them is • With fftshift, the frequencies start at -• Thus the command that makes these frequency points is

omega = ( (-N/2):( (N/2) -1 ) )*2*pi/N

2 N

Example for our N=8 case: omega = (-4:3)*2*pi/8

gives the vector [-pi -3pi/4 -pi/2 –pi/4 0 pi/4 pi/2 3pi/4]

8 pointsStarts at piStops “just shy of pi”

16/29

Page 17: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

ADC

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

Inside “Computer”

memory array

sensor)(tx ][nx

memory array

X[N-1]

)(tx

…1

t0 1 2 3 4 5 6 7

0

0.2

0.4

0.6

0.8

1

n

x[n]

-1.5 -1 -0.5 0 0.5 1 1.5

x 104

0

2

4

6

f (Hz)

|DFT

|

So… What does this tell us??

How does this relate to the CT signal’s CTFT?

How do we answer those questions??? 17

Page 18: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

ADC

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

Inside “Computer”

memory array

sensor)(tx ][nx

)(XCTFT (theory)

)(XDTFT(theory)

Zero-padding to length Nzp

We study the theory of these

Practical computed DFT

…to understand what this shows!

DTFTN(theory)

)(NX

00

memory array

X[Nzp-3]X[Nzp-2]X[Nzp-1]

So… to analyze what we get from the DFT processing for this signal…

… Start at the CTFT @ ADC input!!!! 18/29

Page 19: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

From FT Table we have:bfj

fXbj

X

2

1)(1)(

( ) ( )btx t e u tCTFT of Signal at ADC Input

%%%% Compute the Theoretical CTFTb=2*pi*1000;f=-200000:100:200000;CTFT=1./(j*2*pi*f + b); %%% from CTFT tableplot(f/1e3,abs(CTFT),'r--');

19/29

Page 20: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

)(tx

CTFT

ADCInside “Computer”

sensor

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

memory array memory array

X[N-1]

][nx

20/29

Page 21: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

If we sample x(t) at the rate of Fs samples/second – That is, sample every T = 1/Fs sec – we get the DT Signal coming out of the ADC is:

)(|)(][ nTxtxnx nTt For this example we get:

][][

][)(][

nuanue

nuetuenx

nnbT

bTnnTt

bt

Note: |a| < 1

Now imagine that in theory we have all of the samples x[n] - < n < at the ADC output.

Then, in theory the DTFT of this signal is found using the DTFT table to be:

jae

X1

1)(

DTFT Result…(Theory)

For |a| < 1 which we have because:

0,0& Tbea bT

Sampled Signal

DTFT of Signal at ADC Output

21/29

Page 22: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

%%%% Compute the Theoretical DTFT_infT=1/Fs; a=exp(-b*T); %%% computes exponential decay rate of sampled signalomega=-3*pi:0.01:3*pi;DTFT_inf=1./(1 - a*exp(-j*omega)); %%% from DTFT tableplot(omega/pi,abs(T*DTFT_inf));xlabel('\Omega/\pi (Normalized rad/sample)')ylabel('|T*DTFT_{inf}(\Omega)|')hold onh=plot(f/(Fs/2),abs(CTFT),'r--');axis_x([-3 3])hold off

jae

X1

1)(

22/29

Page 23: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

Our theory says that:

k

sFkXT

X

2

21)((For analysis)

So we should see “replicas” in X() and we do!

We plot TX() to undo the 1/T here

fsF sF0

2sF

2sF

2 2 0

Recall the two

equivalent axes:

Aliasing Error!

Adjusts for T factor

DTFT CTFT

23/29

Page 24: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

)(tx

CTFT

ADCInside “Computer”

sensor

][nx

DTFT

Aliasing Error

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

memory array memory array

X[N-1]

24/29

Page 25: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

DTFT of Signal Stored Inside ComputerNow, in reality we can “collect” only N < samples in our computer:

[ ] , 0 ( 1)("Assume" [ ] 0 elsewhere)

nN

N

x n a n Nx n

The DTFT of this collected finite-duration signal is easily found “by hand”:

j

Nj

N aeaeX

11)(

Note that we think of this as follows:

nwnxnx NN ][][

..and DTFT theory tells us that

1( ) ( ) ( )2N NX X W d

…and this has a “smearing” effect: called “leakage error”

otherwise

NnwN

,0

1,,2,1,0,1

Eq. (7.6) in Kamen & Heck

25/29

Page 26: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

%%%% Compute the Theoretical DTFT_NDTFT_N=(1-(a*exp(-j*omega)).^N)./(1 - a*exp(-j*omega)); plot(omega/pi,abs(T*DTFT_inf));hold onplot(omega/pi,abs(T*DTFT_N),'m');hold offxlabel('\Omega/\pi (Normalized rad/sample)')ylabel('|T*DTFT_{N}(\Omega)|')

For this case the leakage error is these ripples

DTFT DTFTN

26/29

Page 27: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

)(tx

CTFT

ADCInside “Computer”

sensor

][nx

DTFT

Aliasing Error

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

memory array memory array

X[N-1]

DTFTN

Smearing/Leakage Error

27/29

Page 28: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

[0][1]

...[ 1]

xx

x N

[ ]Nx n 21

0

[ ]knN j

NN

n

X k x n

(The only part of

this example we’d really “do”)

Finally… DFT of Signal Stored Inside Computer

Our theory tells us that the zero-padded DFT is nothing more than “points” on DTFTN: )(][ kNzp XkX where 2 0, 1, 2, ..., 1k

k k NN

Spacing between DFT “points”

DTFTN

DFT These are the DFT values we initially computed!

28/29

Page 29: EEO 401 Digital Signal Processing - Binghamtonws.binghamton.edu/Fowler/Fowler Personal Page/EE302_files...EEO 401 Digital Signal Processing Prof. Mark Fowler 1/29 Goal of Practical

)(tx

CTFT

ADCInside “Computer”

sensorSummary of Results:

x[0]x[1]x[2]

x[N-1]

DFT processing

X [0]X[1]X[2]

memory array

Zero-padding to length Nzp

00

memory array

X[Nzp-3]X[Nzp-2]X[Nzp-1]

][nx

DTFT

DTFTN DFT

Aliasing Error

Smearing/Leakage Error

Grid Error

29/29