필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Passband  Modulation
Passband Modulation 2012년 9월 21일
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)”?

채택된 답변

Wayne King
Wayne King 2012년 9월 21일
편집: Wayne King 2012년 9월 21일
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.
  댓글 수: 2
Passband  Modulation
Passband Modulation 2012년 9월 21일
many thx, i would also like to ask can i obtain an equation to relate x[n] and y[n] for n>4?
Wayne King
Wayne King 2012년 9월 21일
It's just a moving average filter:
y(n) = \sum_{k=0}^{N-1} h(k)x(n-k)
with h(n) = 1/N

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 9월 21일
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
Passband  Modulation
Passband Modulation 2012년 9월 21일
it was solved, thx!
Image Analyst
Image Analyst 2012년 9월 21일
No problem. Hopefully though you read what I said and understood it as there was valuable information there.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by