0

I would like to know how to calculate the Pearson correlation coefficient for two complex time series.

Do we simply do enter image description here

Or there is something else?

import numpy as np
    
R = lambda x,y: ((x-x.mean())*(y-y.mean())).sum()/(np.sqrt(((x-x.mean())**2).sum())*np.sqrt(((y-y.mean())**2).sum()))

x,y = np.loadtxt("data.txt",dtype=np.complex128).T

ri = R(x,y)
ri = (ri*ri.conj()).real
print(ri)

File in https://file.io/KzwvQFx8XsXQ

3
  • That denominator doesn't look right. You've only got a single sum there. To make it a bit more readable, i suggest just using numpy.linalg.norm 3 times here. Commented Apr 8, 2023 at 0:05
  • and that the sum is in the wrong spot. R = lambda x,y: np.linalg.norm((x-x.mean())*(y-y.mean())) / (np.linalg.norm(x-x.mean())*np.linalg.norm(y-y.mean())) Commented Apr 8, 2023 at 0:10
  • You are right, I copied the code wrongly. The numerator should be a sum instead of a norm, I believe. Commented Apr 8, 2023 at 2:13

1 Answer 1

1

Keep in mind that complex time series can be correlated not only by a linear scale factor, as is the case for real time series, but also by a linear phase rotation or phase reflection. That results in a complex correlation coefficient.

import numpy as np
def corr_complex_rotational(x, y):
    x_bar = x - np.mean(x)
    y_bar = y - np.mean(y)
    Rxy = x_bar @ y_bar.T.conj() / (len(x)-1)
    Rxx = x_bar @ x_bar.T.conj() / (len(x)-1)
    Ryy = y_bar @ y_bar.T.conj() / (len(x)-1)
    Rxx, Ryy = Rxx.real, Ryy.real  # they are real but carry a 0j that we don't need
    rho = Rxy / np.sqrt(Rxx * Ryy)
    return rho

I recommend consulting the book "Statistical Signal Processing of Complex-Valued Data: The Theory of Improper and Noncircular Signals" by Schreier and Scharf, 2010.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.