0

After reading a no. of posts here itself i have applied an FFT algorithm on the recorded audio(.wav) file to transform it from time domain to frequency domain.

As a result i have got an array containing some values as

magnitude[i] = sqrt(re*re+im*im);

Now as the title says i have to find frequency and amplitude of the signal(complex sound i.e voice) using this magnitude array, but i have no idea of how to do further processing using this array.The size of FFT is 1024 and sample rate is 48000Hz. Please help me for further processing.

Panky90
  • 148
  • 3
  • 10

1 Answers1

1

If you're just looking for the single largest (sinusoidal) component then scan through the magnitude array until you find the maximum value, and then convert the index of this value to its corresponding frequency, i.e.

mag_max = magnitude[0];
i_max = 0;
for (i = 1; i < N; ++i)
{
    if (magnitude[i] > mag_max)
    {
        mag_max = magnitude[i];
        i_max = i;
    }
}

You now have the value of the peak in mag_max and its index in i_max. You can get the frequency like this:

f_max = i_max * Fs / N;

where Fs is the sample rate (and N is the FFT size of course).

Of course if you're looking for something like the pitch of a complex sound (e.g. a voice or a musical instrument) then things get a lot more complicated. You might want to take a look at the Harmonic Product Spectrum algorithm and pitch detection algorithms in general.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Thanks for the quick help Paul, and yes as you have said i am trying to find freq. and amplitude of a complex sound.So how should i do the processing for it with this magnitude array? – Panky90 May 21 '13 at 08:48
  • If you want to do *pitch* detection then you really need to go back to the drawing board. It is possible with FFT-based methods, but it's non-trivial (see "Harmonic Product Spectrum"), and there are better methods. Take a look at the [Wikipedia page on pitch detection](https://en.wikipedia.org/wiki/Pitch_detection_algorithm) as a starting point. – Paul R May 21 '13 at 08:52
  • Ok Paul,I'll go through that wiki page.But do you have some java implementation of any of such algorithm or a java library that can serve the purpose for me? – Panky90 May 21 '13 at 09:01
  • No - I don't use Java. Also, since pitch detection is quite complex it's unlikely that you would just be able to plug in a third party library and use it without understanding the basic concepts. – Paul R May 21 '13 at 09:03
  • Ok thanks for the help and guidance.I'll go through the wiki page and try to implement on of those algorithms after studying them, then will that solve my issue? – Panky90 May 21 '13 at 09:08
  • It really depends on what you're trying to achieve - if you're writing a musical instrument tuner or something like that then yes, HPS should be good enough. If you're trying to extract more complex information (e.g. multiple pitches from a polyphonic instrument, or from music) then you have a much bigger problem. – Paul R May 21 '13 at 09:18
  • Thanks for all the help and time Paul. If there are any further more queries then I'll get back here again. – Panky90 May 21 '13 at 09:40
  • 1
    I have marked this as a correct answer as Paul has correctly pointed me towards the pitch detection algorithms. Thank You very much Paul. I am now working on it. – Panky90 May 24 '13 at 09:04