# Tempo and Metrical Analysis by Tracking Multiple Metrical Levels Using Autocorrelation
## 3 Proposed Method
### Tracking the Metrical Grid
#### 3.3.2 Procedure  
The theoretical periods are inferred based on the measured periods, as we will see in Equation (17). The integration of peak into the metrical grids is done in three steps, related to the extension of metrical layers already registered, the creation of new metrical layers and finally the initiation of new metrical grids. In the following the three steps are presented successively. For each successive time frame \(n\), peaks in the periodicity function (as specified in Section 3.2) are considered in decreasing order of periodicity score. This is motivated by the observation that strongest periodicities, corresponding generally to important metrical levels, tend to show a more stable dynamic evolution and are hence more reliable guides for the tracking of the metrical structure. Weaker autocorrelation peaks, on the contrary, may sometimes result from a mixture of underlying local periodicities, hence might tend to behave more erratically. For each frame, the strongest peaks first considered enable a first estimation of the tempo \(T_{1}(n)\) at that frame, which will be used as a reference when integrating the weaker periodicities. Each peak related to a period (or lag) \(t\) is tentatively mapped to one existing metrical layer \(i\). We consider two ways to estimate the distance between current peak \(t\) and a given metrical layer \(i\): either by comparing current peak lag \(t\) with the actual lag of the peak associated with this metrical layer \(i\) at previous frame \(n-1\):  
\[d_{1}(t,i)=|t-t_{i}(n-1)| \tag{8}\]  
or by comparing current peak lag \(t\) with the theoretical lag at that metrical layer \(i\) knowing the global tempo:  
\[d_{2}(t,i)=|t-\tau_{i}(n)| \tag{9}\]  
For low lag values, small difference in time domain can still lead to importance difference in tempo domain. For that reason, an additional distance is considered, based on tempo ratio:  
\[d_{3}(t,i)=\left|\log_{2}\left(\frac{t}{\tau_{i}(n)}\right)\right| \tag{10}\]  
The distance between current peak \(t\) and a given metrical layer \(i\) can be then considered to be the minimum of the two distances on the time domain:  
\[d(t,i)=\min(d_{1}(t,i),d_{2}(t,i)) \tag{11}\]  
and the closest metrical layer \(i^{*}\) can be chosen as the one with minimal distance:  
\[i^{*}=\operatorname*{arg\,min}_{i}d(t,i) \tag{12}\]Figure 6: Autocorrelation-based periodogram with tracking of the metrical structure for the first 140 s of a performance of the first movement of [PERSON]’s _Brandenburg Concrete No. 2 in F major_, BWV 1047. Each metrical layer is indicated by a line of crosses extending from left to right, and preceded by a number indicating the index of the metrical layer. When the line is interrupted at particular temporal regions, the remaining dotted line represents the temporal tempo at that layer. Metrical levels are shown in black, while other metrical layers are shown in gray. See the text for further explanation. If this metrical period has already been assigned to a stronger peak in current frame \(n\), this weaker peak \(t\) is discarded for any further analysis. In other cases, its integration to the metrical period \(i^{*}\) is carried out if it is close enough, both in time domain (\(d(t,i)\)) and in tempo domain (\(d_{3}(t,i)\)):  
\[d(t,i)<\delta\text{ and }d_{3}(t,i)<\epsilon \tag{13}\]  
In a second step, we check whether the periodicity peak triggers the addition of a new metrical layer in that metrical grid:  
* For all the slower metrical layers \(i\), we find those that have a theoretical period that is in integer ratio with the peak lag \(t\): \[\min\left(\frac{\tau_{i}(n)}{t}\text{ mod }1,1-\left(\frac{\tau_{i}(n)}{t} \text{ mod }1\right)\right)<\epsilon\] (14) where \(\epsilon\) is set to.02 if no other stronger peak in the current time frame \(n\) has been identified with the metrical grid, and else to.1 in the other case. If we find several of those slower periods in integer ratio, we select the fastest one, unless we find a slower one with a ratio defined in Equation (14) that would be closer to 0.