Help Center Help Center

  • Help Center
  • Trial Software
  • Product Updates
  • Documentation

Align Signals Using Cross-Correlation

Many measurements involve data collected asynchronously by multiple sensors. If you want to integrate the signals and study them in tandem, you have to synchronize them. Use xcorr for that purpose.

For example, consider a car crossing a bridge. The vibrations it produces are measured by three identical sensors located at different spots. The signals have different arrival times.

Load the signals into the MATLAB® workspace and plot them.

help xcorr

Compute the cross-correlations between the three pairs of signals. Normalize them so their maximum value is 1.

The locations of the maximum values of the cross-correlations indicate time leads or lags.

Plot the cross-correlations. In each plot display the location of the maximum.

help xcorr

s2 leads s1 by 350 samples; s3 lags s1 by 150 samples. Thus s2 leads s3 by 500 samples. Line up the signals by clipping the vectors with longer delays. The signals are now synchronized and ready for further processing.

help xcorr

alignsignals | finddelay | xcorr

Related Topics

  • Measure Signal Similarities

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

  • América Latina (Español)
  • Canada (English)
  • United States (English)
  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)

Contact your local office

Computes discrete auto or cross correlation

a vector of real or complex floating point numbers.

a vector of real or complex floating point numbers. The default value is x .

a scalar with integer value greater than 1. The default value is n . Where n is the maximum of the x and y vector length.

a character string with possible value: "biased" , "unbiased" , "coeff" , "none" . The default value is "none" .

a vector of real or complex floating point numbers with same orientation as x .

a row vector, containing the lags index corresponding to the c values.

Description

help xcorr

If the maxlags argument is given xcorr returns in c the sequence of auto correlation lags C k=-maxlags:maxlags . If maxlags is greater than length(x) , the first and last values of c are zero.

  • "biased" : c= C /n .
  • "unbiased" : c= C ./(n-(-maxlags:maxlags)) .
  • "coeff" : c= C /(norm(x)*norm(y)) .

help xcorr

  • xcov — Computes discrete auto or cross covariance
  • corr — correlation, covariance
  • fft — Direct or inverse Fast Fourier Transform of a vector, matrix, or hypermatrix

COMMENTS

  1. Align Signals Using Cross-Correlation

    Many measurements involve data collected asynchronously by multiple sensors. If you want to integrate the signals and study them in tandem, you have to synchronize them. Use xcorr for that purpose. For example, consider a car crossing a bridge. The vibrations it produces are measured by three identical sensors located at different spots.

  2. xcorr

    xcorr (x,y) computes the un-normalized discrete cross correlation: and return in c the sequence of auto correlation lags C k=-n:n where n is the maximum of x and y lengths. If the maxlags argument is given xcorr returns in c the sequence of auto correlation lags C k=-maxlags:maxlags. If maxlags is greater than length (x) , the first and last ...

  3. 8. Cross-Correlation Cross-correlation

    In Matlab cross-correlations are computed with the function xcorr which works in the frequency domain. Note that to obtain the discrete version of φxy as defined by equation (8-8), one reverses the arguments (i.e., one calls phixy = xcorr(y,x)). xcorr also pads the end of the shorter input with zeros so that they are the same length. Since ...