MIT-BIH ECG 心電數據+matlab繪圖詳解

本篇是爲了補充MIT-BIH ECG 心電數據的下載和讀取圖解這篇博客,爲大家提供方便。

該篇比較“久遠”,所以網站的內容稍微有些改變,參見:
https://www.physionet.org/cgi-bin/atm/ATM

(1)新網站可以直接導出.mat文件,供matlab或Octave使用,以下圖爲例(當然你也可以嘗試其他的內容):
網頁內容

(2)選中後下載相關文件即可:
下載內容
mat文件當然是數據;
infor裏面有儲存的信息,如果僅僅有mat文件顯然是不行的,因爲mat中的數據後面還要處理一下(除非你不想以mV爲縱座標的單位。。)

註釋後的matlab代碼:

%% usage: plotATM('RECORDm')
% This function reads a pair of files (RECORDm.mat and RECORDm.info) generated
% by 'wfdb2mat' from a PhysioBank record, baseline-corrects and scales the time
% series contained in the .mat file, and plots them.  The baseline-corrected
% and scaled time series are the rows of matrix 'val', and each
% column contains simultaneous samples of each time series.
%
% 'wfdb2mat' is part of the open-source WFDB Software Package available at
%    http://physionet.org/physiotools/wfdb.shtml
% If you have installed a working copy of 'wfdb2mat', run a shell command
% such as
%    wfdb2mat -r 100s -f 0 -t 10 >100sm.info
% to create a pair of files ('100sm.mat', '100sm.info') that can be read
% by this function.
%
% The files needed by this function can also be produced by the
% PhysioBank ATM, at
%    http://physionet.org/cgi-bin/ATM
%
function h = plotATM(Name)
if nargin == 0
    Name = '100m'; 
end

%% 讀取數據
infoName = strcat(Name, '.info');
matName = strcat(Name, '.mat');
Octave = exist('OCTAVE_VERSION');
load(matName);  % 採樣值變量的名字爲val
fid = fopen(infoName, 'rt');
fgetl(fid);   % 第一行
fgetl(fid);   % 第二行
fgetl(fid);   % 第三行
[freqint] = sscanf(fgetl(fid), 'Sampling frequency: %f Hz  Sampling interval: %f sec');  % 得到採樣頻率和採樣間隔
interval = freqint(2);  % 取採樣間隔
fgetl(fid);   % 第五行

if(Octave)  % 一種軟件:http://blog.csdn.net/Forlogen/article/details/54425766
    for i = 1:size(val, 1)
       R = strsplit(fgetl(fid), char(9));
       signal{i} = R{2};
       gain(i) = str2num(R{3});
       base(i) = str2num(R{4});
       units{i} = R{5};
    end
else
    for i = 1:size(val, 1)
        Infor = textscan(fgetl(fid),'%d%s%f%f%s','delimiter','\t');
        row = Infor{1};
        signal{i} = Infor{2};  % 導聯名稱
        gain(i) = Infor{3};    % 增益
        base(i) = Infor{4};    % base
        units{i} = Infor{5};   % 單位
    end
end

fclose(fid);

%% 數據處理並作圖
val(val==-32768) = NaN;  
for i = 1:size(val, 1)
    val(i, :) = (val(i, :) - base(i)) / gain(i);  % 轉化爲mV
end
x = (1:size(val, 2)) * interval; % 採樣時間
plot(x', val');
for i = 1:length(signal)
    labels{i} = strcat(signal{i},'(', units{i},')'); 
end
if length(signal) == 1
    legend(labels{1});
else
    legend(labels);
end
xlabel('Time (sec)');
xlim([min(x) max(x)]);  % 設置橫座標
end

整個操作其實超級簡單,程序也不復雜,數據處理也不復雜,但大概大家缺的應該是資源獲取的途徑吧。

(3)關於ECG後續會有更新(弄點小波分析頻域分析什麼的)。。。

(4)代碼和數據見:MIT-BIH ECG 心電數據+matlab繪圖詳解

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章