Two scripts for showing how the addition of a simple note transition model to a template-matching pitch model, by way of a particle filte, can improve pitch estimates. The example used here is a synthesized rendition of the opening phrase of the first fugue from Bach's Die Kunst der Fuge. Added noise causes the simple pitch model to produce octave confusions. The first model uses a simple discrete state space Hidden Markov Model (HMM) with hand-coded state (note) transition probabilities. The second example, a switching Hidden Markov Model + Linear Dynamic System model (in David Barber's terminology), allows for a continuous range of possible pitch frequencies and uses a continous probability distribution for note transitions. Samples outputs shown below.
(2) Naive estimate (template matching only)
Barber, David (2012). Bayesian Reasoning and Machine Learning. (Cambridge University Press, Cambridge).