Reference frequency computation procedure explanations

I develop a web tool to detect Harmonic Key on a < audio >/< video > node on a web page. I found over wikipedia, the "Harmonic Pitch Class Profiles".

It's a procedure to extract the harmonic key of a song, like so :

• 1 - Input musical signal (OK).
• 2 - Do spectral analysis to obtain the frequency components of the music signal. (OK)
• 3 - Use Fourier transform to convert the signal into a spectrogram. (OK)
• 4 - Do frequency filtering. A frequency range of between 100 and 5000 Hz is used.
• 5 - Do peak detection. Only the local maximum values of the spectrum are considered.

These steps are done with the AnalyserNode of the WebAudioApi.

So, my issue is here, i do not understand the point 6 ; "reference frequency computation procedure". Someone have an example or something ? I don't understand what I am supposed to do at this step.

Here the rest of the procedure :

• 6 - Do reference frequency computation procedure. Estimate the deviation with respect to 440 Hz.
• 7 - Do Pitch class mapping with respect to the estimated reference frequency. [...]
• 8 - Normalize the feature frame by frame dividing through the maximum value to eliminate dependency on global loudness. [...]

I hope I ask my question in the right place. Thanks for your help !

• Have you read the references in your Wiki link? There is probably more information in those academic papers than you can expect somebody to write in an answer here. If you have some more specific questions after reading the papers, you can then ask them here (or possibly on another SE site like "signal processing").
– user19146
Apr 18, 2017 at 13:39

This is a pretty complicated process and unless we stick to talking about step 6 only, I think your question is too broad. So I'm only going to talk about step 6.

The challenge that step 6 is meant to address is the following: There is not a fixed correlation between pitch and frequency. A frequency is a primarily scientific concept. When there is a musical sound played or recorded, either the air or the recording medium is excited in a specific way a certain number of times per second, i.e., at specific frequencies. When human ears hear those frequencies, it can generate a sensation of a pitch (assuming the frequencies together for a certain pattern). So pitch is the brains subjective interpretation of scientifically measurable frequencies. Compare with loudness (subjective) and intensity (scientific).

Because pitch is subjective, more than one set of frequencies can be interpreted as being the same pitch by the human mind. Beyond that, in music theory, there are a finite number of discrete pitches, but frequency is a continuum. So a musician or music theorist may describe a note as being "A4" when it has a fundamental frequency of anywhere between about 425 - 450 Hz. Somehow your software has to check for that possibility and adjust its assignment of frequencies to pitches accordingly.

Now musicians do like to play together in groups, and it's going to sound terrible if one of us things that A4 is 435 Hz and another thinks A4 is 440 Hz, so for a few centuries now, we have developed reference frequencies. That just means that we agree that we are going to tune our instruments (tuning is the adjustment of what frequency is played by each nominal note the instrument plays) based around a single frequency so that we can all play together any time we want (more or less).

At this time, by far the most popular pitch reference is A4 should have a fundamental frequency of 440 Hz, and we call that "A-440". In the past, lower frequencies for A4 have been popular, such as 435 Hz. Once an instrument has been tuned to A-440, all of its notes should be related to the A4 tuning in a specific way. This table shows the fundamental frequency of each note when based on A-440 tuning.

Even though that's a standard, instruments are real-world and humans are fallible, so it's pretty much impossible for any instrument to be spot-on to the A-440 tuning for all of its notes. Even more complicated is the fact that some instruments produce frequency spectra where it's necessary to deliberately mistune certain notes in order for the "mistuned" frequencies to generate the correct pitch sensation (the piano is famous example and this mistuning is called "octave stretching").

So when your software starts decoding frequencies that do not match the A-440 frequency table, it will have to make a best guess as to what pitch sensation is intended, and assign those pitches to those frequencies. That's what step 6 is. The reason why you want to estimate the deviation from 440 Hz is if you pick up a few notes, find they don't match the table but find they are equivalently too high or too low, then you can guess that the whole instrument is in tune with itself, it just isn't properly tuned to A-440. That means you can refine your pitch assignments by expecting all of the notes from that instrument to be too high or too low by approximately the same amount.

Computing the reference frequency is finding what A4 on the given instrument is probably actually tuned to based on the frequencies decoded. For example, if you decode the frequencies of 435, 870, 1305, and 1740, you can be pretty sure that pattern was meant to be A4 that has been tuned to 435 Hz instead of 440, and that's your reference frequency for that recording.