# Android-Java: The reconstruction of the fast Fourier transform of a real signal using libgdx fft for android

Here is an example of calculating the Fourier Transform android using the FFT class from libgdx. The code I have provided is developed on eclipse. Before you start, be sure to download the libgdx jar library files.
Here is a good resource for learning how to install libgdx in eclipse along with some great tutorials on where to begin.

In this example, I also calculate the magnitude and phase of a real one dimensional array or signal. This is useful for many apps, especially those that do image/video or audio processing of some kind. Once the magnitude and phase signals are obtained, the program reconstructs the original array with the inverse Fourier transform. Feel free to use this code, but I ask please at least learn how it works before you use it.

Ensure you also follow this guide which teaches you how to set up a project with libgdx in java desktop and android by badlogic games

Here is the source code:

```package com.spec.example;
import android.app.Activity;
import android.os.Bundle;
import java.lang.String;
import android.util.FloatMath;
import android.widget.TextView;

public class spectrogram extends Activity {
/** Called when the activity is first created. */
float[] array = {1, 6, 1, 4, 5, 0, 8, 7, 8, 6, 1,0, 5 ,6, 1,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] array_hat,res=new float[array.length/2];
float[] fft_cpx,tmpr,tmpi;
float[] mod_spec =new float[array.length/2];
float[] real_mod = new float[array.length];
float[] imag_mod = new float[array.length];
double[] real = new double[array.length];
double[] imag= new double[array.length];
double[] mag = new double[array.length];
double[] phase = new double[array.length];
int n;
float tmp_val;
String strings;
FFT fft = new FFT(32, 8000);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

fft.forward(array);
fft_cpx=fft.getSpectrum();
tmpi = fft.getImaginaryPart();
tmpr = fft.getRealPart();
for(int i=0;i<array.length;i++)
{
real[i] = (double) tmpr[i];
imag[i] = (double) tmpi[i];
mag[i] = Math.sqrt((real[i]*real[i]) + (imag[i]*imag[i]));
phase[i]=Math.atan2(imag[i],real[i]);

/****Reconstruction****/
real_mod[i] = (float) (mag[i] * Math.cos(phase[i]));
imag_mod[i] = (float) (mag[i] * Math.sin(phase[i]));

}

fft.inverse(real_mod,imag_mod,res);
}
}
```

If you want an exact project example, I recommend taking a look at another post: simple fft exampling using libgdx where you can also download the source code.

To see a working example of this library for a signal processing application, you can take a look at my android app on the market, called ‘Enhancement‘.
This application is an educational platform for university students to learn about Digital Signal Processing (DSP) techniques and Speech Enhancement algorithms currently used in teleconferencing, radio communication, mobile phones and even forensic science.  Alternatively you can check out the web site enhancementapp.com or even the ‘Enhancement Demo‘ App on the market.