# Plotting sinewave looks weird.

7 views (last 30 days)
Dexter James Barit on 17 Oct 2020
Commented: Image Analyst on 18 Oct 2020
I'm trying to plot a sinewave with a length of 1000 samples, with a sample rate of 40kHz and center frequency at 19kHz. For some reason when I plot the sinewave it looks weird. Am I plotting this correctly?
fs=40000;
freq=19000;
w=freq/fs;
n=0:999;
x1 = sin(2*pi*w*n);
plot(x1) Image Analyst on 18 Oct 2020
This is what I get
% Plot a sinewave with a length of 1000 samples, with a sample rate of 40kHz and center frequency at 19kHz.
dt = 1/40000 % Samples are separated by 1/40000 of a second.
% 19 kHz means the period is 1/19000 of a second.
period = 1/19000
% Use 1000 samples
t = dt * (1 : 1000);
y = sin(2 * pi * t / period);
plot(t, y, 'b-');
grid on;
xlabel('time', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize); ##### 2 CommentsShowHide 1 older comment
Image Analyst on 18 Oct 2020
Dexter, look at what my code shows:
dt =
2.5e-05
period =
5.26315789473684e-05
So you're taking just barely over 2 samples per period You're sampling every 25 microseconds but the period is 52.6 microseconds -- that's not enough samples to give you enough points to follow one up/down period nice and smoothly. That also means those two sample points will be at slightly different points in each period. The sample points at each period shift slightly as they move along. So the amplitude will vary because you're plucking out the values at different points along the sine wave. This is called aliasing and is why you see a lower beat frequency instead of the main frequency. You're undersampling it. In your class did the instructor mention anything about aliasing or the Nyquist Frequency? Or beat frequency? If not, study up on that.