def corr_x_av_palm(vSeq, tSeq, zInd, yInd, xSeq, dInd): dt = tSeq[-1] - tSeq[-2] corr = [] for p in range(xSeq.size - dInd): u0 = vSeq[:,zInd,yInd,p] u1 = vSeq[:,zInd,yInd,p+dInd] tmp = funcs.crosscorr_FFT(u1,u0,dt) corr.append(tmp[1]) tau = tmp[0] corr = np.average(np.array(corr),axis=0) return tau, corr
def corr_x_av_sowfa(vSeq, tSeq, zInd, ySeq, xSeq, dInd): dt = tSeq[-1] - tSeq[-2] xNum = xSeq.size yNum = ySeq.size pInd_start = xNum*yNum*zInd pInd_end = xNum*yNum*(zInd+1) corr = [] for p in range(pInd_end - pInd_start - dInd): u0 = vSeq[p] u1 = vSeq[p+dInd] tmp = funcs.crosscorr_FFT(u1,u0,dt) corr.append(tmp[1]) tau = tmp[0] corr = np.average(np.array(corr),axis=0) return tau, corr
def crosscorr_palm(t_para, tSeq, dInd, zInd, xNum, vSeq): t_start = t_para[0] t_end = t_para[1] t_delta = t_para[2] fs = 1 / t_delta # sampling frequency t_num = int((t_end - t_start) / t_delta + 1) t_seq = np.linspace(t_start, t_end, t_num) crosscorr_list = [] for p in range(0,xNum-dInd): v0 = vSeq[:,zInd,0,p] v1 = vSeq[:,zInd,0,p+dInd] f0 = interp1d(tSeq, v0, kind='linear', fill_value='extrapolate') v0_ = f0(t_seq) f1 = interp1d(tSeq, v1, kind='linear', fill_value='extrapolate') v1_ = f1(t_seq) tau, corr, phase = funcs.crosscorr_FFT(v1_, v0_, 1/fs, norm_=True) crosscorr_list.append(corr) corr = np.average(np.array(crosscorr_list), axis=0) return tau, corr
u1 = funcs.fourier_series(tSeq, ASeq, omgSeq, kSeq, x1, phiSeq) # white noise n0 = np.random.rand(t_N) * 5 n1 = np.random.rand(t_N) * 5 u0 += n0 u1 += n1 SNR0 = np.var(u0) / np.var(n0) SNR1 = np.var(u1) / np.var(n1) """ auto-correlation coefficient """ tau0, R0 = funcs.autocorr_FFT(u0, fs) tau1, R1 = funcs.autocorr_FFT(u1, fs) """ auto-correlation coefficient """ tau, R, phase__ = funcs.crosscorr_FFT(u0, u1, fs) """ PSD """ segNum = int(120 * fs) freq0, S0 = scipy.signal.csd(u0, u0, fs, nperseg=segNum, noverlap=None) freq1, S1 = scipy.signal.csd(u1, u1, fs, nperseg=segNum, noverlap=None) """ CSD """ segNum = int(120 * fs) freq, S01 = scipy.signal.csd(u0, u1, fs, nperseg=segNum, noverlap=None) S01_ = abs(S01) phase_ = np.angle(S01) """ coherence, co-coherence, phase """ segNum = int(120 * fs) freq, coh, co_coh, phase = funcs.coherence(u0, u1, fs, segNum) """ plot all figures """ allplot(tSeq, u0, u1, tau, tau0, tau1, R, R0, R1, freq, freq0, freq1, S0, S1, S01_, coh, co_coh, phase)