📄 sdfread.m
字号:
for n=1:size(EDF.AFIR.xin,1), EDF.AFIR.x = xinre2(n + (EDF.AFIR.nord:-1:1)); % x(1:EDF.AFIR.nord-1)]; y = EDF.AFIR.w * EDF.AFIR.x'; en = EDF.AFIR.x * EDF.AFIR.x' + EDF.AFIR.gamma; e(n,:) = ddin(n,:) - y'; EDF.AFIR.w = EDF.AFIR.w + (EDF.AFIR.alfa/en) * e(n,:)' * EDF.AFIR.x; end; EDF.AFIR.d = ddin(size(ddin,1)+(1-EDF.AFIR.delay:0),:); S=e; %output %S(:,EDF.AFIR.channel2) = e; %OUTPUTend;%%%%% select the correct secondsif ~EDF.SIE.RAW & EDF.SIE.TimeUnits_Seconds if NoR>0 %EDF.Block, %[StartPos,StartPos+NoS,EDF.AS.startrec*EDF.Dur] if (StartPos < EDF.AS.startrec*EDF.AS.MAXSPR) tmp = S(size(S,1)+(1-EDF.AS.MAXSPR:0),:); if (nargout>2) & EDF.SIE.TH tmp0 = OFCHK(size(S,1)+(1-EDF.AS.MAXSPR:0),:); end; EDF.Block.number(3) = StartPos; EDF.Block.number(4) = (StartPos+NoS); S = [EDF.Block.data(floor(EDF.Block.number(3)-EDF.Block.number(1))+1:EDF.AS.MAXSPR,:); S(1:floor(EDF.Block.number(4)-EDF.AS.startrec*EDF.AS.MAXSPR),:)]; if (nargout>2) & EDF.SIE.TH OFCHK = [EDF.Block.data(floor(EDF.Block.number(3)-EDF.Block.number(1))+1:EDF.AS.MAXSPR,:); S(1:floor(EDF.Block.number(4)-EDF.AS.startrec*EDF.AS.MAXSPR),:)]; EDF.Block.dataOFCHK = tmp0; end; EDF.Block.number(1:2)=(EDF.FILE.POS+[-1 0])*EDF.AS.MAXSPR; EDF.Block.data = tmp; else EDF.Block.number(3) = StartPos; EDF.Block.number(4) = (StartPos+NoS); EDF.Block.number(1:2)=(EDF.FILE.POS+[-1 0])*EDF.AS.MAXSPR; EDF.Block.data = S(size(S,1)+(1-EDF.AS.MAXSPR:0),:); %[floor(EDF.Block.number(3)-EDF.AS.startrec*EDF.AS.MAXSPR)+ 1,floor(EDF.Block.number(4)-EDF.AS.startrec*EDF.AS.MAXSPR)], S = S(floor(EDF.Block.number(3)-EDF.AS.startrec*EDF.AS.MAXSPR)+ 1:floor(EDF.Block.number(4)-EDF.AS.startrec*EDF.AS.MAXSPR),:); if (nargout>2) & EDF.SIE.TH EDF.Block.dataOFCHK = OFCHK(size(S,1)+(1-EDF.AS.MAXSPR:0),:); OFCHK = OFCHK(floor(EDF.Block.number(3)-EDF.AS.startrec*EDF.AS.MAXSPR)+ 1:floor(EDF.Block.number(4)-EDF.AS.startrec*EDF.AS.MAXSPR),:); end; %S = S(EDF.AS.MAXSPR/EDF.Dur*(rem(StartPos,EDF.Dur))+(1:NoR*EDF.AS.MAXSPR),:); end; else EDF.Block.number(3) = StartPos; EDF.Block.number(4) = (StartPos+NoS); EDF.Block.number(1:2)=(EDF.FILE.POS+[-1 0])*EDF.AS.MAXSPR; S = [EDF.Block.data(floor(EDF.Block.number(3)-EDF.Block.number(1))+1:floor(EDF.Block.number(4)-EDF.Block.number(1)),:)]; if (nargout>2) & EDF.SIE.TH OFCHK = [EDF.Block.dataOFCHK(floor(EDF.Block.number(3)-EDF.Block.number(1))+1:floor(EDF.Block.number(4)-EDF.Block.number(1)),:)]; end; %S = EDF.Block.data(floor(StartPos*EDF.AS.MAXSPR/EDF.Dur+1:floor((StartPos+NoS)*EDF.AS.MAXSPR/EDF.Dur),:)]; end;end;%end;%%%%% Resamplingif Mode_RS100 & ~Mode_RAW S=rs(S,EDF.SIE.T); %RS% % Resampling of Overflow Check if nargout>2, % if EDF.SIE.TH, OFCHK=rs(OFCHK, EDF.SIE.T); %RS% end; end;end;function [EDF]=sdftell(EDF)% EDF=sdftell(EDF_Struct)% returns the location of the EDF_file position indicator in the specified file. % Position is indicated in Blocks from the beginning of the file. If -1 is returned, % it indicates that the query was unsuccessful; % EDF_Struct is a struct obtained from sdfopen().%% EDF.FILE.POS contains the position of the EDF-Identifier in Blocks% Version 0.85% 15 Jun 2002% Copyright (c) 1997-2002 by Alois Schloegl% a.schloegl@ieee.org POS = ftell(EDF.FILE.FID);if POS<0 [EDF.ERROR,EDF.ErrNo] = ferror(EDF.FILE.FID); return; end;EDF.FILE.POS = (POS-EDF.HeadLen)/EDF.AS.bpb;EDF.ERROR=[];EDF.ErrNo=0;if (EDF.AS.startrec+EDF.AS.numrec)~=EDF.FILE.POS fprintf(2,'Warning SDFTELL: File postion error in EDF/GDF/SDF-toolbox.\n') EDF.AS.startrec = EDF.FILE.POS;end; function [status]=sdfeof(EDF)% sdfeof(EDF)% returns 1 if End-of-EDF-File is reached% returns 0 otherwise% Copyright (c) 1997-99 by Alois Schloegl% a.schloegl@ieee.org % Version 0.60% 16. Aug. 1999% status=feof(EDF.FILE.FID); % does not work properly%if EDF.FILE.POS~=EDF.AS.startrec+EDF.AS.numrec; status=(EDF.FILE.POS>=EDF.NRec);function [EDF]=sdfseek(EDF,offset,origin)% [EDF]=sdfseek(EDF,offset,origin)% Currently, offset and origin are the number of (EDF) records. % EDF.status contains the value of the older version of [status]=gdfseek(...) %% See also: FSEEK, SDFREAD, SDFWRITE, SDFCLOSE, SDFREWIND, GSFTELL, SDFEOF% Copyright (c) 1997-2002 by Alois Schloegl% a.schloegl@ieee.org % Version 0.85% 15. Juni 2002% 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 strcmp(origin,'bof') origin=-1; elseif strcmp(origin,'cof') origin=0; elseif strcmp(origin,'eof') origin=1; end;if origin==-1 EDF.FILE.POS = offset; OFFSET = EDF.AS.bpb*offset; status = fseek(EDF.FILE.FID,EDF.HeadLen+OFFSET,-1);elseif origin==0 EDF.FILE.POS = EDF.FILE.POS + offset; OFFSET = EDF.AS.bpb*offset; status = fseek(EDF.FILE.FID,OFFSET,0);elseif origin==1 EDF.FILE.POS = EDF.NRec+offset; OFFSET = EDF.AS.bpb*offset; status = fseek(EDF.FILE.FID,OFFSET,1);else fprintf(2,'error SDFSEEK: 3rd argument "%s" invalid\n',origin); return;end;EDF.AS.startrec=EDF.FILE.POS;EDF.AS.numrec = 0;EDF = sdftell(EDF); % not really needed, only for double check of algorithms% Initialization of Bufferblock for random access (without EDF-blocklimits) of data if ~EDF.SIE.RAW & EDF.SIE.TimeUnits_Seconds EDF.Block.number=[0 0 0 0]; % Actual Blocknumber, start and end time of loaded block, % % diff(EDF.Block.number(1:2))==0 denotes no block is loaded; % EDF.Block.number(3:4) indicate start and end of the returned data, [units]=samples. EDF.Block.data=[]; EDF.Block.dataOFCHK=[];end;if 1; %isfield(EDF,'AFIR'); if EDF.SIE.AFIR EDF.AFIR.w = zeros(EDF.AFIR.nC,max(EDF.AFIR.nord)); EDF.AFIR.x = zeros(1,EDF.AFIR.nord); EDF.AFIR.d = zeros(EDF.AFIR.delay,EDF.AFIR.nC); fprintf(2,'WARNING SDFSEEK: Repositioning deletes AFIR-filter status\n'); end;end;if 1; %isfield(EDF,'Filter'); if EDF.SIE.FILT [tmp,EDF.Filter.Z]=filter(EDF.Filter.B,EDF.Filter.A,zeros(length(EDF.Filter.B+1),length(EDF.SIE.ChanSelect))); EDF.FilterOVG.Z=EDF.Filter.Z; fprintf(2,'WARNING SDFSEEK: Repositioning deletes Filter status of Notch\n'); end;end;if 1; %isfield(EDF,'TECG') if EDF.SIE.TECG fprintf(2,'WARNING SDFSEEK: Repositioning deletes TECG filter status\n'); end;end;EDF.FILE.status=status;function datatyp=dt(x)k=1;EDF.GDFTYP(1)=x;if EDF.GDFTYP(k)==0 datatyp=('uchar');elseif EDF.GDFTYP(k)==1 datatyp=('int8');elseif EDF.GDFTYP(k)==2 datatyp=('uint8');elseif EDF.GDFTYP(k)==3 datatyp=('int16');elseif EDF.GDFTYP(k)==4 datatyp=('uint16');elseif EDF.GDFTYP(k)==5 datatyp=('int32');elseif EDF.GDFTYP(k)==6 datatyp=('uint32');elseif EDF.GDFTYP(k)==7 datatyp=('int64');elseif 0; EDF.GDFTYP(k)==8 datatyp=('uint64');elseif EDF.GDFTYP(k)==16 datatyp=('float32');elseif EDF.GDFTYP(k)==17 datatyp=('float64');elseif 0;EDF.GDFTYP(k)>255 & EDF.GDFTYP(k)< 256+64 datatyp=(['bit' int2str(EDF.GDFTYP(k))]);elseif 0;EDF.GDFTYP(k)>511 & EDF.GDFTYP(k)< 511+64 datatyp=(['ubit' int2str(EDF.GDFTYP(k))]);elseif EDF.GDFTYP(k)==256 datatyp=('bit1');elseif EDF.GDFTYP(k)==512 datatyp=('ubit1');elseif EDF.GDFTYP(k)==255+12 datatyp=('bit12');elseif EDF.GDFTYP(k)==511+12 datatyp=('ubit12');elseif EDF.GDFTYP(k)==255+22 datatyp=('bit22');elseif EDF.GDFTYP(k)==511+22 datatyp=('ubit22');elseif EDF.GDFTYP(k)==255+24 datatyp=('bit24');elseif EDF.GDFTYP(k)==511+24 datatyp=('ubit24');else fprintf(2,'Error GDFREAD: Invalid GDF channel type\n'); datatyp='';end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -