⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mwfopen.m

📁 matlab数字信号处理工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
function [HDR]=mwfopen(HDR,PERMISSION,arg3,arg4,arg5,arg6)
% MWFOPEN reads MFER files 
%
% HDR = mwfopen(Filename,PERMISSION);
%
% HDR contains the Headerinformation and internal data
%
% see also: SOPEN, SREAD, SSEEK, STELL, SCLOSE, SWRITE, SEOF


% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
        HDR.FILE.OPEN= 0; 

%	$Revision: 1.3 $
%	$Id: mwfopen.m,v 1.3 2004/05/02 11:00:02 schloegl Exp $
%	(C) 2004 by Alois Schloegl
%	a.schloegl@ieee.org	
%    	This is part of the BIOSIG-toolbox http://biosig.sf.net/


if nargin<1, PERMISSION='rb'; end;
if ischar(HDR)
        tmp=HDR;
        HDR=[];
        HDR.FileName=tmp;
end;

VER = version;

HDR.FILE.FID = fopen(HDR.FileName,PERMISSION,'ieee-be');
HDR.Endianity= 'ieee-be';

%%% Default values %%%
HDR.SampleRate = 1000;
HDR.GDFTYP = 3;        
HDR.AS.bps = 2;
HDR.SPR = NaN;
HDR.NS = 1; 
HDR.NRec = NaN; 
HDR.Off = 0; 
HDR.Cal = NaN; 

fprintf(2,'Warning MWFOPEN: support of MFER format not complete, but in testing state\n');
%% default values 
% standard 12 leads ECG codes 
ECG12LeadsCodes(1:9)={'I';'II';'V1';'V2';'V3';'V4';'V5';'V6';'V1'};
ECG12LeadsCodes(11:15)={'V3R';'V4R';'V5R';'V6R';'V7R'};
ECG12LeadsCodes(61:64)={'III';'aVR';'aVL';'aVF'};
ECG12LeadsCodes(66:69)={'V8';'V9';'V8R';'V9R'};

if ~isempty(findstr(PERMISSION,'r')),		%%%%% READ 
        HDR.FILE.OPEN = 1;
        HDR.FRAME.N = 0; 
        count = 1;
        %while count>0, %~feof(HDR.FILE.FID)
        while ~feof(HDR.FILE.FID)
                tag = fread(HDR.FILE.FID,1,'uchar');
                len = fread(HDR.FILE.FID,1,'char');
                %fprintf(1,'[%i] Tag %i: (%i)\n',ftell(HDR.FILE.FID),tag,len);

                if (len < 0) | (len > 127),
                        l   = mod(len,128);
                        len = fread(HDR.FILE.FID,[l,1],'uchar');
                        %len = 256.^[0:l-1]*len;        
                        len = 256.^[l-1:-1:0]*len;
                end;
                % tmp = fread(HDR.FILE.FID,[1,len],'char');
                % fprintf(1,'[%i] Tag %i: (%i)\n',ftell(HDR.FILE.FID),tag,len);
                
                if 0,
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'char');
                        
                elseif tag==0; 
                        [tmp,count] = fread(HDR.FILE.FID,[1,1],'char');
                        
                elseif tag==1;
                        [tmp,count] = fread(HDR.FILE.FID,[1,1],'char');
                        if 0, 
                        elseif (tmp==0) & strcmp(HDR.Endianity,'ieee-le'),
                                tmp = ftell(HDR.FILE.FID);
                                HDR.Endianity='ieee-be';
                                fclose(HDR.FILE.FID);
                                HDR.FILE.FID = fopen(HDR.FileName,PERMISSION,HDR.Endianity);
                                fseek(HDR.FILE.FID,tmp,'bof');
                        elseif (tmp==1) & strcmp(HDR.Endianity,'ieee-be'),
                                tmp = ftell(HDR.FILE.FID);
                                HDR.Endianity='ieee-le';
                                fclose(HDR.FILE.FID);
                                HDR.FILE.FID = fopen(HDR.FileName,PERMISSION,HDR.Endianity);
                                fseek(HDR.FILE.FID,tmp,'bof');
                        else
                        end;
                        
                elseif tag==2;
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'char');
                        HDR.Version = tmp;
                        
                elseif tag==3;
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'char');
                        HDR.tag03 = tmp;
                        
                elseif tag==4;          % channel number
                        if len == 0;
                                tmp = NaN;
                        elseif len == 1;
                                [tmp,count] = fread(HDR.FILE.FID,1,'uint8');
                        elseif len == 2;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int16');
                        elseif len == 3;
                                [tmp,count] = fread(HDR.FILE.FID,1,'bit24');
                                %[tmp,count] = fread(HDR.FILE.FID,3,'uint8');
                                %tmp = (2.^[16,8,0])*tmp;
                        elseif len == 4;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int32');
                        else
                                fprintf(2,'Error MWFOPEN: len=%i exceeds max length (4) in tag 04h\n',len);
                        end;
                        %[HDR.SPR,count] = fread(HDR.FILE.FID,[1,len],'uchar');
                        HDR.SPR = tmp;
                        
                elseif tag==5;
