import numpy as np
import matplotlib.pyplot as plt
bpm = 60
bps = bpm / 60
capture_length = 2
# plt.xlim(0,10)
num_heart_beats = int(capture_length * bps)
ecg_template = np.tile(pqrst_full , num_heart_beats)
noise = np.random.normal(0, 0.01, len(ecg_template))
ecg_template_noisy = noise + ecg_template
# Plot the noisy heart ECG template
plt.plot(ecg_template_noisy)
plt.xlabel('Sample number')
plt.ylabel('Amplitude')
plt.title('Synthetic Heart Beat with Gaussian noise')
plt.show()
기존 오픈소스 코드에서 pqrst_full 변수가 없길래 구글링하여 pqrst_full을 만들었다.
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as signal
bpm = 60
bps = bpm / 60
capture_length = 2
# The "Daubechies" wavelet is a rough approximation to a real,
# single, heart beat ("pqrst") signal
pqrst = signal.wavelets.daub(10)
# Add the gap after the pqrst when the heart is resting.
samples_rest = 10
zero_array = np.zeros(samples_rest, dtype=float)
pqrst_full = np.concatenate([pqrst,zero_array])
# plt.xlim(0,10)
num_heart_beats = int(capture_length * bps)
ecg_template = np.tile(pqrst_full , num_heart_beats)
noise = np.random.normal(0, 0.01, len(ecg_template))
ecg_template_noisy = noise + ecg_template
# Plot the noisy heart ECG template
plt.plot(ecg_template_noisy)
plt.xlabel('Sample number')
plt.ylabel('Amplitude')
plt.title('Synthetic Heart Beat with Gaussian noise')
plt.show()
이렇게 하니 아래와 같이 정상적으로 가우시안 노이즈가 합쳐진 심장박동 예제가 생성됬다.
갑자기 궁금해져서 가우시안 필터를 합치지 않으면 어떻게 될까 궁금해졌다.
이렇듯 가우시안 필터를 넣지 않으니 아주 깔끔해진 심장박동 예제 데이터가 생성됐다.
이로써 ECG데이터를 임의로 가우시안 노이즈 포함, 제거버전을 만들어보았다.
'논문리뷰 > ECG' 카테고리의 다른 글
MIT-BIH Arrhythmia Database (0) | 2021.12.21 |
---|