Digital Signal Processing Introduction Course R.WEBER SP2 ESI module Traitement Numérique

34
Digital Signal Processing Introduction Course R.WEBER SP2 ESI module Traitement Numérique A] Time and Frequency description of a digital signal B] Digital Filtering : Analysis and Design Tools

description

Digital Signal Processing Introduction Course R.WEBER SP2 ESI module Traitement Numérique. A] Time and Frequency description of a digital signal B] Digital Filtering : Analysis and Design Tools. PART A Time and Frequency description of a digital signal. Temporal Description. ?. - PowerPoint PPT Presentation

Transcript of Digital Signal Processing Introduction Course R.WEBER SP2 ESI module Traitement Numérique

Page 1: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

Digital Signal Processing Introduction Course

R.WEBER

SP2 ESI module Traitement NumériqueA] Time and Frequency description of a digital signalB] Digital Filtering : Analysis and Design Tools

Page 2: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

PART ATime and Frequency description of

a digital signal

Page 3: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 3Dr. R.Weber / Digital Signal Processing

Temporal Descriptionx=[ 2.1 -0.5 1.3 0.5 0 1.7 -0.4 0.3 -1.9 -0.8 ];

n (time index or relative time)

0 1 2 3 4 5 6 7 8 9 10-1

What really happens here ? What really happens here ?

Page 4: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 4Dr. R.Weber / Digital Signal Processing

Theoretical spectral description

"" " " 2f f f

0 0

( ) cos(2 ) sin(2 ) j fn

f f f

x n A j fn B j fn C e

•periodicity of the spectrum •f can be limited to [0, 0.5] for real signal (spectrum symmetry)•f can be limited to [- 0.5 , 0.5] or [0 , 1] for complex signal

The problem :

( ) ( )fC FT x X f Yes, with the Fourier Transform

2( ) ( ) ( ) ,n

j fnFT x X f x n fe

The answer :

X(f+1)=X(f) Remarks :

Page 5: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 5Dr. R.Weber / Digital Signal Processing

Theoretical spectrum of basic signals

Complex exponential 2( ) . Oj f nx n A e

0.5 1 1.5-0.5-1.5 -1 0 f

x = A.*exp(2*pi*j*(0:1023)*fo);2 2( ) ( )OX f A f f

fO

sine wave ( ) .cos(2 )Ox n A j f n x = A.*cos(2*pi*(0:1023)*fo);

0.5 1 1.5-0.5-1.5 -1 0 f

2 22

( ) ( ) ( )4 4O O

A AX f f f f f

fO

( ) ( )x n n impulsex = [ 1 zeros(1,1023)];

2( ) 1X f

0.5 1 1.5-0.5-1.5 -1 0 f

( ) 0 0

(0) 1

n n

( ) 0 0

(0) 1

n n

Page 6: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 6Dr. R.Weber / Digital Signal Processing

Theoretical spectrum of basic signals2(0, )N White Gaussian Noise

x = .*randn(1, 1024);2 2( )X f

0.5 1 1.5-0.5-1.5 -1

2

0 f

General case : time and frequency are related

n

f2( )

dBX f

How will appear •a pure sine wave, •a pure impulse ?

How will appear •a pure sine wave, •a pure impulse ?

specgramdemo(x,Fs);

Page 7: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 7Dr. R.Weber / Digital Signal Processing

Pure delay :

( ) ( )y n x n 2( ) ( ). j fY f X f e

2( ) ( ) oj f ny n x n e ( ) ( )oY f X f f

Modulation or frequency shift:

( ) ( ).cos(2 )Oy n x n f n 1 1( ) ( ) ( )

2 2o oY f X f f X f f

Basic spectral properties (1)

Page 8: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 8Dr. R.Weber / Digital Signal Processing

Basic spectral properties (2) Product and Convolution:

( ) ( ) ( )y n x n h n1

0

( ) ( @ )( ) ( ) ( )Y f X H f X H f d

( ) ( @ )( ) ( ) ( )k

y n x h n x k h n k

( ) ( ) ( )Y f X f H f

Parceval relation :

1+2 2

n=- 0

Energy= ( ) ( )x n X f df

Page 9: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 9Dr. R.Weber / Digital Signal Processing

Theoretical Formulation :

2( ) ( ) ( ) ,n

j ftTF x X f x n fe

Approximations : The Discrete Fourier Transform

No digital implementation possible

1. n [0, M-1]2. Only f / f=k/M

1

0

2( ) ( ) ( ) , 0, , 1

