I am quite new to Java and Signal Processing, but I was assigned a project dealing in audio processing. My topic given to me is a game that has a component of analyzing a song (any given song) and outputs data depending on the frequency currently being played (real time). ie: as the song plays, it outputs the current frequency (every second it outputs the current frequency).

I have been told on stackoverflow to use FFT. they say "just do a FFT" but that means nothing to me? HOW do you do an FFT? I have read tutorials, and basically understand what it is, but have no clue on how to implement it as in:

  • what is the data type of the audio file most suitable for such processing?
  • what exactly is the input of the FFT
  • how do I interpret the results

Can anybody suggest a simple to follow walk through/tutorial on how to process an audio signal? Additionally, if anybody knows a good implementation of FFT for Java, I would appreciate the suggestions.

  • 2
    $\begingroup$ This question appears to be off-topic because it is about basic Java arrays, data types, and reading files. $\endgroup$
    – hotpaw2
    Commented Feb 3, 2014 at 15:06
  • 1
    $\begingroup$ They said I must ask here as it is to do with Signal Processing $\endgroup$ Commented Feb 3, 2014 at 15:57
  • $\begingroup$ Only the last part of your question seems to be about DSP. Try removing the first 2 or 3 parts to be on topic here. $\endgroup$
    – hotpaw2
    Commented Feb 3, 2014 at 18:34

2 Answers 2


Let's see. I have no idea about Java classes or what type of support it has for signal processing, but i will give you some guidelines. The Particular details of the implementation in the language, you have to figure out.

To do any kind of processing on an audio file you need the "raw" data, meaning an audio file wich has uncompressed audio samples. For exmaple, the WAV format, which normally has samples in 16bit signed 2's complement.

If you are going to use a computer and do offline processing, might be a good idea to cast that value to a double (Which in most processors today means 64bit floating point number).

Therefore you will have a continuos stream of double numbers coming from the file. Then you need to define a way to handle the continous data. A standard, very widely used way is to use a circular buffer (even if it is offline, i assume you want your code to be efficient, and loading the entire file to memory as an array is not the best solution). Either that or just a normal buffer, is your choice. The buffer length should be a power of 2 (Do to efficiency of the Cooley-Tukey radix-2 algorithm).

Now you need to do the actual FFT. This is merely a multiplicacion of the buffer (Which mathematically is a vector) by the FFT matrix. How this operation is actually performed in Java, no idea. In C it would be just to pass the pointer to the array and the length to an FFT routine that, either returns a pointer to dinamically allocated memory, or leaves the result in an array that you pass to it.

finally, you arrive at an array of M complex numbers (Assuming the length of the array/buffer/vector with the signal is M). And then you do whatever you want with it.

For instance, you could take the magnitude of each of the complex numbers, and find the maximum, to detect where the fundamental frequency could be (very approximate though).

Extras: More advanced techniques to process would include a pre windowing to avoid leakeage, doing zero-padding to obtain more resolution on the windowed spectrum, etc.

Hope it Helps.


If you are good enough with JAVA you can use the JTRANSFORMS a java library for FFT which may come in help for you

and by your need it sounds like a

enter image description here

Music Visualization using Java Sound API

Music Visualization using FFT in Ruby in 7Steps

you can follow these simple steps as of your requirement:

*Get accustomed to some audio terminology

1.Read the Playing Frame(Lets say a 20-30ms),your frame size depends on your sampling rate lets say you are using a sampling rate 8000 and each sample is 16bit signed little endian,then your frame of 20ms will be 160 samples

Note:try to play a raw file not a compressed mp3 file.

2.Take the Frame of Raw Data and Perform a FFT

3.Perform Proper Windowing

4.your output FFT result will have two components real and complex try to take a magnitude plot from it which is just absolute value of the complex component,your peak gives you the dominant frequency

5.have a look at simple tutorials like below

Good Tutorial on FFT

Engineers Guide to FFT

FFT Tutorial

OverView of FFT


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.