I'm doing a research on the FFT method, and a term that always comes up is "frequency bin". From what I understand, this has something to do with the band created around the frequency of a given sinusoid, but I can't really figure out how. I also figured out how to go from a given bin to its related frequency, but still no intuition on what a frequency bin is.
6 Answers
It's simpler than you think. When we discretize frequencies, we get frequency bins. So, when you discretize your Fourier Transform: $$e^{-j\omega} \rightarrow e^{-j{2\pi k}/{N}}$$ Our continuous frequencies become $N$ discrete bins.
This is exactly why the following is true: $$n^{th}\,\text{bin} = n*\dfrac{\text{sampleFreq}}{\text{Nfft}}$$ where $\text{Nfft}$ is the length of the DFT. Note that the FFT represents frequencies $0$ to $\text{sampleFreq}$ Hz.
(RAB - actually, if $\text{Nfft} = N$, then your bin index will span from $0$ through $N - 1$. Therefore, the frequencies generated will be (0:N-1) * sampleFreq/Nfft
, and you won't get the $N\cdot\text{sampleFreq}/N = \text{sampleFreq}$ bin. That unrepresented bin will alias onto and be summed with
the $0$ bin. Instead, you will get bins (0:9) * sampleFreq/10
In other words, if sampling 10 times per second, and sampling for 1 second, our frequency bins will be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Hz. Notice that the 10 Hz bin is not there.
-
6$\begingroup$ What frequencies does each bin then represent? eg if the formula above come up with 1,000hz for a bin (assume 1 hz wide), then does a bin represent 1000.000 to 1000.999, or is centred - eg 999.5 to 1000.5? $\endgroup$ Jul 13, 2017 at 17:20
-
2$\begingroup$ Check the answer of this question stackoverflow.com/questions/10754549/…. Each bin is SAMPLE_RATE / NUM_POINTS (Hz) wide. And its the center of the bin so its range is half-bin before to half-bin after the center. Also check this en.wikipedia.org/wiki/Histogram, it has some explanation about the 'bin' term. $\endgroup$– mortalisMay 22, 2018 at 10:59
-
$\begingroup$ In my understanding the size of the bins decreases as NUM_POINTS increases, is it correct? That is, we must consider bins instead of points because we have N observations. Is it correct? $\endgroup$ Sep 28, 2022 at 7:10
-
$\begingroup$ How can we get frequency bins higher than 5 Hz for 10 Hz sampling rate? I thought we get -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 Hz bins... Numpy's rfft function (FFT for real input) returns N/2 + 1 bins for even N. $\endgroup$ Mar 31 at 7:54
A frequency bin in 1D generally denotes a segment $[f_l,f_h]$ of the frequency axis, containing some information. It is defined between a low and a high frequency bound $f_l$ and $f_h$. It is related to the series of ranges of numerical value used to sort data in statistical analysis. In higher dimension, it is a volume defined by bounds on each frequency dimension, like an hyper rectangle.
This chunk of the frequency space is often assigned, or "collects", periodicity information like the amplitude, magnitude or energy from a small range of frequencies, often resulting from a Fourier analysis.
Due to data discretization (possibly due to sampling), it is generally not possible to assign a precise amplitude to every frequency location on a real axis. The frequency bin can be derived for instance from the sampling frequency and the resolution of the Fourier transform. However, a portion of the computed amplitude may be attributed to frequencies of the actual signal that are not contained in the bin range. Terms associated to this phenomenon can be leakage, smearing, aliasing, windowing, and depend on the tools used to obtain these amplitudes. An instance is demonstrated on the following figure: a pure sine is sampled, and analyzed through a rectangular window. Although one might expect a single peak, as one would obtain on the full continuous-time signal with a continuous Fourier transform, the peak is not precisely localized with an FFT, and leaks in the neighboring bins.
Very often, the segment $[f_l,f_h]$ is referred to as a single frequency, like the mid-frequency $\frac{f_l+f_h}{2}$ or the lowest frequency $f_l$, yet one should not forget it is an interval, not a single number. Classically, the frequency bins are even in size, non-overlapping, and cover the whole spectrum. On occasion, they can somehow overlap, be non-uniform, for instance when this term is used (rarely) for multirate filter banks.
Similar concepts can be found in probability bins.
An FFT is a method of computing a DFT. And a DFT is a transform of a finite length vector which produces the same finite number of results. However the range of frequencies of a sinusoid that can be windowed to a finite length in order be fed to an FFT is infinite. Thus, each result vector element of an FFT is predominately associated with a small segment of this frequency continuum, rather than a point (the FFT bin center frequency).
Sometimes the bins are idealized as fixed width rectangular filters. But the actual shape of each FFT result bin is not a rectangular bucket, but either Sinc shaped, or shaped like the transform of any non-rectangular window function that has optionally been applied. Note that these result bins can be wider in bulk than the distance between FFT bins, with tails (the stopband) that trail off around the full width of the result. These tails are sometimes referred to as "leakage".
-
$\begingroup$ I don't understand your 2nd paragraph. Please elaborate on the difference, if any, between a "frequency bin" and one of the array elements returned from an FFT. $\endgroup$ Nov 9, 2015 at 22:14
-
$\begingroup$ An FFT result array element is a summary of the spectral contents of the associated bin. Also the correlation against the basis vector associated with that element. $\endgroup$– hotpaw2Nov 10, 2015 at 0:22
-
$\begingroup$ Windowed pure sinusoids within a bin usually have a higher correlation against the basis vector than stuff outside (although this depends on the window applied). $\endgroup$– hotpaw2Nov 10, 2015 at 0:30
Good info here.
From that and knowledge of sampled audio, the highest frequency in the bins cannot be more than half the samplerate (in Hz). Also, according to this stack conversation, 0 is the lowest bin frequency (a.k.a. the DC component). The first link also describes in depth about leakage and compensating for that.
Your “5 Hz sample” completes 5 cycles in approximately 350 samples (0-350). Therefore, 1 cycle is completed in approximately 70 samples, which should be 1/5 of a second, for a 5 Hz signal.
If 70 samples = 1/5 of a second, then 1 second of data = 350 samples. However, you have approximately 1050 samples of data displayed, implying that you have at least 3 seconds of data.
If you present 3 seconds of data to the FFT, then each frequency bin of the FFT would 1/3 Hz. Therefore, bin 30 (your claim of the lower peak bin) would actually equate to 10 Hz, and bin 270 (estimated from chart) would equate to 90 Hz.
I suspect that you appended datasets together and have broken the original frequency content of the original signal.
If you go back and compute 1 second of 5 Hz data (5 cycles over the 1 second sampling interval), and also compute 1 second of 50 Hz data (50 cycles over the sampling interval), and add both signals together rather than concatenating them, then you will end up with 1 second of data, containing both a 5 Hz and a 50 Hz signal. Then when you perform the FFT, you will see peaks in the expected locations.
I hope this helps… ! RAB
I was working with FFTs today and hopefully this can help. My problem is that I had a sample of sinusoids with different periods. Based on my current level of understanding, I had a 5 hz sample and a higher frequency (I think at 50 hz).
in the picture above, I got a peak at ~30 and ~300 hz, but this can't be right. I used shannon sampling theorem to get the desired frequency bins (in my case I needed a bin of 0.19 hz each), incrementing up to 100 hz.
I obtained the formula for the sampling rate from National Instruments
https://www.sjsu.edu/people/burford.furman/docs/me120/FFT_tutorial_NI.pdf
I used GNU GSL for the FFT and GNU PLOT for displaying the waveform. Thank you FSF (free software foundation).
*** RAB - Your “5 Hz sample” completes 5 cycles in approximately 350 samples (0-350). Therefore, 1 cycle is completed in approximately 70 samples, which should be 1/5 of a second, for a 5 Hz signal.
If 70 samples = 1/5 of a second, then 1 second of data = 350 samples. However, you have approximately 1050 samples of data displayed, implying that you have at least 3 seconds of data.
If you present 3 seconds of data to the FFT, then each frequency bin delta of the FFT would be 1/3 Hz. Therefore, bin 30 (your claim of the lower peak bin) would actually equate to 10 Hz (technically, (30-1)*1/3 = 9.67 Hz, since the first bin is 0 Hz, and bin 271 (estimated from chart) would equate to 90 Hz (271-1)*1/3 = 90 Hz.
I suspect that you appended datasets together and have changed the original time duration of the original signal.
If you go back and compute 1 second of 5 Hz data (5 cycles over the 1 second sampling interval), and also compute 1 second of 50 Hz data (50 cycles over the sampling interval), and add both signals together rather than concatenating them, then you will end up with 1 second of data, containing both a 5 Hz and a 50 Hz signal. Then when you perform the FFT, you will see peaks in the expected locations.
I hope this helps… ! RAB