<p>First, I note you are using FastDTW, but &quot;FastDTW is approximate and Generally Slower than the Algorithm it Approximates.&quot;</p>
<p>Before you answer the question in code, you need to answer the question semantically.
Consider the following two cases</p>
<ol>
<li><p>A= CAT and B = CAAAT
In this case, you can interpolate the time series to the same length</p>
</li>
<li><p>C = CAT and B = CATXXXX
In this case, you need to use open ended DTW [b]</p>
</li>
</ol>
<p>[a]<a href="https://arxiv.org/abs/2003.11246" rel="nofollow noreferrer">https://arxiv.org/abs/2003.11246</a>
[b] <a href="https://www.cs.unm.edu/%7Emueen/DTW.pdf" rel="nofollow noreferrer">https://www.cs.unm.edu/~mueen/DTW.pdf</a></p>
Dynamic time warping for a long time series signal with a shorter reference time series signal in fastdtw python package
<p>I have the two following time series signals:</p>
<pre><code>import numpy as np
x = np.cos(2*np.pi*np.power(3*(np.linspace(1, 1000, 1000))/1000, 2))
y = np.cos(2*np.pi*(9*(np.linspace(1, 399, 399))/400))
</code></pre>
<p>so <code>x</code> and <code>y</code> are in shape <code>(1000,)</code> and <code>(399,)</code>, respectively. I want to do two following dynamic time warping with <code>fastdtw</code> python package:</p>
<ol>
<li><code>x</code> is the reference signal (the longer signal):</li>
</ol>
<p>I want to map <code>y</code> into the longer signal shape (<code>x.shape=(1000,)</code>). It's done by the following code:</p>
<pre><code>from scipy.spatial.distance import euclidean
from fastdtw import fastdtw
distance, path = fastdtw(x, y, dist=euclidean) # x:reference signal
inds = [ind[1] for ind in path]
y_warped = y[inds]
</code></pre>
<p>in this case, the above code works correctly and maps <code>y:(399,)</code> into the <code>y_warped:(1000,)</code>.</p>
<ol start="2">
<li><code>y</code> is the reference signal (the shorter signal):</li>
</ol>
<p>I want to map <code>x</code> into the shorter signal shape (<code>y.shape=(399,)</code>).</p>
<pre><code>from scipy.spatial.distance import euclidean
from fastdtw import fastdtw
distance, path = fastdtw(y, x, dist=euclidean) # y:reference signal
inds = [ind[1] for ind in path]
x_warped = x[inds]
</code></pre>
<p>but in this case, I get <code>x_warped</code> in the same shape as <code>x</code>, but I expect to get <code>x.shape=(399,)</code>. How can I warp a longer signal into a shorter signal?
Thanks in advance!</p>