I was wondering how to get the frequency of a wav file.

at the moment i have NumSample = 512 and get the spectrum data of the wav file using FFT every second.

What i want to know is what do i get back from FFT is it 0-511 array of frequency values for that particular bin and if so how can i equate a Hz frequency value from that?

[code:3gy28wn3]

public struct ANALYSIS_DATA

{

public float[] number;

public double Freak;

public double Bin;

}

```
void Start ()
{
analData = new ANALYSIS_DATA();
analData.number = new float[numSamples];
InvokeRepeating("UpdateAnalysis",0.0f,1.0f);
}
public void UpdateAnalysis()
{
/* updates every 1 second */
double max = 0;
int maxpos = 0;
AudioListener.GetSpectrumData(analData.number, 0,FFTWindow.Rectangular);
for(int i=0; i < numSamples; i++)
{
if(Mathf.Abs(analData.number[i])> max)
{
max = Mathf.Abs(analData.number[i]);
maxpos = i;
}
}
if(maxpos > 0)
GetAvgBin(maxpos);
}
public void GetAvgBin(double num)
{
if(num > analData.Bin)
analData.Bin = num;
}
```

[/code:3gy28wn3]

- johnboy007_2006 asked 5 years ago

- You must login to post comments

What the data represents.

To work out what each entry in the array represents, use this formula

entry_hz = (output_rate / 2) / numvalues

The array represents amplitudes of each frequency band from 0hz to the nyquist rate. The nyquist rate is equal to the output rate divided by 2.

For example when FMOD is set to 44100hz output, the range of represented frequencies will be 0hz to 22049hz, a total of 22050hz represented.

If in the same example, 1024 was passed to this function as the numvalues, each entry’s contribution would be as follows.

entry_hz = (44100 / 2) / 1024

entry_hz = 21.53 hz

- Guest answered 5 years ago

- You must login to post comments

**Your Answer**

Please login first to submit.