Oct'04CS32911 CS3291 : Digital Signal Processing '04-05 Section 3 : Discrete-time LTI systems 3.1Introduction: A discrete time system takes discrete time input signal { x[ n ] }, & produces an output signal { y[ n ] }.
Oct'04CS32912 Implemented by general purpose computer, microcomputer or dedicated digital hardware capable of carrying out arithmetic operations on samples of {x[n]} and {y[n]}. {x[n]} is sequence whose value at t=nT is x[n]. Similarly for {y[n]}. T is sampling interval in seconds. 1/T is sampling frequency in Hz. {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. Many types of discrete time system can be considered, e.g.
Oct'04CS32913 (i) Discrete time "amplifier" with output: 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
Oct'04CS32914 (ii) Processing system whose output at t=nT is obtained by weighting & summing present & previous input samples: y[n] = A 0 x[n] + A 1 x[n-1] + A 2 x[n-2] + A 3 x[n-3] + A 4 x[n-4] ‘Non-recursive difference equatn’ with signal flow graph below. Boxes marked " z -1 " produce a delay of one sampling interval.
Oct'04CS32915 (iii) System whose output y[n] at t = nT is calculated according to the following recursive difference equation: y[n] = A 0 x[n] - B 1 y[n-1] whose signal flow graph is given below. Recursive means that previous values of y[n] as well as present & previous values of x[n] are used to calculate y[n]. z -1 x[n] A0A0 B1B1 y[n]
Oct'04CS32916 (iv) A system whose output at t=nT is: y[n] = (x[n]) 2 as represented below. x[n] y[n]
Oct'04CS LTI Systems: To be LTI, a discrete-time system must satisfy: (I) Linearity ( Superposition ): 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 for any values of k 1 and k 2, response to k 1 {x 1 [n]} + k 2 {x 2 [n]} must be k 1 {y 1 [n]} + k 2 {y 2 [n]}. 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]}.)
Oct'04CS32918 (II) Time-invariance : 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. Examples (i), (ii) and (iii) are LTI whereas (iv) is not LTI.
Oct'04CS Impulse-response: Useful to consider response of LTI systems to a discrete time unit impulse, or in short an impulse denoted by {d [n] } with:
Oct'04CS {d[n-N]} is delayed impulse where the only non-zero sample occurs at n=N rather than at n=0. 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 predicted.
Oct'04CS Computing an impulse response: Consider a discrete time system with signal-flow graph below with A1, A2, A3, A4, A5 set to specific constants. Notice the labels X1, X2, etc. Realised by microcomputer running a program with flow-diagram & high-level language implementation as listed next. z -1 z -1 z -1 z -1 x[n] A1 A2 A3 A4 A5 y[n] X1 Y X5 X4 X2 X3
Oct'04CS Zero X1, X2, X3, X4,X5 Set A1,A2,…. INPUT X Y = A1*X + A2*X2 + A3*X OUTPUT Y X5 = X4; X4 = X3; X3 = X2; X2 =X1 clear all; A1=1; A2=2; A3=3; A4=-4; A5=5; x1=0; x2=0; x3=0; x4=0; x5=0; while ~isempty(X) X = input( 'X = '); x1 = X; 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
Oct'04CS Here is another version using MATLAB arrays: A = [ ] ; x = [ ] ; while 1 X = input( 'X = '); x(1)=X; Y=A(1) * X; for k = 2 : 5 Y = Y + A(k)*x(k); end; disp([' Y = ' num2str(Y)]); for k=5:-1:2 x(k) = x(k-1); end;
Oct'04CS And an even more efficient version A = [ ] ; x = [ ] ; while 1 x(1) = input( 'X = '); 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;
Oct'04CS These can be run in MATLAB The ‘while 1’ statement initiates an infinite loop. Program will run for ever or until interrupted by ‘CONTROL+C’
Oct'04CS Impulse-response for this example may be deduced by running program & entering values for X on the keyboard : 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).
Oct'04CS Exercise 3.1: Calculate impulse-responses for difference equations: (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] y[n-1] Solutions: If computer not available we may use a tabulation. 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.
Oct'04CS (i) y[n] = x[n] + 2 x[n-1] + 3 x[n-2] - 4 x[n-3] + 5 x[n-4] nx[n]x[n-1]x[n-2]x[n-3]x[n-4] y[n] :::::: : Solution is:- {.. 0,.., 0, 1, 2, 3, -4, 5, 0,.., 0,...}
Oct'04CS Difference equation (ii): y[n] = 4 x[n] y[n-1] nx[n]y[n-1] y[n] ::: : Solution is: {.., 0,.., 0, 4, -2, 1, -0.5, 0.25, ,...)
Oct'04CS 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] y[n-1] 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).
Oct'04CS Next slide has yet another way of programming difference equations (i.e. digital filters) in MATLAB. But this time, we use a MATLAB function and operate on a whole array of music at once. You can find the music file ‘cap4th.wav’ in
Oct'04CS MATLAB function ‘filter’ used for non-recursive diffce eqn y = filter(A, 1, x) filters signal in array x to create array y. For each sample x(n) of array x: y(n) = A(1)*x(n) + A(2)*x(n-1) A(N+1)*x(n-N) Example (i): y[n] = x[n] + 2 x[n-1] + 3 x[n-2] - 4 x[n-3] + 5 x[n-4] [x, fs, nbits] = wavread ('cap4th.wav'); sound(x,fs,nbits); pause; y = filter ( [ ], 1, x); sound(y,fs,nbits);
Oct'04CS Use of ‘filter’ for recursive difference equatn y = filter(A, B, x) filters signal in array x to create array y using a recursive difference equation. Example (ii): y[n] = 4 x[n] y[n-1] [x, fs, nbits] = wavread ('cap4th.wav'); sound(x,fs,nbits); pause; y = filter ( [4], [1 0.5], x); sound(y,fs,nbits);
Oct'04CS Discrete time convolution: 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: Consider the 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,....}
Oct'04CS Result is not too surprising. It is the difference equation for an LTI system whose impulse response is {.., 0,.., 0, 1, 2, 3, -4, 5, 0,.., 0,..}. Program discussed earlier implements this difference equation, We could complete the example by running it, entering samples of { x[n] }, and noting the output sequence. Alternatively, we could use tabulation as follows:
Oct'04CS y[n] = x[n] + 2x[n-1] + 3x[n-2] - 4x[n-3] + 5x[n-4] n x[n] x[n-1] x[n-2] x[n-3] x[n-4] y[n] : : :: :: : : : :: :: : {y[n]} = {.... 0,....., 0, 1, 4, 10, 8, 6, -2, 15, 0,...., 0,....}
Oct'04CS Proof of discrete time convolution formulae: Only use defns of linearity, time-invariance & impulse-response. Since d[n-m] is non-zero only at n = m, given any sequence {x[n]}, {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 :
Oct'04CS Replacing n-m by k gives the alternative formula. Study the graphical explanation of this proof in Section 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,...}
Oct'04CS Discrete time convolution graphically n 2 3 x[n] d[n] n 2 2d[n-1] n 3 3d[n-2] n 2 h[n] n 2 4 2h[n-1] n 3 6 3h[n-2] n {h[n]} = {..., 0,..., 0, 1, 2, 1, 2, 0,..., 0,...} {x[n]} = {..., 0,..., 0, 1, 2, 3, 0, 0,..., 0,...}
Oct'04CS 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]}
Oct'04CS y[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,...}
Oct'04CS d[n] n 2 2d[n-1] n 3 3d[n-2] n 2 4 2h[n-1] n 3 6 3h[n-2] n 2 h[n] n
Oct'04CS This means that {h[n]} must be either an FIR or an IIR whose samples decay towards zero as n 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 Stability: An LTI system is stable if its impulse-response {h[n]} satisfies:
Oct'04CS = T is “ relative" frequency of sampled sine-wave. Units of are 'radians per sample'. To convert back to true frequency (radians/s ) multiply by 1/T. Note: 1/T = sampling frequency, f S, in samples/second (Hz). ‘radians / sample’ times ‘samples / second’ = ‘radians / second’ Normally process analogue signals in range 0 to f S /2 ( = 1/(2T) ), Restricts to the range 0 to Relative Frequency Study effect of digital filters on sine-waves of different frequencies. Discrete time sine-wave obtained by sampling A cos( t + ). If sampling period is T seconds, resulting discrete time signal is :
Oct'04CS T 3T -T -3T4T -4T cos( t ) cos( T n ) t n = 2 / 8 =2 / (8T)
Oct'04CS Table gives values of & corresponding true frequencies :- Relative frequency True frequency (radians/sample) (radians/s) (Hz) /6 f S /6 f S /12 /4 f S /4 f s /8 /3 f S /3 f s /6 /2 f S /2 f s /4 2 /3 2 f S /3 f s /3 f S f S /2 ‘radians / sample’ ‘samples / second’ = ‘radians / second’
Oct'04CS Relative frequency response Response to sampled sine-waves calculated by defining: If this is applied to a system with impulse response {h[n]}, output would be {y[n]} with :
Oct'04CS n n cos( (2 /8) n ) sin( (2 /8) n)
Oct'04CS H( e j ) is the " relative frequency response " of LTI system. Complex number for any value of . It is DTFT of { h[n] }. Note similarity to the analogue Fourier transform.
Oct'04CS If input is {e j n }, output is same sequence with each element multiplied by H( e j ). When { h[n] } is real, H( e -j ) = H*( e j ). Exercise: Prove this. {e j n } {h[n]} { e j n H(e j n ) } LTI
Oct'04CS Remember the analogue case:- When h(t) is real, H a (j ) = H a *(j ) e j t h a (t) e j t H a (j ) LTI
Oct'04CS Gain and phase responses Expressing H( e j ) = G( ) e j ( ) G( ) = |H( e j )| is "gain ” ( ) = arg ( H( e j ) ) is "phase lead”. Both vary with . If input is {A cos( n)}, output is: { G( )A cos( n + ( )) } Exercise: Prove this When input is sampled sine-wave of rel frequency , output is sine-wave of same frequency , but with amplitude scaled by G( ) & phase increased by ( ).
Oct'04CS Gain & phase response graphs again /4 /23 /4 0 20log 10 [G( )] dB -()-() -()-() G( ) in dB
Oct'04CS Common to plot graphs of G( ) & ( ) against . G( ) often converted to dBs by calculating 20 log 10 ( G( ) ). Restrict to lie in range 0 to & adopt a linear horizontal scale. Example 3.2: Calculate gain & phase response of FIR digital filter in Figure 3.3 where A1 = 1, A2 = 2, A3 = 3, A4 = -4, A5 = 5. Solution: Impulse response is: {.., 0,.., 0, 1, 2, 3, -4, 5,0,.., 0,..}. By the formula established above, H( e j ) = e - j + 3 e -2 j - 4 e -3 j + 5 e - 4 j To obtain the gain and phase at any take modulus and phase. Best done by computer, either by writing & running a simple program, or by running a standard package. A simple program is given at the end of these notes.
Oct'04CS Can use a spread-sheet such as excel (see lecture notes) Another way of calculating gain & phase responses for H( e j ) = e - j + 3 e -2 j - 4 e -3 j + 5 e - 4 j is to start MATLAB and type: A = [ ]; freqz( A ); See later section 3.18 for graphs produced.
Oct'04CS Produces graphs of gain & phase responses of H( e j ). Frequency scale normalised to f S /2 & labelled 0 to 1 instead of 0 to . See Section 3.18 In next section we calculate coeffs of an FIR filter to achieve a particular type of gain & phase response. To calculate gain & phase responses for an IIR filter would be difficult by method used above because impulse-response has infinite number of non-zero terms. There is an easier method in a later section.
Oct'04CS 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’.
Oct'04CS 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.
Oct'04CS ( )/ /4 /23 /4 0 -()-() G( ) in dB - ( )/ Gain, phase & ‘phase-delay’ response graphs Not ‘linear-phase’.
Oct'04CS ( )/ /4 /23 /4 0 -()-() G( ) in dB - ( )/ Gain, phase & ‘phase-delay’ response graphs again This is ‘linear-phase’ as - ( )/ is constant. k
Oct'04CS Linear phase systems of special interest since all sine-waves are 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. In absence of amplitude changes, output signal will be exact replica of input. LTI systems are not necessarily linear phase. A certain class of digital filter can be made linear phase.
Oct'04CS 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 ) : Observe similarities with analogue Fourier transform: (i) (1/2 ) factor, (ii) sign of j n (n replaces t). (iii) variable of integration (d )
Oct'04CS Also note that with DTFT: Negative frequencies are again included. Range of integration is now - to rather than - to . Forward transform is a summation & inverse transform is an integral. This is because {h[n]} is a sequence whereas H(e j ) is function of the continuous variable .
Oct'04CS Problems: 1. Show that y[n]=(x[n]) 2 is 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] 4. For each difference equation 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 f S =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 .
Oct'04CS Progam for gain & phase responses of FIR digital filter. (using complex arithmetic) fs = input('enter fs:'); M = input('Enter order:'); disp('Enter coefficients:'); for N = 0:M C(N+1)=input('coeff = '); end; disp(' FREQ(Hz) GAIN(dB.) PHASE LEAD(deg)'); K = 0; F =0.0; % F is frequency in Hz} while F < fs/2 H=0; W =2*pi*F/fs; for N=0:M H=H+C(N+1)*exp(-j*W*N); end; MD=abs(H); PH = angle(H); GAIN(K+1)=-999; if MD>0 GAIN(K+1)=20*log10(MD);end; PHAS(K+1)=PH*180.0/pi; disp([num2str(F) ' 'num2str(GAIN(K+1)) ' 'num2str(PHAS(K+1))]); F=F+fs/200; K=K+1; end; %while loop
Oct'04CS Progam for gain & phase responses of FIR digital filter. (without complex arithmetic) fs = input('enter fs:'); M = input('Enter order:'); disp('Enter coefficients:'); for N = 0:M H(N+1)=input('coeff = '); end; disp(' FREQ(Hz) GAIN(dB.) PHASE LEAD(deg)'); K = 0; F =0.0; % F is frequency in Hz} while F < fs/2 Hre =0.0; Him =0.0; W =2*pi*F/fs; for N=0:M Hre=Hre+H(N+1)*cos(W*N); Him=Him-H(N+1)*sin(W*N); end; MD=sqrt(Hre*Hre+Him*Him); PH = atan2(Him,Hre); GAIN(K+1)=-999; if MD>0 GAIN(K+1)=20*log10(MD);end; PHAS(K+1)=PH*180.0/pi; disp([num2str(F) ' 'num2str(GAIN(K+1)) ' 'num2str(PHAS(K+1))]); F=F+fs/200; K=K+1; end; %while loop
Oct'04CS Sample run:- FIR FREQUENCY RESPONSE Enter sampling frequency(Hz): 1000 Enter order of FIR filter: 3 Enter coefficients:- H[0] = 1 H[1] = 2 H[2] = 1 H[3] = 2 Output obtained:- Freq(Hz) Gain(DB) Phase(deg) : : : }
Oct'04CS Frequency response of FIR digital filter by MATLAB Given discrete time LTI system with difference equation: y[n] = x[n] + 2 x[n-1] + 3 x[n-2] - 4 x[n-3] + 5 x[n-4] Its impulse response is: {..., 0,..., 0, 1, 2, 3, -4, 5, 0,..., 0,... } Its frequency response is: H( e j ) = e - j + 3 e -2 j - 4 e -3 j + 5 e - 4 j To calculate its gain and phase responses, type: freqz ( [ ]) ; Resulting graphs have a normalised frequency scale with “1” corresponding to = radians/sample; i.e. one half of the sampling frequency.
Oct'04CS329159
Oct'04CS329160