Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Distance between signals using dynamic time warping

`dist = dtw(x,y)`

```
[dist,ix,iy]
= dtw(x,y)
```

`[___] = dtw(x,y,maxsamp)`

`[___] = dtw(___,metric)`

`dtw(___)`

stretches
two vectors, `dist`

= dtw(`x`

,`y`

)`x`

and `y`

, onto
a common set of instants such that `dist`

, the
sum of the Euclidean distances between corresponding points, is smallest.
To stretch the inputs, `dtw`

repeats each element
of `x`

and `y`

as many times
as necessary. If `x`

and `y`

are
matrices, then `dist`

stretches them by repeating
their columns. In that case, `x`

and `y`

must
have the same number of rows.

`[`

returns
the common set of instants, or `dist`

,`ix`

,`iy`

]
= dtw(`x`

,`y`

)*warping path*,
such that `x`

(`ix`

) and `y`

(`iy`

)
have the smallest possible `dist`

between them.

The vectors `ix`

and `iy`

have
the same length. Each contains a monotonically increasing sequence
in which the indices to the elements of the corresponding signal, `x`

or `y`

,
are repeated the necessary number of times.

When `x`

and `y`

are matrices, `ix`

and `iy`

are
such that `x`

`(:,ix)`

and `y`

`(:,iy)`

are
minimally separated.

`dtw(___)`

without output arguments
plots the original and aligned signals.

If the signals are real vectors, then the function displays the two original signals on a subplot and the aligned signals in a subplot below the first one.

If the signals are complex vectors, then the function displays the original and aligned signals in three-dimensional plots.

If the signals are real matrices, then the function displays the original and aligned signals as images.

If the signals are complex matrices, then their real and imaginary portions appear in the top and bottom half of each image.

[1] Sakoe, Hiroaki, and Seibi Chiba. “Dynamic Programming
Algorithm Optimization for Spoken Word Recognition.” *IEEE ^{®} Transactions
on Acoustics, Speech, and Signal Processing*. Vol. ASSP-26,
No. 1, 1978, pp. 43–49.

[2] Paliwal, K. K., Anant Agarwal, and Sarvajit
S. Sinha. “A Modification over Sakoe and Chiba’s Dynamic
Time Warping Algorithm for Isolated Word Recognition.” *Signal
Processing*. Vol. 4, 1982, pp. 329–333.

`alignsignals`

| `edr`

| `finddelay`

| `findsignal`

| `xcorr`