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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by