7

I want to develop musical notes detector as my degree project and I want to do it from scratch. I have written code for ".wav" file which extracts all info from that audio music file and gives me amplitude as a result.

Then I have written a code for DFT - it gives me output as a complex number where one of the axis (real/imaginary) is amplitude/magnitude and other is Phase.

Now the question I want the answer in frequency (in Hertz not in vector) so I can check whether my DFT gives me the proper output or not. How can i convert my DFT output into frequency ?

I have to code this in C language and I don't want to use any built-in library

Paul R
  • 208,748
  • 37
  • 389
  • 560
mossad
  • 73
  • 1
  • 2
  • 7
  • When you say the real axis is amplitude and the imaginary is phase, are you calculating that yourself? Or just pulling that straight from the DFT? When you get the complex result from a DFT, the amplitude is the absolute value of that result, and the phase is the angle (aka argument) of the result. – Drew McGowen Jun 30 '13 at 14:46
  • Yes I am calculating DFT myself,means I got the formula which is " Sigma From k=0 -> N-1 ,For all f(x)* W*N,here W*N=e^(-i 2 PI /N)" like this ...I just convert this formula into my C program. – mossad Jul 01 '13 at 03:34
  • 2
    The bin frequency at the peak FFT magnitude is very often not the note pitch in music audio. – hotpaw2 Jul 01 '13 at 18:12
  • @hotpaw2, I learned this the hard way. What is the correct approach to finding the dominant pitch in a audio clip, then? – yati sagade Jan 19 '14 at 10:53

1 Answers1

16

You need to find the peak magnitude then work out the corresponding frequency:

  • calculate the magnitude of each DFT output bin: magnitude = sqrt(re*re+im*im)
  • find the bin with the largest magnitude, call its index i_max.
  • calculate the equivalent frequency of this bin: freq = i_max * Fs / N, here Fs = sample rate (Hz) and N = no of points in FFT.

See this answer for a more detailed explanation of how bin indices and frequency are related.

Community
  • 1
  • 1
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Sorry Paul R but i did not get it.I also had calculated the magnitude from my DFT result.Now the question is i have to find i_max for each window (1024 samples)? And as per what i read about DFT i just find that magnitude on the 512 sample which is N/2 where i get maximum. m i right.means i want to asj dat ..And also thank you very much..:) – mossad Jul 01 '13 at 03:41