1

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[0] is the constant term
   X[1] is 1 hz
   X[2] is 2 hz
   X[1201] 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[0] is the constant term
   X[1] is 0.5 hz
   X[2] is 1 hz
   X[2400] is the 1199.5 HZ
   X[2401] 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[0] is the constant term
   X[1] is 1 hz
   X[2] is 2 hz
   X[2401] 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 ?

Please suggest on this.

user6363
  • 333
  • 2
  • 4
  • 11

3 Answers3

4

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.

Suggestion for your specific application:

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 DFT (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

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
  • do you also agree with my answer ? – user6363 May 30 '17 at 12:36
  • for 1) yes if the signal is real. for 2) yes you will increase your freq resolution by taking more points (note that independent of any sampling rate, the frequency resolution is always 1/T where T is the length of your buffer in time---if you use windowing this will increase the frequency resolution further (degrade it). for 3) yes agreed for same reason. – Dan Boschen May 30 '17 at 12:39
  • 1
    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
  • If I took 1hz resolution then I can see other signal besides harmonic.. which method you recommend to remove/isolate unwanted signals ? Should I zero unwanted frequency in FFT & ten take the IFFT ? – user6363 May 30 '17 at 13:48
  • 1
    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
  • 1
    See this post regarding why you should not zero the FFT to remove unwanted signals: https://dsp.stackexchange.com/questions/6220/why-is-it-a-bad-idea-to-filter-by-zeroing-out-fft-bins – Dan Boschen May 30 '17 at 16:39
  • 1
    See this post showing the benefit of windowing your time domain signal prior to taking the FFT: https://dsp.stackexchange.com/questions/208/what-should-be-considered-when-selecting-a-windowing-function-when-smoothing-a-t/214#214 – Dan Boschen May 30 '17 at 16:44
  • You are saying "benifit if windowing your time domain signal before taking FFT" you mean to say if I have to do 2400 samples then first apply hamming window to this 2400 samples then apply FFT to it ? – user6363 May 30 '17 at 17:02
  • But what I have read is that in digital filter design first we use to set the frequency response of digital filter then do Discrete inverse Fourier transfer of this.. now you will have time domain response of filter then to remove Gibbs effect you apply hamming window to this time domain response of digital filter... As an result of this you will get further fine tuned impulse response of the filter... But in your reply you are telling to first apply hamming window to 2400 samples & then do FFT.. which process is correct ? Please suggest. – user6363 May 30 '17 at 17:09
  • @user6363 You window before taking the FFT. We may be getting into topics and if so you should probably add another question. From this question if appeared that you were taking the FFT for purpose of observation. If you are doing it as a filtering approach then I would recommend an FIR filter design, and if to null or select certain harmonics I gave you a link in the answer to a simple moving average filter that would work well for that. – Dan Boschen May 31 '17 at 00:06
  • 1
    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 https://dsp.stackexchange.com/questions/37704/fir-filter-design-window-vs-parks-mcclellan-and-least-squares). 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 00:13
  • 1
    If your question was indeed about filtering then this was a good example of "the XY problem" that @Marcus Mueller recently pointed us to: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem: We may have wasted a lot of time talking about the FFT when what you really want to know is how to filter the signal? – Dan Boschen May 31 '17 at 00:15
  • @user6363 had me confused with the filter reference! I take it you were recollecting the use of windowing with filter design which led you to that. In this case for observing spectrum it will minimize spectral leakage at the expense of frequency resolution and minor loss in SNR. The link I gave you in the comment above should help make clearer why you may want to window before taking the fft. Good luck! – Dan Boschen May 31 '17 at 01:12
  • the link what you mentioned in comment " benefit of windowing your tim domain signal prior to taking the FFT" it states "You can of course smooth a time series by filtering it with a window function because a window function has a low-pass characteristic" .. What exactly smoothing means here ? Does it mean that for frequency of interest we will try to keep maximum power and avoid spectral leak to other frequencies ? Also size of the hamming window should be same as size of the time domain samples ? i.e If number of samples N = 2400 then hamming window should also be 2400 ? Please suggest – user6363 May 31 '17 at 11:17
  • 1
    That detail had to do with filtering which we agreed is off-topic---If you have questions with filtering I recommend starting another question (assuming not already answered) and avoid a long discussion here. Are you satisfied with your question related to spectrum observation using the DFT? – Dan Boschen May 31 '17 at 22:06
  • Yes I am satisfied with your answer for spectrum observation.. but as you told "You window before taking the FFT" so I asked this question in terms of spectrum observation only.. that how it will be helpful for spectrum observation ? – user6363 Jun 01 '17 at 00:52
  • 1
    Windowing increases the dynamic range at the expense of frequency resolution. I know the comments are getting buried in the noise, so read back up to my comment where I said "See this post showing the benefit of windowing your time domain signal prior to taking the FFT..." I think if you read that post it should make this comment I just made about dynamic range a lot clearer for you. – Dan Boschen Jun 01 '17 at 02:13
  • 1
    I see that the link I gave is a rather poor choice as it goes back to "What should be considered when selecting a windowing function when smoothing a time series?" which is confusing you. Let me find a better one.... – Dan Boschen Jun 01 '17 at 02:15
  • 1
    Take a look at this one: https://dsp.stackexchange.com/questions/40598/why-would-one-use-a-hann-or-bartlett-window which shows the different sidelobe levels based on different windows used. With low sidelobes, two signals relatively close can be at much greater difference in power levels and you would still see the smaller signal. With high sidelobes, the sidelobes from the stronger signal would bury the weaker signal (so with low sidelobes you have higher dynamic range). By windowing you can decrease the sidelobes, but it will increase the main lobe width so reduces the frequency precision. – Dan Boschen Jun 01 '17 at 02:20
  • 1
    This answer may help you as well: https://dsp.stackexchange.com/questions/32013/intuition-for-sidelobes-in-fft/32086#32086 it is specific to a rectangular window (which means don't multiply by any additional window, but explains well how spectral leakage occurs. Windowing will reduce spectral leakage due to lower sidelobes, which will be clearer hopefully after reading this new post I just referenced. – Dan Boschen Jun 01 '17 at 03:56
  • please can you suggest on this query from me https://dsp.stackexchange.com/q/41389/28698 – user6363 Jun 01 '17 at 17:50
