## 2 Materials and Methods
### A Hardware-Oriented Algorithm for Real-Time Music Key Signature Recognition  
The study discussed in this paper shows that it is possible to determine the kind of key signature associated with a given piece of music based on the analysis of the music signature. This enables the algorithmic generation of the musical notation using the data represented in the MIDI format. The proposed herein idea of determining the key signature is strictly related to the shape analysis of the music signature corresponding to a given piece of work. Each angular sector of the circle of fifths is bound to a particular key signature, featuring the major and minor tonalities of a musical piece. For the sake of brevity, however, we will limit our discussion to the major tonality. Let us consider an example of the ordered tones of the D major scale, i.e., D--E--F\({}_{\text{F}}^{a}\)--G--A--B--C--i----D. In this case, the tones are localized on the right side of the directed axis D\(\flat\to\text{G}\), as well as on the axis itself (applicable are the rules of enharmonic equivalence, i.e., C\({}_{\text{F}}^{a}\equiv\text{D}\flat\) ). The directed axis D\(\flat\to\text{G}\) is therefore associated with the D major scale, hence the corresponding key signature is comprised of two sharps. It is easy to notice that in the circle of fifths the key signature related to the directed axis D\(\flat\to\text{G}\) is obtained by rotating this axis one position in the clockwise direction (Figure 3). In a similar fashion, the directed axis pointing in the opposite direction, i.e., G\(\flat\to\text{D}\) can be associated with the key signature comprised of four flats (Figure 3). Each directed axis Y \(\to\) Z can be associated with a particular key signature--as listed in Table 2. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Directed Axis** & **Number of Sharps (f)** & **Number of Flats (\(\flat\))** \\ \hline B \(\to\) F & 0 & 0 \\ F\({}_{\text{F}}^{a}\to\) C & 1 & - \\ D\(\flat\to\) G & 2 & - \\ A\(\flat\to\) D & 3 & - \\ E\(\flat\to\) A & 4 & - \\ B\(\flat\to\) E & 5 & - \\ F \(\to\) B & 6 or & 6 \\ C \(\to\) F\({}_{\text{F}}^{a}\) & - & 5 \\ G \(\to\) D\(\flat\) & - & 4 \\ D \(\to\) A\(\flat\) & - & 3 \\ A \(\to\) E\(\flat\) & - & 2 \\ E \(\to\) B\(\flat\) & - & 1 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The key signatures (sharps and flats) associated with the directed axes inscribed in the circle of fifths. Figure 3: The directed axes D\(\flat\to\text{G}\) and G \(\to\text{D}\flat\) inscribed in the circle of fifths. As we can see, the process of the key signature recognition, allowing for the automatic generation of musical notation, can be realized based on the analysis of the music signature. The proposed algorithm comprises of the following steps:  
1. Generation of the music signature corresponding to a given fragment of a considered piece of music: 1. For a given fragment of a music piece, calculate the multiplicities of the individual pitch classes: C, D\({}_{\text{D}}\), D, E\({}_{\text{D}}\), E, F, F\({}_{\text{F}}\), G, A\({}_{\text{D}}\), A, B\({}_{\text{D}}\), and B. 2. Determine the maximum value of the multiplicities obtained in (1a): \[X_{max}=max\ \{x_{C},\ x_{C\text{f}/D_{\text{D}}},\ x_{D\text{f}/E\text{v}},\ x_{E},\ x_{F},\ x_{F\text{f}/G\text{v}},\ x_{G},\ x_{G\text{f}/A\text{v}},\ x_{A},\ x_{A\text{f}/B\text{v}},\ x_{B}\}\] 3. Create the vector of the normalized pitch classes: \[\mathbf{K}=\left[k_{A}\ k_{D}\ k_{G}\ k_{C}\ k_{F}\ k_{B\text{v}}\ k_{E\text{v}}, \ k_{A\text{v}}\ k_{D\text{v}}\ k_{F\text{g}}\ k_{B}\ k_{E}\right]\] 4. Create the music signature based on the vector K obtained in (1c). 2. Finding of the main directed axis Y \(\rightarrow\) Z, given the musical signature created in the previous step (1): 1. Determine the characteristic values [Y \(\rightarrow\) Z] for all directed axes inscribed in the circle of fifths. 2. Find the maximum characteristic value [Y \(\rightarrow\) Z], which indicates the main directed axis of the music signature. 3.