Forecasting using SAS Forecast Server, SAS/ETS, and more

Using Cross Correlation to determine time delay between two signals

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor EBB
Occasional Contributor
Posts: 11
Accepted Solution

Using Cross Correlation to determine time delay between two signals

[ Edited ]

 

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.

 

crosscorrelation.PNG

 

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
SAS Employee
Posts: 62

Re: Using Cross Correlation to determine time delay between two signals

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. 

View solution in original post


All Replies
SAS Employee
Posts: 31

Re: Using Cross Correlation to determine time delay between two signals

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.

Solution
‎03-02-2018 10:46 AM
SAS Employee
Posts: 62

Re: Using Cross Correlation to determine time delay between two signals

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. 

Occasional Contributor EBB
Occasional Contributor
Posts: 11

Re: Using Cross Correlation to determine time delay between two signals

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

SAS Employee
Posts: 62

Re: Using Cross Correlation to determine time delay between two signals

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 Smiley Happy

SAS Employee
Posts: 62

Re: Using Cross Correlation to determine time delay between two signals

SAS Employee
Posts: 62

Re: Using Cross Correlation to determine time delay between two signals

[ Edited ]

Let's see how my signature looks now. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 449 views
  • 1 like
  • 3 in conversation