kMM

n

j nDFT x X k x n k Me

FFT(x) = DFT(x) with M a power of 2X=fft(x);

Practical spectral description (1)

Page 10: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 10Dr. R.Weber / Digital Signal Processing

Practical spectrum (n]0,M], f k/M)

0 0.5 k/M

|X(k)|

1/M 2/M

Windowed spectrum (n]0,M])

n

n

Practical spectral description (2)

f

|X(f)|

0.50

Theoretical spectrum (n]-,+ [)M

h(n)

H(f)

Possibility to reduce distortion by using different kinds of windows, h(n)

Page 11: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 11Dr. R.Weber / Digital Signal Processing

WindowingRectangular Hamming

Hann Blackmann-Harris

WINtool sous Maltab

Page 12: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 12Dr. R.Weber / Digital Signal Processing

1 2

0

1( ) ( ) , 0, , 1

kM i nM

k

x n X k e n MM

Inverse DFT :

2M-1 12

n=0 0

( )1 1 Mean Power= ( )

M

k

X kx n

M M M

Parceval relation :

cov(x)

x=ifft(X);

DFT properties

2M-1 12

n=0 0

( ) Energy= ( )

M

k

X kx n

M

Power spectral density

2

( )( )

X kkpsd

M M

Page 13: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 13Dr. R.Weber / Digital Signal Processing

Power Spectral density(1) Spectral line case :a complex exponential or s(n) is sine wave

ˆ( ) ( ) ( )s n s n h n1

0

ˆ( ) ( @ )( ) ( ) ( )k

S k S H k S H dM

( ) ( )OS f A f f with

22

20

ˆ( ) ( )k

S k A H fM

so

DFT

When 00

kf

M

22 22 2

00

ˆ( ) (0) ( )M

n

S k A H A h n

then

What is the measured power spectral density of a sinus wave when using a classical DFT ? What is the measured power spectral density of a sinus wave when using a classical DFT ?

s=sin(2*pi*(0:1023)*20/1024); plot((abs(fft(s)).^2)/1024)

Page 14: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 14Dr. R.Weber / Digital Signal Processing

Power Spectral density (2)

12

2 0

white noise

( )M

n

h n

M

Random noise case :

Problem : each slice of M samples will give a different power spectral density estimation

Problem : each slice of M samples will give a different power spectral density estimation

50% overlap

Solution : averaging of all the local power spectral density

L samplesM samples

2ˆ( )

( ) ( )l l

S kpsd

M

Impact of the windowing

2 2

1

0

( )( ) ( )

S kpsd k H d

M M

1( ) ( )l

l

psd k psdN

1

2

0

1 ( )( ) ( )

( )lMmatlab

l

n

DFT kpsd k

N h n

psd(s,M,Fs,[h(0) h(1) … h(M-1)]) =

2( )X k

M

f=k/M

Page 15: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 15Dr. R.Weber / Digital Signal Processing

Signal Power What is the mean power ? What is the mean power ?

psd

0.5 f0- 0.5 0.5 f0

psd

1

What is the mean power of the sum of signals ?

What is the mean power of the sum of signals ?

Page 16: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 16Dr. R.Weber / Digital Signal Processing

Signal Processing goals

0

( ) ( )N

ii

y n b x n i

x(n)=s(n)+b(n) processingprocessing y(n)=s’(n)+b’(n)

Example :

s(n)

x(n)=s(n)+b(n)

Spectral point of view

Goal :•s’(n) s(n)•Power(b’(n)) 0

Temporal point of view

Signal to noise ratio : dB 10SNR =10log s

b

P

P

dB 10'

New SNR =10log s

b

P

P

Page 17: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

PART BLinear Digital Filtering :

Analysis and Design Tools

Page 18: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 18Dr. R.Weber / Digital Signal Processing

Linear Digital filtering

x(n) FilterFilter y(n)

0 1

( ) ( ) ( )N D

i ii i

y n b x n i a y n i

recursive partnon recursive part

Basic properties :

if x1(n) FilterFilter y1(n)

if x2(n) FilterFilter y2(n)then x1(n)+x2(n) FilterFilter y1(n)+y2(n)Linearity

Temporalreproducibility

if x(n) FilterFilter y(n) then x(n-T) FilterFilter y(n-T)

Formulations : temporal view

y = filter(b,a,x);b = [ b0 b1 … bN]; a = [ 1 a1 … aD];

1.

Page 19: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 19Dr. R.Weber / Digital Signal Processing

