필터 지우기
필터 지우기

Plot convolution of continuous signal

조회 수: 15 (최근 30일)
Michelle Watson
Michelle Watson 2020년 6월 23일
댓글: Jiahao CHANG 2020년 6월 23일
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?

답변 (1개)

Jiahao CHANG
Jiahao CHANG 2020년 6월 23일
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
Michelle Watson
Michelle Watson 2020년 6월 23일
Thanks for the information!
Yes the x-axis values are fixed. However, I'd like the y-axis to have the proper values as well. See the Desmos screencap below:
Also, could you elaborate on why exactly what your t1 variable does? Does it scale the length of m to fit the t values I set? If so, what is the purpose of the 6/length(m)? Why 6?
Is it possible to just have the convolution (m) already be scaled according to the signals that I input? (he1, he2)?
Why can he1 and he2 be plotted as a function of t? But when I try to plot m (which is a function of he1 which is a function of t), it gives these errors?
If this is not possible, how do I go about scaling m? Would I need to scale each value of me at each t value?
Thanks again!
Jiahao CHANG
Jiahao CHANG 2020년 6월 23일
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.

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

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by