16 oct'09comp30291 section 31 university of manchester school of computer science comp30291:...

65
16 Oct'09 Comp30291 Section 3 1 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time LTI systems

Upload: jodie-jacobs

Post on 12-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 1

University of Manchester

School of Computer Science

Comp30291: Digital Media Processing 2009-10

Section 3 :

Discrete-time LTI systems

Page 2: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 2

3.1 Introduction

• Consider a DSP system as implemented by a digital processor.

• Takes discrete time input signal { x[ n ] },& produces an output signal { y[ n ] }.

SYSTEM input {x[n]}

output {y[n]}

Page 3: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 3

• {x[n]} is sequence whose value at t=nT is x[n].

• Similarly for {y[n]}.

• T is sampling interval in seconds (T = 1/FS).

• {x[n-N]} is sequence whose value at t=nT is x[n-N].

{x[n-N]} is {x[n]} with every sample delayed by N

sampling intervals.

Sequences representing digital signals

Page 4: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 4

(i) Discrete time ‘amplifier’:

y[n] = A . x[n].

• Described by ‘difference equation’: y[n] = A x[n].

• Represented in diagram form by a ‘signal flow graph’:

x[n] y[n] A

Examples of discrete time systems

Page 5: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 5

(ii) Non-recursive digital filter

• Output at t=nT obtained by weighting & summing present & previous input samples: e.g.

y[n] = A0 x[n] + A1 x[n-1] + A2 x[n-2] + A3 x[n-3] + A4x[n-4]

• This is a ‘non-recursive difference equation’ • Represented by signal flow graph below.• Boxes marked ‘ z -1 ‘ produce a delay of one sampling interval.

z-1 z-1 z-1 z-1 x[n]

A0 A1 A2 A3 A4

y[n]

Page 6: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 6

(iii) Recursive digital filter

• Output at t= nT calculated from a recursive difference equation:

e.g. y[n] = A 1 x[n] - B 2 y[n-1]

• Represented by signal flow graph below.

z-1

x[n] A1

B2

y[n]

• Recursive means that previous values of y[n] as well as present & previous values of x[n] are used to calculate y[n].

Page 7: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 7

(iv) A non-linear system

• Output at t=nT calculated from some non-linear equation, e.g. y[n] = (x[n]) 2

• Represented below:

x[n]

y[n]

Page 8: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 8

(I) A DSP system is linear if: • Given any two discrete time signals {x 1 [n]} & {x 2 [n]},

if {x 1 [n]} {y 1 [n]} & {x 2 [n]} {y 2 [n]} then response to k 1{x 1[n]} + k 2{x 2[n]} must be k 1{y1[n]} + k 2 {y 2 [n]} for any values of k 1 and k 2 ,

•To multiply a sequence by k, multiply each element by k, k{x[n]} = {k x[n]}. •To add two sequences together, add corresponding samples, {x[n]} + {y[n]} = {x[n] + y[n]}.)

3.2. Linearity & time-invariance

Page 9: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 9

(II) A DSP system is ‘time-invariant’ if:

• Given any discrete time signal {x[n]}, if response to {x[n]} is {y[n]}, response to {x[n-N]} must be {y[n-N]} for any N.

• Delaying input by N samples only delays output by N samples.

• An LTI system is both linear & time-invariant

• Examples (i), (ii) and (iii) are LTI whereas (iv) is not LTI .

Page 10: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 10

3.3. Discrete time unit impulse

• Useful to consider response of LTI systems to a discrete time unit impulse , or in short an impulse denoted by {d [n] } with:

0 n : 0

0 n : 1d[n]

... ...

1

-3 -2 -1 1 2 3 4 5

n

0

d[n-4]

... ...

1

-3 -2 -1 1 2 3 4 5

d[n]

n

0

{d[n-N]} is delayed impulse where the only non-zero sample occurs at n=N rather than at n=0.

Page 11: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 11

• When input is {d[n]}, output is impulse-response {h[n]}.

• If impulse-response of an LTI system is known, its response to any other input signal may be obtained.

Impulse-response

Page 12: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 12

3.4. Implementing signal-flow-graphs

• Consider the non-recursive signal flow graph below with A1, A2, A3, A4, A5 set to specific constants. • Notice the labels X1, X2, etc.

