How to convolve signal and transfer function

19 vues (au cours des 30 derniers jours)
Tawseef Patel
Tawseef Patel le 9 Nov 2021
Commenté : Paul le 9 Nov 2021
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

Réponse acceptée

Star Strider
Star Strider le 9 Nov 2021
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 commentaires
Star Strider
Star Strider le 9 Nov 2021
As always, my pleasure!
.
Paul
Paul le 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')

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by