6

I've been attempting to find a library that would enable to perform FFT (Fast Fourier Transform) on some EEG signals in Android.

with help of Geobits, I've finally found the code that might help me do FFT on an EEG signal. But I am having a hard time figuring out how does the code actually work. I want to know what float array x and y are for and maybe an example that might help me a little more.

Community
  • 1
  • 1
Jonathan
  • 2,728
  • 10
  • 43
  • 73
  • 1
    http://stackoverflow.com/questions/9272232/fft-library-in-android-sdk – Geobits Oct 18 '12 at 21:07
  • Thanks @Geobits I'll go over it right now. But I am a CS student and not familiar with FFT so having a hard time figuring the algorithm out – Jonathan Oct 18 '12 at 21:10
  • 1
    Well, if you just want to *perform* an FFT, you don't need to truly understand it. If you want to actually understand it, try [this link with more of an explanation](http://astro.berkeley.edu/~jrg/ngst/fft/fft.html). – Geobits Oct 18 '12 at 21:14
  • I am just confused on what does public class FFT and public void fft(double[] x, double[] y) do? and what do the values n, m and x and y represent? – Jonathan Oct 18 '12 at 21:15
  • Ah, you might want to read up a bit then. the `int n` in the constructor should be the window size you want(basically the number of samples, and controls precision, etc). The x/y look like they correspond to real/imaginary components. – Geobits Oct 18 '12 at 21:27
  • okay I'll read a little into it and get back with you. Thanks :) – Jonathan Oct 18 '12 at 21:28
  • I think it makes sense now. N is the # of samples. x and y when fed into the function are the x-y coordinates in the time domain. after the function is done running, they become the frequency domain coordinates.Am I understanding this right? and This is the ([reference](http://www.ele.uri.edu/~hansenj/projects/ele436/fft.pdf)) – Jonathan Oct 19 '12 at 00:26

1 Answers1

3

An fft should return a series of complex numbers (could either be rectangular coordinates, or polar: phase and magnitude) for a specific range of frequencies...

I'm still working through the expressions, but I'll bet dollars to donuts that the x and y arrays are the real (x) and imaginary (y) components of the complex numbers that are the result of the transformation.

The absolute value of the sum of the squares of these two components should be the magnitude of the harmonic component at each frequency (conversion to polar).

If the phase is important for your application, keep in mind that the the FFT (as with any phasor) can either be sine referenced or cosine referenced. I beleive sine is the standard, however.

see:

http://www.mathworks.com/help/matlab/ref/fft.html

http://mathworld.wolfram.com/FastFourierTransform.html

Since the FFT gives a truncated approximation to an infinite series created by a harmonic decomposition of a periodic waveform any periodic waveform can be used to test the functionality of your code.

For an example, a square wave should be easy to replicate, and has very well known harmonic coefficients. The resolution of the data set will determine the number of harmonics that you can calculate (most fft algorithms do best with a data set that has a length equal to a power of two, and is a number of integral wavelengths of the longest frequency that you want to use).

The square wave coefficients should be at odd multiples of the fundamental frequency and have magnitudes that vary inversely with the order of the harmonic.

http://en.wikipedia.org/wiki/Square_wave

Daniel Saban
  • 478
  • 3
  • 16