Home » Android » android – Get frequency wav audio using FFT and Complex class

android – Get frequency wav audio using FFT and Complex class

Posted by: admin June 16, 2020 Leave a comment

Questions:

It’s been asked a lot, but I still stuck about implement FFT class on Android
I need to process my audio data using FFT…

I already read the almost same question here How can I get frequency data from PCM using FFT
and here How to get frequency from fft result?
and more questions but still find no answer even after I tried the answers given…

FFT Class I’m using:
http://www.cs.princeton.edu/introcs/97data/FFT.java

The complex class to go with it: http://introcs.cs.princeton.edu/java/97data/Complex.java.html

Here’s my code

I assume the audioData array contains the raw audio data,but my code catch the exception and return “N is not a power of 2”

Is it anything wrong with my code ??
How do I pass it to FFT.java class and get the fftResult ??

Or is there an other way to convert time domain data to frequency data that more easier ?

It’s been a few months since I get stuck with this… My project is too compare 2 audio of *.wav files,
Any help would be appreciated… 🙂

How to&Answers:

I already found the answer… 🙂

I create method to calculate array value from audio…

Then I called it in class Write Audio..

Answer:

It sounds like your immediate problem is “N is not a power of 2.” In this case, N is probably referring to the size of the data you are putting into your FFT. Most FFT algorithms only work on blocks of data that have a size that is a power of 2.

Are you trying to put the entire file into an FFT at once? If so, you may need to read more background material to understand what you are doing. Maybe start here: http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html