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...



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<br>function y=mydiffeq (x)<br>x= [0 x];<br>y=zeros (size (x));<br>for k=2:length (x)<br>y (k) =x (k) +2.*x (k-1) -0.95. *y (k-1);<br>end<br>y=y (2:end) ;<br>

Extracted text: %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) ;
PartA CODE-<br>n=0:99;<br>x1=ones (size(n));<br>x2=0.5.^n;<br>y1=mydiffeq(x1);<br>y2=mydiffeq(x2);<br>y3=mydiffeq(x1+2.*x2);<br>y4=y1+2. *y2;<br>stem(n,y3);<br>hold on<br>stem(n,y4);<br>hold off<br>xlabel('n');<br>legend('T[x1+2*x2]','y1+2*y2*);<br>PartB CODE-<br>n=0:99;<br>x1=1. *(n>10);<br>x2=1.*(n>=20);%delayed version of x1<br>y1=mydiffeq(x1);<br>y2=mydiffeq(x2);<br>stem(n, y1);<br>hold on<br>stem(n, y2);<br>hold off<br>xlabel('n');<br>legend ('y[n] for x[n]','y[n] for x[n-10]')<br>

Extracted text: 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]')

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here