# HPS Algorithm for detecting the fundamental frequency of a guitar string

When you plucked on a string, the string is vibrate and except the fundamental frequency, there are an integer multiple of the fundamental frequency, which are the harmonics.

I know that the HPS algorithm is a tool to find the fundamental frequency, but I don't understand the downsample part. How can I know how many times I need to downsample the signal?

I read somewhere that the fundamental frequency can be given by measuring the harmonic frequencies and their GCD (greatest common division)

another source says that there's a need to use the Hanning method. can someone please explain this algorithm?

OK Lets go!

I consider HPS a very simple algorithm, this image representation show exactly how HPS work !

Yeah is highly recommended apply a hann window for every framed data !

What do you need to do is apply one window function over your framed signal, then apply FFT, you need just the first half absolute values from FFT, its give you the Magnitude, now downsample it for N time, Multiply all downsampled and at the end find the peak.

How can I know how many times I need to downsample the signal?

Will depend, the more time you downsample you signal more accurate HPS can be, this has a cost that limits the frequency analysis, for example, imagine that you have a signal sampled at 44100hz, you use FFTsize = 4096 and you decide to make 5 time downsample, its tell me that you can not pick up frequencies above 4403Hz!

floor(4096 / 5) =  819
floor(819 /2) = 409
floor((44100/4096) * 409) = 4403


i might suggest looking up the good ol' Average Magnitude Difference Function (AMDF) or Average Squared Difference Function (ASDF) or Autocorrelation as means of determining the period which is the reciprocal of the fundamental frequency.

• Could you please elaborate on those methods, or cite a source? – Mauren Mar 25 '14 at 0:25