Trouble trying to plot the output of an input signal with an impulse response
19 views (last 30 days)
Show older comments
Here is my code where I took the convolution of an input signal x(t) and the impulse response h(t). I took the laplace of each signal and multiplied those laplace values. My problem is trying to plot the impulse response. I tried to define t from 0 - 10 seconds with a dt of 0.01, but this would error out when I tried to find my Laplace results for X(s) and H(s), so I removed it and it worked fine. However, I am not sure how to plot the impulse response and output response y(t) without a defined t value? Any help would be greatly appreciated. Here is my code:
syms t s;
>> x = (5/7)*exp(-t) - (12/7)*exp(-8*t); % x = x(t)
>> h = cos(2*t) + 4*sin(2*t); % h = h(t)
>> % Define the Laplace of the impulse function h(t) = cos(2t) + 4sin(2t)
>> H = laplace(cos(2*t) + 4*sin(2*t)); % H = H(s)
>> pretty(H)
s 8
------ + ------
2 2
s + 4 s + 4
% Define the Laplace of the input function x(t) = (5/7)e(-t) - (12/7)e(-8t)
>> X = laplace((5/7)*exp(-t) - (12/7)*exp(-8*t)); % X = X(s)
>> pretty(X)
5 12
--------- - ---------
7 (s + 1) 7 (s + 8)
% Define Y(s) as the convolution of x(t) * h(t) = X(s) x H(s)
Y = X*H; % Y = Y(s)
pretty(Y)
/ 5 12 \ / s 8 \
| --------- - --------- | | ------ + ------ |
\ 7 (s + 1) 7 (s + 8) / | 2 2 |
\ s + 4 s + 4 /
% Define the Inverse Laplace of Y(s) = [(5/(7(s + 1))) - (12/(7(s + 8)))]*[(s/(s^2 + 4) + (8/(s^2 + 4)]
y = ilaplace(Y); % y = y(t)
pretty(y)
exp(-t) - cos(2 t)
subplot(312)
plot(t,x);
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
0 Comments
Answers (2)
Star Strider
on 4 Jun 2022
syms t s;
x = (5/7)*exp(-t) - (12/7)*exp(-8*t); % x = x(t)
h = cos(2*t) + 4*sin(2*t); % h = h(t)
% Define the Laplace of the impulse function h(t) = cos(2t) + 4sin(2t)
H = laplace(cos(2*t) + 4*sin(2*t)); % H = H(s)
% pretty(H)
H
% Define the Laplace of the input function x(t) = (5/7)e(-t) - (12/7)e(-8t)
X = laplace((5/7)*exp(-t) - (12/7)*exp(-8*t)); % X = X(s)
% pretty(X)
X
% Define Y(s) as the convolution of x(t) * h(t) = X(s) x H(s)
Y = X*H; % Y = Y(s)
% pretty(Y)
Y
% Define the Inverse Laplace of Y(s) = [(5/(7(s + 1))) - (12/(7(s + 8)))]*[(s/(s^2 + 4) + (8/(s^2 + 4)]
y = ilaplace(Y); % y = y(t)
% pretty(y)
subplot(312)
fplot(x, [0 10]);
grid
.
2 Comments
Star Strider
on 4 Jun 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
See Also
Categories
Find more on Spectral Measurements 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!