Plotting Discrete Time Functions

583 views (last 30 days)
Bradley Johnson
Bradley Johnson on 22 Sep 2020
Answered: Austin Holmes on 11 Nov 2021
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?

Answers (2)

Austin Holmes
Austin Holmes on 11 Nov 2021
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 on 23 Sep 2020
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);

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!