python 希尔伯特变换_python scipy signal.hilbert用法及代码示例
使用希爾伯特變換來計算分析信號。
默認情況下,轉換是沿著最后一個軸完成的。
參數:
x:array_like信號數據。必須是真實的。
N:int, 可選參數傅立葉分量的數量。默認:x.shape[axis]
axis:int, 可選參數沿其進行轉換的軸。默認值:-1
返回值:
xa:ndarray沿軸的每個1-D數組x的解析信號
注意:
分析信號x_a(t)信號的x(t)是:
其中F是傅立葉變換,U是單位階躍函數,y是x的希爾伯特變換。[1]
換句話說,頻譜的負一半被清零,從而將實值信號轉換為復數信號。希爾伯特變換信號可以從np.imag(hilbert(x)),以及來自的原始信號np.real(hilbert(x))。
參考文獻:
2
Leon Cohen,“ Time-Frequency分析”,1995年。第2章。
3
艾倫·奧本海姆(Alan V. Discrete-Time Signal Processing,第三版,2009年。第12章。ISBN13:978-1292-02572-8
例子:
在此示例中,我們使用希爾伯特變換來確定amplitude-modulated信號的幅度包絡和瞬時頻率。
>>> 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)
總結
以上是生活随笔為你收集整理的python 希尔伯特变换_python scipy signal.hilbert用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cad拆分快捷键的使用方法
- 下一篇: go语言适合用来做什么