clear all;
clc;
close all;
%------ 具体数据------------------------------------------------------
PATH= 'E:\MIT-BIH\100'; % path, 这里就是写刚才你保存的数据地址
HEADERFILE= '100.hea';
ATRFILE= '100.atr';
DATAFILE='100.dat';
SAMPLES2READ=6600;
% 文件格式为文本格式
% attributes-file 文件以二进制格式
% data-file
% 读取的数据样本点数为 660000
% in case of more than one signal:
% 2*SAMPLES2READ samples are read
%取字节的低四位
%绘制一段心电图形
% data in format 212
%------ LOAD HEADER DATA --------------------------------------------------
signald= fullfile(PATH, DATAFILE);
fid2=fopen(signald,'r');
A= fread(fid2, [3, SAMPLES2READ], 'uint8')'; % matrix with 3 rows, each 8 bits long,
= 2*12bit
fclose(fid2);
%=----------------------载入二进制数据-----------------------------------------
M2H= bitshift(A(:,2), -4);
M1H= bitand(A(:,2), 15);
M( : , 1)= bitshift(M1H,8)+ A(:,1); %低四位向左移八位
M( : , 2)= bitshift(M2H,8)+ A(:,3); %高四位向左移八位
M = M-1024;
据
plot (M(100:1200,1));
%字节向右移四位,即取字节的高四位
%这个 M 就是咱们解码出来的数