How to convolve signal and transfer function
20 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 9 Nov 2021
Try this —
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), 'same');
figure
plot(t, y)
grid
xlabel('t')
ylabel('y(t)')
.
5 Comments
Paul
on 9 Nov 2021
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')
More Answers (0)
See Also
Categories
Find more on Spectral Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


