Can't plot convolution
8 views (last 30 days)
Show older comments
Gabriel Ramirez
on 15 May 2018
Commented: Gabriel Ramirez
on 15 May 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?
0 Comments
Accepted Answer
Image Analyst
on 15 May 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');
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!