# A Hardware-Oriented Algorithm for Real-Time Music Key Signature Recognition
## 4 Discussion  
The algorithm presented in this paper provides the means for an effective, real-time recognition of the key signature associated with a given piece of music, based on the analysis of a very small number of initial notes. In essence, the method boils down to the classification of the music signature represented as a set of vectors inscribed in the circle of fifths. It is worth emphasizing that the idea presented herein can be very easily implemented in hardware as an SoC (System on Chip) solution. This is because the main directed axis of the music signature is determined using a small number of addition and comparison operations. In light of the above, the developed algorithm seems to be more attractive than the algorithms based on tonal profiles--which inherently require computation of many correlation coefficients [25; 26; 28; 29; 30; 31; 32]--and many other, significantly more complex methods [5; 6; 10; 18; 21; 23; 24; 33]. Additionally, the proposed algorithm has a unique feature of a fast decision-making process and high stability of its outcome. In many cases, the correct music key signature can be found based on just a few notes, e.g., after playing the first chord. It is also worth noting that the algorithm can be used in a continuous fashion, even after finding the matching music key signature. In such a case, the key signature will be corrected as soon as a better match is detected. It becomes clear when looking at the music signatures corresponding to a fragment of the [PERSON]'s Prelude Op. 28, No. 21 (Figure 12), obtained for different number of analyzed notes--starting with the first two notes. Figure 11: Comparison of the efficacies \(\delta\), defined as the percentage of the music pieces for which the key signature was correctly recognized, obtained for the proposed key signature recognition algorithm and the algorithm implemented in an electronic music instrument, based on [PERSON]’s preludes, etudes, and nocturnales. Figure 12: Music notation representing a fragment of [PERSON]’s Prelude Op. 28, No. 21. Analyzing the music notation shown in Figure 12, one can easily notice that the bass cleft part is dominated by double sounds. Table 3 presents the lengths of the pitch-class vectors making up the music signatures corresponding to different numbers of notes taken into account during the analysis. The music signatures themselves are shown in Figure 13.  
Figure 13: Music signatures corresponding to the fragment of the composition presented in Figure 12, obtained for 2, 3, 5, 7, 9, 11, 13, and 15 notes; the red arrow represents the main directed axis. \begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline \multicolumn{2}{c}{**Number of Notes:**} & **2** & **3** & **5** & **7** & **9** & **11** & **13** & **15** \\ \hline \multirow{8}{*}{**C**} & C & & & & & & 0.29 & 0.29 & 0.25 \\  & C\(\sharp\)/D\(\flat\) & & & & & 0.17 & 0.14 & 0.29 & 0.38 \\  & D\(\sharp\)/E\(\flat\) & & & & 0.2 & 0.17 & 0.14 & 0.14 & 0.13 \\  & E & & & 0.25 & 0.2 & 0.17 & 0.14 & 0.14 & 0.13 \\  & F & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\  & F\(\sharp\)/G\(\flat\) & & & & & & & & \\  & G & & & 0.25 & 0.2 & 0.17 & 0.14 & 0.14 & 0.13 \\  & G\(\sharp\)/A\(\flat\) & & & & & 0.2 & 0.17 & 0.14 & 0.14 & 0.13 \\  & A & & & & 0.2 & 0.17 & 0.14 & 0.14 & 0.13 \\  & A\(\sharp\)/B\(\flat\) & 1 & 0.33 & 0.25 & 0.2 & 0.33 & 0.29 & 0.43 & 0.38 \\  & B & & & & & & & & \\ \hline \hline \end{tabular}
\end{table} 
Table 3: The lengths of pitch-class vectors making up the music signatures corresponding to the music notation shown in Figure 12, obtained for different numbers of initial notes. Table 4 shows the results of the key signature recognition obtained using the proposed algorithm, as well as the algorithms based on the following tonal profiles: Krumhansl-Kessler, Temperley, and Albrecht-Shanahan. One can clearly see how many notes it takes for each algorithm to make a decision, how the decision changes as the number of the analyzed notes increases, and how stable it is.