database 将 MIT-BIH 心律失常 ECG 数据库加载到 MATLAB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6283929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load MIT-BIH Arrhythmia ECG database onto MATLAB
提问by L.fole
I am working on ECG signal processing using neural network which involves pattern recognition. As I need to collect all the data from Matlab to use it as test signal, I am finding it difficult to load it on to the Matlab. I am using MIT Arrhythmia database here.
我正在使用涉及模式识别的神经网络进行心电图信号处理。由于我需要从 Matlab 收集所有数据以将其用作测试信号,因此我发现很难将其加载到 Matlab。我在这里使用 MIT 心律失常数据库。
The signal needs to be indexed and stored as data structure in Matlab compatible format.
Presently, the signal is in .atrand .datformat.
信号需要被索引并存储为 Matlab 兼容格式的数据结构。目前,信号是在.atr和.dat格式。
How can you load MIT-BIH Arrhythmia database onto Matlab?
如何将 MIT-BIH 心律失常数据库加载到 Matlab 上?
采纳答案by Rashid
You can use physionet ATMto get .matfiles which are easier to work with.
您可以使用 physionet ATM获取更易于使用的.mat文件。
In the inputpart select the desired leads, length, database and sample.
在输入部分选择所需的导联、长度、数据库和样本。
In the toolboxselect export as .mat:
在工具箱中选择export as .mat:


Then download the '.mat' file,
然后下载“.mat”文件,


In order to open the file in MATLAB, here is a sample code:
为了在 MATLAB 中打开文件,这里是一个示例代码:
load ('100m.mat') % the signal will be loaded to "val" matrix
val = (val - 1024)/200; % you have to remove "base" and "gain"
ECGsignal = val(1,1:1000); % select the lead (Lead I)
Fs = 360; % sampling frequecy
t = (0:length(ECGsignal)-1)/Fs; % time
plot(t,ECGsignal)
and you will get,
你会得到,


However, If you were to read annotationfiles for arrhythmiaor QRS complexesthat would be another problem.
但是,如果您要阅读心律失常或QRS 复合波的注释文件,那将是另一个问题。
Edit
编辑
The baseand gaincome from the infofile (second picture). This file gives you various information regarding the ECG signal.
该基地和增益来自信息文件(第二张照片)。该文件为您提供有关 ECG 信号的各种信息。