%                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'uchar');
                        if len == 0;
                                tmp = 1;
                        elseif len == 1;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int8');
                        elseif len == 2;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int16');
                        elseif len == 3;
                                [tmp,count] = fread(HDR.FILE.FID,1,'bit24');
                                %tmp = (2.^[16,8,0])*tmp;
                                %tmp = (2.^[0:8:16])*tmp;
                        elseif len == 4;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int32');
                        else
                                fprintf(2,'Error MWFOPEN: max length exceeded in tag 05h\n');
                        end;
                        HDR.NS = tmp; %*256.^[len-1:-1:0]';

                elseif tag==6;
                        if len == 0;
                                tmp = NaN;
                        elseif len == 1;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int8');
                        elseif len == 2;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int16');
                        elseif len == 3;
                                [tmp,count] = fread(HDR.FILE.FID,1,'bit24')
                                %tmp = (2.^[16,8,0])*tmp;
                        elseif len == 4;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int32');
                        else
                                fprintf(2,'Error MWFOPEN: max length exceeded in tag 06h\n');
                        end;
                        HDR.NRec = tmp;
                                
                elseif tag==7;
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'uchar')
                        HDR.Pointer = tmp*256.^[0:len-1]';
                        
                elseif tag==8;
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'uchar');
                        if tmp==0,
                                HDR.MFER.WaveFormType = 'undefined';
                        elseif tmp==1,
                                HDR.MFER.WaveFormType = 'ECG_STD12';
                        elseif tmp==2,
                                HDR.MFER.WaveFormType = 'ECG_LTERM';
                        elseif tmp==3,
                                HDR.MFER.WaveFormType = 'Vectorcardiogram';
                        elseif tmp==4,
                                HDR.MFER.WaveFormType = 'Stress_ECG';
                        elseif tmp==5,
                                HDR.MFER.WaveFormType = 'ECG_LTERM';
                        else
                                HDR.MFER.WaveFormType = tmp;
			end
                        
                elseif tag==9; 
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'uchar');
                        HDR.Label=char(tmp);
                        
                elseif tag==10;
                        [tmp,count] = fread(HDR.FILE.FID,[1,len],'uchar');
                        if tmp==0;	% int16, default
                                HDR.GDFTYP = 3;
                                HDR.AS.bps = 2;
                        elseif tmp==1;	% uint16
                                HDR.GDFTYP = 4;
                                HDR.AS.bps = 2;
                        elseif tmp==2;	% int32
                                HDR.GDFTYP = 5;
                                HDR.AS.bps = 4;
                        elseif tmp==3;	% uint8
                                HDR.GDFTYP = 3;
                                HDR.AS.bps = 1;
                        elseif tmp==4;	% 16bit status
                                HDR.GDFTYP = 4;
                                HDR.AS.bps = 2;
                        elseif tmp==5;	% int8
                                HDR.GDFTYP = 1;
                                HDR.AS.bps = 1;
                        elseif tmp==6;	% uint32
                                HDR.GDFTYP = 6;
                                HDR.AS.bps = 4;
                        elseif tmp==7;	% float32
                                HDR.GDFTYP = 16;
                                HDR.AS.bps = 4;
                        elseif tmp==8;	% float64
                                HDR.GDFTYP = 17;
                                HDR.AS.bps = 8;
                        elseif tmp==9;	% 8 bit AHA compression 
                                HDR.GDFTYP = 4;
                                HDR.AS.bps = NaN;
                                fprintf(2,'Error MWFOPEN: compression not supported, yet.\n');
                        end;
                        
                elseif tag==11;       
                        [tmp1,count] = fread(HDR.FILE.FID,2,'int8');
                        len = len - 2;
                        if len == 1;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int8');
                        elseif len == 2;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int16');
                        elseif len == 3;
                                [tmp,count] = fread(HDR.FILE.FID,1,'bit24');
                        elseif len == 4;
                                [tmp,count] = fread(HDR.FILE.FID,1,'int32');
                        end;
                        e = 10^tmp1(2);
                        if     tmp1(1)==0, 
                                HDR.Xphysdim = 'Hz';
                                HDR.SampleRate=tmp*e;
                        elseif tmp1(1)==1, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -