# A Hardware-Oriented Algorithm for Real-Time Music Key Signature Recognition
## 3 Results  
In order to verify the effectiveness of the proposed key signature finding algorithm, a number of experiments, based on a music benchmark set comprised of [PERSON]'s preludes and fugues (Das Wohltemperierte Klavier--book I and book II) and [PERSON]'s preludes, etudes, and nocturnales, were carried out. At first, the number of notes needed to determine the key signature had to be selected. Initially, for each of the analyzed pieces of music, this number was set to 2. If it was not possible to determine the key signature using just two notes, the analyzed fragment was extended to three, four, five and even more notes (if needed). If the analyzed fragment had had a multi-note chord at the beginning, the analysis was started using the number of notes comprising that chord, and then, if needed, the number was increased. The results of the conducted analysis are shown in Figures 6 and 7. In the case of [PERSON]'s preludes for book I, the key signatures were correctly identified for 23 pieces (96%). The developed algorithm did not indicate the right key signature for only 1 piece (Prelude No. 24). The determination of the main directed axis A\(\flat\to\) D was in that case possible for a fragment containing as many as 8 notes. The corresponding key signature (associated with the directed axis A\(\flat\to\) D) comprised of 3 sharps, which is one sharp more than the original tonality of the examined piece. It is worth emphasizing that the key signature evaluation process for [PERSON]. [PERSON]'s preludes for book I was based on the analysis of very short fragments of music, containing 3.35 notes on average. For 5 preludes (21%) as little as 2 notes were sufficient. All of these preludes were in the major scale, and the two analyzed notes corresponded to the first and third degrees of that scale. Figure 4: The main directed axis D\(\flat\to\) G and its corresponding key signature comprised of two sharps (2*). Figure 5: Musical notation from Figure 1, supplemented with the key signature determined using the proposed algorithm. In the case of [PERSON]'s preludes for book II, the key signatures were correctly identified for 22 pieces (92%). The proposed algorithm did not indicate the right key signature for 2 pieces--Preludes No. 6 and No. 8. For these preludes, it was possible to determine the main directed axes via an analysis of fragments of music containing 3 notes. Unfortunately, additional chromatic symbols, which were present in the considered fragments, pointed to different tonalities. In general, the key signature evaluation process for [PERSON]'s preludes for book II was based on the analysis of fragments of music containing 4.72 notes on average. Figure 6: The number of notes needed to determine the key signatures of the analyzed fragments of music by [PERSON]: \(\blacklozenge\)correct recognition of the key signature; x—incorrect recognition of the key signature. Much worse results were observed for the collection of [PERSON]'s fugues. For the [PERSON]'s fugues for book I, misclassification occurred in as many as nine cases (38%)--7 fugues in the minor scale and 2 fugues in the major scale. The encountered difficulties in determining the key signatures can be associated with the specific nature of the analyzed works. It needs to be emphasized that sometimes the tonality indicated by the initial sounds differs from the tonality of the whole piece of music, hence it can be very difficult or even impossible to clearly determine the key signature by analyzing just a couple of initial notes. In such cases, the musical notation usually contains additional chromatic symbols. This was the case for Fugues No. 2, 4, 12, 16, 18, and 20. Application of the developed algorithm to 15 of [PERSON]'s fugues from book I resulted in correctly classified key signatures. On average, the correct classification of the key signature required the analysis of fragments comprised of the initial 3.6 notes. In the case of [PERSON]'s fugues from book II, the key signatures were correctly identified for 16 pieces (67%).