2

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.

Mohammad M
  • 1,327
  • 7
  • 13
  • thanks for reply ..If suppose my sampling frequency is fs = 20602 = 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
  • so my calculation in point-2 & point-3 .. which one is correct ? – user6363 May 30 '17 at 11:24
  • point 2 is correct. in noisy cases you have to use more samples to reduce the noise and there is a trade-off between between frequency resolution and error(noise). – Mohammad M May 30 '17 at 11:32
  • in point 2 to do 4800 point fft dont you think that i have to do sampling at rate od 20604 = 4800 hz ? because you said "N point FFT you are sampling the signal spectrum over one period with N samples". please suggest – user6363 May 30 '17 at 11:51
  • No, only your input to FFT must have 4800 samples, either by zero-padding or from the original signal. – Mohammad M May 30 '17 at 11:55
  • Why must there be 4800 samples? Zero padding does not do anything to increase the frequency resolution. (if the harmonics are the only signals present, 80 samples would be enough at a 4800 Hz sampling rate, where each bin would be centered on a 60 Hz harmonic!) – Dan Boschen May 30 '17 at 12:01
  • ok thanks .. if suppose i have to sample frequency 4 times ...at 20604 = 4800 hz ...then do FFT .. then what frequency will be output at each index ? – user6363 May 30 '17 at 12:02
  • do you also agree with my answer ? – user6363 May 30 '17 at 12:36
  • @MohammadMohammadi Welcome to DSP.SE! I didn't realize you had answered the question by the time I completed mine! – Dan Boschen May 30 '17 at 12:44
  • let me explain it with an example. If you have a picture which sampled every 1mm, the nominal resolution is 1mm. But if you blur that picture and sample it each 1mm, again your nominal resolution is 1mm but your effective resolution is degraded. – Mohammad M May 30 '17 at 13:44
  • Zero padding a signal will increase the nominal frequency resolution of fft but effective resolution will not increase. To increase effective frequency resolution you have to increase your acquisition time. – Mohammad M May 30 '17 at 13:48
-1

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[0] is the constant term
   X[1] is 0.5 hz
   X[2] is 1 hz
   X[2400] is the 1199.5 HZ
   X[2401] 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[0] is the constant term
   X[1] is 0.5 hz
   X[2] is 1 hz
   X[4800] is the 2399.5 HZ
   X[4801] 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[0] is the constant term
   X[1] is 1 hz
   X[2] is 2 hz
   X[2401] is the 2400 HZ
user6363
  • 333
  • 2
  • 4
  • 11