Programming Language to use for creating Hidden Markov Model

Oct 19, 2010 at 11:21pm

Programming Language to use for creating Hidden Markov Model

Hello all.

I’m attempting to program a Hidden Markov Model using a tutorial by Mark Stamp. I want to program Hidden Markov Models that would recognize pitch sequences, interval sequences, patterns in spectrum analysis, etc. and they would be interacting directly with Max in terms of midi and MSP. I know that the MNM library has some already programmed Hidden Markov Models and I have looked at them, but I would really like to program these HMMs without learning the FTM language. I know Java the best out of Javascript, C, and Java and I think the programming would be easiest in Java. However, I can learn C or Javascript if these will make the program run better. What do you think would be the best language to program these Hidden Markov Models in, in terms of how they interact with MaxMSP, the ease of connection to MaxMSP and efficiency.

If you want to look at the pseudo-code that I will be typing it up, it is on the 13th page of the following tutorial…


Oct 20, 2010 at 6:50am

Hello bwu,

i can’t tell you which language is the best ; it depends of if you want to use a library or not, do it all by yourself …

but if you want an exemple i did a HMM external [foxtrot] not so long ago …

you can find it here (with C sources) : or somewhere in the “Tralala” folder of my share page (Vanille Béchamel and Pizza Olives) if you want the last updated version.

[foxtrot] is :
Ergodique HMM,
with rescaling to avoid underflow,
Baum Welsh for learning,
(but without Viterbi) …

as i’m not a C super expert, maybe that’s not a good idea ;-)
but anyway you can do what you want with the code, modify and so … improve it ?

” … recognize pitch sequences, interval sequences, patterns in spectrum analysis … “

i don’t think [foxtrot] is good to do that (without modifications) as most of time in PDF i found on the web for gesture following (and co) people implement left/right HMM, and use Viterbi …

PS : i did that to : , but to be honest i don’t have use it so much …

Nov 2, 2010 at 4:01pm

Thanks for the info. I checked out foxtrot, but because I’m not a c++ person (at all!) I couldn’t really get much out of it.

So I’m almost done writing an HMM in java and I really hope to start using it soon. I’m finding it difficult to find articles describing how people have been using HMM’s with music though. I’ve found a couple, 1 on drum sound detection… ( ) that I really have to take a closer look at sometime soon. However I would really like to find some articles (or literature) that have already helped some people out.

Nov 3, 2010 at 7:14am

Hello bwu,

HMM are used in so many kinds of problems … do you want to deal with MIDI data stream ?

Most papers i found was about how to implement HMM ; many about gesture followers, score followers, speech recognition, fO tracking, but none about HMM in generative music process (what interests me) …

PDF i kept are in french (just few in english) ; if you tell me what you expected to do with HMM, i can search in my HD, if i have something about …

Have a look at IRCAM ? Some of them are on line (but less than last year ???) …

PS : [foxtrot] is C code ; I’m not C++ used too ;-)

Nov 3, 2010 at 2:19pm

thx for the link to the hmm tutorial !
I’ve always wanted to check out hmm, but have never found an understandable introduction…

I don’t know if this is of any help to you, but
here’s a paper on “multiple-f0 tracking based on a high-order HMM”:

Nov 4, 2010 at 7:35pm

Thanks all. I found some nice articles on ircam. I’m not part of the network so some of them are blocked but it’s nice to know what people are even using HMM for. I’m looking at a couple of them. I think I’m going to start using the HMM program by trying to follow midi, which is something that I found an article on on ircam’s website.

Ultimately, we would like to have the HMM listen to a live performance (for which it has been trained) and be able to recognize melodies, textures etc. For instance, if we play a trill on a saxophone we would like the program to simply recognize the trill and output something as simple as a bang to max. Then we would work with the bang from there. I think we’re restricting our use to a monophonic instrument (likely a saxophone). Hopefully we’ll be able to do a little bit more interesting stuff such as recognizing patterns in spectral analysis using an analyzer.

However, my vision is very malleable. I’d like to emphasize that I’m really not really aware of how people are using hidden markov models in music right now, so I’m really open to LOTS of ways that the hidden markov model can be used. Actually I’ve just finished the program and I’m pleased to say that it seems to be working well. My next task is incorporating the model into max using the mxj object (which I need to learn about).

@mudang, if you’re using the tutorial I would highly recommend pairing it with the Rabiner tutorial on Hidden markov models, which is more complicated, but more reputable and detailed. As far as I can tell though, the pseudo-code from the one that I posted above is generally right. There is only 1 mistake that I noticed, but it was pretty easy to find looking at the rest of the paper.


You must be logged in to reply to this topic.