Impulse response

x(n)

FilterFilter

y(n)

Formulation :

h = filter(b,a,x);x = [ 1 zeros(1,29)];

Finite impulse response (FIR)

( ) for k=0, , N

( ) 0 elsekh k b

h k

Infinite impulse response (IIR)

/ ( ) 0o ok h k k k

0

( ) ( )N

ii

y n b x n i

0

1

( ) ( )

( )

N

ii

D

ii

y n b x n i

a y n j

Non recursive

Recursive

Consequences :

( ) 0 0

(0) 1

n n

( ) 0 0

(0) 1

n n

(n) =(n)

The impulse response

h(n)=h(n)

Page 20: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 20Dr. R.Weber / Digital Signal Processing

Example :c=0.95 c=0.985 c=0.995

c=0.999 c=1 c=1.001

h(n)

Application to stability

Formulation :+

i=0

Stable if h(i)

Finite impulse response (FIR)( ) for k=0, , N

( ) 0 elsekh k b

h k

Always stable

Infinite impulse response (IIR) Risk of instability2( ) ( ) 2 cos(2 ) ( 1) ( 2) 0.01o oy n x n c f y n c y n f Example :

x = [ 1 zeros(1,400)];c=0.985;b= 1;a=[1 -2*c*cos(2*pi*0.01) c.^2]; h = filter(b,a,x);plot(h)

Consequences :

Page 21: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 21Dr. R.Weber / Digital Signal Processing

Convolution

0

1

0

Filter type Implementation Stability

( ) ( )

very good : N+D be careful

( )

( ) ( ) poor if N large guaranteed

N

ii

D

ii

N

ii

y n b x n i

a y n i

y n b x n i

0

( ) ( ) ( ) ( @ )( )k

y n h k x n k h x n

=

( ) ( ) ( )k

x n x k n k

Formulation :

x(n)

+

x(2)(n-2)+

x(1)(n-1)+

x(0)(n)

x(3)(n-3)

+

Filter with impulse response h(n)

Filter with impulse response h(n)

-- A recursive filter can be approximated by a non recursive one

which is coherent !

Remarks :

( @ )( ) ( )h n h n

h(n)

Page 22: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 22Dr. R.Weber / Digital Signal Processing

The Z-transform( ) ( )( ) ( ) , n

n

F z ZT f z f n z z

Formulation :

useful (and simple) properties:

Given X(z)=ZT(x) and Y(z)=ZT(y)- linearity : ZT(x(n) + y(n)) = X(z) + Y(z)- convolution : Zt[(x@y)(n)] = X(z) Y(z)- ZT(x(n+1)) = z X(z) ; ZT(x(n+k)) = zk X(z)- ZT(x(n-1)) = z-1 X(z) ; ZT(x(n-k)) = z-k X(z)

These make the ZT very interesting !

0 1

( @ )( ) ( ) ( ) ( )N D

i ii i

h x n y n b x n i a y n i

( ( )) ( )ZT h n H z

Application to the filtering:ZT

ZT

0

0

0 with 1

Ni

iiD

ii

i a

b z

a z

( )

( )

Y z

X z

Page 23: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 23Dr. R.Weber / Digital Signal Processing

Stability rule

root polynomial0 1decomposion

0 1,

,( )( ) .

( )

NNi

iD Ni i

D Di

ii i

p i

o izb zH z K z

a z z

z

z

Formulation :

Im(z)

Re(z)

x

x

x

x

x

o

o

o

1

1

Instable filtero

o zerosx poles

Stable filterFilter stability if |zp,i|<1

Verify this rule with the previous example

Verify this rule with the previous example

2( ) ( ) 2 cos(2 ) ( 1) ( 2)oy n x n c f y n c y n

zplane(b,a);

Page 24: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 24Dr. R.Weber / Digital Signal Processing

Frequency response (1)

Formulation :

2( ) oj f nx n e

Filter with impulse response h(n)

Filter with impulse response h(n)

2 2

0

( ) at

( ) ( @ )( )

( )o o

o

j f n j f k

k

FT h f

y n x h n

e h k e

2

0

( ) ( ) ( ) j fk

k

H f FT h h k e

x = [ 1 zeros(1,1023)];c=0.985;b= 1;a=[1 -2*c*cos(2*pi*0.2) c.^2]; h = filter(b,a,x);H= fft(h);f=(0:1023)/1024;plot(f,10*log10(abs(H).^2));

2( )

dBH f

( ) ( ) ( )Y f X f H f

