Generating and plotting functions.
Mostrar comentarios más antiguos
I just started picking up MATLAB and I've been trying to generate these signals for a while.

This is what ive attempted so far:
t=[-1:0.1:3];
y=exp(-t/3);
plot(t,y)
Help would be greatly appreciated.
2 comentarios
Ameer Hamza
el 26 de Dic. de 2020
Can you show what have you already tried? https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
mar gal
el 26 de Dic. de 2020
Respuestas (2)
Ameer Hamza
el 26 de Dic. de 2020
The exponent also contain abs() function. You can write it like this
t = -1:0.1:3;
y = exp(-abs(t)/5);
plot(t,y)
Also, the u(), the unit step function can be defined like this
u = @(x) (u>=0)*1;
So for an arbitrary range of t values, following will work
u = @(x) (x>=0)*1;
t = -5:0.1:5;
y = exp(-abs(t)/5).*(u(t+1)-u(t-3));
plot(t,y)
Image Analyst
el 26 de Dic. de 2020
You can use linspace() and then logical indexing to move the step function to the correct location. Then combine. Here's a hint:
numElements = 1000; % Arbitrary - Most of the pixels across the screen.
% Make t axis.
t = linspace(-10, 10, numElements);
% Make step function that goes from 0 to 1 at t=0.
u = ones(1, numElements);
u1 = u;
% Make shifted step function that goes from 0 to 1 at t=-1.
% Zero out u uptil t == -1
u1(t < -1) = 0;
subplot(3, 1, 1);
plot(t, u1, 'b-', 'LineWidth', 2);
grid on;
title('u(t + 1)', 'FontSize', 20);
xlabel('t', 'FontSize', 20);
% Make shifted step function that goes from 0 to 1 at t=3.
u2 = u;
% Zero out u uptil t == 3
u2(t < 3) = 0;
subplot(3, 1, 2);
plot(t, u2, 'b-', 'LineWidth', 2);
grid on;
title('u(t - 3)', 'FontSize', 20);
xlabel('t', 'FontSize', 20);
y = % See if you can do this with abs() and dot star to to element by element multiplication
% Should be something times something minus something times something.
subplot(3, 1, 3);
plot(t, y, 'b-', 'LineWidth', 2);
grid on;
title('y(t)', 'FontSize', 20);
xlabel('t', 'FontSize', 20);
% Maximize figure window.
g = gcf;
g.WindowState = 'maximized'

Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!