LoginSignup
0
2

More than 1 year has passed since last update.

【時系列解析】ホワイトノイズ

Posted at

時系列データのホワイトノイズ(白色雑音)の定義

R_0 = 1, R_k = 0 (k \neq 0)

kはlag。lagが0の時は全てのデータは一致しているので自己相関は1、それ以外のlagでは自己相関が0になる時系列データのこと。

pythonでホワイトノイズを生成

平均0、標準偏差1のホワイトノイズ

mean = 0
sd = 1
x = np.random.normal(mean, sd, 300)
plt.figure(figsize=(12,4))
plt.plot(x)
plt.show()

スクリーンショット 2023-01-09 17.30.41.png

自己相関を確認。

import statsmodels.api as sm
sm.graphics.tsa.plot_acf(x, lags=100)
plt.show()

スクリーンショット 2023-01-09 17.32.43.png
偶然、95%信頼区間外にあるデータもあるが、k = ±1,±2,・・・,±100において自己相関がほぼ0であることが確認できる。

ホワイトノイズのスペクトル

ホワイトノイズのスペクトル(フーリエ変換後の値のこと)があらゆるスペクトルをフラットに含んでいることなどを図示しようとしたが、想定した綺麗な結果(y=10のようなフラットな直線)にはならなかった。

White_Noise
mean = 0
sd = 1
size = 300
x = np.random.normal(mean, sd, size)
X = np.fft.fft(x)
freqs = np.fft.fftfreq(len(x))
fig2, ax2= plt.subplots()
ax2.stem(freqs, np.abs(X), use_line_collection=True) # フーリエ変換の結果をステム(茎)プロットする
ax2.set_xlabel('Frequency in Hertz[Hz]')
ax2.set_ylabel('Frequency Domain (Spectrum) Magnitude')
ax2.set_xlim(0)
plt.show()

スクリーンショット 2023-01-09 18.01.54.png

sinカーブのスペクトル

sin_curve
f_s = 1000# サンプルを観測する間隔
f = 100 #周波数
sin_range = np.linspace(0,10,f_s)
x = np.sin(f * 2 * np.pi * sin_range)
plt.plot(sin_range, x)
plt.show()

スクリーンショット 2023-01-09 18.13.29.png

フーリエ変換、スペクトルの確認
X = np.fft.fft(x)
freqs = np.fft.fftfreq(len(x))*f_s

fig2, ax2= plt.subplots()
ax2.stem(freqs, np.abs(X), use_line_collection=True) # フーリエ変換の結果をステム(茎)プロットする
ax2.set_xlabel('Frequency in Hertz[Hz]')
ax2.set_ylabel('Frequency Domain (Spectrum) Magnitude')
ax2.set_xlim(0)
plt.show()

一応、ラインスペクトル(単振動の場合のスペクトル)っぽい形を確認できる。
スクリーンショット 2023-01-09 18.28.57.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2