Search code examples
javaandroidaccelerometerfft

FFT interpretation


I am wokring on an Android project where I am using FFT for processing accelerometer data and I have problems understanding how are these things actually working. I am using jTransform library by Piotr Wendykier in the following way:

        int length = vectors.length;
        float[] input = new float[length*2];
        for(int i=0;i<length;i++){
            input[i]=vectors[i];
        }

        FloatFFT_1D fftlib = new FloatFFT_1D(length);
        fftlib.complexForward(input);

        float outputData[] = new float[(input.length+1)/2];
        if(input.length%2==0){
            for(int i = 0; i < length/2; i++){

                outputData[i]= (float) Math.sqrt((Math.pow(input[2*i],2))+(Math.pow(input[2*(i)+1], 2)));
            }
        }else{
            for(int i = 0; i < length/2+1; i++){

                outputData[i]= (float) Math.sqrt((Math.pow(input[2*i],2))+(Math.pow(input[2*i+1], 2)));
            }
        }

        List<Float> output = new ArrayList<Float>();
        for (float f : outputData) {
            output.add(f);
        }

the result is an array with following data output data visualization.

I have problem with interpreting the output data..The data are from 10 seconds long interval, and the sampling frequency is 50Hz..While capturing I was moving the phone up and down cca each 3/4 second in my hand, so is possible that the extreme which is about x value 16 could be the period of the strongest component of the signal? I need to obtain the frequency of the strongest component in the signal..


Solution

  • The frequency represented by each fft result bin is the bin number times the sample rate divided by the length of the fft (convolved with a Sinc function giving it non-zero width, to get a bit technical). If your sample rate is 50 Hz and your fft's lenght is fft length is 512, then bin 16 of the fft result would represent about 1.6 Hz which is close to having a period of 0.7 seconds.

    The spike at bin 0 (DC) might represent the non-zero force of gravity on the accelerometer.