Digital Signal Processing (DSP) Signal Analysis€¦ ·  · 2017-12-02Digital Signal Processing...

Post on 24-May-2018

244 views 6 download

Transcript of Digital Signal Processing (DSP) Signal Analysis€¦ ·  · 2017-12-02Digital Signal Processing...

Digital Signal Processing (DSP) Signal Analysis

Student Handouts: Course materials for this program are the sole property of Penn State Great Valley and cannot be reproduced or used for any purposes without the expressed consent of Penn State Great Valley.

What we’ll cover today

§  Fourier Series §  Fourier Transforms §  Sampling and Aliasing §  Complex Signals § DFT § Matlab examples

Introduction

•  Analysis – Provides an explanation from observation. For example, you have a signal what can you say about the structure of that data. Or you know the input and the system, what can you say about the output?

•  Design – You know the input and the desired output, what system do you need to achieve the desired result. Often the information is limited and so there is no single right answer to the problem.

Introduction

Fourier  series

Fourier  Transform

Spectral  Analysis

Z-­‐transforms

Filter  Design

System  Design

• Analysis • Design

Fourier Series • What is it?

Ø Periodic signals, signals that repeat for ever can be represented by a linear combination of sine waves and cosine waves Ø This representation is called a Fourier Series.

•  A French mathematician, Joseph Fourier (1786-1830) developed a powerful method for analyzing periodic waves.

Fourier Series

• Periodic Wave

Fourier Series

( ) ( )f t f t nT= +( ) ( )f t f t nT= +

f t f t nT⎛ ⎞⎛ ⎞⎜ ⎟⎜ ⎟⎜ ⎟⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

= +

• A periodic signal is defined by

• where T is called the period and n is an integer

Fourier Series

( )0 0cos 2 / sin 2 /k k

k kf t a kt T b kt Tπ π⎛ ⎞ ⎛ ⎞

⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

∞ ∞

= == +∑ ∑

( )

( )0

0

2 cos 2 /

2 sin 2 /

Tk

Tk

a f t kt T dtTb f t kt T dtT

π

π

⎛ ⎞⎜ ⎟⎝ ⎠

⎛ ⎞⎜ ⎟⎝ ⎠

=

=

Where

• If f(t) is even, then the b’s are zero • If f(t) is odd, then the a’s are zero

Fourier Series - Example

-4 -3 -2 -1 0 1 2 3 4-2

-1.5

-1

-0.5

0

0.5

1

1.5

2Periodic signal

Fourier Series - Example 1

2 4( 1) 1,3,5,

0 0,2,4,0 0,1,2,3,4,

k

k

k

k

a kka kb k

π−

= − =

= =

= =

LLL

• Follow along as we do this problem with Matlab • What is T?

Fourier Series Example

-4 -3 -2 -1 0 1 2 3 4-1.5

-1

-0.5

0

0.5

1

1.5 Approximation with 6 terms

time

Ampli

tude

Fourier Series Complex Form

• Euler’s Relationship cos sin

cos 2sin 2

j

j j

j j

e j

e e

e ej

θ

θ θ

θ θ

θ θ

θ

θ

⎛ ⎞ ⎛ ⎞⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

⎛ ⎞⎜ ⎟⎝ ⎠

⎛ ⎞⎜ ⎟⎝ ⎠

= +

+=

−=

1j= −

Fourier Series - Complex Form

( )

( )

2 /

/2/

/2

12

j kt Tk

kT

j kt Tk kk

T

f t c e

a jbc f t eT

π

π

=−∞

=

−= =

• Each complex frequency is of form 2 pj f te π

Fourier Series – Complex Form

• The magnitude of each frequency component

2 222 21 4 2

"Power" "Voltage"

k kk k k k

a bc c a b+= = +

• The phase of each frequency component is given by

arctan kk

k

baφ

⎛ ⎞⎜ ⎟⎜ ⎟⎜ ⎟⎝ ⎠

−=

Fourier Series - Spectrum

• The spectrum of the Fourier Series is the magnitude and phase of the coefficients as a function of frequency. Example sin(2*pi*3*t).

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

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1 "Voltage" Spectrum

Frequency Hz

Mag

nitud

e

c-1c1

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

-2

-1

0

1

2

3

π/2

-π/2

Phase Spectrum

Frequency Hz

Pha

se

Fourier Series - Spectrum

• Find the spectrum of the following two signals

cos 2 3tπ⎛ ⎞⎜ ⎟⎝ ⎠

sin 2 3 4t ππ⎛ ⎞⎜ ⎟⎜ ⎟⎝ ⎠

+

Fourier Series – Spectrum

-4T -3T -2T -T 0 T 2T 3T 4T-1

