Plotting Discrete Time Functions

213 次查看(过去 30 天)
I need to plot 5 cos(π n /6 - π/2) as a discrete tim signal. But I am not getting the proper result.
n = [-5:0.001:5];
y = 5*cos(pi*(n/2)-(pi/2));
stem(n,y);
What am I missing from this code to get the discrete time signals?

回答(2 个)

Austin Holmes
Austin Holmes 2021-11-11
The original poster asked for the discrete time signal not the continuous time signal. A discrete time signal just means sampling your continuous signal at discrete time intervals.
The simplest way this can be done is by increasing your step in n.
n = [-5:0.25:5];
y = 5*cos(pi*(n/2)-(pi/2));
stem(n,y);
The proper way to do this would be determining a sampling rate and implementing it in your code.

Freedom TSOKPO
Freedom TSOKPO 2020-9-23
I've just began with Matlab and I don't even know the function stem.
But I think this code can do it
clear all; clc;
n = -5:0.001:5;
y = 5*cos((n-1)*pi/2); %5*cos(pi*(n/2)-(pi/2));
figure
% axis([-6 6 -4 4]);
plot(n,y);

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by