z-1 z-1 z-1 z-1 x[n]

A1 A2 A3 A4 A5

y[n]

X1

Y

X5X4X2 X3

• Realised by MATLAB program & flow-diagram on next slides.

Page 13: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 13

Set X1, X2, X3, X4, X5 to zero

Set values of A1,A2, A3, A4, A5

INPUT X1

Y = A1*X1 + A2*X2 + A3*X3 +A3*X4 + A5*X5

OUTPUT Y

X5 = X4; X4 = X3; X3 = X2; X2 =X1

Flow-diagram for non-recursive signal-flow-graph

Page 14: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 14

clear all;

A1=1; A2=2; A3=3; A4=-4; A5=5;

X1=0; X2=0; X3=0; X4=0; X5=0;

while 1

X1 = input( 'X1 = ');

Y= A1*X1 + A2*X2 + A3*X3 + A4*X4 + A5*X5 ;

disp([' Y = ' num2str(Y)]);

X5 = X4 ; X4 = X3; X3 = X2 ; X2 =X1;

end;

MATLAB program for non-recursive signal flow graph

Page 15: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 15

More efficient version

A = [1 2 3 -4 5 ]’ ;x = [0 0 0 0 0 ]’ ; while 1 x(1) = input( ‘x(1) = '); Y=0; for k = 1 : 5 Y = Y + A(k)*x(k); end; disp([' Y = ' num2str(Y)]); for k=5:-1:2 x(k) = x(k-1); end;end;

Page 16: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 16

Even more efficient version

A = [1 2 3 -4 5 ]' ;x = [0 0 0 0 0 ]' ; while 1

x(1) = input( 'x(1) = ');Y = A(1)*x(1);for k = 5 : -1: 2

Y = Y + A(k)*x(k);x(k) = x(k-1);

end;disp(['Y = ' num2str(Y)]);

end;

Page 17: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 17

• The ‘while 1’ statement initiates an infinite loop.

• Program runs for ever or until interrupted by ‘CONTROL+C’

• Either of the following prints out value of Y:

disp(['Y = ' num2str(Y)]);

disp(sprintf(‘Y=%d’,Y));

• A = [1 2 3 -4 5]’ makes A a column vector (not a row). Note ’.

Comments

• Ready to be converted to DSP assembler.

Y = Y + A(k)*x(k); x(k) = x(k-1);

One DSP instruction:Mult-acc-shift - MACS

Page 18: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 18

clear all;x=[0 1 0 0 0 0 0 0 0 0]';a = [1 2 3 -4 5]';y=filter(a,1,x);y

Use of ‘filter’ to implement non-rec signal-flow-graph- & thus to produce its impulse-response

• Just writing ‘y’ without ‘;’ prints out the array.

Page 19: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 19

Impulse-response for non-rec signal-flow-graph• Use any of previous versions & enter values for X1 :

0, 0, 0, 1, 0, 0, 0, 0, .... • Sequence of output samples printed out will be :

0, 0, 0, A1, A2, A3, A4, A5, 0, 0, .... • Impulse-response can also be obtained by tabulation (later). • Output must be zero until input becomes equal to 1 at n=0• Impulse response is:

{..., 0, ..., 0, A1, A2, A3, A4, A5, 0, 0, ... ,0, ...}

where the sample at n=0 is underlined. • Only five non-zero output samples are observed.• This is a ‘ finite impulse-response ‘ (FIR).

Page 20: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 20

(i) y[n] = x[n] + 2 x[n-1] + 3 x[n-2] - 4 x[n-3] + 5 x[n-4]

(ii) y[n] = 4 x[n] - 0.5 y[n-1]

• Difference eqn (i) will produce a finite impulse-response.• Difference eqn (ii) produces infinite response whose samples

gradually reduce in amplitude but never quite become zero.

Exercise 3.1

•Calculate impulse-responses, by tabulation, for:

Page 21: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 21

n x[n] x[n-1] x[n-2] x[n-3] x[n-4] y[n]-1 0 0 0 0 0 00 1 0 0 0 0 11 0 1 0 0 0 22 0 0 1 0 0 33 0 0 0 1 0 -44 0 0 0 0 1 55 0 0 0 0 0 0: : : : : : :

Impulse-response for example (i) by tabulation

Impulse response is: {.. 0, .., 0, 1, 2, 3, -4, 5, 0, .., 0, ...}

y[n] = x[n] + 2 x[n-1] + 3 x[n-2] - 4 x[n-3] + 5 x[n-4]

Page 22: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 22

n x[n] y[n-1] y[n]0 1 0 41 0 4 -22 0 -2 13 0 1 -0.54 0 -0.5 0.255 0 0.25 -0.125: : : :

Impulse-response by tabulation for Example (ii)

Impulse response is: {.., 0, .., 0, 4, -2, 1, -0.5, 0.25, -0.125, ...)

y[n] = 4 x[n] - 0.5 y[n-1]

Page 23: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 23

n x[n] y[n-1] y[n]0 1 0 41 0 4 -82 0 -8 163 0 16 -324 0 -32 645 0 64 128: : : :

Further example: Impulse-response by tabulation

• Impulse response is: {.., 0, .., 0, 8, 16, -32, 64, 128, ...)

• This IIR filter is ‘unstable’ (see later)

y[n] = 4 x[n] - 2 y[n-1]

Page 24: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 24

• Difference equation (i) is "non-recursive" & produces a finite impulse response (FIR). • Difference equation (ii) is " recursive " . • Impulse-response of a recursive difference equation can have an infinite number of non-zero terms. In this case it is an infinite impulse-response (IIR).

3.5. FIR & IIR digital filters

• A ‘digital filter’ is a digitally implemented LTI discrete time system governed by a difference equation of finite order; e.g. :

(i) y[n] = x[n] + 2 x[n-1] + 3 x[n-2] - 4 x[n-3] + 5 x[n-4]

(ii) y[n] = 4 x[n] - 0.5 y[n-1]

Page 25: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 25

clear all;

Y2=0;

while 1

X1 = input( 'X1 = ');

Y1= 4*X1 - 0.5*Y2 ;

Y2 = Y1; % for next time round

disp([' Y1 = ' num2str(Y)]);

end;

MATLAB program for recursive signal flow graph

- example (ii)

Page 26: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 26

y = filter(A, B, x) filters signal in array x to create array y.

For FIR example (i), A = [ 1 2 3 -4 5 ] & B = [1].

For IIR example (ii), A = [4], B = [1 0.5]

Consider a third IIR example:

y[n] = 2x[n] + 3x[n-1] + 4x[n-2] -0.5 y[n-1] - 0.25 y[n-2]

In this case set A = [2 3 4]

and B = [1 0.5 0.25].

Why are A & B defined in this way?

Use of ‘filter’ for FIR & IIR digital filters

Page 27: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 27

• A digital filter has a ‘system function’ which is

MM

NN

zazbzbb

zazazaazH

...

...)(

22

110

22

110

with b0 = 1

for the difference equation:

][...]2[]1[

][...]2[]1[][][

21

210

Mnybnybnyb

Mnxanxanxanxany

M

N

• A contains [a0 a1 ... aN] & B contains [b0, b1, ..., bM] .

• Reasons for this & more details will be given later in course.

• ‘filter’ can be used without knowing why H(z) is defined in this way.

Definition of A & B in ‘y = filter(A,B,x);’

Page 28: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 28

If impulse-response of an LTI system is {h[n]} its response to any input {x[n]} is an output {y[n] } whose samples are given by the following ‘convolution’ formulae:

m

m] x[nh[m] y[n]

k

k]h[n x[k]y[n]or

3.6. Discrete time convolution

• Formulae are equivalent.

• Clearly, if we know impulse-response {h[n]} we can produce the response to any other input sequence, from either of these formulae.

•Proof of convolution in Appendix 3A.

Page 29: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 29

Calculate response of a system with impulse response: {h[n]} = { ..., 0,..., 0, 1, 2, 3, -4, 5, 0, .....0, .... } to {x[n]} = { ... 0, ... , 0 , 1, 2, 3, 0, ..., 0, ....}Solution: By first discrete time convolution formula,

4]5x[n3]4x[n2]3x[n1]2x[n x[n]

zero are msr eother t all since m] x[nh[m]

m] x[nh[m] y[n]

4

0m

-m

Example

This is difference equation for an LTI system with impulse response {.., 0, .., 0, 1, 2, 3, -4, 5, 0, .., 0, ..}

Page 30: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 30

Completing the Example

• Program discussed earlier implements this difference equation,

• We could run it, and enter {0 1 2 3 0 0 0 0...},

• Output sequence produced is what we want.

• Alternatively, we could use tabulation as follows:

Page 31: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 31

Response of: y[n] = x[n] +2x[n-1]+3x[n-2]-4x[n-3] +5x[n-4]to input sequence {...,0,1,2,3,0,...} by tabulation

n x[n] x[n-1] x[n-2] x[n-3] x[n-4] y[n]: : : : : : :-1 0 0 0 0 0 00 1 0 0 0 0 11 2 1 0 0 0 42 3 2 1 0 0 103 0 3 2 1 0 84 0 0 3 2 1 65 0 0 0 3 2 -26 0 0 0 0 3 157 0 0 0 0 0 0: : : : : : :{y[n]} = { .... 0, ....., 0, 1, 4, 10, 8, 6, -2, 15, 0, ...., 0, ....}

Page 32: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 32

3.7. Stability An LTI system is stable if its impulse-response {h[n]} satisfies:

finite is ][

n

nh

This means that {h[n]} must be either an FIR or an IIR whose samples decay towards zero as n .

Page 33: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 33

3.8. Causality

An LTI system operating in real time must be ‘causal’ which

means that its impulse-response {h[n]} must satisfy:

h[n] = 0 for n < 0.

Non-causal system would need “crystal ball ” to predict future.

Page 34: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 34

Illustration of stability & causality

Looks stable

but is not causal.

n

h[n] h[n]

n

Causal, but not stable

h[n]

Causal & looks stable.

n

Page 35: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 35

• = T is ‘relative frequency’ of sampled sinusoid. • Units of are 'radians per sample'.

3.9. Relative Frequency

• Study effect of digital filters on sinusoids of different frequencies.• Discrete time sinusoid obtained by sampling A cos(t + ). • If sampling frequency is Fs Hz, and T=1/Fs, we obtain:

x[n] = A cos(nT + ) = A cos(n + )

Page 36: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 36

Radians per sample

• To convert back to true frequency (radians/s ) multiply by Fs.

• radians / sample samples / second = radians / second

• Analogue signals in range 0 to FS/2 Hz =1/(2T)

• Restricts to the range 0 to .

Page 37: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 37

T

3T-T

-3T 4T-4T

cos( t )

1

3-1

-3 4-4

cos( T n )

t

n

= 2 / 8

=2 / (8T)

Page 38: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 38

Values of & corresponding true frequencies

Relative frequency True frequency(radians/sample) (radians/s) (Hz)

0 0 0/6 fS/6 fS/12/4 fS/4 fs/8/3 fS/3 fs/6/2 fS/2 fs/42/3 2fS/3 fs/3 fS fS/2

‘radians / sample’ ‘samples / second’ = ‘radians / second’

Page 39: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 39

3.10. Relative frequency response

It us useful to analyse the response to a sampled sinusoid:

x[n] = Acos(n + )

To begin with, set A=1, =0 and remember de Moivre’s Theorem:

)sin()cos( njne nj

Easier to calculate response to the complex signal x[n] = ejn

than to cos(n) directly.

Page 40: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 40

Relative frequency response (cont)

If x[n] = ejn is applied to a system with impulse-response {h[n]}, output would be, by convolution :

(DTFT) ][ ][)( where

)(

][

][

][][ )(

n

nj

m

mjj

jnj

m

mjnj

m

mjnj

m

mnj

enhemheH

eHe

emhe

eemh

emhny

Page 41: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 41

• H( e j ) is the DTFT of { h[n] }.

• It is called the ‘relative frequency-response’

• Complex number for any value of .

• Note similarity to the analogue Fourier transform.

(FT) )()(

(DTFT) ][)(

a dtethjH

enheH

tja

n

njj

Discrete time Fourier Transform (DTFT)

Page 42: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 42

• If input is x[n]=e j n, output is same sequence with each

element multiplied by H( e j ).

n

njj enheH ][)(

e j n

{h[n]}

e j n H(e j ) LTI

Recap

Page 43: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 43

3.11. Gain & phase responses

• G() = |H( e j )| is ‘gain’ • () = arg ( H( e j ) ) is ‘phase lead’. • Both vary with . • Can express: H( e j ) = G() e j ()

• If input is {A cos(n)}, output is: { G()A cos(n + ()) }

When input is sampled sinusoid of relative frequency , output is sinusoid of same frequency , but with amplitude scaled by G() & phase increased by ().

Page 44: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 44

Gain & phase response graphs again

/4 /2 3/40

20log10[G()] dB-()

-()

G() in dB

Page 45: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 45

Graphs of G() & () against .

• G() often converted to dBs by calculating 20 log10( G() ).

• Restrict to lie in range 0 to

• Adopt a linear horizontal frequency scale.

Page 46: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 46

Example Derive frequency-response of FIR digital filter below.

z-1 z-1 z-1 z-1 x[n]

1 2 3 -4 5

y[n]

• Impulse-response is: {.., 0, .., 0, 1, 2, 3, -4, 5 ,0, .., 0,..}. • By the formula established above, • H( e j ) = 1 + 2 e - j + 3 e -2 j - 4 e -3 j + 5 e - 4 j

Page 47: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 47

Example: Plot gain & phase responses of this FIR filter

• To do this ‘by hand’, we would need to take modulus & phase of expression for H( e j ).• Fortunately we almost never need to do this ‘by hand’ (except for very simple expressions).• Best done by MATLAB.

• To calculate gain & phase responses for H( e j ) = 1 + 2 e - j + 3 e -2 j - 4 e -3 j + 5 e - 4 j

start MATLAB and type: freqz( [1 2 3 -4 5] );

Page 48: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 48

Page 49: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 49

‘freqz’ graphs of gain & phase responses

• Frequency scale normalised to fS/2 & labelled 0 to 1 instead of 0 to .

• To plot freq-response for an IIR filter equally straightforward using ‘freqz’ if you know how to define the system function.

•See earlier.

•More about this in a later section.

Page 50: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 50

• In next section we see how FIR filter coefficients can be chosen to achieve a particular type of gain & phase response.

• Tells us how the MATLAB function ‘fir1’ works in principle.

• In later sections, principles of IIR digital filter design will be considered also

FIR & IIR digital filter design

Page 51: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 51

Phase delay

• Assume input is {A cos(n)},

• Output is: { G() A cos ( n + () ) }

= { G() A cos ( [ n + () / ] ) }

= { G() A cos ( [ n - (-() / ) ] ) }

• Phase lead () delays sine-wave by -()/ sampling intervals

• This is ‘phase-delay’.

Page 52: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 52

3.12. Linear phase response

• If -()/ remains constant for all values of ,

i.e. if -() = k for constant k,

system has ‘linear phase’ response.

• Graph of -() against on linear scale would then be

straight line with slope k where k is "phase delay"

i.e. the delay measured in sampling intervals.

• This need not be an integer.

Page 53: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 53

-()/

/4 /2 3/40

-()

G() in dB

-()/

Gain, phase & ‘phase-delay’ response graphs

Not ‘linear-phase’.

Page 54: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 54

-()/

/4 /2 3/40

-()

G() in dB

-()/

Gain, phase & ‘phase-delay’ response graphs again

This is ‘linear-phase’ as -()/ is constant.

k

Page 55: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 55

Why is linear phase a good property?

• All sinusoids delayed by same number of sampling intervals.

• Input signal expressed as Fourier series will have all its

sinusoidal components delayed by same amount of time.

•No ‘phase distortion’ due to different delays at different

frequencies.

• LTI systems are not necessarily linear phase.

• A certain class of digital filter can be made linear phase.

Page 56: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 56

3.13. Inverse DTFT

• Frequency-response H( e j ) is DTFT of {h[n]}.

• Inverse DTFT formula allows {h[n]} to be deduced from H(e j ) :

<<-: )(2

1][ ndeeHnh njj

• This formula requires H(ej) for in range - to .• Negative frequencies?? • Not a problem because when { h[n] } is real, H( e -j ) = H*( e j ) where * denotes complex conj.

Page 57: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 57

Similarities with inverse analogue Fourier Transform

<<-: )(2

1][ ndeeHnh njj

Notice: (i) (1/2) factor, (ii) sign of jn (n replaces t).

(iii) variable of integration (d)

<<-: )(

2

1)( tdejHth tj

aa

Inverse DTFT

Inverse FT

Page 58: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 58

Also note that, with inverse DTFT• Range of integration is now - to rather than - to .

• DTFT is a summation & inverse DTFT is an integral.

• This is because {h[n]} is a sequence

whereas H(e j ) is function of the continuous variable .

Page 59: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 59

3.14 Problems1. Why is y[n]=(x[n]) 2 not LTI.2. If {h[n]}= { .. 0, .. , 0, 1, -1, 0, .. 0, .. }, calculate response to {x[n]} = { .... 0, .., 0, 1, 2, 3, 4, 0, .., 0, ... }.3.. Produce a signal flow graph for each of the following difference equations: (i) y[n] = x[n] + x[n-1] (ii) y[n] = x[n] - y[n-1] (iii) y[n] = 2x[n] +3x[n-1] +2x[n-2] - 0.5 y[n-1] -0.25 y[n-2]4. For difference equations (i) & (ii) in question 3, determine the impulse- response, & deduce whether the system it represents is stable and/or causal.5. Calculate, by tabulation, the output from difference equation (ii) in question 3 when the input is the impulse-response of difference equation (i).6. If fS =8000 Hz, what true frequency corresponds to /5 radians/sample?7. Sketch the gain & phase responses of the system referred to in question 2. (You don't need a computer program.) Is it a linear phase system?8. Calculate the impulse-response for y[n] = 4x[n] + 2y[n-1]. Is it stable?9. Show that input {cos(n)} produces an output {G()cos(n+())}.10. For y[n]=x[n]+2x[n-1]+3x[n-2]+2x[n-3]+x[n-4], sketch phase-response and comment on its significance. Show that () = -2.

Page 60: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 60

Appendix 3A: Proof of discrete time convolution formulae

Only use linearity, time-invariance & impulse-response. Since d[n-m] is non-zero only at n = m, given any sequence {x[n]},

m

m]x[m]d[nx[n]

m]}[m]{d[nx{x[n]}

m

{x[n]} is sum of infinite number of delayed impulses{d[n-m]} each multiplied by a single element, x[m]. Response to {d[n-m]} is {h[n-m]} for any value of m. response to {x[n]} is :

n allfor m][m]h[nxy[n] i.e. m]}[m]{h[nx{y[n]}

mm

Page 61: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 61

• Replacing n-m by k gives the alternative formula. • Study the graphical explanation of this proof in Section 3.17.

n

2

3

x[n]

2

h[n]

n

{h[n]} = { ..., 0, ..., 0, 1, 2, 1, 2, 0, ..., 0...}

{x[n]} = { ..., 0, ..., 0, 1, 2, 3, 0, 0, ..., 0, ...}

Page 62: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 62

Discrete time convolution graphically

n

23

x[n]

d[n]

n

2

2d[n-1]

n

3

3d[n-2]

n

2

h[n]

n

2

42h[n-1]

n

3

63h[n-2]

n

{h[n]} = { ..., 0, ..., 0, 1, 2, 1, 2, 0, ..., 0,...}

{x[n]} = { ..., 0, ..., 0, 1, 2, 3, 0, 0, ..., 0, ...}

Page 63: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 63

2

4

6

8

10

y[n]

n

Express:

{x[n]} = {d[n]} + 2 {d[n-1]} + 3 {d[n-2]}

Response is:

{y[n]} = {h[n]} + 2 {h[n-1} + 3 {h[n-2]}

Page 64: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 64

2

4

6

8

10y[n]

n

n

2

3

x[n]

{ d[n] } {h[n]}

+ 2{ d[n-1 ]} + 2 { h[n-1]}

+ 3 { d[n-2] } + 3 { h[n-2] }

{h[n]} = { ..., 0, ..., 0, 1, 2, 1, 2, 0, ..., 0,...}

{x[n]} = { ..., 0, ..., 0, 1, 2, 3, 0, 0, ..., 0, ...}

Page 65: 16 Oct'09Comp30291 Section 31 University of Manchester School of Computer Science Comp30291: Digital Media Processing 2009-10 Section 3 : Discrete-time

16 Oct'09 Comp30291 Section 3 65

d[n]

n

2

2d[n-1]

n

3

3d[n-2]

n

2

4

2h[n-1]

n

3

63h[n-2]

n

2

h[n]

n