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

📄 edfread.m

📁 该程序可以读取欧洲格式.edf和.rec的数据
💻 M
字号:
function [S,count]=edfread(EDF,arg2,Mode,arg4)% [S]=edfread(EDF_Struct,[NoR STARTPOS],Mode)% Loads selected Records of an EDF File (European Data Format for Biosignals)
% one block per column (EDF raw form)%          size(S)=[samples_per_record x number_of_Records]
%% [S]=edfread(EDF_Struct,[NoR STARTPOS],Mode,CHAN)
% if CHAN (all elements must be non-negative) is provided, the channels are reordered
%         the channels are ordered column-wise
%         In case CHAN=0 all channels are loaded
%         size(S)=[max(samples_per_chan), number_of_channels]
%
% [S]=edfread(EDF_Struct,[NoR STARTPOS],Mode,ReRefMx)
% the channels are re-referenced with ReRefMx. Usually Mode=0 has to be used.
% any element in ReRefMx must be negative, otherwise arg4 is used as channel selector CHAN
%         the channels are ordered column-wise
%         size(S)=[max(samples_per_chan), size(ReRefMx,2)]
%
% INPUT:
%   EDF_Struct  struct as defined by EDFOPEN(filename)
%   NoR      read next NoR units, units can be seconds or blocks 
%   STARTPOS [otional] goto STARTPOS before reading, units can be seconds or blocks 
%   Mode	0 	autoscaling,      read NoR blocks
%       	1* 	No autoscaling,   read NoR blocks, default
%        	2 	autoscaling,      read NoR seconds
%       	3 	No autoscaling,   read NoR seconds
%
% OUTPUT:
%   S           data
%   
 %	Version 3.08
%	12.11.1998%	Copyright (c) 1997-98 by Alois Schloegl%	a.schloegl@ieee.org	
                      % 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.if nargin<4 
        chan=1:EDF.NS; 
else
        if arg4==0 
                chan=1:EDF.NS; 
                %ReRefMx=eye(ns);
        elseif any(arg4<0)
                chan=find(any(arg4,2))';
                ReRefMx=arg4;
        else
                chan=reshape(arg4,1,prod(size(arg4)));
                ReRefMx=sparse(arg4,arg4,1);
        end;
        
        if any(EDF.SPR(chan)~=EDF.SPR(chan(1))) fprintf(2,'Warning EDFREAD: channels do not have the same sampling rate\n');end;
end;
if nargin<3 Mode=1; end;if nargin<2 arg2=1;end;

% Position file pointer and calculate number of Records
if any(Mode==[2 3])
        if ~all(~rem(arg2,EDF.Dur))
                fprintf(2,'Warning EDFREAD: arg2 does not fit to blocklength of EDF File of %i s.\n',EDF.Dur);
        end;
        arg2=arg2/EDF.Dur;
end;

if length(arg2)>1
        [status,POS]=edfseek(EDF,arg2(2),'bof'); 
end;
Records=arg2(1);

[s, count]=fread(EDF.FILE.FID,[EDF.AS.spb, Records],'int16');
count=floor(count/EDF.AS.spb);

if count<1 fprintf(2,'Warning EDFREAD: only % i blocks were read instead  of %i\n',count,Records); end;
bi=[0;cumsum(EDF.SPR)]; 
if any(Mode==[0 2])          % Autocalib 
        for k=chan,
                s(bi(k)+1:bi(k+1),:)=s(bi(k)+1:bi(k+1),:)*EDF.Cal(k)+EDF.Off(k);
        end;
end;

if nargin==4
        maxspr=max(EDF.SPR(chan));
        S=zeros(maxspr*Records,length(chan));
        if ~all(EDF.SPR(chan)==EDF.SPR(chan(1)))
                for k=1:length(chan),
                        K=chan(k);
                        tmp=reshape(s(bi(K)+1:bi(K+1),:),EDF.SPR(K)*Records,1);
                        S(:,k)=reshape(tmp(:,ones(1,maxspr/EDF.SPR(K)))',maxspr*Records,1);
                end;
        else
                for k=1:length(chan),
                        K=chan(k);
                        S(:,k)=reshape(s(bi(K)+1:bi(K+1),:),maxspr*Records,1);
                end;
        end;
        if any(arg4<0)
                S=S*ReRefMx(chan,:);
        end;
else
        S=s;
end;

⌨️ 快捷键说明

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