Page 25: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 25Dr. R.Weber / Digital Signal Processing

Simple filter design method

1. Draw the frequency response, H(f), you are looking for.2. Compute the impulse response, h(n), by applying an inverse Fourier Transform3. By truncating the length of this response, you obtain a sequence of values which

are also the non-recursive coefficients of an approximate FIR version of your filter.

H(f)

f n

h(n)FT-1

n

happrox(n)

L values

Checking :

Ripple can not be removed even with L large

Solution : other type of windowing (hamming, hanning, blackmannharris…)

rectangularwindowing

Page 26: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 26Dr. R.Weber / Digital Signal Processing

2

-2 2

z=0 0

( ) ( ) = ( ) = ZT(h) j f

kj fk j f

ek k

H f h k e h k e

Another formulation :

2

0 0

2

0 0

now ( ) so ( )

N Ni j fi

i ii iD D

i i fii i

i i

b z b eH z H f

a z a e

( )

( )( )

FT bH f

FT a

c=0.985;b= 1;a=[1 -2*c*cos(2*pi*0.2) c.^2]; %zero padding to increase frequency resolutionb=[b zeros(1,1023)]; a=[a zeros(1,1020)];H= fft(b)./fft(a);f=(0:1023)/1024;plot(f,10*log10(abs(H).^2));

[H,f

]=fr

eq

z(b

,a,1

024,1

);

2( )

dBH f

Frequency response (2)

Page 27: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 27Dr. R.Weber / Digital Signal Processing

Another formulation :

2z

2

1=

1

,

z

,

=

( )( ) ( ) .

( )j f

N

D N i

i

j f

De

p

e

o i

i

zH f H z K z

z

z

z

2

1 1

1 1

2

,

,

,

,

( )( ) . .

( )

N N

i ic

j f

jD D

i i

fc

o i

p ip

o i

if

fe

eH f K K

M

z M

z

f=0

X

X

O

f=0.25

f=0.5

,1o

fM

,2o

fM,2p

fM

,1p

fMO

zplane(b,a);

2( )

dBH f

Frequency response (3)

Page 28: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 28Dr. R.Weber / Digital Signal Processing

Frequency response (4)

Page 29: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 29Dr. R.Weber / Digital Signal Processing

pure delay :

( ) ( )h n n

( ) ( ) ( @ )( )y n x n x h n

2( ) ( )( ) j fH f TF h f e

( ) 2Hphase f f 1

groupe_delay( ) - ( )2 Hf phase f

f

general case :

( )Hphase f

1- ( )

2 Hphase ff

Time responses for the given frequencies

grpdelay(b,a,1024,1);freqz(b,a,1024,1);

x(n) FilterFilter

2( )

dBH f

Phase response (1)

Page 30: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 30Dr. R.Weber / Digital Signal Processing

linear phase filter :0( ) 2Hphase f f

Yes, if FIR filters with symmetric or antisymmetric coefficients

23.5 samples

24 samples ( )h n

( )h n

No, if IIR

0

1

( ) ( )

( )

N

ii

D

ii

y n b x n i

a y n i

Phase response (2)

Page 31: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 31Dr. R.Weber / Digital Signal Processing

Filtered Power Spectral density

( ) .cos(2 )Ox n A j f n

x(n) FilterFilter y(n) Problem : What is the psd after filtering ?

Problem : What is the psd after filtering ?

|H(f)|

2

1

0.5 f0

2( ) (0, )x n N

f0

Page 32: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 32Dr. R.Weber / Digital Signal Processing

Attenuation

Ripple

StopbandPassband

Transition band

Filter Specifications(1)

Page 33: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 33Dr. R.Weber / Digital Signal Processing

General rules :

then

Attenuation

Ripple

Transition Band

•If or

or

0

1

( ) ( )

( )

N

ii

D

ii

y n b x n i

a y n i

Order or complexity

• For a given specification, IIR is always less complex than FIR But be careful to the stability (and the phase linearity) !

Attenuation

Ripple

Transition band

Filter Specifications (2)

Page 34: Digital Signal Processing Introduction Course  R.WEBER SP2 ESI module Traitement Numérique

2006-2007 34Dr. R.Weber / Digital Signal Processing

Basic FIR methods : ordre 63 64 coefficients, linear phase

Bandpass :

Basic IIR methods : order 24 50 coefficients

Equiripple Least-square

Butterworthorder 12 26 coefficients

Cauer or Elliptic

2( )

dBH f

( )Hphase f

Basic Design Methods