Can't plot convolution
8 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Image Analyst
2018-5-15
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');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!