添加2个正弦波后发生干涉图案峰值的相位

时间:2016-06-15 22:11:28

标签: python signal-processing

给定2个正弦波,我通过添加它们来计算得到的正弦波。现在我想计算干涉图案出现峰值的相位。

这是我生成的情节: enter image description here

这是我想要创建的图像。我想绘制子图A: enter image description here

以下是我使用的脚本:

import numpy as np
import matplotlib.pyplot as plt

w_s = 10*2*np.pi
w_d = 11.5*2*np.pi
a_s = 1
a_d = 1
phi_d = 0

x =np.arange(0,2,0.01)

v_s = [a_s*np.cos(w_s*t) for t in np.arange(0,2,0.01)]
v_d = [a_d*np.cos(w_d*t + phi_d) for t in np.arange(0,2,0.01)]
resultant = [sum(i) for i in zip(v_s, v_d)]

f, (ax1, ax2,ax3) = plt.subplots(3, sharex=True, sharey=True)
ax1.plot(x,resultant,'k')
ax1.set_ylabel('sum')
ax2.plot(x, v_d,'b')
ax2.set_ylabel('dendrite')
ax3.plot(x, v_s,'r')
ax3.set_ylabel('soma')
f.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
plt.setp([a.get_yticklabels() for a in f.axes[:3]], visible=False)
plt.xlabel('Time(s)')
plt.show()

1 个答案:

答案 0 :(得分:2)

使用Hilbert Transform计算分析信号,从而计算envelope and instantaneous phase

import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

t = np.arange(0, 2, 0.01)

a1, f1, phi1 = 1, 10, 0
a2, f2, phi2 = 1, 11.5, 0
s1 = a1 * np.cos(2 * np.pi * f1 * t + phi1)
s2 = a2 * np.cos(2 * np.pi * f2 * t + phi2)


fig, (axsum, ax1, ax2) = plt.subplots(3, sharex=True, figsize=(10,8))

axsum.plot(t, s1+s2, 'k')
axsum.set_ylabel("sum")

ax1.plot(t, s1, 'b')
ax1.set_ylabel("signal 1")

ax2.plot(t, s2, 'r')
ax2.set_ylabel("signal 2")
ax2.set_xlabel("time in s")


sum_analytic = signal.hilbert(s1+s2)
axsum.plot(t, np.abs(sum_analytic), 'g', lw=2)
for ix in signal.argrelmax(np.abs(sum_analytic))[0]:
    axsum.axvline(t[ix], color='r', lw=2)

envelope of signal

您可能需要查看NumPy tutorial,例如,您的所有列表推导都不是必需的。