'Series' object has no attribute 'flags' 오류가 나타나는 이유는

Pandas의 Series 데이터에 flags 속성이 없어서 문제가 생긴것이다.

 

이에 해당 Series를 numpy형태로 변형시켜서 기존 함수의 input값으로 넣어주면 해결된다.

 

나의 문제되는 코드는 

sig,notes=hb.get_patient_data(patient,norm=True)
#FFT PLOT
plt.subplot(221)
self.fft_plot(sig,label='Orig Sig',color='b')

self.fft_plot 에서 sig에 flags가 없다는 문제였는데 아래와 같은 코드를 통해 수정하니 해결되었다.

 

sig,notes=hb.get_patient_data(patient,norm=True)
#FFT PLOT
plt.subplot(221)
np_sig=sig.to_numpy()
self.fft_plot(np_sig,label='Orig Sig',color='b')

 

 

'프로그래밍' 카테고리의 다른 글

[Window10]RTX 3090 + CUDA 11.1 + cuDNN 8.0.5 + Python3.6  (0) 2021.12.20
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예제 데이터

이렇듯 가우시안 필터를 넣지 않으니 아주 깔끔해진 심장박동 예제 데이터가 생성됐다.

 

이로써 ECG데이터를 임의로 가우시안 노이즈 포함, 제거버전을 만들어보았다.

'논문리뷰 > ECG' 카테고리의 다른 글

MIT-BIH Arrhythmia Database  (0) 2021.12.21

+ Recent posts