In the last sentence it says: To convert from raw units to the physical units shown above, subtract 'base' and divide by 'gain'.
在最后一句话中说:要将原始单位转换为上面显示的物理单位,请减去“基数”并除以“增益”。
回答by Sriram
You need the program rddata.m(MATLab script) from this website. The program can be found here. rddata.mis probably the only program you will need to read the ecg signals. I remember having used this program and database myself not too long ago.
您需要此网站上的程序rddata.m(MATLab 脚本)。该程序可以在这里找到。可能是您读取心电图信号所需的唯一程序。我记得不久前自己使用过这个程序和数据库。rddata.m
回答by Amit Juneja
So I read this answer 3 months ago and removed the base and gain. It turns out , i completely shifted my R-peaks in various directions, screwing up all my results. While I am not sure if doing this is necessary in matlab or not, DO NOT DO THIS if you are not preprocessing your signal in matlab. I was preprocessing my signal in python, and all I did to normalizae it was
所以我在 3 个月前阅读了这个答案并删除了基础和增益。事实证明,我在各个方向上完全移动了我的 R 峰值,搞砸了我所有的结果。虽然我不确定在 matlab 中是否需要这样做,但如果您不在 matlab 中预处理信号,请不要这样做。我在 python 中预处理我的信号,我所做的一切都是为了规范它
val = val/2047 % (2047 is the max volt range of signals)
and used butterworth filters to remove artifacts (range 0.5hz-45hz)
并使用 Butterworth 过滤器去除伪像(范围 0.5hz-45hz)
CORRECTION
更正
The cutoff i selected is 0.5 to 45not 5-15 as I previously reported. This cutoff preserves the QRS for various arrhythmias without adding too much noise
我选择的临界值是0.5 到 45,而不是我之前报告的 5-15。这个截止保留了各种心律失常的 QRS 波,而不会增加太多的噪音
# baseline correction and bandpass filter of signals
lowpass = scipy.signal.butter(1, highfreq/(rate/2.0), 'low')
highpass = scipy.signal.butter(1, lowfreq/(rate/2.0), 'high')
# TODO: Could use an actual bandpass filter
ecg_low = scipy.signal.filtfilt(*lowpass, x=ecg)
ecg_band = scipy.signal.filtfilt(*highpass, x=ecg_low)
回答by Niu
There is a tutorial for using matlab to read the data. tutorial for matlab user
有使用matlab读取数据的教程。matlab 用户教程
install "The WFDB Toolbox for Matlab" from the link above. Add the folder of the toolbox to the path in matlab.
Download the ECG signal. Be sure to download
'.atr', '.dat' and '.hea'together for the signal you are to deal with.Command in matlab is as follows :
[tm,signal,Fs]=rdsamp( filename , 1 ) ; [ann,type]=rdann( filename , 'atr' ) ;Note: for signal '101', its name is '101'. And you can check the detail information about rdsamp and rdann from the tutorial.
从上面的链接安装“The WFDB Toolbox for Matlab”。将工具箱的文件夹添加到matlab中的路径中。
下载心电图信号。一定要
'.atr', '.dat' and '.hea'一起下载你要处理的信号。matlab 中的命令如下:
[tm,signal,Fs]=rdsamp( filename , 1 ) ; [ann,type]=rdann( filename , 'atr' ) ;注意:对于信号'101',它的名字是'101'。您可以从教程中查看有关 rdsamp 和 rdann 的详细信息。
回答by Harun
just use it
就用它
A=input('Enter Variable: ','s');
load(A);
a=(val(1,:));
b=fir1(100,[0.1,0.25],'stop');
y2=filter(b,1,a);
figure;
plot(y2);
回答by Léo Léopold Hertz ??
Use ATMto extract .matas described by Kamtal(now known Rashid). However, note that to see the .infofile in some cases, you need to click the arrow
按照Kamtal(现在称为 Rashid)的描述,使用ATM提取.mat。但是,请注意,在某些情况下要查看.info文件,您需要单击箭头