-0.5

0

0.5

1

1.5

2Pulse Train

• Compute the Complex Fourier Series for the following signal. The pulse width is 0.1*T.

Fourier Transform

• What happens when you do not have a periodic signal?

Ø Fourier Transform •  Generated from Fourier Series as the period becomes infinitely large. •  The interval between frequencies goes to zero. • Discrete spectrum becomes continuous

Fourier Transform

( ) ( )2 21 ( )2j ft j ft

a aF f f t e dt f t F f e dfπ ππ

⎛ ⎞⎜ ⎟⎝ ⎠

∞ ∞−

−∞ −∞= =∫ ∫

• The frequency f has units of Hertz or cycles per second. Also can be written in terms of radians (2*pi*f) as

( ) ( ) ( ) ( )j t j ta aF f t e dt f t F e dω ωω ω ω

∞ ∞−

−∞ −∞= =∫ ∫

Fourier Transform

• Find the Fourier Transform of

( ) 1, - 2 20, Elsewhere

T Ttf t⎧⎪⎪⎨⎪⎪⎩

≤ ≤=

• Find the inverse Fourier Transform of 0 02 2a

A AF f f f f fδ δ⎛ ⎞ ⎛ ⎞⎛ ⎞⎜ ⎟ ⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠ ⎝ ⎠

= − + +

• Where 0f fδ ⎛ ⎞⎜ ⎟⎝ ⎠− is the Dirac delta function

0 0g f f f g f dfδ⎛ ⎞ ⎛ ⎞ ⎛ ⎞⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠⎝ ⎠ ⎝ ⎠

−∞= −∫

Fourier Transform of Sampled Data

•  Consider Notion of frequency in discrete world • Supposed that you had two signals,

( ) ( ) 61 2sin 2 and sin 2 10 f t t f t tπ π⎛ ⎞⎛ ⎞

⎜ ⎟⎜ ⎟⎝ ⎠ ⎝ ⎠

= =

• Say you sampled the first at a 10 Hz rate and the second at a 10 Megahertz rate. What would the data be?

Fourier Transform of Sampled Data

sin(2* *0.1* )nf nπ=

• In both cases the sampled signal is:

•  Thus a knowledge of the sampled data is not always sufficient. What else would clarify this?

Fourier Transform of Sampled Data

• If I know the sampling frequency, I would know the true frequency.

• Once data is sampled, the true frequency is lost. All that remains is the normalized frequency.

rns

ff f=

Discrete Time Functions •  A discrete time signal that is periodic with period M can be decomposed into a Fourier Series.

( ) ( )/2 1 /2 1

2 /2 /

/2 1 /2 1

1 and M M

j kn Mj kn Mk k

k M n Mx n c e c x nM

ππ

⎛ ⎞ ⎛ ⎞⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

⎛ ⎞ ⎛ ⎞⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

− −−

=− − =− −

= =∑ ∑

• A discrete-time aperiodic function has a Fourier Transform

( ) ( )1/2

2 2 2 2

1/2 and j f j fn j f j fn

d dnX e x n e x n X e e dfπ π π π⎛ ⎞ ⎛ ⎞

⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

∞−

=−∞ −

= =∑ ∫

Discrete Fourier Transform ( ) ( )

1/22 2 2 2

1/2 and j f j fn j f j fn

d dnX e x n e x n X e e dfπ π π π⎛ ⎞ ⎛ ⎞

⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠

∞−

=−∞ −

= =∑ ∫

• Note that the limit of integration is -½ to ½. Why is that?

• Note that ( )2j fdX e π is periodic with period 1.

• Even though x(n) is not periodic, it’s Fourier Transform is.

Example

• Consider the following signal that has 21 non-zero values. Generate its Fourier Transform.

-(N-1)/2 0 N-1)/2-1

-0.5

0

0.5

1

1.5

2non-periodic pulse

Example • We will work it together and should get

2sin

sinj f

d

fNX e

π

π

⎛ ⎞⎜ ⎟⎛ ⎞ ⎝ ⎠⎜ ⎟⎜ ⎟ ⎛ ⎞⎝ ⎠ ⎜ ⎟⎝ ⎠

=

-0.5 -1/N 0 1/N 0.5

0

NDiscrete Fourier Transform of pulse

Summary • The Fourier transform of a discrete signal is continuous whenever the discrete time signal is non-periodic. • The real-world frequencies are effectively normalized by the sampling frequency resulting in normalized frequencies in the digital world. • The normalized frequencies are always between - ½ and ½. • The discrete Fourier transform is always periodic whether or not the discrete signal is periodic. If the discrete signal is periodic, the Fourier transform only exists at discrete frequencies. If the discrete signal is continuous, the Fourier transform is periodic. If you look beyond the - ½ to ½ interval, you will see the periodic extension of whatever is in the interval - ½ to ½. One can look over any period. Sometimes it is convenient to observe over the interval of 0 to 1 instead. • The interval - ½ to ½. Is called the Nyquist interval.

