0
\$\begingroup\$

In Fourier analyses and FFT we see the power spectrum with a frequency resolution.

I'm trying to understand the meaning of it. What is binning? What does power spectrum indicate.

To expound my question I give the following example.

Lets say I add cosines at different frequencies and phases as:

1Hz with amplitude 4

2HZ with amplitude 2

3Hz with amplitude 1

4HZ with amplitude 0.5

5Hz with amplitude 2

6HZ with amplitude 0.8

7Hz with amplitude 1

8HZ with amplitude 2

9HZ with amplitude 3

10HZ with amplitude 0.1

11HZ with amplitude 0.3

12HZ with amplitude 0.5

And lets say I want to create a power spectrum by binning with frequency resolution 4Hz, so I will have 3 bins as:

So for the first bin I will have 1Hz 2Hz 3Hz and 4Hz

for the second bin I will have 5Hz 6Hz 7Hz and 8Hz

for the third bin I will have 9Hz 10Hz 11Hz and 12Hz

So my first bin will correspond frequencies between 1Hz and 4Hz and the power be quantified by squaring amplitides and adding them as: (4^2 + 2^2 + 1^2 + 0.5^2)

my second bin will correspond frequencies between 5Hz and 8Hz and the power be quantified by squaring amplitudes and adding them as: (2^2 + 0.8^2 + 1^2 + 2^2)

my third bin will correspond frequencies between 9Hz and 12Hz and the power be quantified by squaring amplitides and adding them as: (3^2 + 0.1^2 + 0.3^2 + 0.5^2)

Did I understand the meaning of power spectrum and the frequency resolution? Before digging in to FFT I just want be sure about the big picture.

\$\endgroup\$
  • \$\begingroup\$ Take a look at this Math SE answer: math.stackexchange.com/a/42030/164077 \$\endgroup\$ – Greg d'Eon Oct 21 '15 at 12:00
  • \$\begingroup\$ what is a bin in this context? is that an interval where the signal powers with frequencies in that interval are added up? \$\endgroup\$ – user16307 Oct 21 '15 at 12:05
  • \$\begingroup\$ The whole point is that it doesn't work exactly like that. I'll write an answer. \$\endgroup\$ – Greg d'Eon Oct 21 '15 at 12:06
1
\$\begingroup\$

So for the first bin I will have 1Hz 2Hz 3Hz and 4Hz

No.

The FFT computes the Discrete Fourier Transform (DFT). The DFT is the integral $$ X_k = \sum_{n=0}^{N-1} x_n \left(\cos(2\pi kn/N) - j\sin(2\pi kn/N)\right) $$ Just to make things simpler, I'm going to ignore the sine terms, so we can talk about the sum $$ X'_k = \sum_{n=0}^{N-1} x_n \cos(2\pi kn/N) $$

This sum has a couple of nice properties. If our original function was just the cosine $$ x_n = \cos(2\pi \mathbf{1} n/N) $$ then the sum is $$ X'_k = \begin{cases} N / 2, & n = \mathbf{1} \\ 0, & n \neq \mathbf{1} \end{cases} $$ In real life, this means that your 4 Hz signal will not appear in any of the other bins (8 Hz, 12 Hz, etc). Nice - we can detect a 4 Hz signal by looking in the bin $k = 1$. This pattern repeats if you replace the bolded \$\textbf{1}\$ with any other integer - the signal will only appear in one bin.

Things fall apart when you stop using integers. If I replace the \$\textbf{1}\$ with a fraction like \$\textbf{1/4}\$ or \$\textbf{6/4}\$, then the sum is much harder to calculate. If you do this in Matlab or some other programming language, you'll find that these coefficients are not all zero! Some of your 6 Hz signal finds its way into all of these coefficients.

To get a rough idea of how the coefficients are spread out, they'll look like a scaled sinc function:

Sinc function

This happens to all of your frequencies that are not a multiple of 4 Hz. Yuck! To avoid this, you can try filtering the signal before you take the FFT by using a window function, which will cause this spectral leakage to shrink. However, you can't totally remove it unless you can manage to take the FFT with 1 Hz bins. (Note that you'll still be stuck with all of the 0.5 Hz noise leaking across the intervals - there'll always be something left over.)

This doesn't really answer your question as stated, but I hope it pushes you in the right direction.

