EKT 430 Digital Signal Processing – MATLAB Assignment 1 CHAPTER 1 TIME DOMAIN REPRESENTATION OF SIGNALS AND SYSTEMS 1. Addition and Multiplication Of Two Arbitrary Sequences a) Write a MATLAB function sigadd(x1,n1,x2,n2) which implements the signal addition y(n) x1 (n1 ) x2 (n2 ) . The sequences x1 (n1 ) is defined over the index sequence n1 , and the sequence x2 (n2 ) is defined over n2 . b) Test your code with the following sequences: x1 = 20100312for –4n1 3 x2 = 203–1–2–22for–2n2 4 Hint: The MATLAB commands min() and max() are helpful. c) Modify the program in in 1a) to mult(x1,n1,x2,n2) which implements the signal multiplication y(n) x1 (n1 ).x2 (n2 ) . The sequences x1 (n1 ) is defined over the index sequence n1 , and the sequence x2 (n2 ) is defined over n2 . d) Test your code with the same sequence as in 1b). 2. Up-Sampling and Down-Sampling The basic operations in sampling rate alteration systems are up-sampling and down-sampling. Down-sampling by an integer n is simply done by taking every n-th sample of the original sequence. Up-sampling by an integer factor m is done by inserting m-1 zeros between two consecutive samples of the original sequence. Develop 2 separate programs which perform up-sampling and down-sampling based on an appropriate function headers given as following: a) %up-sampling function[]=up_sampling(x,m); % x = input signal by user % m = factor of up-sampling b) %down-sampling function[]=down_sampling(x,m); % x = input signal by user % m = factor of up-sampling for any given input signal, and for any desired factor, m of up-sampling and down sampling. Both programs should be able to display/output figures corresponding to before and after up-sampling/down-sampling process. 1/2 EKT 430 Digital Signal Processing – MATLAB Assignment 1 3. Convolution The predefined MATLAB-function conv assumes that the two sequences begin at n=0. It neither provides nor accepts any timing information if the sequences have arbitrary support. Hence, a start and end point of the convolution sequence y(n) is needed. Design a modified version of conv (conv_m), which performs the convolution of arbitrary support sequences. An appropriate function header is given below. function[y,ny] = conv_m(x,nx,h,nh) % Modified convolution function % [y,ny] = conv_m(x,nx,h,nh) % y = convolution result % ny = support of y % x = first signal on support nx % nx = support of x % h = second signal on support nh % nh = support of h Test your function with the following sequences: x[n] {3,11, 7, 0, 0, 1, 4, 2} for 4 n 3 h[n] {2,3, 0, 5, 2,1} for 1 n 4 Plot your answer in a figure. 4. Linear Constant Coefficient Difference Equation An important subclass of LTI discrete-time systems is characterized by a linear difference equation with constant coefficients given by: N k 0 M dk . y[n k ] pk .x[n k ] k 0 In the followingM-file, some basic systems are evaluated using theMATLAB function filter(). 2/2 EKT 430 Digital Signal Processing – MATLAB Assignment 1 %Program E3_1.m %Evaluating the difference equation close all; clear all; clc; L_length = 128; k = (0 : L_length-1); b1 = 0.25*[1 1 1 1]; a1 = [1]; b2 = [1]; a2 = [1 0.5 -0.75 -0.75]; x = [1,zeros(1, L_length -1)]; % input sequence y1 = filter(b1,a1,x); % output of the first system y2 = filter(b2,a2,x); % output for the second system figure; subplot(311); stem(k,x); axis([min(k),max(k),-0.1, 1.1]); title('input sequence x'); ylabel('amplitude'); subplot(312); stem(k,y1); axis([min(k),max(k),min(y1)-.1,max(y1)+.1]); title('output sequence y_1 of the first system'); ylabel('amplitude'); subplot(313); stem(k,y2); axis([min(k),max(k),min(y2)-.1,max(y2)+.1]); title('output sequence y_2 of the second system'); ylabel('amplitude'); xlabel('sample index'); a) Give the difference equation for each system! Hint: Investigate the function filter(). b) Identify the type and the order of each system. c) Change the vector a2 of the second system to a2 = [1 0.75 -0.5 -0.5]. What happens and why? 5. Impulse Response Determine and plot the impulse response of the systems given below. a) y[n] 2 x[n] x[n 1] x[n 2] b) y[n] 2 x[n] 3x[n 6] y[n 2] y[n 3] Use the MATLAB function impz() to determine the impulse response of each system. Give the type of each system (FIR or IIR). 3/2 EKT 430 Digital Signal Processing – MATLAB Assignment 1 6. LTI Discrete-Time Systems and its Interconnections This part deals with the interconnection of LTI discrete-time systems. As a starting point, the numerator and denominator polynomials of two systems with rational z-transforms are specified as follows: %System b1 = [1 a1 = [1 %System b2 = [1 a2 = [1 1 0.5 -15 2 -15 0.1 0.9]; %numerator coefficients 6]; %denominator coefficients 6]; %numerator coefficients 0.8]; %denominator coefficients a) Check the LTI properties of the systems by inspection of the difference equations. b) Check the BIBO-stability by investigating the impulse response plot. d) The above two systems are interconnected in the following. System 1 System 2 Test the stability of the two new systems. Explain your result. 4/2 EKT 430 Digital Signal Processing – MATLAB Assignment 1 CHAPTER 2 TRANSFORM DOMAIN REPRESENTATION OF DISCRETE TIME SIGNALS 1. Discrete-Time Fourier Transform (DTFT) and Frequency Response The code below computes the frequency response of an LTI discrete-time system resulting in: b b e j ... bM e jM H (e j ) 0 1 j a0 a1e ... aN e j N %Program E4_1.m %DTFT-Computation close all; clear all; clc; k=128; %number of frequency points w=0:pi/k:pi; b=[0.008 -0.033 0.05 -0.033 0.008]; a=[1 2.37 2.7 1.6 0.41]; H=freqz(b,a,w); figure; subplot(221); plot(w/pi,real(H)); grid; title('Real part of X(exp(-j\omega))'); xlabel('\omega/\pi'); ylabel('Amplitude'); subplot(222); plot(w/pi,imag(H)); grid; title('Imaginary part of X(exp(-j\omega))'); xlabel('\omega/\pi'); ylabel('Amplitude'); subplot(223); plot(w/pi,abs(H)); grid; title('Magnitude Spectrum of X(exp(-j\omega))'); xlabel('\omega/\pi'); ylabel('Amplitude'); subplot(224); plot(w/pi,angle(H)); grid; title('Phase Spectrum of X(exp(-j\omega))'); xlabel('\omega/\pi'); ylabel('Phase/radians'); a) Use the function unwrap to remove the discontinuities in the phase response. b) Give the difference of the plots generated by the command freqz(b,a) (without a semicolon) and the plots generated in the above code. c) Given the frequency response below: 0.5 2e j 1.7e j 2 H (e j ) 1 2e j 1.5e j 2 Determine and plot the magnitude response and the unwrapped phase response. 5/2 EKT 430 Digital Signal Processing – MATLAB Assignment 1 d) Compute the magnitude response of the sequences given below and that of the Modulated sequence y = x1.*x2. x1 = cos(pi/7*n); % original sequence x2 = cos(pi/2*n); % modulation sequence Plot your results and verify the spectrum of the modulated sequence. 2. Discrete Fourier Transform The N-point DFT of a finite-length sequence x(n) defined for 0 n N 1 is given by: N 1 X [k ] x[n]e j 2 kn/ N n0 k 0,1,..., N 1 and the inverse DFT is defined as: x[n] 1 N 1 j 2 kn / N X [k ]e N n0 a) Develop a function that calculates the N-Point DFT of a given sequence using the above equation of the definition of the DFT. An appropriate header is given below. function [X_k] = dft(x_n,N) % computes the DFT using the definition equation % ----------------------------------------------% [X_k] = dft(x_n,N) % X_k : DFT coefficients (k in the range 0 : N-1) % x_n : N-point finite duration sequence % N : Length of DFT Verify your function using the sample vector: x=[0 0.125 0.25 0.375 0.5 0.625 0.75 0.875] and the MATLAB function fft(). Compare these two results. b) The inverse DFT can also be computed using the following expression: j x[n] .DFTN* ( jX * (k )) N Develop two functions inMATLAB implementing the definition equation and the above alternate approach computing the IDFT. The headers of the functions are provided below. 6/2 EKT 430 Digital Signal Processing – MATLAB Assignment 1 function [x_n] = idft1(X_k,N) % computes the IDFT using the definition equation % ------------------------------------------------% [x_n] = idft1(X_k,N) % X_k : DFT coefficients (k in the range 0 : N-1) % x_n : N-point sample vector % N : Length of IDFT function [x_n] = idft2(X_k,N) % computes the IDFT using the alternative approach % ------------------------------------------------% [x_n] = idft2(X_k,N) % X_k : DFT coefficients (k in the range 0 : N-1) % x_n : N-point sample vector % N : Length of IDFT Verify your functions using the vector given in 2a) and the MATLAB function ifft(). 3. Rational Transfer Functions a) The numerator and denominator coefficients of three rational transfer functions are given below. num1 = [2 5 9 5 3]; den1 = [5 45 2 1 1]; num2 = [.33 .33 .33]; den2 = [1]; num3 = [1 -1.17557 1]; den3 = [1 -1.16969 0.990025]; Give the pole-zero plots and check the stability of the systems. c) The pole locations, zero locations and the gain constant of a rational transfer function are given below: Poles 1 0.3, 2 2.5, 3 0.2 j 0.4, 4 0.2 j 0.4 Zeros 1 0.5, 2 0.75, 3 0.6 j 0.7, 4 0.6 j 0.7 Gain k 3.9 i) ii) iii) Give the pole zero plot. Give the numerator and denominator of the rational transfer function. Determine the partial-fraction expansion. --------------------------------------------------THE END--------------------------------------------Notes: Please submit your MATLAB Assignment 1 by/before: 29 August 2008(Friday) 7/2