how to plot a continuous signal

I want to plot x(t) = cos(200*pi*t*u(t)) and define u(t) seprately and then plot x(-t),x(t/3)
i wrote this
x = @(t) cos(200*pi*t*u(t));
t = linspace(-1, 1);
figure(1)
plot(t, x(t))
grid
function y = u(x)
y=0;
if x>=0
y=1;
end
end

 采纳的回答

This should get you started:
u = @(t) t>=0;
x = @(t,u) cos(200*pi*t.*u(t));
t = linspace(-1, 1);
figure(1)
plot(t, x(t,u))
grid
Extending that:
u = @(t) t>=0;
x = @(t,u) cos(200*pi*t.*u(t));
t = linspace(-1, 1);
figure(1)
plot(t, x(t,u))
hold on
plot(t, x(-t,u))
plot(t, x(t/3,u))
hold off
grid
Experiment to get different results.

8 个评论

thanks a lot
whats about 1/x(t,u) & x(1/t,u)
I think the eror is devided by zero
how can i solve it?
My pleasure.
Add: 1E-14 (or some similar small value) to whatever is in the denominator. That will still result in a very large number, however not Inf or NaN.
Note that in those instances, you need to use element-wise division, ./. See the documentation section on Array vs. Matrix Operations for a fulll discussion.
ok
now i want to plot A*exp(j*2*pi*t)
which A is a constant variable and j is an imaginary unit
Try this:
A = 42; % Universal Answer (HHGTTG)
y = @(t) A*exp(1j*2*pi*t)
t = linspace(-1, 1);
figure
plot(t, real(y(t)),'-b', t, imag(y(t)), '--')
grid
legend('\Re', '\Im')
Experiment to get the result you want.
Thanks.
i want to stem y[n]=y[n-2]+x[n]+2x[n-1] which is recursive and y[0]=1,y[-1]=5, x[n]=(1.5.^n).*u[n]
delta = @(d) d==0;
and also stem conv(y,delta)
can you help me?
This should be posted as a new Question.
I asked in that way too.
I will delete this Comment in a few minutes, then.

请先登录,再进行评论。

更多回答(1 个)

Asif
Asif 2024-4-4

0 个投票

t=0:0.01:5; %Time from 0 to 5 seconds with a step size of 0.01 seconds
%Define the continous signal ( for example, a sinusoidal signal)
% Frequency=2; %Frequency of the sinusoid in HZ
Amplitude=1; % Amplitude of the sinusoid
Phase = pi/4; %phase of the sinusoid ( in radians)
signal = Amplitude*sin(2*pi*Frequency*t+Phase);
% plot the continuous signal
plot(t, signal,'b','Linewidth',6);
xlabel('xTime(s)X');
ylabel('Ampltitude');
title('Continuous Sinusoidal signal');
grid on

类别

帮助中心File Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by