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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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) ;
Transcribed Image 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-
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]')
Transcribed Image 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]')
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY