我想知道Python中是否有函数envelope
具有与此相同的结果
我已经在Python中尝试过envelope
函数,但是有这个结果并且它与我想要的不符。
虽然您没有提到您使用的确切功能,但您似乎使用了两种不同的信封。
你在matlab中调用信封的方式,相关的描述是:
[yupper,ylower] = envelope(x)返回输入序列x的上下包络,作为其分析信号的幅度。使用在希尔伯特中实现的离散傅立叶变换找到x的分析信号。该函数最初删除x的平均值,并在计算包络后将其添加回来。如果x是矩阵,则包络在x的每列上独立运行。
基于此,我想你会想要一种在python中获得Hilber变换的方法。这方面的一个例子可以找到here:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
signal = chirp(t, 20.0, t[-1], 100.0)
signal *= (1.0 + 0.5 * np.sin(2.0*np.pi*3.0*t) )
analytic_signal = hilbert(signal)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.unwrap(np.angle(analytic_signal))
instantaneous_frequency = np.diff(instantaneous_phase) / (2.0*np.pi) * fs
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax0.plot(t, signal, label='signal')
ax0.plot(t, amplitude_envelope, label='envelope')
ax0.set_xlabel("time in seconds")
ax0.legend()
ax1 = fig.add_subplot(212)
ax1.plot(t[1:], instantaneous_frequency)
ax1.set_xlabel("time in seconds")
ax1.set_ylim(0.0, 120.0)
导致:
有时我会使用obspy.signal.filter.envelope(data_array);但是你只能得到你给出的例子中的上面一行。 Obspy是一个处理地震图的非常有用的包。