1
$\begingroup$

I was looking some Harmonic Product Spectrum algorithm examples and I came up with this:

//Implement Harmonic Product Spectrum
for(k = 0; k < buffer_size / 8; k++)
{
    sum[k] = magFFT[k] * magFFT[2*k] * magFFT[3*k];
    // find fundamental frequency (maximum value in plot)
    if( sum[k] > max_value2 && k > 0 )
    {
        max_value2 = sum[k];
        fund_freq = k;
    }
 }
 fund_freq1 = fund_freq * 8000 / buffer_size;

What I dont understand is the reason behind the last line, I tested it and it works but I couldn't find an explanation for that multiplication. Can anyone help me please?

Source of code: SOURCE

$\endgroup$
4
  • 1
    $\begingroup$ is your sampling rate 16 kHz or 8 kHz, by any chance? $\endgroup$ Commented Aug 15, 2017 at 19:22
  • $\begingroup$ It's 8kHz, you have any ideas? $\endgroup$ Commented Aug 15, 2017 at 19:26
  • 1
    $\begingroup$ Based on your reply to Marcus' comment, it converts the found DFT index $k$ into the analog frequency in Hertz for a hardwired(?) sampling frequency of 8000 Hz, where buffersize shall denote the DFT length $N$. $\endgroup$
    – Fat32
    Commented Aug 15, 2017 at 19:35
  • 1
    $\begingroup$ sorta interesting pitch detection algorithm. it won't work right if there is a missing fundamental (but other odd harmonics are present). $\endgroup$ Commented Aug 15, 2017 at 23:53

1 Answer 1

1
$\begingroup$

"8000 / buffer_size" is frequency resolution, decide by sample length or "buffer_size",

you know the sampling interval is "1/8000", the whole time length 'T' of the sequence is "buffer_size/8000", then '1/T' is frequency resolution,

in your code,if 'k' is 0, represent 0hz,is the signal's dc part,if 'k' is 1,represent '1/T' or "8000 / buffer_size" hz, then you can see 'k' correspond with frequency bin "k*8000 / buffer_size" .

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.