I am trying to understand the behaviour of the phase-locking-value, as e.g. defined here, by some simple examples.
Basically, I am creating two signals with the same frequency & amplitude, where the phase-offset between the two is random. Now, as expected, at most time points the PLV gives me a low value indicating that there is not a consistent pattern of phase onset. However, at the beginning & end of the signal, there are some strange effects. I suppose that these might be somehow introduced by the Hilbert transform, or is this a problem with my implementation?
Here is how I defined the function:
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def plv(x,y,trial_axis=0):
hilbert_x = signal.hilbert(x)
hilbert_y = signal.hilbert(y)
normed_x = hilbert_x/np.absolute(hilbert_x)
normed_y = hilbert_y/np.absolute(hilbert_y)
p = np.absolute(np.mean(normed_x*normed_y.conj(),axis=trial_axis))
return p
Here we have a plot of the behaviour:
t = np.linspace(0,10,1000)
N = 50
s_1 = np.array([np.sin(10*2*np.pi*t) for i in range(N)])
s_2 = np.array([np.sin(10*(2*np.pi*t)+np.random.uniform(low=0,high=2*np.pi) ) for i in range(N)])
p = plv(s_1,s_2)
plt.plot(p)