Sampling and Aliasing

-3

-2

-1

0

1

2

3

time

analo

g

-B 0 B

Xa(f)

-2.5

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

time

digital

-F_s -B 0 B F_s

Analog Fourier Transform

Discrete Discrete Fourier Transform

Aliasing • Aliasing occurs when the sampling rate is insufficient. It is a phenomena that is familiar to all.

• What happens with aliasing is that frequencies get mapped into lower frequencies.

• We will illustrate this using Matlab and a sinusoidal

Aliasing Example • We will take a f0= 2 Hertz sinusoidal and sample it at first a sampling frequency of 8*f0.

•  We will repeat it at a rate of 3*f0

• Finally, we will repeat it a rate of 7*f0/8

Example • Speech has rough bandwidth of 3 or 4 kHz and is sampled at 8 kHz. However the presence of noise beyond 4 kHz is a problem. The spectrum looks like:

0 2 4 6 8-0.5

0

0.5

1

1.5

Frequency in kHz

Analog frequency response of telephony siganl

Speech

Interference

Noise

Example

• Typical sampling rates for audio is 8K Hertz • Will that work? Why or why not? • What do we need to do?

Example

0 1 2 3 4 5 6 7 8-0.5

0

0.5

1

1.5 Antialiasing filter

Frequency in kHz

Filte

r gain

Example • In practice, this is not possible. You can not transition from 1 to 0 gain in 0 frequency. • We need a transition band •  Filter specs are often in dB units (20log10(gain)). Typical specs:

0 dB, 0 3.5 kHz40 dB, 4.5 kHz

Gain fGain f

= ≤ ≤≤− ≥

Example

• This filter is not practical: Ø High order – Virtually impossible for orders greater than 15. Ø Would be expensive and bulky. Ø Would introduce significant phase distortion.

What is Phase Distortion

• Best understood in terms of music. Say you had a musical note composed of two frequencies say 4 and 6 KHz. When you filter that note, the 4 KHz and 6 KHz may differ in the time it takes to get through the filter. This create phase distortion

Phase Distortion

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1.5

-1

-0.5

0

0.5

1

1.5

time

original note

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1.5

-1

-0.5

0

0.5

1

1.5filter note with phase distortion

time

Example – How to solve the problem?

• Oversample, digital filter and decimate. Say we sample at a 32KHz rate and decimate by 4

ADC Hd(  f) Dec  by  4    Ha(f) x1(t) x2(t) x3(t) x4(t) x5(t)

0 2 4 8 16 24 320

0.5

1

1.5

Ha(f)

Example – How to solve the problem

• Analog Filter clears out some of the noise, but the interference still is there.

Example: how to solve the Problem?

0 2 4 8 16 24 320

0.5

1

1.5

Fs/2

Hd(f)

• Digital filter eliminate the interference and noise without phase distortion.

Digital to Analog Reconstruction

DSP ADC DAC

• The digital to analog converter acts as a filter • If we put a sequence of {1,0,0,0,…} into the DAC we would get as an output:

Digital to Analog Converter

0 Ts0

0.5

1

1.5Impulse response of DAC

DAC Frequency Response

0 Fs 2Fs 3Fs 4Fs 5Fs0

0.5

1

1.5

frequency

Digital to Analog Reconstruction

00

1

2

0 B0

1

2

00

0 B Fs 2Fs0

1

2

00

0 B Fs 2Fs0

1

2

00

1

2

0 B0

1

2

Reconstruction Filter

DAC Analog  LPF DigiBal  Interpolator

H1(f) HDAC(f) H2(f)

Reconstruction Filters

0 Fs 2Fs0

1

2

X_1(f

)

0 Fs 2Fs0

0.5

1

1.5

H_1(f

)

0 Fs 2Fs0

1

2

X_2(f

)

0 Fs 2Fs0

0.5

1

1.5

H_2(f

)

0 Fs 2Fs0

1

2

X_4(f

)

frequency

HDAC(f)

Complex Signals

• Complex signals play an important role in signal processing

( ) ( ) ( )r ix t x t jx t= +

• An alternative representation

( ) ( ) ( )

( ) ( )( )

2 2

1tan

r i

i

r

x t x t x t

x tx t

x t

⎛ ⎞⎜ ⎟⎜ ⎟⎜ ⎟⎜ ⎟⎝ ⎠

= +

=

Complex Signals

