# FFT of any sinusoidal signal — how many point fft to take?

suppose I have to measure the DFT of an 60 hz sinusoidal signal and calculate upto 20 harmonics of this. Value of the 20th harmonic will be 20*60 = 1200 HZ. Then my sampling frequency should be >= 20*60*2 >= 2400 hz

1. Now how many point FFT i have to calculate to estimate information about harmonics ?

2. Is number of points in FFT(N) equal to the sampling frequency ?

3. How number of points in FFT(N) related to the sampling frequency ?

4. Is there any advantage with output off FFT if we sample at higher rate ?

Is bellow three estimates are correct ?

1> If suppose my sampling frequency is fs = 20*60*2 = 2400 then, What i know is that the frequency range [0,fs] is represented by 2400 point. I.e each point represent 2400hz/2400 = 1 HZ information. Then output of FFT will be, really only need to look at the first N/2+1 samples

   X is the constant term
X is 1 hz
X is 2 hz
X is the 1200 HZ


2> If suppose my sampling frequency is fs = 20*60*2 = 2400 then, What i know is that the frequency range [0,fs] is represented by 2400 point. can i take 4800 sample points ? I.e each point represent 2400hz/4800 = 0.5 HZ information. Then output of FFT will be, really only need to look at the first N/2+1 samples

   X is the constant term
X is 0.5 hz
X is 1 hz
X is the 1199.5 HZ
X is the 1200 HZ


Is there any advantage here to take more number of samples to calculate the FFT ? One thing i note is that spectrum is more dense with each point having 0.5 HZ of information, will my calculation of FFT will be more accurate in this case ?

3> If suppose my sampling frequency is fs = 20*60*4 = 4800 = then, What i know is that the frequency range [0,fs] is represented by 4800 point. I.e each point represent 4800hz/2400 = 1 HZ information. Then output of FFT will be, really only need to look at the first N/2+1 samples

X is the constant term
X is 1 hz
X is 2 hz
X is the 2400 HZ


Now in this case FFT is generating information upto 2400 hz but i need upto 1200 hz. Is there any advantage with output off FFT if we sample at higher rate ?

Required Sampling Frequency:

If the signal is real, then yes the sampling frequency must be greater than twice the highest frequency for a signal bandwidth that extends down to DC. However if the signal is complex then the sampling frequency should be greater than the highest frequency for same case. This is because a complex signal has a unique spectrum over the Nyquist frequency range of $\pm f_s/2$ where $f_s$ is the sampling rate, while for a real signal the negative frequencies are the complex conjugate of the positive frequencies (identical magnitude, opposite phase).

Note that prior to sampling an analog anti-alias filter is required on the signal, otherwise energy if present in higher Nyquist zones (frequencies above the Nyquist frequency range defined above) will alias into the Nyquist frequency range being observed. (see this post which explains how aliasing occurs: Aliasing after downsampling). It is not feasible to implement a brick-wall filter, so additional margin to the sampling rate is usually added to allow for the characteristics of the anti-alias filter. For this you need to understand the properties of the signal signal of interest prior to sampling (as once sampled there is no way to distinguish an alias from a signal in the first Nyquist zone!). For example in your case, where you are interested in observing the signal out to 20 Harmonics of 60 Hz: The anti-alias filter should pass the 20th harmonics without distortion and then reject the higher harmonics so that you can minimize the sampling rate needed. You would then choose the sampling rate depending on your filter implementation such that no energy folds in to distort the 20th harmonic.

How Many Point FFT is Needed:

This has been answered several times, so see the links given below for further details and caveats, but the main point is that the frequency resolution of each "point" is 1/T Hz where T is the length of your signal in seconds. Further the bins in the DFT (the FFT is just an algorithm that computes the DFT) as typically returned extend from DC to one bin less that $f_s$. Due to aliasing the DC is equivalent to $n f_s$ where n is any integer, and likewise for all other frequencies in the DFT, so the DFT that extends frmo DC to $f_s$ equivalently extends from DC to one bin less than $f_s/2$ and then from $-f_s/2$ to one bin less than $f_s$ (see fftshift in Matlab). As detailed in the links given, due to the relationship of the sampling rate and the total length in time T of your signal, each bin will have a frequency resolution of $1/f_s$ when no windowing is used.

Note importantly that each bin of the DFT is the result of a Sinc filter, so if your sampling rate is not an integer multiple of 60 Hz, you will also have the effect of "scalloping loss" that will distort the measurement of each harmonic. (see the "Bank of Filters" explanation at this link: Intuition for sidelobes in FFT). By choosing a sampling rate that is an integer multiple of 60 Hz, each 60 Hz harmonic will be properly centered in each bin.

