I'm using the following code the plot a sine wave in Matlab,
Fs = 12000; % sampling frequency in Hz
dt = 1/Fs; % seconds per sample
StopTime = 0.25; % seconds
t = (0:dt:StopTime-dt)'; % seconds
Fc = 5000; % hertz
x = sin(2*pi*Fc*t);
figure; % Plot the signal versus time:
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
The code tends to work in general but when I try to plot a 5kHz sine wave, I get the following results:
I know that you need the sampling frequency to be at least 2 times the maximum frequency you want to plot (Nyquist theorem). So why is this happening?