File Exchange > Data Analysis >    Correlation Shift

Author:
Antoine Couturier
Date Added:
6/15/2018
Last Update:
9/17/2018
Downloads (90 Days):
127
Total Ratings:
6
File Size:
2978 KB
Average Rating:
File Name:
CorrelShift.opx
File Version:
2.10
Minimum Versions:
License:
Free
Type:
App
Summary:

Align signals with cross correlation.

Screen Shot and Video:
Description:

This App will align datasets by finding delay corresponding to maximal correlation


How to Use ?
•    Worksheet: select at least 2 Y columns, click the App icon and select linear or circular correlation.
The 1st dataset is the reference dataset. All the others will be aligned to the reference dataset.

•    Graph: if there are at least 2 dataplots, click the App icon and select linear or circular correlation.
The 1st dataplot is the reference dataplot. All the others will be aligned to the reference dataplot.  New dataplots are added and corresponds to nth dataplot aligned to 1st dataplot. For clarity and emphasis purpose, the source nth dataplot transparency is set to 80%.

New XY columns corresponding to nth dataset aligned to reference dataset are added into source worksheet, with Shift and Correlation values printed into column Comments header. If a dataset duration is smaller than 50% of reference dataset duration, an Adjusted Correlation value is also computed and corresponds to the correlation value limited to the aligned matching parts.

Linear Correlation
Prior to correlation, the sampling frequencies are checked. If they are different, the dataset with lowest sampling rate is internally oversampled to the highest sampling rate.

The new X column is a copy of the source column, offseted by the amount of shift.
The new Y column is a copy of the source column.

Circular Correlation
Prior to correlation, the sampling frequencies are checked. If they are different, the dataset with lowest sampling rate is internally oversampled to the highest sampling rate.
In circular correlation, the nth dataset will be wrapped (i.e. shifted circularly) for finding best match with 1st dataset. Thus, the 2 source datasets are supposed to have the same initial X values, and nth dataset duration should not be shorter than 1st dataset duration. Whatever the case, the new XY columns will fulfill those conditions.

The new X column starts at same initial value than 1st dataset, has same sampling rate than 2nd dataset and same duration than longest dataset.
The new Y column is a copy of the source column (padded with 0 if needed), wrapped in the rightward direction by the amount of shift.

 

Installation
Download the file CorrelShift.opx, and then drag-and-drop onto the Origin workspace. An icon will appear in the Apps Gallery window.

A sample project is available with many examples. Right click on App icon and select Show Samples Folder

Updates:

- Support all types of numeric data
- Better handling of user's options
- Option to add transparency to source dataplot or remove it
- Circular correlation: option to keep source X if unique
- Bug fixes

Reviews and Comments:
01/08/2024couturierHi Emhong
It seems to me you talking about pearson's correlation, which is not the purpose of this App

01/27/2023emhongThe CC = -1 should come out when the next two Y pairs are correlated, right?
X Y1 Y2
1 1 52
2 2 51
3 3 50
4 4 49
...
...
50 50 3
51 51 2
52 52 1

Is there a reason why CC=0.829 and linear shift=21 are coming out?
Please let me know.

01/27/2023emhongThe CC = -1 should come out when the next two Y pairs are corrected, right?
X Y1 Y2
1 1 52
2 2 51
3 3 50
4 4 49
...
...
50 50 3
51 51 2
52 52 1

Is there a reason why CC=0.829 and linear shift=21 are coming out?
Please let me know.

04/10/2021闫文波 

02/26/2021couturierHi woodster,
For circular correlation, I'm using an OC function dedicated for this purpose.
I agree that results may be misleading with pure sines, but with real life signals, the shift can be offseted with many periods.
For your case, I would advise to use linear correlation, with which you will get the expected results.

02/15/2021woodsterThis is really useful, however it could be even better with a couple of tweaks. For example, when the second dataplot leads the first, the time shift appears to be calculated using:

max x value - calculated circular shift value

This isn't obvious to begin with, and it is also slightly wrong as it doesn't match the circular shift given when the second dataplot lags the first, unless you take the next value up from the calculated circular time shift (I checked this with simple sine and cosine functions). It would be great if the circular shift could just be provided as an absolute time shift between two peaks, with a positive or negative value to denote the direction. This can then easily be converted to a phase shift when the frequency is known