Suppose a system is implemented with the difference equation: y(n) = x(n) + 2 x(n − 1) − 0.95 y(n − 1) Write your own Matlab function, mydiffeq, to implement this difference equation using a for loop. (Type help for to see how to use the for loop.) If the input signal is N -samples long (0 ≤ n ≤ N − 1), your program should find the first N sample of the output y(n) (0 ≤ n ≤ N − 1). Remember that Matlab indexing starts with 1, not 0, but don’t let this confuse you. Use x(−1) = 0 and y(−1) = 0. (a) Is this system linear? Use your Matlab function to confirm your answer: y1 = mydiffeq(x1) y2 = mydiffeq(x2) y3 = mydiffeq(x1+2*x2) Use any signals x1, x2 you like.
Hello I need help getting this to work in matlab. Im suppose to get this to show a plot but the code i have in the image is not working. Please help. THank you.
Difference Equations
Suppose a system is implemented with the difference equation:
y(n) = x(n) + 2 x(n − 1) − 0.95 y(n − 1)
Write your own Matlab function, mydiffeq, to implement this difference equation using a for loop. (Type help for to see how to use the for loop.) If the input signal is N -samples long (0 ≤ n ≤ N − 1), your program should find the first N sample of the output y(n) (0 ≤ n ≤ N − 1). Remember that Matlab indexing starts with 1, not 0, but don’t let this confuse
you.
Use x(−1) = 0 and y(−1) = 0.
(a) Is this system linear? Use your Matlab function to confirm your answer: y1 = mydiffeq(x1)
y2 = mydiffeq(x2)
y3 = mydiffeq(x1+2*x2)
Use any signals x1, x2 you like.
(b) Compute and plot the impulse response of this system. Use x = [1, zeros(1,100)]; as input.
![%The following is the definition of the function mydiffeg
function y=mydiffeq (x)
x= [0 x];
y=zeros (size (x));
for k=2:length (x)
y (k) =x (k) +2.*x (k-1) -0.95. *y (k-1);
end
y=y (2:end) ;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1296c196-158c-4a2c-9587-82b5996e9fed%2Ffd165efb-3ff1-4b50-8f99-91c0b2418d1f%2F3cioh9_processed.png&w=3840&q=75)
![PartA CODE-
n=0:99;
x1=ones (size(n));
x2=0.5.^n;
y1=mydiffeq(x1);
y2=mydiffeq(x2);
y3=mydiffeq(x1+2.*x2);
y4=y1+2. *y2;
stem(n,y3);
hold on
stem(n,y4);
hold off
xlabel('n');
legend('T[x1+2*x2]','y1+2*y2*);
PartB CODE-
n=0:99;
x1=1. *(n>10);
x2=1.*(n>=20);%delayed version of x1
y1=mydiffeq(x1);
y2=mydiffeq(x2);
stem(n, y1);
hold on
stem(n, y2);
hold off
xlabel('n');
legend ('y[n] for x[n]','y[n] for x[n-10]')](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1296c196-158c-4a2c-9587-82b5996e9fed%2Ffd165efb-3ff1-4b50-8f99-91c0b2418d1f%2Fv4mvxf_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images









