# Constraint-Based Time-Scale Modification of Music Recordings for Noise Beautification
## 3 Constraint-Based Alignment Task as Optimization Problem  
In this section, we formalize our constraint-based alignment task. Recall that we are given two signals: the MRI noise signal to be superimposed and the music signal to be adapted. In this context, the noise signal serves as reference that defines the constraints, whereas the music signal serves as source that is to be modified according to the constraints. In the following, the time axis of the noise signal is referred to as _reference_ time axis, while the time axis of the music signal is called the _source_ time axis. In both cases, we are given a finite set of specified time points, which we also call _alignment points_ (APs). In the case of the reference time axis, let \(M\in\mathbb{N}\) be the number of APs and  
\[\mathcal{R}:=\{r_{1},r_{2},...,r_{M}\} \tag{1}\]be the set of APs with \(r_{1}<r_{2}<\ldots<r_{M}\). Each \(r_{m}\in\mathbb{R}\) is given in seconds, \(m\in[1:M]:=\{1,2,...,M\}\). Similarly, in the case of the source time axis, let \(N\in\mathbb{N}\) be the number of APs and  
\[\mathcal{S}:=\{s_{1},s_{2},...,s_{N}\} \tag{2}\]  
be the set of APs with \(s_{1}<s_{2}<\ldots<s_{N}\).  
Based on these notions, our overall goal is to temporally modify the source signal such that the reference APs are superimposed by suitable source APs. To model an alignment between reference and source APs, we introduce a _mapping function_  
\[\varphi:\mathcal{R}\rightarrow\mathcal{S} \tag{3}\]  
which assigns a source AP \(\varphi(r_{m})\in\mathcal{S}\) to each of the reference APs \(r_{m}\in\mathcal{R}\), \(m\in[1:M]\). Furthermore, when modifying the source signal, we only want to apply local time-scale modifications where the temporal order of time events is preserved. Therefore, we require a _monotonicity condition_ expressed by  
\[\varphi(r_{m})<\varphi(r_{m+1}) \tag{4}\]  
for \(m\in[1:M-1]\). In the following we say that a mapping function is _valid_ if it fulfills the monotonicity condition of Equation (4). As indicated by Figure 2, there are many possible valid mapping functions. More precisely, the number of valid mapping functions is \((^{N}_{M})\). This leads to the questions which of these mapping functions are \"suitable\" and how to find them.  
In our application scenario, we want to temporally modify the source signal by applying non-linear TSM. In the case of a music signal with a more or less steady beat, a global change in tempo may be acceptable. However, strong local changes in the tempo may result in an unrhythmical, thus unpleasant version. Motivated by this observation, we are looking for mapping functions with as little as possible local fluctuations. Intuitively, we model this requirement by introducing an error measure that depends on second-order derivatives. Based on the discrete nature of our mapping problem, we define an error function \(\epsilon(\varphi)\) for a given valid mapping function \(\varphi\) as follows:  
\[\delta_{1}(r_{m}) := \frac{\varphi(r_{m+1})-\varphi(r_{m})}{r_{m+1}-r_{m}}\quad\text{ for }\quad m\in[1:M-1], \tag{5}\] \[\delta_{2}(r_{m}) := \frac{\delta_{1}(r_{m+1})-\delta_{1}(r_{m})}{r_{m+1}-r_{m}}\quad \text{for }\quad m\in[1:M-2],\] (6) \[\epsilon(\varphi) := \sum_{m=1}^{M-2}|\delta_{2}(r_{m})|. \tag{7}\]  
Obviously, there are many more ways to define suitable error measures, e.g., using the sum over squared \(\delta_{2}\)-values or the maximum over all \(\delta_{2}\)-values. The definition in Equation (7) should be regarded as one possible choice; the subsequent considerations can be applied to other error measures as well. Figure 2 illustrates the definition of our error measure by means of two examples. Based on the error measure, an _optimal_ mapping function is defined to be  
\[\varphi^{*}:=\text{argmin}\left\{\epsilon(\varphi)\ \mid\ \varphi\text{ is a valid mapping function}\right\}. \tag{8}\]  
Note that, in general, there may be more than one optimal valid mapping function.