# CrossCorrelation

# Usage

This function is used to calculate the cross correlation function of given two time series. For discrete time series, cross correlation is given by

which represent the similarities between two series with different index shifts.

Name: CROSSCORRELATION

Input Series: Only support two input numeric series. The type is INT32 / INT64 / FLOAT / DOUBLE.

Output Series: Output a single series with DOUBLE as datatype. There are data points in the series, the center of which represents the cross correlation calculated with pre-aligned series(that is in the formula above), and the previous(or post) values represent those with shifting the latter series forward(or backward otherwise) until the two series are no longer overlapped(not included). In short, the values of output series are given by(index starts from 1)

Note:

  • null and NaN values in the input series will be ignored and treated as 0.

# Examples

Input series:

+-----------------------------+---------------+---------------+
|                         Time|root.test.d1.s1|root.test.d1.s2|
+-----------------------------+---------------+---------------+
|2020-01-01T00:00:01.000+08:00|           null|              6|
|2020-01-01T00:00:02.000+08:00|              2|              7|
|2020-01-01T00:00:03.000+08:00|              3|            NaN|
|2020-01-01T00:00:04.000+08:00|              4|              9|
|2020-01-01T00:00:05.000+08:00|              5|             10|
+-----------------------------+---------------+---------------+

SQL for query:

select crosscorrelation(s1, s2) from root.test.d1 where time <= 2020-01-01 00:00:05

Output series:

+-----------------------------+--------------------------------------------------+
|                         Time|crosscorrelation(root.test.d1.s1, root.test.d1.s2)|
+-----------------------------+--------------------------------------------------+
|1970-01-01T08:00:00.001+08:00|                                               0.0|
|1970-01-01T08:00:00.002+08:00|                                               4.0|
|1970-01-01T08:00:00.003+08:00|                                               9.6|
|1970-01-01T08:00:00.004+08:00|                                              13.4|
|1970-01-01T08:00:00.005+08:00|                                              20.0|
|1970-01-01T08:00:00.006+08:00|                                              15.6|
|1970-01-01T08:00:00.007+08:00|                                               9.2|
|1970-01-01T08:00:00.008+08:00|                                              11.8|
|1970-01-01T08:00:00.009+08:00|                                               6.0|
+-----------------------------+--------------------------------------------------+

# examples on zeppelin

link: http://101.6.15.213:18181/#/notebook/2GETVW6AT (opens new window)