How to do convolution in time domain in Matlab

8 Ansichten (letzte 30 Tage)
mandy
mandy am 27 Okt. 2015
Kommentiert: zi-yan liu am 20 Mai 2020
I am learning the use of the convolution command and I am trying to do convolution of two rect signals in Matlab. Every time I type in the code below I get the error that the vectors must be the same length. If i look in my workspace it says that x=1x80001double and t=1x40001double. I need to know how to fix this error. Also, should I be using the heaviside command for doing convolution of rects in matlab? I want to make sure that the convolution will turn out correct.
t=-20:0.001:20;
y=heaviside(t+1)-heaviside(t-1)
plot(t,y);
axis([-10 10 0 2])
figure
t1=-20:0.001:20;
y1=heaviside(t+1)-heaviside(t-3)
plot(t1,y1)
axis([-10 10 0 2])
figure
x=conv(y, y1);
plot(x,t)
t=-20:0.001:20;
  1 Kommentar
zi-yan liu
zi-yan liu am 20 Mai 2020
The error lies in the last line: t=-20:0.001:20: The length of x is 1x80001double, but the length of the t is 1x40001double. So, you cannot get a plot successfully.
To get the conv plot, you need to fix the value of t of the last plot to -40:0.001:40.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by