With relationship to choosing the sampling rate and number of bins for your specific application, if the 60 Hz and its harmonics are the dominant signal and you don't have other signal energy of significance then there is a simple solution that will work quite elegantly in accurately estimating each harmonic with minimum measurement distortion. As described above, choose a sampling rate that is an integer multiple of 60 Hz, high enough to allow for the anti-alias filter used, and then choose the number of points such that each bin passes a harmonic of 60 Hz and rejects all the other harmonics. This means the number of samples in the FFT is $f_s/60$ where $f_s$ is an integer multiple of 60 Hz > 2400 Hz (assuming your signal is real). For example 4800 Hz may be a good choice as you suggest in your options (allowing for a fairly relaxed anti-alias filter!), and in this case $N =4800/60= 80$ points. So in this case $f_s=4800 Hz$ and with 80 points each point is 60 Hz, so 0, 60, 120, 180 etc centered on each harmonic and perfectly nulling the other Harmonics. The actual magnitude measured for each point is the total area under the Sinc function frequency response for each bin, so if there is other energy present at non-harmonic frequencies, this would distort the magnitude measured in each bin. But if the harmonics are dominant, this would be an excellent and simple approach. This is somewhat similar to the objective in this link in removing harmonic signals (Different way to separate a particular frequency from a signal) as each bin in the DFT is a rotated moving average filter just as done in this referenced link when only one bin is of interest. Note from that link how every other harmonic is nulled!

Please see these other responses which will further help give insight:

Specific frequency resolution

FFT frequency resolution

Number of FFT points required for a specific frequency resolution for an oversampled signal

FFT and number of samples relations

What happens when N increases in N-point DFT

• but why do you need 1 Hz resolution? If there is other signals you are trying to see or isolate besides the harmonics this would make sense, but if the harmonics are quite strong relative to the background noise you can get away with 80 samples as I described. – Dan Boschen May 30 '17 at 12:41
• Yes if you want to see other signals besides the harmonics in frequency then increasing the number of samples is a good approach. You should look into windowing as well and get a better understanding of that as you will want to trade both resolution which was discussed here and dynamic range. Also no do not zero unwanted frequencies as a method of filtering (worst way to filter). Both of these are addressed in other posts; I will try to find them to point you there. – Dan Boschen May 30 '17 at 16:39
• See this post regarding why you should not zero the FFT to remove unwanted signals: dsp.stackexchange.com/questions/6220/… – Dan Boschen May 30 '17 at 16:39
• See this post showing the benefit of windowing your time domain signal prior to taking the FFT: dsp.stackexchange.com/questions/208/… – Dan Boschen May 30 '17 at 16:44
• Yes what you are describing specifically is the windowing approach to filter design which I generally find inferior to algorithms like least squares and the Parks-McClellan equiripple design (see dsp.stackexchange.com/questions/37704/…). Your question was not about filter design however, just how many points in the FFT-- so my answer was specific to observation of spectrum using the FFT. In this case you window the data in time and then take the FFT. – Dan Boschen May 31 '17 at 0:13

Let me first explain something about FFT and then you can find values of parameters that you need. Your signal's spectrum is periodic (because you have a discrete signal) so we only consider the distribution over one period. If these period were normalized to [0 2*pi] range, 2*pi is regarded as your sampling frequency and pi is the maximum possible frequency in spectrum regarding that sampling rate. Your sampling rate must be at least double of your signal's maximum frequency to avoid aliasing.

When you calculate N point FFT you are sampling the signal spectrum over one period with N samples. So N determine the frequency resolution of your obtained spectrum.

• thanks for reply ..If suppose my sampling frequency is fs = 20*60*2 = 2400 then, What i know is that the frequency range [0,fs] is represented by 2400 point. can i take 4800 sample points FFT ? – user6363 May 30 '17 at 11:04
• Yes, your input signal must have 4800 number of samples, if your number of samples is smaller then you could zero pad your signal to obtain that number of samples. – Mohammad M May 30 '17 at 11:10
• you said .."Yes, your input signal must have 4800 number of samples," then what should be my sampling frequency ? – user6363 May 30 '17 at 11:11
• Sampling frequency is determined by maximum frequency of your continuous signal. it's not related to number of point used for FFT. – Mohammad M May 30 '17 at 11:13
• your acquisition duration must be long enough to produce the required number of samples. – Mohammad M May 30 '17 at 11:14

Suppose 20th harmonic is 20*60 = 1200hz

1> If fs = 20*60*2 = 2400hz
now Taking N=2400 or 4800 points won't change the frequency range you're looking at as long as you have the same fs...
If N = 4800, then output of FFT will also be N = 4800
and output of the fft will be represent maximum spectral information upto fs/2 ..
and each index of FFT will represent frequency increment of (fs/2)/(N/2) = 1200/2400 = 0.5
& Spectrum information which can be get from this FFT is upto fs/2 = 2400/2 = 1200

   X is the constant term
X is 0.5 hz
X is 1 hz
X is the 1199.5 HZ
X is the 1200 HZ


2> If fs = 20*60*4 = 4800hz
now Taking N=4800 or 9600 points won't change the frequency range you're looking at as long as you have the same fs...

If N = 9600, then output of FFT will also be N = 9600
and output of the fft will be represent maximum spectral information upto fs/2 ..
and each index of FFT will represent frequency increment of (fs/2)/(N/2) = 2400/4800 = 0.5
& Spectrum information which can be get from this FFT is upto fs/2 = 4800/2 = 2400 hz

   X is the constant term
X is 0.5 hz
X is 1 hz
X is the 2399.5 HZ
X is the 2400 HZ


If N = 4800 , then output of FFT will also be N = 4800
and output of the fft will be represent maximum spectral information upto fs/2 ..
and each index of FFT will represent frequency increment of (fs/2)/(N/2) = 4800/4800 = 1
& Spectrum information which can be get from this FFT is upto fs/2 = 4800/2 = 2400 hz

   X is the constant term
X is 1 hz
X is 2 hz
X is the 2400 HZ