Why is plot using range of values with increments not proper?

I am a begginer using matlab for college lab. I am trying to experiment with the range with increment operation and I notice some weird output.
When I use greater increment values the output starts becoming wrong but when i use smaller increment values the output become correct. I have attached the code below and their respective outputs for reference
F = 2000;
t = 0.99:0.001:1;
x = sin(2*pi*F*t);
plot(t,x);
In the above code, in the y axis output the values go above the normal sine range [-1,1]
F = 2000;
t = 0.999:0.00001:1;
x = sin(2*pi*F*t);
plot(t,x);
While for this code the output works percectly.
Could anyone please give an insight in this?
Thank you

 採用された回答

DGM
DGM 2022 年 1 月 4 日
編集済み: DGM 2022 年 1 月 4 日

0 投票

"In the above code, in the y axis output the values go above the normal sine range [-1,1] "
No they don't. Look at the labels again. All of those values are close to zero. It's just a matter of aliasing. There are only 11 samples.
F = 2000;
t = 0.99:0.001:1;
x = sin(2*pi*F*t);
plot(t,x,'*'); hold on;
% plot the exact same thing with more points
t = linspace(0.99,1,1000);
x = sin(2*pi*F*t);
plot(t,x);

1 件のコメント

Laxman Chinnannavar
Laxman Chinnannavar 2022 年 1 月 4 日
Oh, Thanks @DGM, didnt see the 10^(-12) at the side.

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by