フィルターのクリア

How can the individual samples be visable in the plot

2 ビュー (過去 30 日間)
Yian Chen
Yian Chen 2021 年 9 月 26 日
編集済み: Image Analyst 2021 年 9 月 26 日
Like sin(2*pi*100*t) and t is between 0-0.5S, how could there be 25 samples?

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 26 日
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 件のコメント
Yian Chen
Yian Chen 2021 年 9 月 26 日
Hi, thanks for your answer, and s do mean second, if I want my samples defined from 0 to 0.5s but does not include 0.5s, how can I make it?
Image Analyst
Image Analyst 2021 年 9 月 26 日
編集済み: Image Analyst 2021 年 9 月 26 日
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]);

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 26 日
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)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by