what is the purpose of the command line “y=y(1:64)”
Show older comments
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)”?
Accepted Answer
More Answers (1)
Image Analyst
on 21 Sep 2012
The purpose seems to be to crop a convolved signal strangely so as to cause a phase shift. It's essentially doing a convolution with a box filter (a sliding mean window). See this code:
yConvFull = conv(x, [1 1 1 1 1]/5);
yConvSame = conv(x, [1 1 1 1 1]/5, 'same');
yConvCroppedWeirdly = yConvFull(1:64);
% Warning - the x axes are not aligned.
% Need to align
xSame = 0:63;
xFull = -2:65;
figure;
plot(xFull, yConvFull, 'r-', 'LineWidth', 7);
hold on;
plot(xSame, yConvSame, 'b-');
plot(xSame, yConvCroppedWeirdly, 'g-');
grid on;
legend('full', 'same', 'Weird');
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0.5 1 .5]);
You'll notice that my "yConvCroppedWeirdly" is the same as your y, and that is a filtered signal cropped asymmetrically so as to include some "invalid" values (values where x was not in all 5 parts of the signal, but was 0 instead). I'd guess this homework exercise is to illustrate to you how you need to be careful when getting near the edges of your signal when you do digital filters. You need to take into account "edge effects" and the values of the "x" for the elements as the x can change depending on what kind of convolution you do (i.e., what kind of edge effect handling you want to use.)
2 Comments
Passband Modulation
on 21 Sep 2012
Image Analyst
on 21 Sep 2012
No problem. Hopefully though you read what I said and understood it as there was valuable information there.
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!