| 2.11.5 corr1Menu InformationAnalysis: Signal Processing: Correlation
 Brief InformationCompute correlation of two signals
 Command Line Usage
1. corr1 ix1:=Col(1) ix2:=Col(2); 
 2. corr1 ix1:=Col(1) ix2:=Col(2) type:=circular; 
 3. corr1 ix1:=Col(1) ix2:=Col(2) norm:=1; 
 4. corr1 ix1:=Col(1) ix2:=Col(2) type:=circular norm:=1 oy:=(col(3),col(4));
 X-Function Execution OptionsPlease refer to the page for additional option switches when accessing the x-function from script
 Variables
| Display Name
 | Variable Name
 | I/O and
 Type
 | Default Value
 | Description |  
| Input | ix1 | Input
 vector
 | <active> | Specifies the first input signal.
 |  
| Input | ix2 | Input
 vector
 | <active> | Specifies the second input signal. If you would like to calculate auto-correlation, this should be the same as Input Signal 1.
 |  
| Sampling Interval | interval | Input
 double
 | 1.0 | Specifies the sampling interval. The default is <auto>, which corresponds to an automatically-computed interval.
 |  
| Type | type | Input
 int
 | line | Specifies whether to compute a linear correlation or a circular correlation.
 Option list
 linear :Linear
This is suitable for signals whose data points outside the input range can be viewed as zeros.
circular:Circular
This is best suited for signals that repeat periodically.
 |  
| Normalize | norm | Input
 int
 | 0 | Specifies whether the result should be normalized
 |  
| Output | oy | Output
 XYRange
 | <new> | Specifies the output range
 See the syntax here.
 |  
 Examples  To compute the auto-correlation of signals in Column 1 of the active worksheet, use the script command:
 corr1 ix1:=col(1) ix2:=col(1)
   To change the method of correlation, open the dialog from the Origin menu, Analysis: Signal Processing: FFT: Correlation. In the dialog, select the options and click OK.
   To perform correlation to data using a pre-saved smoothing theme file, save your preferences in the corr1 dialog, and then execute it by typing the following script command, using your own saved-theme title:
 corr1 -t "my correlation theme.oth"
 // Use correlation to detect time delay between two signals
//Create a  workbook and import the sample data
newbook sheet:=0 name:=Correlation;
newsheet xy:="YYYXY" labels:="Signal 1|Signal 2|Shifted Signal 2";
fname$ = System.path.program$ +"Samples\Signal Processing\Correlation.dat";
impasc;
string bkname$ = %H; // save the book name as plotting will create new window to change %H
//Calcualte correlation
corr1 ix1:=1 ix2:=2 type:=line oy:=(4,5);
//Get the maximum correlation and calculate the time difference
stats ix:=5 max:=maxcorr;
shift=col(4)[list(maxcorr, col(5))] + 1;
//Shift Signal 2 and plot
copydata irng:=col(2) orng:=col(3)[shift];
%a=nameof(col(3))$;
plotxy iy:=1 plot:=200 ogl:=Layer1;
plotxy iy:=[bkname$]1!col(3) plot:=200 ogl:=Layer1;
set %a -c 3; More InformationFor more information, please refer to our User Guide.
 
 
 Related X-Functionsfft1, ifft1
 
 Keywords:linear, circular |