MATLAB: What is the purpose of the command line “y=y(1:64)”

command line

Generate x[n]=2cos(0.2*pie*n), with a length of N=64 , that is,0<n<63 , using “x=2*cos(0.2*pi*n)” with “n=[0:63]”. Use the following MATLAB code to produce y[n] from x[n]:
x1=[0 0 0 0 x];
x2=[0 0 0 x 0];
x3=[0 0 x 0 0];
x4=[0 x 0 0 0];
x5=[x 0 0 0 0];
y=(x1+x2+x3+x4+x5)/5;
y=y(1:64);
plot(n,x,'b',n,y,'r')
legend('x[n]','y[n]');
What is the purpose of the command line “y=y(1:64)”?

Best Answer

It gives you an output signal the same length as your original signal, x. The following operations create a signal with 68 samples.
x1=[0 0 0 0 x];
x2=[0 0 0 x 0];
x3=[0 0 x 0 0];
x4=[0 x 0 0 0];
x5=[x 0 0 0 0];
y=(x1+x2+x3+x4+x5)/5;
So y = y(1:64);
gives you a signal with length 64.