Can't plot convolution

8 visualizaciones (últimos 30 días)
Gabriel Ramirez
Gabriel Ramirez el 15 de Mayo de 2018
Comentada: Gabriel Ramirez el 15 de Mayo de 2018
Hi, I'm having trouble plotting the convolution between a square wave and sine function, here is the code:
t=[0:0.001:1.5];
f=40 %square wave frequency
d=[0:1/f:1.5]; %repetition each 1/40
y=pulstran(t, d,'rectpuls',0.01);
f_s= 10; %sine wave frequency
sin_10= sin(2*pi*f_0*t); %sine wave
r = conv(y,sin_10);
subplot( 3, 1, 1); plot(t,y); title('Square wave');
subplot( 3, 1, 2); plot(t,sin_10); title('Sine wave');
subplot( 3, 1, 3); plot(t,r); title('Square and Sine convolution')
It gives me the error: Error using plot Vectors must be the same length.
Any help?

Respuesta aceptada

Image Analyst
Image Analyst el 15 de Mayo de 2018
Remember, the convolution is larger than the two input signals. It's the sum of the two signal lengths. You need to take that into account and expand your t, or else use the 'same' option in conv().
r = conv(y, sin_10, 'same');
  1 comentario
Gabriel Ramirez
Gabriel Ramirez el 15 de Mayo de 2018
Thank you so much. It is my second code in Matlab, I don't understand the comands quiet well yet, thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots 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!

Translated by