Trouble trying to plot the output of an input signal with an impulse response

3 ビュー (過去 30 日間)
Anthony Walden
Anthony Walden 2022 年 6 月 4 日
回答済み: tedros 2024 年 4 月 16 日
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.

回答 (2 件)

Star Strider
Star Strider 2022 年 6 月 4 日
Use the fplot function —
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
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
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
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 件のコメント
Anthony Walden
Anthony Walden 2022 年 6 月 4 日
Thank you for the assist, that helped tremendously!
Star Strider
Star Strider 2022 年 6 月 4 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

サインインしてコメントする。


tedros
tedros 2024 年 4 月 16 日
how to find the out put y(t) of a state matric

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by