How to convolve signal and transfer function

Hello,
I have a input signal given by
Vin(t) = u(t)-u(t-3)
and a transfer function in time domain given by
h(t) = ( exp^(-2*t)/6 ) + ( 3/16*exp(-t) ) - ( exp(-5*t)/48 )
I want to be able to convolve these two equations but i am unsure of how to do so. I have read through the documentation for conv() but cannot find a way to do this.
Any help would be greatly appreciated.
Thanks

 Accepted Answer

Try this —
t = linspace(0, 10)
t = 1×100
0 0.1010 0.2020 0.3030 0.4040 0.5051 0.6061 0.7071 0.8081 0.9091 1.0101 1.1111 1.2121 1.3131 1.4141 1.5152 1.6162 1.7172 1.8182 1.9192 2.0202 2.1212 2.2222 2.3232 2.4242 2.5253 2.6263 2.7273 2.8283 2.9293
u = @(t) heaviside(t);
Vin = @(t) u(t)-u(t-3);
h = @(t) ( exp(-2*t)/6 ) + ( 3/16*exp(-t) ) - ( exp(-5*t)/48 );
y = conv(Vin(t), h(t), 'same');
figure
plot(t, y)
grid
xlabel('t')
ylabel('y(t)')
.

5 Comments

Thank you for your reply. The only thing I wanted to ask as a follow up is, if I take the input signal into the frequency domain via laplace and same with the transfer function I get a graph similar to the one attached.
syms s t
% input
vint = heaviside(t) - heaviside(t-3);
vins = laplace(vint);
% transfer function
ht = ( exp(-2*t)/6 ) + ( 3/16*exp(-t) ) - ( exp(-5*t)/48 );
hs = laplace(ht);
% output
ws = (vins*hs) ;
wt = ilaplace(ws);
fplot(wt, [-1,10]); hold on; fplot(vint, [-1 10])
which does not resemble the graph that you have attached in your response. Any clue as to why that may be? They should both be returning the same output.
Thanks
The reult using the laplace transform is correct.
However a similar result can occur with conv with the 'full’ (default) option —
t = linspace(0, 10);
u = @(t) heaviside(t);
Vin = @(t) u(t)-u(t-3);
h = @(t) ( exp(-2*t)/6 ) + ( 3/16*exp(-t) ) - ( exp(-5*t)/48 );
y = conv(Vin(t), h(t));
figure
plot(t,y(1:numel(t)))
grid
xlabel('t')
ylabel('y(t)')
.
Works! Thank you so much.
As always, my pleasure!
.
A few thoughts to consider.
syms s t
% input
vint(t) = heaviside(t) - heaviside(t-3);
vins = laplace(vint);
Keep in mind that Matlab assumes that t covers all of real line. Because ht is (I think) supposed to be the impulse response, it's best to ensure that ht(t) = 0 for t < 0.
% transfer function
ht(t) = (( exp(-2*t)/6 ) + ( 3/16*exp(-t) ) - ( exp(-5*t)/48 )) * heaviside(t);
hs = laplace(ht);
% output
ws = (vins*hs) ;
wt(t) = ilaplace(ws);
As shown in the plot, wt is not zero for t<0, so probably best to enforce that as well
wt(t) = wt(t) * heaviside(t);
figure; hold on
fplot(wt, [-1,10]); % output
%fplot(vint, [-1 10]); % input
%fplot(ht, [-1 10]); % impulse response
Note that wt is now zero for t < 0.
Can also compute the exact output using the convolution integral
syms tau real
wt1(t) = int(vint(tau)*ht(t - tau),tau,-inf,inf);
fplot(wt1, [-1 10],'o')
The conv() function computes the convolution sum, which can approximate the convolution integral when scaled by the time step in the data. Also, need to be careful when using heaviside() to generate samples of a continuous signal because of the default value of heaviside(0)
t = linspace(0, 10);
dt = t(2) - t(1);
%u = @(t) heaviside(t); % by default, heavside(0) = 1/2, but at t = 0, we should have u(0) = 1 by definition of unit step
u = @(t) (t>=0);
Vin = @(t) u(t)-u(t-3);
h = @(t) ( exp(-2*t)/6 ) + ( 3/16*exp(-t) ) - ( exp(-5*t)/48 );
y = conv(Vin(t), h(t))*dt; % must scale by dt
plot(t,y(1:numel(t)),'-x')
legend('wt - Laplace','wt - convolution integral','wt - convolution sum')

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!