Link to home
Start Free TrialLog in
Avatar of chudyksg
chudyksgFlag for United Kingdom of Great Britain and Northern Ireland

asked on

FFT Java

I used this tutorial that uses DFT http://jvalentino2.tripod.com/dft/index.html but the algorithm is too slow. Does anyone knows any similar tutorials explaining step by step of trasnforming audio into frequency domain using FFT? I wanted to use jtransforms library http://sites.google.com/site/piotrwendykier/software/jtransforms but can't find any examples how to use it. What method use, what input does it take? It is not specified. Anybody can help me with that?
Avatar of garypfirstech
garypfirstech

I am no expert on this stuff but since no one else has answered, I'll give it a shot.

Try this (I haven't tested it but it should be close):

First, change "int x[] = new int[n];" to "double x[] = new double[n];"

Then, replace the last box with the following:
DoubleFFT_1D f = new DoubleFFT_1D(n/2);
f.realForwardFull(x);
for (int j = 0; j < n; j += 2) {
	double amplitude = 2 * x[j]/n;
	double frequency =(j/2) * h / T * sample_rate;
	System.out.println("frequency = "+frequency+", amp = "+amplitude);
}

Open in new window


Be sure to check these results against your existing algorithm to determine if this method is correct.

Also, since the transform only uses the first half of x, you can save time in the loop populating x by changing "for (int i = 0; i < n*2; i+=2) {" to "for (int i = 0; i < n; i+=2) {".  There's no sense populating values that you're not using.
Avatar of Jose Parrot
There is a complete package, including Java source code at
http://sites.google.com/site/piotrwendykier/software/jtransforms

It covers 1D, 2D and 3D. You should select what algorithm is the right for your needs, but most common is DFT.  The author claims it as the fastest FFT around and a benchmark is shown, to compare it against other packages.

It was developed in Unix environment, but compiles without problems in Windows or Linux, providing the right Java libraries.

Jose
ASKER CERTIFIED SOLUTION
Avatar of Jose Parrot
Jose Parrot
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial