Solved

FFT Java

Posted on 2011-02-15
3
1,786 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:chudyksg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Expert Comment

by:garypfirstech
ID: 34910288
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.
0
 
LVL 18

Expert Comment

by:Jose Parrot
ID: 34935025
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
0
 
LVL 18

Accepted Solution

by:
Jose Parrot earned 500 total points
ID: 34935103
oops, sent uncompleted answer...

Please note that you should select if you need 1D, 2D or 3D functions.
Let use single precision (faster) if it is enough for your case. If you need the best precision, then use the doubleFFT functions. As noticed by garypfirstech about work with just half of the matrix, due its symmetry, this package has such approach too..

You must first create the instance, by calling FloatFFT_2D (or 1D or 3D).
Must populate the matrix, with random numbers by calling fillMatrix_2D or filling it by yourself.
Use showReal_2D to watch the results and
writeToFileReal_2D to save it.

If you have difficulty with this package, you can also try the fft pacjkage at sourceforge: http://sourceforge.net/projects/jfftpack/ , but the Piotr's one is faster.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question