Hilbert变换的物理意义:将一个一维实数信号变为二维复平面上的信号,复数的模和角度代表了信号的幅度和相位。换句话说,频谱的负一半被清零,从而将实数信号转换为复数信号。
参数:
x:array_like信号数据。必须是真实的。
N:int, 可选参数傅立叶分量的数量。默认:x.shape[axis]
axis:int, 可选参数沿其进行转换的轴。默认值:-1
返回值:
xa:ndarray沿轴的每个1-D数组x的解析信号
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
我们创建一个rp,其频率从20 Hz增加到100 Hz,并应用幅度调制。
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)