Files
ECG_by_Diffenert_CNN_Test/some-test/wfdb_use.py
T
2023-03-18 16:23:57 +08:00

52 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import numpy as np
import wfdb
import matplotlib.pyplot
PATH = '../MIT-BIT/'
# file error with read_ecg_data(data) parameter data false
def read_ecg_data(data):
# get the data from the ecg data file and set begin and end points
record = wfdb.rdrecord(PATH + 'data', sampfrom=0, sampto=1500)
# return type record
print(type(record))
print(dir(record))
# get the Lead signal (len、filename、number、signalname、Sample rate
print(record.p_signal)
print(np.shape(record.p_signal))
print(record.sig_len)
print(record.record_name)
print(record.n_sig)
print(record.sig_name)
print(record.fs)
# get type
annotations = wfdb.rdann(PATH + data, 'atr')
print(type(annotations))
print(dir(annotations))
# get R
print(annotations.sample)
# get label of Heart beat
print(annotations.sample)
# num
print(annotations.ann_len)
# show label of beat
print(wfdb.show_ann_labels())
matplotlib.pyplot.draw_ecg(record.p_signal)
return record.p_signal
if __name__ == '__main__':
read_ecg_data(100)