Generating and plotting functions.

6 次查看(过去 30 天)
mar gal
mar gal 2020-12-26
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 个)

Ameer Hamza
Ameer Hamza 2020-12-26
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
Image Analyst 2020-12-26
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'

Community Treasure Hunt

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

Start Hunting!

Translated by