The purpose of this problem is to use MATLAB to perform disc
The purpose of this problem is to use MATLAB to perform discrete-time convolution and to solve a linear difference equation. Consider an LTI system described by the difference equation y[n] - 0.8y[n-l] = 2x[n] under the assumption of initial rest. We want to use MATLAB to compute the output y[n] for the following three inputs x[n]: (i) u[n] - u(n-2), (ii) u[n] - 2u[u-2] + u[n-6], and (iii) (0.7)^n u[n]. This should be done for each input using the three methods given below. For each method, turn in a listing of the code used to compute y[n], along with plots of x[n] and y[n] on the same axes (using an appropriate range of n to adequately illustrate the solution). a) Design a program to implement this equation directly in MATLAB. That is, your program should perform the recursion similar to that in Example 2.15. b) Design a program to implement the convolution sum directly. This should be written for arbitrary x[n] and h[n]. c) Use the conv() function to compute the convolution. The conv() function is a built in function of MATLAB. Compare the results that you obtain to those in parts a) and b).
Solution
a)
function [t,index]= recursion
b)
x = input(\'Enter x: \');
h = input(\'Enter h: \') ;
Ni = length(x);
Nh = length(h);
y = 2 x(n)0.8y(n-1)(1,Ni+Nh);
t = zeros(1,Nh);
for i = 1:Ni+Nh-1
if i<=Ni
t(1)= x(i);
for j = 1:Nh
y(i) = y(i) + h(j)*t(j);
end
for k = Nh:-1:2
t(k) = t(k-1);
end
else
t(1)= 0;
for j = 1:Nh
y(i) = y(i) + (h(j)*t(j));
end
for k = Nh:-1:2
t(k) = t(k-1);
end
end
end
