我有两个信号
T fnktptr; //Error: field ‘Event<int()>::fnktptr’ invalidly declared function type
我想获得连贯性
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
import mpld3
from scipy import signal
mpld3.enable_notebook()
nfft = 256
dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t)) * 0.1 # white noise 1
nse2 = np.random.randn(len(t)) * 0.1 # white noise 2
# two signals with a coherent part and a random part
s1 = np.sin(2*np.pi*1*t) + nse1
s2 = np.sin(2*np.pi*1*t+np.pi) + nse2
plt.plot(s1, 'r', s2, 'g')
plt.show()
和相移
cxy, fcoh = plt.cohere(s1, s2, nfft, 1./dt)
fcoh,cxy = signal.coherence(s1,s2, nfft=nfft, fs=1./dt)
plt.hold(True)
plt.plot(fcoh, cxy)
#plt.xlim(0, 5)
plt.show()
我尝试使用(csd, f) = mlab.csd(s1, s2, NFFT=nfft, Fs=1./dt)
fig = plt.figure()
angle = np.angle(csd,deg =False)
angle[angle<-np.pi/2] += 2*np.pi
plt.plot(f, angle, 'g')
plt.hold(True)
(f, csd) = signal.csd(s1, s2, fs=1./dt, nfft=nfft)
angle = np.angle(csd,deg =False)
angle[angle<-np.pi/2] += 2*np.pi
plt.plot(f, angle,'r')
#plt.xlim(0,5)
plt.show()
和scipy
。谁能解释为什么我会得到不同的结果?