• The complex signal can be written as ( ) ( ) ( ) ( )

j x tr ix t x t e x t jx t

⎛ ⎞⎜ ⎟⎜ ⎟⎝ ⎠= = +

• Complex sinusoidal ( ) ( )cos sinj te t j tω ω ω= +

-1 0 1-1

0

1

Real Signal

Imag

inary

signa

l

1

ω t

Frequency Response of Complex Sinusoidal

• Whereas real a sinusoidal of frequency f0 has energy at f0 and –f0. • Complex sinusoidal of frequency f0 has energy only at f0. • These complex signals play an important role in communications where the signals are bandlimited around some center frequency, usually the modulated carrier signal. These signals must be demodulated to recover the information.

Complex sinusoidal

-f0 0 f0-0.5

0

0.5

1

1.5

2

frequency

0-0.5

0

0.5

1

1.5

2

frequency

Implementation of Complex Signals

02j f nTe π−

x(n)

02j f nTe π−

y(n) x(n)

0cos 2 f nTπ⎛ ⎞⎜ ⎟⎝ ⎠

0sin 2 f nTπ⎛ ⎞⎜ ⎟⎝ ⎠

( )ry t

( )iy t

Sampling Complex Signal

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

n=0

n=1

n=2

n=3

020 with 8

j f t sFe fπ−=

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

n=1

n=2

n=3

020

7 with 8j f t sFe fπ−

=

Aliasing!

Discrete Fourier Transform (DFT)

• Suppose that we have a discrete-time signal, x(n), n=0,1,2,…,N-1. • We want to compute the Fourier Transform.

( )2 2j f j fnn

X e x n eπ π⎛ ⎞⎜ ⎟⎜ ⎟⎝ ⎠

∞−

=−∞= ∑

• There are two problems Ø The limits are doubly infinite Ø The frequency is continuous

Discrete Fourier Transform (DFT)

• Start with the FT ( )2 2j f j fnn

X e x n eπ π⎛ ⎞⎜ ⎟⎜ ⎟⎝ ⎠

∞−

=−∞= ∑

• Assume that the signal is 0 for n<0 and n>N-1. ( )

12 2

0

Nj f j fn

nX e x n eπ π⎛ ⎞

⎜ ⎟⎜ ⎟⎝ ⎠

−−

==∑

• Compute on a frequency grid

( )21

0

kj nN N

nX k x n e

π⎛ ⎞⎜ ⎟⎜ ⎟⎜ ⎟⎜ ⎟⎝ ⎠⎛ ⎞

⎜ ⎟⎝ ⎠

−−

==∑% N- Point DFT

DFT • Here is Matlab code for computing the DFT

N=input(' Enter N'); Xr=zeros(N,1); Xi=zeros(N,1); for k=1:N, f=(k-1)/N; for n=1:n, Xr(k)=Xr(k)+xr(n)*cos(2*pi*f*(n-1))+xi(n)*sin(2*pi*f*(n-1)); Xi(k)=Xi(k)+xi(n)*cos(2*pi*f*(n-1))-xr(n)*sin(2*pi*f*(n-1)); end end

DFT • This takes 4N2 multiplies. The Cooley-Tukey (1965) showed how to compute the DFT with 2*N*log2(N). This made the DFT practical. • The DFT= the FT equation shown previously • The FFT (Fast Fourier Transform) is the Cooley-Tukey algorithm to compute the DFT

DFT

x(n) X(k)

•  Note first half of X(k) corresponds to positive frequencies, second half negative. • k=0 f=0, k=1, f=1/N, k=2, f=2/N, etc.

DFT

0 N-1-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

2.5

n

x(n)

0 0.5 10

0.5

1

1.5

f/Fs

|X(f)|

• Note periodic nature of the DFT. Also note the values of X(f) from 0.5 to 1 is the same as the values from -0.5 to 0.

CW Radar Example Tx

Osc  f0

Rx

f0 fd1 fd2

CW Radar Example

• Processing steps Ø Multiply by Ø LPF Ø ADC Ø MEM Ø FFT Ø Display

02j f te π

CW Radar Example

-4000 -3000 -2000 -1000 0 1000 2000 3000 40000

0.025

0.05

0.075

0.1

0.125

0.15

0.2

Frequency in Hertz

Time i

n sec

onds

Matlab Examples • We will take several examples and work them together with Matlab. • First lets look at sin 2 5tπ⎛ ⎞

⎜ ⎟⎜ ⎟⎝ ⎠

• We will look at various sampling frequencies and positive and negative frequencies • We will multiply by the cos(2*pi*5*t) and look at the spectrum of product • We will look at • Finally, we will look at the product of a complex sinusoid and another signal.

2 5j te π−