You are here : matlabSignal Processingalignsignals

alignsignals() - Signal Processing

[Xa,Ya]
= alignsignals(X,Y) estimates
the delay, D, between the two input signals, X and Y,
and returns the aligned signals, Xa and Ya.If Y is delayed with respect
to X, then D is positive and X is
delayed by D samples.If Y is advanced with respect
to X, then D is negative and Y is
delayed by –D samples.Delays in X or Y can
be introduced by prepending zeros.example[Xa,Ya]
= alignsignals(X,Y,maxlag) uses maxlag as
the maximum window size to find the estimated delay, D,
between the two input signals, X and Y.
It returns the aligned signals, Xa and Ya.example[Xa,Ya]
= alignsignals(X,Y,maxlag,'truncate') keeps
the lengths of the aligned signals, Xa and Ya,
the same as those of the input signals, X and Y,
respectively. If the estimated delay, D, is positive,
then D zeros are prepended to X and
the last D samples of X are
truncated. If the estimated delay, D, is negative,
then –D zeros are prepended to Y and
the last –D samples of Y are
truncated. Notes  


X and Y are row or
column vectors of length LX and LY,
respectively.If D ≥ LX,
then Xa consists of LX zeros.
All samples of X are lost. If –D ≥ LY,
then Ya consists of LY zeros.
All samples of Y are lost.To avoid assigning a specific value to maxlag when
using the 'truncate' option, set maxlag to [].example[Xa,Ya,D]
= alignsignals(___) returns the estimated delay, D.
This syntax can include any of the input arguments used in previous
syntaxes.


Syntax

[Xa,Ya]
= alignsignals(X,Y) example[Xa,Ya]
= alignsignals(X,Y,maxlag) example[Xa,Ya]
= alignsignals(X,Y,maxlag,'truncate') example[Xa,Ya,D]
= alignsignals(___) example


Example

Align Two Signals Where the First Signal Lags by Three SamplesOpen This Example
Align signal Y with respect to X by advancing it three samples.
Create two signals, X and Y. X is exactly the same as Y, except X has three leading zeros and one additional following zero. Align the two signals.X = [0 0 0 1 2 3 0 0];
Y = [1 2 3 0];

[Xa,Ya] = alignsignals(X,Y)

Xa =

     0     0     0     1     2     3     0     0


Ya =

     0     0     0     1     2     3     0

Align Two Signals Where the Second Signal Lags by Two SamplesOpen This Example
Align signal X when Y is delayed with respect to X by two samples.
Create two signals, X and Y. Y is exactly the same as X, except Y has two leading zeros. Align the two signals.X = [1 2 3];
Y = [0 0 1 2 3];
maxlag = 2;

[Xa,Ya,D] = alignsignals(X,Y,maxlag)

Xa =

     0     0     1     2     3


Ya =

     0     0     1     2     3


D =

     2

Align Two Signals Where the Second Signal Is NoisyOpen This Example
Align signal Y with respect to X, despite the fact that Y is a noisy signal.
Create two signals, X and Y. Y is exactly the same as X with some noise added to it. Align the two signals.X = [0 0 1 2 3 0];
Y = [0.02 0.12 1.08 2.21 2.95 -0.09];

[Xa,Ya,D] = alignsignals(X,Y)

Xa =

     0     0     1     2     3     0


Ya =

    0.0200    0.1200    1.0800    2.2100    2.9500   -0.0900


D =

     0

You do not need to change the input signals to produce the output signals. The delay D is zero.Align Two Signals Using the 'truncate' OptionOpen This Example
Invoke the 'truncate' option when calling the alignsignals function.
Create two signals, X and Y. Y is exactly the same as X, except Y has two leading zeros. Align the two signals, applying the 'truncate' directive.X = [1 2 3];
Y = [0 0 1 2 3];

[Xa,Ya,D] = alignsignals(X,Y,[],'truncate')

Xa =

     0     0     1


Ya =

     0     0     1     2     3


D =

     2

Observe that the output signal Xa has a length of 3, the same length as input signal X.In the case where using the 'truncate' option ends up truncating all the original data of X, a warning is issued. To make alignsignals issue such a warning, run the following example.Y = [0 0 0 0 1 2 3];

[Xa,Ya,D] = alignsignals(X,Y,[],'truncate')
Warning: All original data in the first input X has been truncated because the
length of X is smaller than the estimated delay D: to avoid truncating this data
do not use the 'truncate' option. 

Xa =

     0     0     0


Ya =

     0     0     0     0     1     2     3


D =

     4

Align a Signal and a Periodic Repetition of ItOpen This Example
Align signal Y with respect to X, despite the fact that Y is a periodic repetition of X. Return the smallest possible delay.
Create two signals, X and Y. Y consists of two copies of the nonzero portion of X separated by zeros. Align the two signals.X = [0 1 2 3];
Y = [1 2 3 0 0 0 0 1 2 3 0 0];

[Xa,Ya,D] = alignsignals(X,Y)

Xa =

     0     1     2     3


Ya =

     0     1     2     3     0     0     0     0     1     2     3     0     0


D =

    -1


Output / Return Value


Limitations


Alternatives / See Also


Reference