Note: This page has been translated by MathWorks. Please click here

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

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

Estimate delay(s) between signals

`D = finddelay(X,Y)`

D = finddelay(...,maxlag)

`D = finddelay(X,Y)`

, where `X`

and `Y`

are
row or column vectors, returns an estimate of the delay `D`

between `X`

and `Y`

,
where `X`

serves as the reference vector. If `Y`

is
delayed with respect to `X`

, then `D`

is
positive. If `Y`

is advanced with respect to `X`

,
then `D`

is negative. Delays in `X`

and `Y`

can
be introduced by prepending zeros.

`X`

and `Y`

need not be exact
delayed copies of each other, as `finddelay(X,Y)`

returns
an estimate of the delay via cross-correlation. However this estimated
delay has a useful meaning only if there is sufficient correlation
between delayed versions of `X`

and `Y`

.
Also, if several delays are possible, as in the case of periodic signals,
the delay with the smallest absolute value is returned. In the case
that both a positive and a negative delay with the same absolute value
are possible, the positive delay is returned.

`D = finddelay(X,Y)`

, where `X`

is
a matrix of size * M_{X}*-by-

`Y`

is a
matrix of size `D`

of
estimated delays between each column of `X`

and the
corresponding column of `Y`

. With this usage the
number of columns of `X`

must be equal to the number
of columns of `Y`

(i.e., `D = finddelay(...,maxlag)`

,
uses `maxlag`

as the maximum correlation window size
used to find the estimated delay(s) between `X`

and `Y`

.
The usage of `maxlag`

is detailed in the table below.

By default, `maxlag`

is equal to *max( L_{X},L_{Y}) – 1* for two
vector inputs (where

`X`

and `Y`

, respectively), `maxlag`

is
input as `[]`

, it is replaced by the default value.
If any element of `maxlag`

is negative, it is replaced
by its absolute value. If any element of `maxlag`

is
not integer-valued, or is complex, `Inf`

, or `NaN`

,
then `finddelay`

returns an error.The calculation of the vector of estimated delays, `D`

,
depends on `X`

, `Y`

, and `maxlag`

as
shown in the following table.

`maxlag` | `X` | `Y` | `D` is calculated by... |
---|---|---|---|

Integer-valued scalar | Row or column vector or matrix | Row or column vector or matrix | Cross-correlating the columns of `X` and `Y` over
a range of lags –`maxlag` :`maxlag` . |

Integer-valued row or column vector | Row or column vector of length L ≥ 1_{X} | Matrix of size -by-M_{Y} (N_{Y} > 1, M_{Y} > 1)N_{Y} | Cross-correlating `X` and column of j`Y` over
a range of lags –`maxlag` ():j`maxlag` (),
for j = 1:j. N_{Y} |

Integer-valued row or column vector | Matrix of size -by-M_{X} (N_{X} > 1, M_{X} > 1)N_{X} | Row or column vector of length L ≥ 1_{Y} | Cross-correlating column of j`X` and `Y` over
a range of lags –`maxlag` ():j`maxlag` (),
for j = 1:j. N_{X} |

Integer-valued row or column vector | Matrix of size -by-M_{X} (N_{X} > 1, M_{X} > 1)N_{X} | Matrix of size by-M_{Y}- (N_{Y} > 1, M_{Y} = N_{Y} > 1)N_{X} | Cross-correlating column of j`X` and
column of j`Y` over a range of
lags –`maxlag` ():j`maxlag` (),
for j = 1:j.N_{Y} |

`X`

as Multiple ChannelsIf you wish to treat a row vector `X`

of length * L_{X}* as
comprising one sample from

`X`

so
that it appears as a matrix. Then each column of `X`

will
be considered a channel.For example, `X = [1 1 1 1]`

is considered
a single channel comprising four samples. To treat it as four different
channels, each channel comprising one sample, define a new matrix `Xm`

:

Xm = [1 1 1 1; 0 0 0 0];

Each column of `Xm`

corresponds to a single
channel, each one containing the samples `1`

and `0`

.

The `finddelay`

function uses the `xcorr`

function of Signal Processing Toolbox™ to
determine the cross-correlation between each pair of signals at all
possible lags specified by the user. The normalized cross-correlation
between each pair of signals is then calculated. The estimated delay
is given by the negative of the lag for which the normalized cross-correlation
has the largest absolute value.

If more than one lag leads to the largest absolute value of the cross-correlation, such as in the case of periodic signals, the delay is chosen as the negative of the smallest (in absolute value) of such lags.

Pairs of signals need not be exact delayed copies of each other. However, the estimated delay has a useful meaning only if there is sufficient correlation between at least one pair of the delayed signals.

`alignsignals`

| `dtw`

| `edr`

| `findsignal`

| `xcorr`

Was this topic helpful?