# Tempo and Metrical Analysis by Tracking Multiple Metrical Levels Using Autocorrelation
## 3 Proposed Method
### Tracking the Metrical Grid
#### 3.3.2 Procedure
* Similarly, for all the faster metrical layers, \(i\) we find those that have a theoretical pulse lag that is in integer ratio with the peak lag: \[\min\left(\frac{t}{\tau_{i}(n)}\text{ mod }1,1-\left(\frac{t}{\tau_{i}(n)} \text{ mod }1\right)\right)<\epsilon\] (15)
* If we have found both a slower and a faster period, we select the one with stronger periodicity score. * This metrical layer, of index \(i_{R}\), will be used as reference onto which the new discovered metrical layer is based. The new metrical index \(i^{*}\) is defined as: \[i^{*}=i_{R}*\left[\frac{t}{\tau_{i}(n)}\right]\] (16)  
Finally, if the strongest periodicity peak in the given time frame \(n\) is strong enough (with periodicity score above a certain threshold \(\theta\)) and is not associated with any period of the metrical grid(s) currently active, a new metrical grid is created, with a single metrical period (with \(i=1\)) related to that peak. All active metrical grids are tracked in parallel. A metrical grid stops being further extended whenever there in no peak in the given frame that can extend any of the dominant periods. Mechanisms have also been conceived to fuse multiple grids whenever it turns out that they belong to a single hierarchy. The global tempo associated with the metrical grid is updated based on the actual lags measured along the different metrical periods in the current frame \(n\). For each metrical period \(i\) and for the peak lag \(t_{i}\) associated with it, we obtain a particular estimation of the global lag (i.e., the lag at periodicity index 1), namely \(\frac{t_{i}}{t}\). We can then obtain a global estimation of the global lag by averaging these tempo estimations at different periods, using as a weight the autocorrelation score \(s_{i}\) of those peaks:  
\[d_{2}(t,i)=|t-\tau_{i}(n)| \tag{9}\]0  
Not all metrical periods are considered, because there can be a very large number of those, and many of the higher periods provide only redundant information that tends to be unreliable. For that reason, a selection of the most important--or _dominant_--metrical periods is performed, corresponding to the set \(D\) in previous equation. Each time a new metrical grid is initiated, the first metrical period (\(i=1\)) is considered to be dominant. Any other metrical period \(i\) becomes dominant whenever the last peak integrated is strong (i.e., with an autocorrelation score higher than a given threshold \(\theta\)) and if the reference metrical period upon which layer \(i\) is based is also dominant. The actual updating of the global tempo is somewhat more complex than the description given in the previous paragraph, because we consider the evolution of the tempo from the previous frame to the current frame, and limit the amplitude of the tempo change up to a certain threshold. This enables a certain kind of \"inertia\" to the model such that unrelated periodicities in the signal will not lead to sharp discontinuities in the tempo curves. Values used for some parameters defined in this section: \(\delta=0.07\), \(\epsilon=0.2\), \(\theta=0.15\).