![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1424083/image.png)
Plotting a sine wave going wrong
2 ビュー (過去 30 日間)
古いコメントを表示
So I am trying to plot a simple sine wave, and I used the code recommended here.
% Constants
fs = 8000; % Sample rate (Hz)
duration = 1; % Duration of the signal (seconds)
frequency = 3000; % Frequency of the sine wave (Hz)
% Time vector
t = 0:1/fs:duration-1/fs;
% Generate the sine wave
x = sin(2*pi*frequency*t);
% Plot the sine wave
plot(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sine Wave');
But it is a very weird plot. Why is that happening?
Here's the full plot for reference:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1424073/image.png)
0 件のコメント
回答 (2 件)
Ishit
2023 年 7 月 1 日
編集済み: Ishit
2023 年 7 月 1 日
Hi Bhargava,
This is beacuse of high frequency.
Increasing the frequency of a sine plot leads to a higher number of oscillations. And thus these lines seems to overlap.
In figure below you can observe as term inside of sin increases, the period decreases.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1424083/image.png)
Credits: https://www.quora.com
0 件のコメント
Image Analyst
2023 年 7 月 1 日
You're plotting so many cycles that the blue curves all overlap and make the plot solid. Either plot fewer points, or use the zoom tool to zoom way in.
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!