Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

3.x[n]=[1 -2 3 6 -5].

Perform the following, y[n]=2x[n-1]+x[n+1]+x[n-2] in MATLAB, plot the


result along with x[n].
Ans.
clc;
clear all;
close all;
x=[1 -2 3 4 5];
t=length(x);
u=0:(t-1);
subplot(4,2,1);stem(u,x);
p=-1;
t1=p:(t+p-1);
j=1;
for i=1:t
x1(j)=x(i);
j=j+1;
end
subplot(4,2,2);stem(t1,x1);
p1=1;
t2=0:(t+p1-1);
l=1;
for k=1:t
x2(l)=x(k);
l=l+1;
end
p2=2;
t5=p2:(t+p2-1);
m=1;
for n=1:t
x3(m)=x(n);
m=m+1;
end
subplot(4,2,3);stem(t5,x3);
s=zeros(1,p1);
s1=[s x2];
subplot(4,2,4);stem(t2,s1);
s2=2*s1;
s3=zeros(1,5);
y3=[x1 s3];
s4=zeros(1,5);
y4=[s4 x3];
s5=zeros(1,4);
y5=[s5 s2];
y11=y3+y4+y5;

t3=1:10;
subplot(4,2,5);stem(t3,y11);

You might also like