【Python】노이즈를 포함한 신호를 2진화
목적
오실로스코프에서 관찰된 파형과 같은 노이즈를 포함하는 신호를 2진화한다.
도전
노이즈의 영향으로 변화의 타이밍이나 변화의 횟수가 정확하게 요구되지 않는다.

해결책
이동 평균으로 데이터를 평활화한 후 이진화한다.
코드
import numpy as np
import matplotlib.pyplot as plt
# 時間行列
t = np.linspace(0,10,100)
# 真値
y_true = np.sin(t) + 1/3*np.sin(3*t) + 1/5*np.sin(5*t)
# 観測値(真値+ノイズ)
y_obs = y_true + np.random.randn(100)*0.3
# 平均化に使用する行列
num = 5 # 移動平均に用いる個数
k = np.ones(num)/num # 平均化に使用する行列の重み。移動平均なので均等
# 観測値を移動平均
y_fil = np.convolve(y_obs, k, mode='same')
# 移動平均を2値化(0より大きければ1,0以下であれば0)
y_bin = np.zeros(len(y_fil))
y_bin[y_fil>0] = 1
# グラフ化
fig, ax = plt.subplots()
ax.plot(t, y_true,'r') # 真値
ax.plot(t, y_obs,'k-') # 観測値
ax.plot(t, y_fil,'b--') # 移動平均
ax.plot(t, y_bin,'g-.') # 二値化
ax.legend(['真値','観測値','移動平均','二値化'], prop={"family":"MS Gothic"})
# グラフを保存
fig.savefig("img.png")
결과
Reference
이 문제에 관하여(【Python】노이즈를 포함한 신호를 2진화), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/sgeboku/items/bb66559197d6666c7eea
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
노이즈의 영향으로 변화의 타이밍이나 변화의 횟수가 정확하게 요구되지 않는다.

해결책
이동 평균으로 데이터를 평활화한 후 이진화한다.
코드
import numpy as np
import matplotlib.pyplot as plt
# 時間行列
t = np.linspace(0,10,100)
# 真値
y_true = np.sin(t) + 1/3*np.sin(3*t) + 1/5*np.sin(5*t)
# 観測値(真値+ノイズ)
y_obs = y_true + np.random.randn(100)*0.3
# 平均化に使用する行列
num = 5 # 移動平均に用いる個数
k = np.ones(num)/num # 平均化に使用する行列の重み。移動平均なので均等
# 観測値を移動平均
y_fil = np.convolve(y_obs, k, mode='same')
# 移動平均を2値化(0より大きければ1,0以下であれば0)
y_bin = np.zeros(len(y_fil))
y_bin[y_fil>0] = 1
# グラフ化
fig, ax = plt.subplots()
ax.plot(t, y_true,'r') # 真値
ax.plot(t, y_obs,'k-') # 観測値
ax.plot(t, y_fil,'b--') # 移動平均
ax.plot(t, y_bin,'g-.') # 二値化
ax.legend(['真値','観測値','移動平均','二値化'], prop={"family":"MS Gothic"})
# グラフを保存
fig.savefig("img.png")
결과
Reference
이 문제에 관하여(【Python】노이즈를 포함한 신호를 2진화), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/sgeboku/items/bb66559197d6666c7eea
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import numpy as np
import matplotlib.pyplot as plt
# 時間行列
t = np.linspace(0,10,100)
# 真値
y_true = np.sin(t) + 1/3*np.sin(3*t) + 1/5*np.sin(5*t)
# 観測値(真値+ノイズ)
y_obs = y_true + np.random.randn(100)*0.3
# 平均化に使用する行列
num = 5 # 移動平均に用いる個数
k = np.ones(num)/num # 平均化に使用する行列の重み。移動平均なので均等
# 観測値を移動平均
y_fil = np.convolve(y_obs, k, mode='same')
# 移動平均を2値化(0より大きければ1,0以下であれば0)
y_bin = np.zeros(len(y_fil))
y_bin[y_fil>0] = 1
# グラフ化
fig, ax = plt.subplots()
ax.plot(t, y_true,'r') # 真値
ax.plot(t, y_obs,'k-') # 観測値
ax.plot(t, y_fil,'b--') # 移動平均
ax.plot(t, y_bin,'g-.') # 二値化
ax.legend(['真値','観測値','移動平均','二値化'], prop={"family":"MS Gothic"})
# グラフを保存
fig.savefig("img.png")
결과
Reference
이 문제에 관하여(【Python】노이즈를 포함한 신호를 2진화), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/sgeboku/items/bb66559197d6666c7eea
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(【Python】노이즈를 포함한 신호를 2진화), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/sgeboku/items/bb66559197d6666c7eea텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)