# Pitch class profiling

Currently, I am developing a piece of software for chord recognition. There are FFT and pitch class profiling on it. I tried using the pitch class profile proposed by Takuya Fujishima, but the result is not quite accurate. This may be because I misinterpreted the pitch class profile algorithm.

I don't understand the folowing formula formula:

$p(k)= [12 \;log_2( \frac {l}{N} \cdot \frac {f_{sr}} {f_{ref}})]$ $mod$ $12$

1. What are $f_{ref}$,and $N$ here?
2. Does $N$ mean the sample size of FFT (4096,1024,etc.) or the total bins of the spectrum?
• How are you determining that the result isn't accurate? By what measure is the result not accurate? – hotpaw2 Jan 11 '14 at 19:57
• i would suggest trying out using the $\LaTeX$ utility here. instead of using periods for multiplication and the like. so what does the variable $I$ mean? – robert bristow-johnson Jan 11 '14 at 20:48
• okay, someone cleaned up the OP question. so now my question is what does the variable $l$ mean? – robert bristow-johnson Jan 12 '14 at 5:32
• well, I tried using wav file of chord A minor, and the result is inaccurate. l means index of the current bin – wendy0402 Jan 12 '14 at 17:12
• then what's $k$? – robert bristow-johnson Jan 12 '14 at 18:49

I know this is an old thread, but for reference for future enthusiasts in this field:

The equation for the full PCP algorithm as described by Fujishima is as follows:

$$PCP(p)=\sum_{ls.t.M(l)=p}^{l}||X(l)||^2$$

$$M(l)=\mathrm{round}\left[12\log_2 \left(\dfrac{f_\text{s} \ l}{N f_\text{ref}} \right) \right]\operatorname{mod} 12$$

The confusion that OP has is in regards to the 2nd equation:

$N$ is how many samples are used to calculate the FFT, or typically known as the FFT size. Note that a larger $N$ (more samples, longer time) would mean higher resolution of the FFT.

$f_\text{s}$ is the sampling frequency of the audio file you are processing. Typically this is 44 100Hz.

$f_\text{ref}$ is the reference frequency for the pitch class you are trying to match. This is typically a set of 12 frequencies, representing the fundamental frequencies of the 12 semitones of a classical keyboard. For your reference, they are [16.35, 17.32, 18.35, 19.45, 20.60, 21.83, 23.12, 24.50, 25.96, 27.50, 29.14, 30.87], starting from C0 to B0.

To understand this equation better, the collective term of $f_\text{s} l/N$ is equivalent to converting the FFT bins into the actual frequency that bin represents. $l$ here is just the bin counts for the FFT output. So for every bin of the FFT, the associate frequency can be calculated with this term.

Because every octave is effectively a double in frequency to the previous octave (if C0 is 16.35Hz, then C1 = 2*C0 = 32.70 C2 = 2*C1). So to reverse this, we take the $\log_2$ of the calculated frequency from the previous step.

Now to the first equation, note the summation if for all $l$, such that $M(l) = p$. This means for all of the different pitch classes p (0-11), we must only use bins in the FFT such that $M(l) = \textrm{the pitch classes}$. To find such conditions, we sweep the fref for all frequencies in the FFT so we find the frequencies that contributes the most to the individual pitch classes.

Note that the $M(l)$ equation should not give you a negative number. The reason for this is the FFT creates both positive and negative frequencies. But for all real signals (such as audio signals), the negative frequencies is just a reflection of the positive frequencies. You only really need to deal with the positive frequencies, which resides in the first half of the output from the FFT. Or you can use a rFFT (such as the one in python - numpy) algorithm that specifically deals with real signals, and will only return to you the positive frequencies.

If you were to implement this algorithm, you would do the following:

1. Pick a pitch class profile (lets say you want to look at $PCP(0)$ to find all notes that falls under the musical C)

2. Now, according to the 1st equation, you need to find all $l$ such that $M(l) = 0$

3. You go to the 2nd equation, going through all the bins of your FFT (which is l). You also set your $f_\text{ref}$ to be the reference frequency for the PCP bin you're after (at this case, since we are looking for C, we can set the $f_\text{ref}$ to 16.35Hz).

4. Find all values of $l$, such that $M(l) = 0$. Go back to the 1st equation, now with the subset list of $l$, take the magnitude of the FFT at those specific bins ($l$), to find the final sum for pitch class 0.

• okay, i don't see how your first and second equations are related. other than $l$, what do they have in common? – robert bristow-johnson Oct 8 '15 at 3:36
• the only thing that relates the 2 equation is $l$, the 2nd equation calculates a subset of $l$ that can then be applied to the first equation. I've added some implementation details to my answer. – lyricos Oct 9 '15 at 15:17
• okay, i will spend some time reading this to see if i can connect the dots. – robert bristow-johnson Oct 10 '15 at 21:46

$f_{ref}$ is the reference frequency corresponding to the first pitch class profiling (or PCP[0]), $N$ is the number of samples in the sound that is used to implement the short time Fourier transform. The original sound sequence will be split into overlapping segments with the length of $N$.

• is it possible if the result of 12log2(l/N*fsr/fref) is minus? because that is what i get, thank you – wendy0402 Jan 13 '14 at 5:13