How can I plot convolution of rect(t/2)*sgn(t)
29 次查看(过去 30 天)
显示 更早的评论
The exercise I am trying to complete requires me to: Compute and plot the following convolution integral by using "conv.m" in MATLAB. rect(t/2)*sgn(t)
CODE 1 t=-5:0.01:5; 2 x=abs(t)<1; 3 h=sign(t); 4 y=conv(x,h); 5 plot(t,y);
ERRORS Error using conv2 First and second arguments must be single or double.
Error in conv (line 39) c = conv2(a(:),b(:),shape);
Error in three (line 4) y = conv(x,h);
采纳的回答
Star Strider
2012-9-1
You have to make the small adjustment of plotting every other value of y (since y is about twice the length of t), but if you want to plot y as a function of t, this will work:
t = -5:0.01:5;
x = double(abs(t) < 1)); % Convert logical to double
h = sign(t);
y = conv(x,h);
figure(1)
plot(t,y(1:2:end)) % Plot every other value of y
更多回答(2 个)
Azzi Abdelmalek
2012-8-31
t=-5:0.01:5;
x=abs(t);
h=sign(t);
[tt,y]=conv(x,h);
plot(y); % y and t have'nt the same length
2 个评论
Azzi Abdelmalek
2012-9-1
beacause y and t have'nt the same length. x , h and t have the same length but not with y=conv(x,h) . then instead of plot(t,y) which is false, use plot(y)
daltonicox
2013-9-13
how can i plot this: g(t) = rect(t/2) * [δ(t+2) - δ(t+1)]. As matter of fact, i want to plot the convolution of this functions. But i'm having trouble creating the rect function. If anyone can help me, i would appreciate it very much.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!