I'm interested in learning the frequency spectrum of a constant sound. However, there is background noise. My plan is to record the sound for 1 second, take the FFT, and then doing this 5 times and taking the average (for each frequency bin). This should decrease the variance of the magnitudes across frequencies.

But I wonder what's the difference (ie, pro/con) of this versus just recording for 5 seconds and calculating the FFT?



I would say that you answered part of your own question by noting the reduction of variance with averaging.

Most books tend to present signals that are either random or deterministic but signals can be somewhat of both character to varying extent.

If your signal tends towards the deterministic, and high SNR, there isn’t a lot variation to reduce so the higher resolution of the longer FFT would probably be more preferable in most applications.

If you have a low SNR tone, you want to do as much averaging as other considerations would permit to reduce that noise.

One can also overresolve with long FFTs. Pure steady tones are rare. Real tones have some bandwidth and you want your FFT bins to match that bandwidth.

Averaging has some other advantages like reducing the down stream data rates like if you are displaying real time STFT displays.

Depending on your application, there are other more specific tradeoffs between averaging and FFT length.

  • $\begingroup$ by "higher resolution" with a longer FFT, you mean frequency resolution right? $\endgroup$ – user173729 Jul 18 at 16:35
  • $\begingroup$ basically yes. or greater fine details if you prefer $\endgroup$ – Stanley Pawlukiewicz Jul 18 at 16:50

By constant sound, I suppose you mean pure tone, i.e. a real valued sinusoidal.

Averaging raw bin values across DFT frames will not work properly unless the tones are in the same phase relative to the frame. This happens naturally if you have a tone that has a whole number cycles in each frame and the frames are back to back.

To make it clearer. Suppose there is a whole number of cycles in a frame, but you leave a half cycle gap to the next frame. The bin value in the second DFT will be completely out of phase (180 degrees, or $\pi$ radians) and the average will be zero as you would expect the magnitudes to be equal.

Even with back to back frames, if there aren't a whole number of cycles per frame the same type of interference effects will occur.

Therefore, you can only meaningfully average magnitudes across frames in most cases.

You are better off doing it all in one frame if the sound persists steadily across the interval. This will also separate the bin of interest from the bins of any other tones that may be in your sound. You don't need to calculate the entire DFT (aka FFT) if you are only interested in a few bins, they can be calculated individually.

If you are talking about multiple tones with various durations you might consider separate DFTs. A DFT works best on a steady tone across the entire frame.

  • $\begingroup$ I meant to average only the magnitude across frames as that's the only thing I care about. The tone might be considered the sum of different sinusoids (say, 1khz and 4khz). I'm just worried that there might short bursts of noise (say lasts for 0.5 seconds) at a frequency of say, 2khz, which would mess up the result. I only want to result to show significant magnitude at 1khz and 4khz. Hence the question whether I should do a single FFT across a long time or averaging many shorter FFTs if I want to minimize the effect of random noise. thanks $\endgroup$ – user173729 Jul 18 at 16:33
  • $\begingroup$ @user173729 It can get complicated. If you averge, say 25 numbers, then bust them into five groups of five, average each group, then average the averages, you will get the same result. The same is true for the variance of "ideal noise". Not all noise is ideal though. Chunks allows you to evaluate each chunk for "a good read" and discard chunks that fail. By tossing the phase you are also tossing accurate parameter estimation, which may or may not be important. What you have described is very similar to a spectogram. Perhaps some research in that area will help you out. $\endgroup$ – Cedron Dawg Jul 18 at 17:02

One additional but important point where more detail can be added is the frequency resolution obtained. The frequency resolution (specifically the equivalent noise bandwidth) is 1/T where T is the duration (when a rectangular window is used; any other window will broaden this resolution further at the benefit of increased sidelobe suppression). When you take the FFT of a 5 second duration of sound, each bin has a resolution of 1/5 Hz. In contrast, if you take the FFT of a 1 second duration, the frequency resolution would be 1 Hz.

Here is a post where I explain this in more detail with examples:

What happens when N increases in N-point DFT


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.