After I pushed this forward to developers here, we got improvements in the documentation herein Section 4.
我把这种期待开发后这里,我们得到了文档中的改善这里的第4节。
If they are all integers in the range [-2^N, 2^N-1 ] or [ 0, 2^N ], they are probably digital. Compare the values to see if they are in the expected physiological range of the signal you are analyzing. For example, if the header states that the signal is an ECG stored in milivolts, which typically has an amplitude of about 2mV, a signal of integers ranging from -32000 to 32000 probably isn't giving you the physical ECG in milivolts...
If they are not integers then they are physical. Once again you can quickly compare the values to see if they are in the expected physiological range of the signal you are analyzing.
如果它们都是 [-2^N, 2^N-1 ] 或 [ 0, 2^N ] 范围内的整数,则它们可能是数字。比较这些值,看看它们是否在您正在分析的信号的预期生理范围内。例如,如果标题指出信号是以毫伏为单位存储的心电图,其幅度通常约为 2mV,那么范围从 -32000 到 32000 的整数信号可能不会以毫伏为单位提供物理心电图...
如果它们不是整数,那么它们就是物理的。您可以再次快速比较这些值,看看它们是否在您正在分析的信号的预期生理范围内。
0-9-10 wfdb - physical units
0-9-10 wfdb - 物理单位
We say that signals are in 'physical units' when the values are used to represent the actual real life values as closely as possible, although obviously everything on the computer is digital and discrete rather than analogue and continuous. This includes our precious 64 bit double precision floating point values, but this is as close as we can get and already very close to the actual physical values, so we refer to them as 'physical'.
-
For example, if a 15 bit signal is collected via a capturing device, Physionet will likely store it as a 16 bit signal. Each 16 bit block stores an integer value between -2^15 and 2^15-1, and using the gain and offset stated in the header for each channel, the original physical signal can be mapped out for processing.
当使用值尽可能接近地表示实际的现实生活值时,我们说信号以“物理单位”表示,尽管显然计算机上的一切都是数字和离散的,而不是模拟和连续的。这包括我们宝贵的 64 位双精度浮点值,但这是我们所能得到的,并且已经非常接近实际物理值,因此我们将它们称为“物理”。
——
例如,如果通过捕获设备收集 15 位信号,Physionet 可能会将其存储为 16 位信号。每个 16 位块存储一个介于 -2^15 和 2^15-1 之间的整数值,并使用每个通道标头中规定的增益和偏移量,可以映射出原始物理信号进行处理。
The default units are now physical units where base and gain should be added stated in the header for each channel, so the physical signal can be mapped out for processing.
默认单位现在是物理单位,其中应在每个通道的标题中添加基础和增益,因此可以映射出物理信号进行处理。
% rawUnits
% A 1x1 integer (default: 0). Returns tm and signal as vectors
% according to the following values:
% rawUnits=0 - Uses Java Native Interface to directly fetch data, returning signal in physical units with double precision.
% rawUnits=1 -returns tm ( millisecond precision only! ) and signal in physical units with 64 bit (double) floating point precision
% rawUnits=2 -returns tm ( millisecond precision only! ) and signal in physical units with 32 bit (single) floating point precision
% rawUnits=3 -returns both tm and signal as 16 bit integers (short). Use Fs to convert tm to seconds.
% rawUnits=4 -returns both tm and signal as 64 bit integers (long). Use Fs to convert tm to seconds.
rawUnits=1, rawUnits=2use also physical units.
rawUnits=3, rawUnits=4use then again analog/digital units where you need to remove base and gain.
If you use rawUnits=1or rawUnits=2, you need to adjust for base and gain where base = 1024and gain = 200
rawUnits=1,rawUnits=2也使用物理单位。
rawUnits=3,rawUnits=4然后在需要删除基数和增益的地方再次使用模拟/数字单位。如果您使用rawUnits=1或rawUnits=2,则需要调整 base 和增益 wherebase = 1024和gain = 200
# Kamtal's method in considering base and gain
load('201m.mat');
val = (val - 1024)/200; % you have to remove "base" and "gain"
ECGsignal = val(1,16:950); % select the lead (Lead I)
See the .info file below where you can get the baseand gain. There is also the unit mVwhich suggests the values should be near 2after the base-gain operations.
请参阅下面的 .info 文件,您可以在其中获取base和gain。还有一个单位mV表明2在基本增益操作之后值应该接近。
<0-9-9 wfdb - analog/digital units so base and gain by default; now only rawUnits=3,4for analog units
<0-9-9 wfdb - 模拟/数字单位,因此默认为基础和增益;现在仅rawUnits=3,4适用于模拟单元
After selection ATM, you should be able to see the list where you can select .infofile after the export as described in Kamtal's answer. The .infofile instructs to remove so-called baseand gainfrom the data before use
选择 ATM 后,您应该能够看到可以在导出后选择.info文件的列表,如 Kamtal 的回答中所述。该.INFO文件指示,除去所谓的基地和增益从使用前的数据
Source: record mitdb/201 Start: [00:02:10.000]
val has 2 rows (signals) and 3600 columns (samples/signal)
Duration: 0:10
Sampling frequency: 360 Hz Sampling interval: 0.002777777778 sec
Row Signal Gain Base Units
1 MLII 200 1024 mV
2 V1 200 1024 mV
To convert from raw units to the physical units shown
above, subtract 'base' and divide by 'gain'.
Comparing wrong answers here! [Deprecated]
在这里比较错误的答案![已弃用]
Kamtal (now called Rashid) answer is about the old wfdb system which used digital units without removal of base and gain
Kamtal(现在称为 Rashid)的答案是关于旧的 wfdb 系统,该系统使用数字单位而不去除基数和增益
# Kamtal's method in considering base and gain
load('201m.mat');
val = (val - 1024)/200; % you have to remove "base" and "gain"
ECGsignal = val(1,16:950); % select the lead (Lead I)
# Method without considering base and gain
load('201m.mat');
ECGsignal2 = val(1,16:950);
# http://www.mathworks.com/matlabcentral/fileexchange/10502-image-overlay
imshow(imoverlay(ECGsignal, ECGsignal2, uint8([255,0,0])))
and you get the difference between my method and his method
你会明白我的方法和他的方法之间的区别



