Plotting sine wave using rad/samp

조회 수: 4 (최근 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 CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by