# Enhancement of Conventional Beat Tracking System Using Teager-Kaiser Energy Operator
## 2 Dataset and Methods  
### Onset Detection  
Usually, onset detection algorithms use some pre-processing steps to reduce redundant information and to improve detection accuracy. In this study, we propose a new method of pre-processing based on the TKEO. The TKEO (\(\Psi\{s(t)\}\)) is a nonlinear energy operator that can be calculated using the following formula:  
\[\Psi\{s(t)\}=\left(\frac{\mathrm{d}s(t)}{\mathrm{d}t}\right)^{2}-s(t)\cdot\frac{ \mathrm{d}^{2}s(t)}{\mathrm{d}t^{2}}, \tag{1}\]  
i.e., we compute the square of the first derivative (which denotes the square of the rate of signal change) and then subtract the signal multiplied by the second derivative (which determines the acceleration at that point). We speed up the temporal changes of the signal module by removing the slow changes because we consider the rate of change. It is known that the faster the time changes, the higher the frequency components appear in the spectrum. By taking the first derivative into account, we increase the magnitude of higher frequencies of the spectrum [22]. In our discrete approach, we firstly downsample the input signal \(x[n]\) to 22,050 Hz. Next, we apply the TKEO, i.e., we calculate the corresponding discrete non-causal form:  
\[\Psi[x[n]]=x^{2}[n]-x[n-1]\cdot x[n+1], \tag{2}\]  
which creates an energy profile of the given audio sample. In comparison to the conventional squared energy operator, the TKEO takes into account also signal's frequency [23] and it can have negative values, e.g., see Figure 1. Differences in spectra for the same audio track (clarinet recording) are shown in Figure 2. It is interesting how the dominant spectral components have changed--the clarinet has naturally strong odd harmonics, but the TKEO has changed their magnitude. Figure 1: Original signal and the same signal after application of the TKEO pre-processing. In the following step, we calculate the onset envelope using the perceptual model. We use Short-Time Fourier Transform (STFT) with Hann window (hop-factor: 512 samples) and then the conversion to the perceptual model with log-power mel-frequency representation: 120 mel bands, max frequency at 10 kHz and min frequency at 27.5 Hz. We get the matrix \(|X[m,k]|\), where \(m\) denotes the index of the frame and \(k\) the frequency bin or index of the mel band. These settings were inspired by SuperFlux calculation [3]. In the next step, we calculated the spectral flux. The basic version of spectral flux is defined as the \(l_{1}\)-norm of consecutive frames [24]:  
\[SF[m]=\frac{1}{K}\sum_{k=0}^{K-1}H(|X[m+1,k]|-|X[m,k]|), \tag{3}\]  
for \(m=0,1,2,\ldots,M-2\), where \(H[x]=(x+|x|)/2\) is the half-wave rectifier, \(M\) is the number of frames, and \(K\) is half of STFT frequency bins, or number of mel bands. A half-wave rectifier is used to set negative values to zero and positive differences are summed across all frequency bands. Spectral flux gives us information, how energy in spectra changes in time. Finally, a peak-picking function is applied (default LibROSA settings) to identify time positions of onsets and therefore new tones in the audio signal. An example of this system based on the mel-frequency representation, but without the use of TKEO, is shown in Figure 3. It represents a solo clarinet part. The onset function detected many false peaks and marked positions, where tones were not played. For comparison, Figure 4 shows the same signal, but in this case, pre-processed by the TKEO. The peak-picking function now marked all real onsets with better accuracy and without any false positive detection. The colorbar in dB (Figure 5) is presented separately because of the proper alignment of a spectrogram and onset function but is the same for all spectrograms (produced by matplotlib package) in this paper. Figure 2: Spectrograms of the same clarinet recording—the second one is using a TKEO step. Figure 4: Spectrogram and onset detection function for a solo clarinet with the TKEO. Figure 5: Colorbar.