# Relationship between Fs (the Nyquist frequency), and the frequency used with a sine wave

Say you are given a vector t =[...] for the time to be used to generate a sine wave of a certain frequency say FHz. I have all the data for t so I can conclude what dt is (my dt = 1d-5). Now I am to do an FFT analysis and plot magnitude vs frequency so I expect to get my original amplitude and also get back the original phase This what I do:

frequency = ...; %This in Hz

dt = t(2) - t(1); %which is equal to 1d-5

fs = 2*frequency; % should this be 1/dt? or something else?

Nfft = fs;

intensity = sin(2*pi*frequency*t);

FFT_intensity =fft(intensity,Nfft)/Nfft;

magIntensity = abs(FFT_intensity);

f=linspace(-fs/2, fs/2, Nfft);

plot(f,fftshift(magIntensity))


The results I get are sometimes correct and sometimes incorrect, it seems like when I chop the length of the t vector or change fs (say fs = 1/dt instead) I get the wrong amplitude ( and wrong phase, not shown here)... In general how to relate FHz, Fs and t? I can actually include the numbers I am using if that makes any difference. Thank you for any input.

• You might be having problems with boundary conditions. Oct 2, 2014 at 16:46
• I am not sure what you mean, I don't have boundary conditions, unless I am misunderstanding you. Oct 2, 2014 at 16:47
• This is a variant of one of the most frequently asked questions on this site. Please search this site and see e.g. this question and its answers. Oct 2, 2014 at 17:10

The sampling frequency fs is 1/dt. Conceptually, if the time between samples is $T$, then you have $1/T$ samples per second, which is the sampling frequency.

Next, you need to make sure that frequency, the sine wave's frequency, is less than the Nyquist frequency, which is fs/2.

For interpreting the spectrum (FFT_intensity), please see the answer pointed to by Matt L.

The un-interpolated FFT result peak bin amplitude will only be correct for frequencies that are exactly integer periodic for the length of your FFT. Other frequencies will show rectangular windowing artifacts (so called "leakage") which will scallop the peak bin amplitude. There do exist interpolation methods to correct for the amplitude of these between-FFT-bin-center frequencies.

The phase for these (not exactly integer periodic within the FFT aperture length or between-FFT-bin-center) frequencies will be the phase at the center of the FFT aperture (not at the start), and with the phase referenced to this center point flipped 180 degrees for all odd numbered FFT result bins.