How to find peak frequency
Closed this issue · 1 comments
mgsoftwaring commented
Thanks for the reply
you gave me some sample data but I have to replace them with real data I take the biffer that gives me back nAudio
I changed the coce like this, in the meantime I don't have to plot but find the peak frequency of the voice or song:
void WaveIn_DataAvailable (object? sender, NAudio.Wave.WaveInEventArgs e)
{
for (int i = 0; i <e.Buffer.Length / 2; i ++)
AudioValues [i] = BitConverter.ToInt16 (e.Buffer, i * 2);
// get FFT and FFT frequencies
double [] paddedAudio = FftSharp.Pad.ZeroPad (AudioValues);
double [] fft = FftSharp.Transform.FFTpower (paddedAudio);
double fftFreqPeriod = FftSharp.Transform.FFTfreqPeriod (sampleRate, fft.Length);
double fftFreqSpacing = 1.0 / fftFreqPeriod;
}
And now?
https://user-images.githubusercontent.com/4165489/195965290-06f570c8-caa2-4b4c-90af-62c2fe0652b0.png
I try to find the peak frequency of the graph, if you can complete the code for me?
Help me kindly, I have little experience in the audio field. If i can
Thank's
Mimmo
swharden commented
// find frequency with the highest FFT power
double peakFrequency = 0;
double peakPower = 0;
for (int i = 0; i < fft.Length; i++)
{
if (fft[i] > peakPower)
{
peakPower = fft[i];
peakFrequency = i * fftFreqPeriod;
}
}