I am trying to come up with an algorithm that gets the proper chord name given certain Notes, user may or may not inform which from the notes is the root.

I suppose that the process in recognizing a chord name differs for how many notes are given, so maybe there should be an algorithm for triads, one for 4 note chords, and another for 5+ notes? Or is there a general way of approaching this? maybe chord patterns?

  • 1
    You could transform every pitch class set to its prime form, and then use that as a key for a chord dictionary. This answer contains information about how to find the prime form: music.stackexchange.com/questions/82120/… Also check out en.wikipedia.org/wiki/Set_theory_(music) Commented Jul 20, 2019 at 18:14
  • 1
    What in your opinion is a proper chord name? Even the proper chord name...? Can you give an example of an improper chord name? Commented Jul 20, 2019 at 21:11
  • @YourUncleBob this is pretty interesting, I did not knew about Set Theory, I think I'll get a book. Commented Jul 21, 2019 at 21:17
  • Actually, the prime form of a pitch-class set in set theory is found through rotation and mirroring, which means e.g. that a major and minor triad both have prime form (0,3,7). For your use case, you should use only rotation, not mirroring, so that you get (0,4,7) for major triads. Commented Jul 21, 2019 at 21:38
  • You haven't said what your input or output data will be. Commented Jul 22, 2019 at 13:41

1 Answer 1


Some chords (at least in Common Practice Period harmony) cannot be named out of context. Some trivial examples: F-Ab-Db-F is a Db major chord in and of itself but if resolved to G, it may be a Neapolitan Sixth.

The collection: Ab-C-Eb-F# is a German Sixth if resolved to G-C-E-G thence to G-B-D-G(or F). It's a dominant seventh if resolved to Db-F-Ab or perhaps a tritone substitution. Possibly using F# for the German Sixth and Gb for the dominant seventh helps however composers do approach the chord as a German Sixth and resolve it as dominant seventh and vice versa.

Some ambiguities are matters of taste. In San Antonio Rose (the only song I can think of quickly that does this) the opening chords are Bb-Eb-C7-F7; when I play this piece or other similar pieces I think I-IV-II7-V7 (especially as vocalists may want me to transpose) but while laying out a chord scheme during composing, I think I-IV-V7/V-V7 which shows the structure and would explain a Bb-Eb-C7-d-g-c6-F7-Bb as a secondary dominant resolving on a deceptive cadence followed by a cycle of fifths.

One thing you could do (to get back to the original question) is to rearrange the note collection to have as many thirds as possible and name the chord from there. Moving the notes around should indicate which inversion one has. D-F-G-B can be arranged to be G-B-D-F with a maor third followed by by three minor thirds.

  • 1
    Maximizing the number of thirds makes sense to me, thanks I'll try it this way. Commented Jul 21, 2019 at 21:24
  • N6 versus Db is analysis (identifying function in a key) versus naming (identifying root and chord quality.) Commented Jul 22, 2019 at 13:39

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.