# A Hardware-Oriented Algorithm for Real-Time Music Key Signature Recognition
## 1 Introduction  
The tonality of musical pieces is inextricably linked to the musical notation, in which the key signatures play an important role. Advances in musical instrumentation enabled automation of the process of musical notation generation based on the analysis of a recorded piece of music, e.g., some of the modern musical instruments provide this kind of functionality, enabling the presentation of the generated musical notation on the built-in LCD screen. The optimal solution, however, would be the generation of such data in a real-time manner, which inherently requires a time-efficient determination of the key signatures defining the way in which particular notes are presented. The following question arises: how to effectively, i.e., in real-time and based on a few sounds, determine the key signature of a given piece of music? The method proposed in this paper seems to be a promising solution for this problem. The authors of this paper started their search for an effective algorithm enabling recognition of the key signature corresponding to a given piece of music as a result of their experiences with electronic keyboard instruments providing the functionality of a real-time presentation of the musical notation representing the currently played song. Numerous experiments have shown imperfections of the algorithms behind such functionalities--even in the case of advanced professional devices. The approach presented in this paper could potentially be applied to improve the effectiveness of the automated generation of music notation in terms of the music key signature recognition. It is worth emphasizing that the proposed algorithm is oriented towards hardware implementation, as there are nosophisticated computations involved. The music key signature can be detected based on just a few initial notes of a given composition. In the case of misclassification, the decision can be corrected and the already generated music notation retranscribed. There are a number of tonal models one can find in the literature these days. Among them exists a variety of spiral array models [1; 2; 3], which constitute the expansion of the harmonic networks first described by [PERSON]. Such spiral models can be used to detect the pitch classes of musical pieces; however, this task requires a series of complicated calculations [4; 5]. Generally, the tonal analysis comes down to the determination of the chords occurring in the analyzed pieces of music [4; 6; 7; 8; 9; 10] and is deeply rooted in the theoretical foundations of music. The chords appearing in the musical works are sometimes pictured in graphical form [11], making it possible to visualize emotions associated with the music [12; 13] or to picture the content of musical compositions [12; 13; 14]. Tonal analysis laid the foundations for the design of algorithmic music composition systems [10; 15; 16], as well as the algorithmic methods for the recognition of musical genres [17; 18; 19; 20]. The data to be analyzed can be derived from MIDI files, for cases where notes are encoded in a symbolic manner [21], or from audio files, which contain digital, sampled versions of the acoustic signals. Particularly noteworthy are the digital signal processing algorithms enabling data acquisition from audio files [4; 9; 22; 23; 24]. Despite significant achievements in the field of digital signal processing, however, the problem of effective, real-time algorithmic generation of musical notation has not yet been solved. Nowadays, the computationally simplest music tonality detection algorithms are mostly based on various types of music key profiles [25; 26; 27; 28; 29; 30; 31; 32], which can be obtained as a result of an expert assessment [28; 30], statistical analysis of a number of musical samples [25], or the outcome of an advanced modelling implementing probabilistic reasoning [31; 32].