Getting Frequency Components with FFT

Posted by ruhig brauner on Stack Overflow See other posts from Stack Overflow or by ruhig brauner
Published on 2013-07-01T23:02:58Z Indexed on 2013/07/01 23:05 UTC
Read the original article Hit count: 145

Filed under:
|
|

so I was able to solv my last problem but i stubmled upon the next already.

So I want to make a simple spectrogram but in oder to do so I want to understand how FFT-libaries work and what they actually calculate and return. (FFT and Signal Processing is the number 1 topic I will get into as soon as I have time but right now, I only have time for some programming exercises in the evening. ;) )

Here I just summarized the most important parts:

int framesPerSecond;
int samplesPerSecond;
int samplesPerCycle; // right now i want to refresh the spectogram every 

DoubleFFT_1D fft; 
WAVReader audioIn;

double audioL[], audioR[];
double fftL[], fftR[];

.....

framesPerSecond = 30;
audioIn= new WAVReader("Strobe.wav");
int samplesPerSecond = (int)audioIn.GetSampleRate();
samplesPerCycle = (int)(audioIn.GetSampleRate()/framesPerSecond);
audioL = new double[samplesPerCycle*2];
audioR = new double[samplesPerCycle*2];
fftL = new double[samplesPerCycle];
fftR = new double[samplesPerCycle];
for(int i = 0; i < samplesPerCycle; i++) { 
// don't even know why,... 
    fftL[i] = 0;
    fftR[i] = 0;
}
fft = new DoubleFFT_1D(samplesPerCycle);

.....

for(int i = 0; i < samplesPerCycle; i++) {
    audioIn.GetStereoSamples(temp);
    audioL[i]=temp[0];
    audioR[i]=temp[1];                        
}
fft.realForwardFull(audioL);  //still stereo
fft.realForwardFull(audioR);
System.out.println("Check");
for(int i = 0; i < samplesPerCycle; i++) { 
//storing the magnitude in the fftL/R arrays
    fftL[i] = Math.sqrt(audioL[2*i]*audioL[2*i] + audioL[2*i+1]*audioL[2*i+1]); 
    fftR[i] = Math.sqrt(audioR[2*i]*audioR[2*i] + audioR[2*i+1]*audioR[2*i+1]);
}

So the question is, if I want to know, what frequencys are in the sampled signal, how do I calculate them? (When I want to print the fftL / fftR arrays, I get some exponential formes at both ends of the array.)

Thx :)

© Stack Overflow or respective owner

Related posts about java

Related posts about audio