Skip to content

Instantly share code, notes, and snippets.

@ground0state
Created January 23, 2020 14:43
Show Gist options
  • Save ground0state/f60bf2562669b52cdae6bb5d2242eb23 to your computer and use it in GitHub Desktop.
Save ground0state/f60bf2562669b52cdae6bb5d2242eb23 to your computer and use it in GitHub Desktop.
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