필터 지우기
필터 지우기

problem with a matlab code for discrete-time convolution

조회 수: 8 (최근 30일)
Benjamin
Benjamin 2012년 4월 16일
답변: Gui Chen 2021년 1월 21일
Here is my code.
n= -25:25
x= cos(2*pi*n/.3).*(n>=0)
h= (cos(pi*n/.3)+(sin(pi*n/3)/sqrt(3))).*(n>=0)
y= conv(h,x)
plot(n,x)
hold on
plot(n,h)
hold on
plot(n,y)
title ('Plot of input X[n], impulse response h[n] and the convolution of the two Y[n]')
xlabel ('Variable n')
ylabel ('amplitude of signal')
hold on
I have got to plot the input x, impulse response h and the convolution of the two using the conv command but i am getting the error
"??? Error using ==> plot
Vectors must be the same lengths.
Error in ==> lab6p3 at 9
plot(n,y)"
I am using the R2011a student version of matlab
thank you in advance

답변 (3개)

Wayne King
Wayne King 2012년 4월 16일
n= -25:25;
x= cos(2*pi*n/.3).*(n>=0);
h= (cos(pi*n/.3)+(sin(pi*n/3)/sqrt(3))).*(n>=0);
y= conv(h,x);
n1 = -25:length(y)-1-25;
stem(n1,y,'markerfacecolor',[0 0 1]);

Wayne King
Wayne King 2012년 4월 16일
You have to realize the result of linearly convolving two input signals, h and x, is length(h)+length(x)-1
so you need a new n vector that matches your output y in length.
Your y vector has the expected length of length(h)+length(x)-1 = 101
  댓글 수: 1
Benjamin
Benjamin 2012년 4월 16일
How would I do that?
sorry still getting used to matlab

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


Gui Chen
Gui Chen 2021년 1월 21일
You should take care of the length after the convolution. You could take a look at this video. https://youtu.be/JlUM0XHTSSQ

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by