Plotting sine wave using rad/samp
4 次查看(过去 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);
0 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!