Plotting sine wave using rad/samp

3 ビュー (過去 30 日間)
Vinci
Vinci 2018 年 8 月 30 日
コメント済み: Sven 2018 年 8 月 30 日
If I need to plot a sine wave sampled at 8kHz for 4 seconds with a frequency of pi/10 rad/samples, would this be the right way to go about it?
Fs = 8000; % Sampling frequency
stopTime = 4; % Run time (seconds)
dr = pi/10; % Radians per sample
stopSample = Fs * stopTime; % Total samples
totalRad = (Fs * stopTime * dr); % Total radians for run time
r = 0:dr:totalRad; % Rad step for run time
% Generate sine wave
x = sin(r*dr);

採用された回答

Sven
Sven 2018 年 8 月 30 日
Almost correct. You need to change your r vector to get the correct time vector, because you only want to plot the sine wave for 4 seconds.
r = linspace(0,stopTime,stopSample);
linspace creates a vector with evenly spaced points between 0 and stopTime. stopSample is the number of points. The plotted data is now not even a fourth of a full sine wave which makes sense, because your frequency is 0.05 Hz ( pi/10/(2*pi) ) which makes a full sine wave take 20 seconds.
  2 件のコメント
Vinci
Vinci 2018 年 8 月 30 日
How does the sample rate of 8000 effect the frequency? I thought it would be: 8000*(pi/10)/(2*pi) = 400Hz
Sven
Sven 2018 年 8 月 30 日
The sample rate does not affect the frequency itself. A sample rate of 8000 Hz just says, that you get 8000 data points per second or 1 data point every 125us.
If you are sampling a frequency of 1 Hz, a full periode takes 1 second, so you have 8000 data points per cycle, which lets you see a perfectly round sine wave if plotted. If the frequency for example is 4000 Hz, a periode takes only 250us and you only get 2 data points per cycle.
There is also something called the nyquist frequency which is half the sampling frequency, in your case 4000 Hz. This is the maximum frequency you can detect when doing an FFT of your sampled data, because you need at least 2 data points per cycle for that.
I hope that helps you to understand.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWaveform Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by