Skip to contents

Computes the dynamic time warping distance between a signal and each of its modes.

Usage

measureDTW(signal, modes)

Arguments

signal

Non-empty finite numeric vector without dim.

modes

Finite numeric matrix with one row per sample of signal and one column per mode. Attributes other than dim do not reach the outputs.

Details

With the local cost \(d_{ij} = (x_i - c_j)^2\) and the accumulation $$G_{ij} = d_{ij} + \min\{G_{i-1,j-1}, G_{i-1,j}, G_{i,j-1}\},$$ \(G_{00} = 0\) and infinite cost outside the matrix, the distance is \(\sqrt{G_{NN}}\), without normalization by the length of the path. The work grows with the square of the number of samples for each mode.

Value

Numeric vector with one distance per mode, in the units of the signal.

Examples

Time <- seq_len(1000) / 1000
Tones <- cbind(cos(2 * pi * 2 * Time), 0.25 * cos(2 * pi * 24 * Time),
               0.0625 * cos(2 * pi * 288 * Time))
measureDTW(signal = rowSums(Tones), modes = Tones)
#> [1]  4.012609 17.006447 21.428475