turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Forecasting
- /
- Using Cross Correlation to determine time delay be...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
# Using Cross Correlation to determine time delay between two signals

[ Edited ]
Options

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2018 02:48 AM - edited 03-02-2018 10:46 AM

What I have is two signals in time (x=time in seconds, y=Force) and they are lagged (see graph bellow). The lag is unknown to me and I have more than 5000 of this pair of curves. I need to align all this pairs or curves to enable other posterior analysis.

To do that, I would normally use the cross correlation method to find the the point in time where the two signals are best aligned in seconds . After I have the this optimal set point, I can use this number to correct one of the time series and make them match.

The problem is that I never did this in sas and I was wondering if there is a procedure that I can use or I need to code this in sas base from scratch myself. I google quite a bit and I'm not sure if what I call a cross correlation could be done with proc timeseries, or proc ARIMA in EG or even with some TS node in EM.

I would take any recommendation regardless of it is the name of a procedure, a sas base program, or an em node.

Thanks!!

Accepted Solutions

Solution

03-02-2018
10:46 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2018 09:52 AM

You can use PROC TIMESERIES to compute crosscorrelations. You need to use the CROSSCORR and CROSSVAR statements. Here is simple example.

```
data temp;
call streaminit(123);
do i=1 to 103;
x = rand("Uniform");
y = lag3(x);
if i > 3 then output;
end;
drop i;
run;
proc timeseries data = temp crossplot=all outcrosscorr=outcrosscorr;
crosscorr lag n ccov ccf ccfstd;
var x;
crossvar y;
run;
```

I am not sure exactly what the purpose of your analysis is, but you may want to look also at the SIMILARITY procedure. It allows you to compute a distance matrix between series using time warping rather than cross-correlation.

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2018 09:50 AM

You can call PROC TIMESERIES to compute cross correlation of two time series. See the following for a simple code example:

proc timeseries data=sashelp.pricedata out=_NULL_ outcrosscorr=crosscorr;

crosscorr _ALL_ / nlags=12;

id date interval=month;

var sale price;

by region line product;

run;

You can also check http://support.sas.com/documentation/cdl/en/etsug/66840/HTML/default/viewer.htm#etsug_timeseries_syn... for more details on the PROC and related functionalities.

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.

Solution

03-02-2018
10:46 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2018 09:52 AM

You can use PROC TIMESERIES to compute crosscorrelations. You need to use the CROSSCORR and CROSSVAR statements. Here is simple example.

```
data temp;
call streaminit(123);
do i=1 to 103;
x = rand("Uniform");
y = lag3(x);
if i > 3 then output;
end;
drop i;
run;
proc timeseries data = temp crossplot=all outcrosscorr=outcrosscorr;
crosscorr lag n ccov ccf ccfstd;
var x;
crossvar y;
run;
```

I am not sure exactly what the purpose of your analysis is, but you may want to look also at the SIMILARITY procedure. It allows you to compute a distance matrix between series using time warping rather than cross-correlation.

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mitrov

03-02-2018 09:55 AM

Thanks for that! I also thought about DTW but it does not fit to what I need to do afterwards with the data.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2018 10:15 AM

BTW, I forget to mention that if you use SAS Studio, the forecasting tasks provide an easy point-and-click interface that generates code for this type of analysis and much more.

I should put this sentence as my signature

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mitrov

03-02-2018 10:33 AM

Links:

Time Series and Forecasting tasks

Time Series Modeling and Forecasting

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mitrov

03-02-2018 10:35 AM - edited 03-02-2018 11:21 AM

Let's see how my signature looks now.

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.