Use of syms, piecewise & conv commands
Afficher commentaires plus anciens
I'm trying to define the values of x(t) at various values of t to plot the input h(t) and x(t) vs the output y(t) after performing convolution. I am getting the a error when trying to run my code and am hoping one of the experts on here may be able to assist. I'm still quite new to MATLAB, I've looked at the associated help documetation, however the error code points me to the inbuilt conv() function which is way over my head. My code is below, along with the error message I am receiving.
Thanks in advance for any help.
Code
t = [0:1:10] % define range of t values
h = (exp(-(t-2)).*heaviside(t-2)); % define function h(t)
%x = t .* (t >= 0) .* (t <= 1); % define function x(t) (commented out to attempt piecewise command)
syms x(t)
x(t) = piecewise((0 <= t) & (t <= 1), t, 0)
y = conv(h, x); % carry out convolution
figure;
plot(t, h, 'r', 'LineWidth', 1, 'DisplayName', 'h(t) = e^{-(t-2)} * u(t-2)'); % plotting h(t)
hold on; % holf to allow multiple plots on one axes
plot(t, x, 'b', 'LineWidth', 1, 'DisplayName', 'x(t) = t (0 <= t <= 1)'); % plotting x(t)
plot(t, y, 'g', 'LineWidth', 1, 'DisplayName', 'y(t) = x(t) * h(t)'); % plotting y(t)
xlabel('t'); % add x-label
ylabel('Amplitude'); % add y-label
title('Plot of h(t), x(t), and y(t)'); % add title
legend('Location', 'northeast'); % define legend location
grid on; % add grid
hold off; % hold off to allow plotting of figure
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Modulation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



