gpt4 book ai didi

python - 如何获取并绘制信号包络线

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:16 25 4
gpt4 key购买 nike

我想知道Python中是否有一个函数envelope可以得到与此相同的结果

picture

我已经在 Python 中尝试过 envelope 函数,但有这个结果,它与我想要的不符。

result

最佳答案

虽然您没有具体提及您使用的功能,但似乎您正在使用两种不同类型的信封。

matlab中调用envelope的方式,相关描述为:

[yupper,ylower] = envelope(x) returns the upper and lower envelopes of the input sequence, x, as the magnitude of its analytic signal. The analytic signal of x is found using the discrete Fourier transform as implemented in hilbert. The function initially removes the mean of x and adds it back after computing the envelopes. If x is a matrix, then envelope operates independently over each column of x.

基于此,我想您会寻找一种在 python 中获得希尔伯变换的方法。可以找到这样的示例 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)

结果:

enter image description here

关于python - 如何获取并绘制信号包络线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37968221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com