Plot convolution of continuous signal
47 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to plot the convolution of 2 continuous signals. My figure has the correct shape, but the values are very large.
t= -2.5:.001:3.5;
he1 = (1-t).*(heaviside(t)-heaviside(t-1));
he2 = (t).*(heaviside(t+2)-heaviside(t-2));
m=conv(he1,he2);
subplot(224); plot(m); grid on;
xlabel('t'); ylabel('h_s(t), series (conv integral)');
When I try to plot
subplot(224); plot(t, m); grid on;
Error: Error using plot. Vectors must be the same length.
When I try to plot
subplot(224); plot(t, m(t)); grid on;
Error: Array indices must be positive integers or logical values.
When I try
t= -2.5:.001:3.5;
he1 = @(t) (1-t).*(heaviside(t)-heaviside(t-1));
he2 = @(t) (t).*(heaviside(t+2)-heaviside(t-2));
m=conv(he1(t),he2(t));
subplot(224); plot(m); grid on;
xlabel('t'); ylabel('h_s(t), series (conv integral)');
^ Define functions @t, I get the same plot as below
Problem: bottom right figure.
How do I get my convolution plot to have the same values as the original functions?
0 Commenti
Risposte (1)
Jiahao CHANG
il 23 Giu 2020
Hi Michelle,
Your code
t= -2.5:.001:3.5;
he1 = (1-t).*(heaviside(t)-heaviside(t-1));
he2 = (t).*(heaviside(t+2)-heaviside(t-2));
m=conv(he1,he2);
subplot(224); plot(m); grid on;
xlabel('t'); ylabel('h_s(t), series (conv integral)');
gives you the wrong value of 't' because you didn't define the x vector so Matlab will display the length of the variable 'm'.
subplot(224); plot(t, m); grid on;
goes wrong because t and m are not in the same length. (t is 1*6001 and m is 1*12001)
So i suggest you to use
t1= -2.5:6/length(m):3.5-6/length(m);
And the code should be like
t= -2.5:.001:3.5;
he1 = (1-t).*(heaviside(t)-heaviside(t-1));
he2 = (t).*(heaviside(t+2)-heaviside(t-2));
m=conv(he1,he2);
t1= -2.5:6/length(m):3.5-6/length(m);
subplot(224); plot(t1,m); grid on;
xlabel('t'); ylabel('h_s(t), series (conv integral)');
Try this and tell me whether it is want you want;)
2 Commenti
Jiahao CHANG
il 23 Giu 2020
For the y-axis value, if you want to achieve the same equation as you shown in this picture, setting variables by directly using these equations is easier.
Yes, t1 is a variable scale the length of m so that they could match. 6 is because your minimum time is -2.5 and max is 3.5 so the total time is 3.5-(-2.5)=6. In order to match the same length of m, you need to divide your time into length(m) pieces, each piece(or step) equals to 6/length(m). Because you already set the last number equals to 3.5, so maybe it is better to change that line as
t1= -2.5:6/(length(m)-1):3.5;
I'm not sure whether I understand this question or not. The length of convolution(m) equals to the length of he1+he2-1. You can see some examples of conv here.
he1 and he2 can plotted as a function of t is because for each t(i), you have and only have one he1(i) to match. However m has more values than he1 and t so that they can't match because the length are different. And Im not sure whether this is meaningful.
To understand this, you should know that the time you put
t= -2.5:.001:3.5;
is a discrete not continious.
Vedere anche
Categorie
Scopri di più su Graphics Object Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!