problem with a matlab code for discrete-time convolution
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (3)
Wayne King
el 16 de Abr. de 2012
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]);
0 comentarios
Wayne King
el 16 de Abr. de 2012
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
Gui Chen
el 21 de En. de 2021
You should take care of the length after the convolution. You could take a look at this video. https://youtu.be/JlUM0XHTSSQ
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!