![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/796884/image.png)
Plotting Discrete Time Functions
381 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (3)
Austin Holmes
am 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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/796884/image.png)
The proper way to do this would be determining a sampling rate and implementing it in your code.
0 Kommentare
Freedom TSOKPO
am 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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/364645/image.png)
0 Kommentare
Satyam
am 5 Aug. 2024 um 9:15
t = -1:0.01:1;
impulse_continuous = @(t) t == 0;
unit_step_continuous = @(t) t >= 0;
unit_ramp_continuous = @(t) t .* (t >= 0);
exponential_continuous = @(t) exp(t);
sine_continuous = @(t) sin(2*pi*t);
cosine_continuous = @(t) cos(2*pi*t);
n = -10:10;
impulse_discrete = @(n) n == 0;
unit_step_discrete = @(n) n >= 0;
unit_ramp_discrete = @(n) n .* (n >= 0);
exponential_discrete = @(n) exp(n/10);
sine_discrete = @(n) sin(2*pi*n/10);
% Discrete Cosine Function
cosine_discrete = @(n) cos(2*pi*n/10);
% Plot Continuous Functions
figure;
subplot(3,2,1);
plot(t, impulse_continuous(t), 'LineWidth', 2);
title('Continuous Impulse Function');
xlabel('Time (t)');
ylabel('\delta(t)');
axis([-1 1 -0.5 1.5]);
grid on;
subplot(3,2,2);
plot(t, unit_step_continuous(t), 'LineWidth', 2);
title('Continuous Unit Step Function');
xlabel('Time (t)');
ylabel('u(t)');
axis([-1 1 -0.5 1.5]);
grid on;
subplot(3,2,3);
plot(t, unit_ramp_continuous(t), 'LineWidth', 2);
title('Continuous Unit Ramp Function');
xlabel('Time (t)');
ylabel('r(t)');
axis([-1 1 -0.5 1.5]);
grid on;
subplot(3,2,4);
plot(t, exponential_continuous(t), 'LineWidth', 2);
title('Continuous Exponential Function');
xlabel('Time (t)');
ylabel('e^t');
axis([-1 1 -0.5 3]);
grid on;
subplot(3,2,5);
plot(t, sine_continuous(t), 'LineWidth', 2);
title('Continuous Sine Function');
xlabel('Time (t)');
ylabel('sin(2\pi t)');
axis([-1 1 -1.5 1.5]);
grid on;
subplot(3,2,6);
plot(t, cosine_continuous(t), 'LineWidth', 2);
title('Continuous Cosine Function');
xlabel('Time (t)');
ylabel('cos(2\pi t)');
axis([-1 1 -1.5 1.5]);
grid on;
% Plot Discrete Functions
figure;
subplot(3,2,1);
stem(n, impulse_discrete(n), 'filled');
title('Discrete Impulse Function');
xlabel('n');
ylabel('\delta[n]');
axis([-10 10 -0.5 1.5]);
grid on;
subplot(3,2,2);
stem(n, unit_step_discrete(n), 'filled');
title('Discrete Unit Step Function');
xlabel('n');
ylabel('u[n]');
axis([-10 10 -0.5 1.5]);
grid on;
subplot(3,2,3);
stem(n, unit_ramp_discrete(n), 'filled');
title('Discrete Unit Ramp Function');
xlabel('n');
ylabel('r[n]');
axis([-10 10 -5 15]);
grid on;
subplot(3,2,4);
stem(n, exponential_discrete(n), 'filled');
title('Discrete Exponential Function');
xlabel('n');
ylabel('e^{n/10}');
axis([-10 10 -0.5 3]);
grid on;
subplot(3,2,5);
stem(n, sine_discrete(n), 'filled');
title('Discrete Sine Function');
xlabel('n');
ylabel('sin(2\pi n/10)');
axis([-10 10 -1.5 1.5]);
grid on;
subplot(3,2,6);
stem(n, cosine_discrete(n), 'filled');
title('Discrete Cosine Function');
xlabel('n');
ylabel('cos(2\pi n/10)');
axis([-10 10 -1.5 1.5]);
grid on;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!