Incorrect continuous signal convolution values in Matlab

I am trying to convolve the following signals in Matlab:
and
for a=0.5. The result, say z(t) is:
So here is my Matlab code:
%Define initial signals
alpha = .5;
Ts = 0.01;
t_x = -5:Ts:5;
x = heaviside(t_x);
t_y = -5:Ts:5;
y = heaviside(t_y).*(alpha.^abs(t_y));
%Plot initial signals
figure(1)
plot(t_x,x);
xlabel('t');
ylabel('x(t)');
axis([min(t_x)-1 max(t_x)+1 min(x)-1 max(x)+1]);
figure(2)
plot(t_y,y);
xlabel('t');
ylabel('y(t)');
axis([min(t_y)-1 max(t_y)+1 min(y)-1 max(y)+1]);
%Convolution
z = Ts*conv(x,y);
t_z = min(t_x)+min(t_y):Ts:max(t_x)+max(t_y);
figure(3)
plot(t_z,z);
xlabel('t');
ylabel('z(t)');
axis([min(t_z)-1 max(t_z)+1 min(z)-1 max(z)+1]);
The problem is that the final signal that Matlab calculates has incorrect values for values of t greater than 5. I have checked this in detail and noticed that the signal is wrong for t > max(t_x). Here is the final plot:
What am I doing wrong?

 채택된 답변

Star Strider
Star Strider 2016년 6월 27일
The convolution is actually defined only for your ‘t_x’ vector (that must be the same as ‘t_y’).
For example, if you have the Symbolic Math Toolbox, run this:
syms a t x y
assume(t>0)
assume(a>0)
x(t) = 1;
y(t) = a^t;
X = laplace(x);
Y = laplace(y);
Z = X*Y;
z = ilaplace(Z)
za = subs(z, a, 0.5);
figure(1)
fplot(za, [-5 5])

댓글 수: 6

Konstantinos
Konstantinos 2016년 6월 27일
편집: Konstantinos 2016년 6월 27일
What do you mean by "The convolution is actually defined only for your ‘t_x’ vector..."? I suppose you mean that this is the range that Matlab calculates the convolution at. Also, if this is correct then why the values of z(t) for t>5 are nonzero? Generally, if signals x(t) and y(t) are defined in [n1,m1] and [n2,m2] respectively their convolution z(t) should be defined in [n1+n2, m1+m2]. Is there any workaround to solve this since I don't have the Symbolic Math Toolbox? Thanks.
My pleasure.
It’s only defined over the time you calculated it on, here being ‘t_x’, and since you actually defined t>0, only for positive ‘t’.
The Symbolic Math Toolbox result for:
fplot(za, [0 5])
is:
You would get the same if you plotted the symbolic result:
z =
(a^t - 1)/log(a)
This code would give your the same result:
t = linspace(0, 5);
Ts = mean(diff(t));
x = ones(size(t));
y = 0.5 .^ t;
z = Ts*conv(x,y);
figure(2)
plot(t, z(1:length(t)))
grid
I am actually confused. So what we are doing basically is that we crop the result of the convolution to keep only the left part of it that has the same length with the first signal x like
conv(x,y,'same')
does. But, as I said before, the convolution of x(t) defined in [n1, m1] and y(t) defined in [n2, m2] should be defined in [n1+n2, m1+m2], which is easily proven from theory. What I need is the whole convolution, not just a part of it. If the values that exceed the length of x in
conv(x,y,'full')
(which is the default Matlab behavior in conv(x,y)) are garbage, then why Matlab returns them? For example if length(t_x) == length(t_y) it should return only half of them.
Don’t be confused. The convolution is defined in the system you quoted for t ≥ 0. So you can only calculate and plot it on that region.
The output of conv is definitely not ‘garbage’, because it is used for a variety of other applications, including filtering and polynomial multiplication.
For your purposes, you defined the convolution on the interval [0,5], and when you calculated it, the function gave you the correct result on that interval, the same as the symbolic result:
z = @(a,t) (a.^t - 1)./log(a);
that will reproduce the fplot result if you choose to plot it.
Konstantinos
Konstantinos 2016년 6월 29일
편집: Konstantinos 2016년 6월 29일
Anyway, I found the answer on some university notes. The problem is that I am trying to convolve two signals of infinite duration. In this case, the convolution is only valid in the interval that the first signal is defined at (this is a Matlab convention about the conv(...) function). You can see more inside the PDF. If you don't know Greek, you can check the code :) Thank you!
My pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Signal Processing Toolbox에 대해 자세히 알아보기

제품

질문:

2016년 6월 27일

댓글:

2016년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by