Plotting the convolution of two signals

I am given two functions x(t) =5[u(t+1)-u(t-1)] and h(t)=u(t-1)-u(t-7). I am asked to convolve these two signals and plot the result in the range -3 to 10. Here is the code that I wrote:
t=-3:0.1:10; t_c=-3:0.05:10; h_t=heaviside(t-1)-heaviside(t-7); x_t1=5.*(heaviside(t+1)-heaviside(t-1)); c_x_h=conv(x_t1,h_t); figure(1) plot(t_c,c_x_h)
However, since this is a simple convolution I verified it by hand and it does not look like the plot i get in MATLAB. The max value should be 10 but in MATLAB i get 100. Also, the duration of the function should be 8 but i get 4 with MATLAB. Please help.

 채택된 답변

Rick Rosson
Rick Rosson 2014년 10월 23일

1 개 추천

Please try:
t_c = -6:0.1:20;
and:
dt = t(2) - t(1);
c_x_h = dt*conv(x_t1,h_t);

댓글 수: 4

Dennis
Dennis 2014년 10월 23일
Thank you for the tip Rick. I tried that and it worked. I am unclear as to why the dt is needed though and why t_c needed to be extended to -6 to 20. Thanks again for your time.
Baiyu Zhang
Baiyu Zhang 2018년 6월 28일
What is dt = t(2)-t(1)? What does it mean?
Celeste MacNeil
Celeste MacNeil 2018년 10월 14일
What do you mean dt = t(2)-t(1)?
Celeste MacNeil
Celeste MacNeil 2018년 10월 14일
I assume you just mean the step?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

IKRAM jebali
IKRAM jebali 2017년 3월 31일

0 개 추천

Hello! Thank you. I'had the same problem. Me too amnclear as to why the dt is needed though and why t_c needed to be extended to -6 to 20. I use it but i don't know why? There is any answer please. Thank you.

댓글 수: 1

Because the length of the convolution of two matrices of ,length m and n will be m+n-1. inorder to get the same vector size, you need to do this.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Stem Plots에 대해 자세히 알아보기

태그

질문:

2014년 10월 23일

댓글:

2018년 10월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by