I'm a physics student with a great interest in music. I'm researching (as a kind of hobby) in topics which include math applied to music, acoustics, etc. In the last days I've realized that having a computer application to make musical analysis would help me a lot in my research.

The idea is to develop a software which can make an harmonic analysis of a song. I would like to use a MIDI, or MusicXML, or something like that, as an input. And then I would like to obtain the key and chords of the song.

I've been looking into the Internet for days, but I haven't found anything useful.

Some things:

  • I've read about some chord recognition algorithms for audio. However, it looks like I cannot adapt this approach to the MIDI input, because they use the intensity of each frequency in the spectrum.

  • I know the song could have modulations, or parts where a chord is not clear. Instead of applying some kind of dark magic which gives me the perfect and ideal answer of every chord and key in the song, I would prefer to state the problem as follows:

    1. Given a set of notes (for example, a complete measure), which we assume to be part of the same chord, get the best guess for the chord and a coefficient to indicate how good is the guess (for example, ~1.0 if the computer is very sure about that chord, ~0.0 if it isn't).
    2. Given a set of chords (for example, 20 chords) which we assume to be in the same key, guess which is this key and give me a coefficient.
  • I'm also interested to know if it's possible to determine key using the notes directly, instead of the chords.

That rules would allow me to slice the MIDI (for example, in measures) and apply the algorithm to detect chords and/or keys in the sheet music.

So, do you know any algorithm to perform this task? Any ideas? Do you know some literature about this?

Thank you in advance =)

1 Answer 1


I don't know of any clear-cut fully worked out published approach, but there is a lot of research out there. Here are some pointers.

David Temperley's is a leading researched in this field and his paper An Algorithm for Harmonic Analysis his the most in depth approach I've seen so far (although very heavy on the music theory side). His book The Cognition of Basic Musical Structures may be of interest, but I have not read myself. His Melisma project may also interest you, as its harmony recognition module addresses your concern and the source code his freely available.

Automatic chord recognition with known algorithm is a nice introduction to the subject of chord recognition. It's a college paper, but seems sound to me and it summarizes nicely different possible approaches.

COCHONUT: RECOGNIZING COMPLEX CHORDS FROM MIDI GUITAR SEQUENCES presents a graph based algorithm for chord identification from symbolic "noisy" data (i.e. non filtered and non quantized performance MIDI data).

A different approach to chord recognition is presented in Automatic Chord Recognition from Audio Using a Supervised HMM Trained with Audio-from-Symbolic Data. Although it is more focused in audio information retrieval, the statistical (Markov Model based) approach to chord identification may be of interest, as it is the most used approach. There is research about other approaches though, like neural networks or the newer machine learning techniques .

You may wish to contact to developers of the Music21 python musicology library to learn how they implemented the chord identification method.

Here are some pointers for additional online resources, most articles require purchase, but online search and abstracts are generally available:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.