\$\endgroup\$
  • \$\begingroup\$ your answer is great for a person who is into it. but i dont undertsand anything. i only know Fourier series and trying to understand Fourrier transforms and FFT. I wanted to have a big picture in mind without complicated terminology about the bins. I still dont understand what a bin accounts for a frequancy resolution:-( \$\endgroup\$ – user16307 Oct 21 '15 at 12:40
  • \$\begingroup\$ Something that neither the question or answer really address is the (time) sampling rate. If the questioner can add/superposition 1 through 12 Hz sine waves, then the sample rate is necessarily 24 samples/sec or greater. Assuming the FFT is the same length of the time sequence, the frequency resolution will be enough so that there is not leakage between frequency bins. \$\endgroup\$ – Jotorious Oct 21 '15 at 12:40
  • \$\begingroup\$ The meaning of "frequency bin" is really frequency sampling. Think of a discrete time signal x[n]. For every different n there is a signal value x. This means that the continuous time signal has effectively been mapped or transformed into a different domain, the discrete time domain. In this case all the signal amplitude for the continuous time interval from t to t+T has been somehow integrated into a single value. so basically the integral of x(t) over t to t+T trasnforms into x[n]. When you do an FFT, you are transforming signals from the time domain, to the frequency domain. That is X[k]. \$\endgroup\$ – Jotorious Oct 21 '15 at 12:49
  • \$\begingroup\$ Just like when you transform x(t) into x[n] you have a sort of integration interval, the same is when you transform x(t) into X(f), or x[n] into X[k]. From the Continous time domain this is a short continuous interval of time. In the Discrete time domain this is a set of discrete instants in time. In the Continuous frequency domain, this is a short continuous interval of frequencies, in the discrete frequency domain this is a set of discrete instants in frequency (colloquially frequencies). It seems like verbiage is and poss. the fundies of transforms and and domains are confusing you. \$\endgroup\$ – Jotorious Oct 21 '15 at 12:57
  • \$\begingroup\$ what is T? is that 1/sampling_frequency? \$\endgroup\$ – user16307 Oct 21 '15 at 14:04
0
\$\begingroup\$

You stipulate that the frequency resolution is 4Hz. This means that the time duration of the signal you convert is 0.25 seconds. It is easy to see that the 1Hz, 2Hz signals etc will not have had a whole number of cycles in that time.

Unfortunately, when you use the FFT (which is just an efficient way to do a DFT) to compute the spectrum of a signal which contains incomplete cycles of sine waves, the energy will 'leak' between bins.

If you crank up a copy of MATLAB, or Octave, or SciPy with Python, and load these waveforms, or better still just one waveform so as not to confuse yourself, into a signal and FFT them, then this is what you will see. Using a 1Hz, or 2Hz, or 3Hz input signal will result in some energy ending up in every bin. Using a 4Hz signal, because it fits exactly into 0.25 seconds, will give you energy in just the 4Hz bin, and nowhere else.

There are a number of technicalities to be mastered to get 'sensible' spectrum analysis type results out of an FFT when incomplete cycles of sine waves go in. Using a window function to multiply the signal before FFTing reduces the effect of partial cycles spilling energy into the wrong bins. Generally, a resolution of about 20% the spacing of your input signals is needed if you want to resolve them, using typical windows.

There is not the space in an answer like this for a full tutorial on spectrum analysis. Just be aware that an FFT is only part of what's needed to get from time signals to a meaningful power spectrum.

The output of the FFT is often called 'bins'. This is just terminology. In an n-point times series, you have a signal described by n complex values, that are usually called samples, sometimes 'time samples'. When the signal is FFT'd, you have a different description of exactly the same signal, with the same total power (see Parseval's theorem), with n complex frequency values, that are sometimes called 'frequency samples', but more often called 'bins'. Both bins and samples run from 0 to n-1, beware Matlab that uses 1 to n indexing!

The amplitude of the Nth bin, is the voltage of the input sinewave with N cycles in the length of the time input. Nothing more, nothing less. The FFT assumes that all input sinewaves are exactly periodic. If you try to put in one that isn't, it will assume that it is, giving you results you don't expect for spectrum analysis. So when your output has 4Hz resolution, it only expects input multiples of 4Hz. A short length of 1Hz signal is therefore broken down into components at 4Hz and multiples thereof that will reconstruct its shape.

Because of this assumption of input periodicity, the FFT probably isn't the best place to start when trying to understand spectral analysis.

Unless - until you get happy with what's going on, always use a long FFT, use a resolution better than 20% of your finest input frequency spacing. This will guarrantee you at least 5 cycles difference in the input. This means that spectral leakage will at least be manageable, you will see something that looks plausible, even if it's not strictly correct. Then later, you can add a window function (look these up) and this 5 cycle rule will mean that you will still be able to resolve your input signals, while getting much less leakage than you had before.

I have had a quick look around the web, and haven't found anything worth linking to you, because I note the key word 'intuitive', and most stuff I can find is full of formulae.

You need to play with some inputs, and see some outputs. Get a copy of MATLAB (low cost to students), Octave (free), Python+SciPy (free) or even an Excel spreadsheet (ubiquitous), build some time series, and see where the spectrum power goes. Keep the resolution fine, that is at least 5 cycles in the time record, and 5 cycles difference between closest spaced signals. Keep the signals an integer number of cycles, at least at first.

\$\endgroup\$
  • \$\begingroup\$ i dont understand:-( \$\endgroup\$ – user16307 Oct 21 '15 at 11:35
  • \$\begingroup\$ If it helps, I didn't once. I've updated my answer a bit, read again. \$\endgroup\$ – Neil_UK Oct 21 '15 at 12:44
  • \$\begingroup\$ "The amplitude of the Nth bin, is the voltage of the input sinewave with N cycles in the length of the time input. Nothing more, nothing less." What is N? Is that the number of samples in time series? And secondly, I dont get the rest of this sentence "the voltage of the input sinewave with N cycles in the length of the time input" What does that mean? Do you mean 4th bin is the voltage amplitude of the 4Hz component? \$\endgroup\$ – user16307 Oct 21 '15 at 12:49
  • \$\begingroup\$ If you take a time record which contains 3 cycles of sinewave, when you do an FFT it will show up in the 3rd bin, N cycles of sinewave shows up in the Nth bin. The resolution is 1/timeRecordLength, so a 500mS time record will have 2Hz resolution, each bin has a centre frequency of 2*binNumber Hz \$\endgroup\$ – Neil_UK Oct 21 '15 at 13:01
  • \$\begingroup\$ @user44635, if you do an FFT... of equal length... I only keep harping on this, because in the original question, the questioner seemed to be specifying a different resolution than that which the FFT would give. A 12 sample long time sequence gets transformed via a FFT into a 12 sample long frequency sequence. \$\endgroup\$ – Jotorious Oct 21 '15 at 13:12

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.