首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >读取 MIT-BIH 心律数据

读取 MIT-BIH 心律数据

作者头像
caoqi95
发布2019-03-28 12:02:00
2.1K0
发布2019-03-28 12:02:00
举报

安装 wfdb

pip install wfdb

这个包是专门用来读取 PhysioNet 这个网站的数据集的内容的。具体内容可以参考文档

下载数据集

在自己的项目目录下克隆:

git clone https://github.com/Nospoko/qrs-tutorial.git
cd qrs-tutorial

这个包是用于下载数据集的,但是这个包目前只基于 Python2.7 ,不嫌麻烦的话,可以自己进行简单的修改。mitdb.pydownload.py 两个文件是我进行修改过的,可以在这个链接上查看。修改完后,可以成功下载 MIT-BIH 的心律数据集,其他数据集没有尝试。修改完成后,编写下面的代码下载数据集:

import wfdb as wf
import numpy as np
from datasets import mitdb as dm

# Load paths of avaliable data files
records = dm.get_records()
print('There are {} record files'.format(len(records)))

读取心律数据

这部分参考 demo.ipynb

使用 rdrecord 函数读取数据记录
# Select one of them
path = records[0]
print('Loading file:', path)

# read the record and plot the data by using 'rdrecord' function
record = wf.rdrecord(path)
wf.plot_wfdb(record=record, 
              title='Record 100 from MIT-BIH Arrhythmia Database')
使用简化的 rdsamp 函数读取某些通道和截取部分
signals, fields = wf.rdsamp(path)
print(fields)
=============
{'fs': 360,
 'sig_len': 650000,
 'n_sig': 2,
 'base_date': None,
 'base_time': None,
 'units': ['mV', 'mV'],
 'sig_name': ['MLII', 'V5'],
 'comments': ['69 M 1085 1629 x1', 'Aldomet, Inderal']}
使用 rdann 读取注释
annotation = wf.rdann(path, 'atr')
annotation.fs ### 获取采样频率
===============
360
读取记录和注释
# read a wfdb record and annotation. 
# Plot all channels, and the annotation on top of channel 0

record = wf.rdrecord(path, sampto=15000)
annotation = wf.rdann(path, 'atr', sampto=15000)

wf.plot_wfdb(record=record, annotation=annotation,
               title='Record 100 from MIT-BIH Arrhythmia Database',
               time_units='seconds')
读取一小片段 ECG 数据

ECG 信号的实际数值存储在属性 p_signal 数组中,我们可以从其中一个通道绘制一个小片段:

from matplotlib import pyplot as plt

# Select one of the channels (there are two)
chid = 0
data = record.p_signal
channel = data[:, chid]

print ('ECG channel type:', record.sig_name[chid])

# Plot only the first 2000 samples
howmany = 2000

# Calculate time values in seconds
times = np.arange(howmany, dtype = 'float') / record.fs
plt.plot(times, channel[ : howmany])
plt.xlabel('Time [s]')
plt.show()

想获取更多的信息可以使用 help(),比如想获得更多的 record 信息:

参考

[1]. wfdb-python

[2]. Nospoko/qrs-tutorial

[3]. Machine Learning for medicine: QRS detection in a single channel ECG signal (Part 1: data-set creation)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.01.16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装 wfdb
  • 下载数据集
  • 读取心律数据
    • 使用 rdrecord 函数读取数据记录
      • 使用简化的 rdsamp 函数读取某些通道和截取部分
        • 使用 rdann 读取注释
          • 读取记录和注释
            • 读取一小片段 ECG 数据
            • 参考
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档