MATLAB: How to calculate the impulse response

output sequence

How do I write the code in order to get the impluse response for the following equation:
y[n]=x[n]+x[n-1]+x[n-2]

Best Answer

f=100;% frequanecy
fs=1000;
n=[1:1000]*f/fs;
u=ones(n,1)
x(n)=2*cos(0.5*pi*n).u(n);
% ~ (check indexes im not sure ..)
y(n)=x(n(3:1000))+x(n(2:999))+x((1:998))