# Calculate the frequency with spectrum data

**URL:** <https://qa.fmod.com/t/calculate-the-frequency-with-spectrum-data/14042>\
**Category:** FMOD Engine\
**Created:** [August 11, 2018, 7:00pm UTC](https://qa.fmod.com/t/calculate-the-frequency-with-spectrum-data/14042 "2018-08-11T19:00:06Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![fleshy](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@fleshy](https://qa.fmod.com/u/fleshy)\
**Post date:** [August 17, 2018, 1:44pm UTC](https://qa.fmod.com/t/calculate-the-frequency-with-spectrum-data/14042/3 "2018-08-17T13:44:59Z")

</div>

> [@](#):
>
> nyquistLength refers to half the entries in the resulting array. It will be the window size divided by 2. Its a bit of a misleading name really.
> 
> You will want to divide the nyquist frequency (samplingrate /2) by half of the window size (ie 1024 fft length = 512 entries) to get the hz value per entry.
> 
> That means it should be along these lines:
> 
> ```
> nyquistRate = sampleRate / 2
> numEntries = (numValues / 2)
> hzPerEntry = nyquistRate / numEntries
> for (count = 0; count < numEntries; count+)
> {
> entrypower = spectrumData[channel][count] * hzPerEntry
> // pick the biggest power here or process the array to get a better result
> // (count+0.5) * hzPerEntry will be the frequency to display.
> }
> 
> ```
> 
> Otherwise the FFT dsp also has a way to get the dominant frequency from a channel:  
> FMOD\_DSP\_FFT\_DOMINANT\_FREQ  
> [https://fmod.com/resources/documentation-api?page=content/generated/FMOD\_DSP\_FFT.html](https://fmod.com/resources/documentation-api?page=content/generated/FMOD_DSP_FFT.html)
> 
> Edit: I missed the part where you need to halve the number of values to match the nyquistLength, as the 2nd half is a mirror image and has the imaginary parts of the complex numbers.

Hello Cameron,thanks for the answer! The values returned by freq are too small, the highest freq is 11.87. With the FMOD\_DSP\_FFT\_DOMINANT\_FREQ I get 3310, 2765 and so on as the peak frequency. Am I missing something?

---

_[View the full topic](https://qa.fmod.com/t/calculate-the-frequency-with-spectrum-data/14042)._
