Created
January 23, 2020 14:43
-
-
Save ground0state/f60bf2562669b52cdae6bb5d2242eb23 to your computer and use it in GitHub Desktop.
This code is from https://org-technology.com/posts/Hilbert-transform.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy import signal | |
import matplotlib.pyplot as plt | |
import sys | |
# 時系列のサンプルデータ作成 | |
f1 = 120 | |
f2 = 150 | |
n = 256 # データ数 | |
dt = 0.001 | |
fs = 1/dt # サンプリング間隔 | |
t = np.linspace(1, n, n)*dt-dt | |
y = np.sin(2*np.pi*f1*t)+2*np.sin(2*np.pi*f2*t)+0.1*np.random.randn(t.size) | |
# ヒルベルト変換 <https://org-technology.com/posts/Hilbert-transform.html> | |
yh = signal.hilbert(y) | |
plt.figure(figsize=(10, 5)) | |
plt.plot(t, y) | |
plt.plot(t, abs(yh), linewidth=2) | |
plt.axis("tight") | |
plt.xlabel("Time [s]") | |
plt.ylabel("Amplitude") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment