How can the individual samples be visable in the plot
1 view (last 30 days)
Show older comments
Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?
0 Comments
Accepted Answer
Image Analyst
on 26 Sep 2021
OK, I have a second answer. Maybe your "S" is not a value when you say 0.5S. Maybe "S" really means " seconds". In that case, try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
fprintf('Beginning to run %s.m ...\n', mfilename)
% Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?
numSamples = 25;
t = linspace(0, 0.5, numSamples);
y = sin(2 * pi * 100 * t);
plot(t, y, 'b.-', 'LineWidth', 3, 'MarkerSize', 40);
grid on;
title('y = sin(2 * pi * 100 * t)', 'FontSize', 18);
xlabel('time in seconds', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m.\n', mfilename)
2 Comments
Image Analyst
on 26 Sep 2021
Edited: Image Analyst
on 26 Sep 2021
Just change to
t = linspace(0, 0.49999999999, numSamples);
or you can set the range of x in the plot with xlim(), like to see from 0 to 0.4, use
xlim([0, 0.4]);
More Answers (1)
Image Analyst
on 26 Sep 2021
Here, try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
fprintf('Beginning to run %s.m ...\n', mfilename)
% Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?
S = 100; % Whatever S is (we don't know because you didn't specify)
numSamples = 25;
t = linspace(0, 0.5 * S, numSamples);
y = sin(2 * pi * 100 * t);
subplot(2, 1, 1)
plot(t, y, 'b.-', 'LineWidth', 3, 'MarkerSize', 30);
grid on;
title('y = sin(2 * pi * 100 * t) with 25 samples (it is badly aliased)', 'FontSize', 18);
xlabel('t', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
% We have bad aliasing. Let's see what it looks like without aliasing.
numSamples = 2000;
t2000 = linspace(0, 0.5 * S, numSamples);
y2000 = sin(2 * pi * 100 * t2000);
subplot(2, 1, 2)
plot(t2000, y2000, 'r.-', 'LineWidth', 1);
grid on;
title('y = sin(2 * pi * 100 * t) with 2000 samples', 'FontSize', 18);
xlabel('t', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m.\n', mfilename)
0 Comments
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!