Home > bioelectromagnetism > eeg_load_scan_cnt.m

eeg_load_scan_cnt

PURPOSE ^

eeg_load_scan_cnt - Load continuous NeuroScan data.

SYNOPSIS ^

function [x,y,tex,elec,cal,oth]=loadcnt(filen,elec,start,last);

DESCRIPTION ^

 eeg_load_scan_cnt - Load continuous NeuroScan data.

    [X,Y,LAB,ELEC,CAL,OTH]=LOADCNT(FILEN,ELEC,START,LAST) elec defines 
       which electrodes are read, size - rows data in y. If elec=[] then 
    reads all channels data between start and end points. If elec
    is string then only matched are read and with elec corresponding
    channelnumbers are returned. lab is lab(elec). Text oth is ['rev  '
    ;'date ';'time ';'nchan';'rate ';'datas';'Chann';'size';'TeegT']
    read by scanhead.

    filen can be filename or file identifier. Because function scanelec,
    scanhead are slow, variables lab, cal and oth are saved into 
    file.mat file in directory "Headers". If *.cnt file is changed you 
    have to remove file.mat for new parameters to be read.

DIAGNOSTICS
    Perhaps sensitive to different SynAmps parameters. Used global 
    variable is DIRS.

REFERENCES
    Neurosoft. Structure of data headers. 1993.

SEE ALSO
    Uses scanhead, scanelec, showwait.

EXAMPLES
                    % load and show first 1000 points
    [x,y,la,el,ca,ot]=loadcnt('x70001a1.cnt',[],1,1000);
    figure
    plotdata(x,y,la,[50 50]);ot,xlabel('t (s');ylabel('100 uV');
    print Help\loadcnt -djpeg

                    % test loading large samples
    [x,y1]=loadcnt('testec','FZ',1,30010);
    [x,y2]=loadcnt('testec','FZ',30000,30100);[y1(30000:30010),y2]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,y,tex,elec,cal,oth]=loadcnt(filen,elec,start,last);
0002 
0003 % eeg_load_scan_cnt - Load continuous NeuroScan data.
0004 %
0005 %    [X,Y,LAB,ELEC,CAL,OTH]=LOADCNT(FILEN,ELEC,START,LAST) elec defines
0006 %       which electrodes are read, size - rows data in y. If elec=[] then
0007 %    reads all channels data between start and end points. If elec
0008 %    is string then only matched are read and with elec corresponding
0009 %    channelnumbers are returned. lab is lab(elec). Text oth is ['rev  '
0010 %    ;'date ';'time ';'nchan';'rate ';'datas';'Chann';'size';'TeegT']
0011 %    read by scanhead.
0012 %
0013 %    filen can be filename or file identifier. Because function scanelec,
0014 %    scanhead are slow, variables lab, cal and oth are saved into
0015 %    file.mat file in directory "Headers". If *.cnt file is changed you
0016 %    have to remove file.mat for new parameters to be read.
0017 %
0018 %DIAGNOSTICS
0019 %    Perhaps sensitive to different SynAmps parameters. Used global
0020 %    variable is DIRS.
0021 %
0022 %REFERENCES
0023 %    Neurosoft. Structure of data headers. 1993.
0024 %
0025 %SEE ALSO
0026 %    Uses scanhead, scanelec, showwait.
0027 %
0028 %EXAMPLES
0029 %                    % load and show first 1000 points
0030 %    [x,y,la,el,ca,ot]=loadcnt('x70001a1.cnt',[],1,1000);
0031 %    figure
0032 %    plotdata(x,y,la,[50 50]);ot,xlabel('t (s');ylabel('100 uV');
0033 %    print Help\loadcnt -djpeg
0034 %
0035 %                    % test loading large samples
0036 %    [x,y1]=loadcnt('testec','FZ',1,30010);
0037 %    [x,y2]=loadcnt('testec','FZ',30000,30100);[y1(30000:30010),y2]
0038 
0039 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0040 
0041 %Mention source when using or modifying these Shareware tools
0042 %JVIR, Jussi.Virkkala@occuphealth.fi
0043 %JVIR,  7-Feb-1999 Saving into Headers location not Data Headers.
0044 %JVIR,  3-Feb-1999 Modified for PCWIN Matlab 5.2.
0045 %
0046 %   J.Virkkala 30-Jun-94
0047 %   J.Virkkala 12-Jan-95 Added parameter oth.
0048 %   J.Virkkala 24-Jan-95 Saving header values into file.mat.
0049 %   J.Virkkala 22-Feb-95 SynAmps working, Strings as file name.
0050 %   J.Virkkala  3-Mar-95 Part of ScanUtil.
0051 %    J.Virkkala 23-May-95 Still some problems with SynAmps.
0052 
0053 global DIRS 
0054 % only integer positions accepted
0055 start=round(start);last=round(last);
0056 %*** FILENUMBER OR NAME AS PARAMETER ***
0057 if isstr(filen),
0058     file=fopen(filen,'r','l');
0059 else
0060     file=filen;
0061 end;
0062 if file==-1,errorr('hff','loadcnt');break;end
0063 name=[filename(file) '.mat'];
0064 if exist(name),eval(['load ' name]);else 
0065     % load electrodes calibration
0066     showwait('loading calibrations - %1.0f');
0067     [a,a,d]=scanelec(['lab';'bas';'sen';'cal'],'',file);
0068     n=size(d,1);
0069     nchannels=n/5;
0070     lab=d(2:5:n,:);
0071     for i=1:nchannels;
0072         cal(i,1)=eval(d(i*5-2,:));  % baseline
0073         cal(i,2)=eval(d(i*5-1,:));  % sensitivity
0074         cal(i,3)=eval(d(i*5,:));    % calibration
0075     end;
0076     [a,a,oth]=scanhead(['rev  ';'date ';'time ';'ncha ';'rate ';'datas';...
0077             'Chann';'size ';'TeegT'],file);
0078     bs=10*eval(oth(4,:));
0079     oth=putstr(mat2str(floor(eval(oth(6,:))/bs)*bs-1),oth,6,1);
0080     if ~exist('ele'),ele=[];end   % created by eegevent
0081     eval(['save ''Headers' DIRS name ''' cal lab oth ele']);   
0082     showwait('');
0083 end; 
0084 nchannels=size(lab,1);
0085 % if all electrodes
0086 if isempty(elec);elec=1:nchannels;end;
0087 
0088 % if want to look match
0089 if isstr(elec);
0090     e=[];
0091     for i=1:size(elec,1);
0092         p=strfind(lab,deblank(elec(i,:)));
0093         % if found
0094         if size(p)~=[0,0];
0095             p=p(:,1);
0096             if size(e,1)>size(p,1);
0097                 p(size(e,1),1)=0;
0098             end;
0099             if size(e,1)==0;
0100                 %JVIR           p=p(find(p~=e)); % with same string possible diffent text
0101             end;
0102             p=p(1,1);
0103             size(e);
0104             if p;if size(e)==[0,0];e=p;else;e=[e;p];end;end;
0105         end;
0106     end;
0107     % names -> corresponding numbers
0108     elec=e';
0109 else
0110     elec=elec(:)';
0111 end;   
0112 
0113 M=3000;y1=[];
0114 %*** REPEATINGS FOR LONG SAMPLES ****
0115 %JVIR, 4-Feb-1999
0116 y=[];
0117 x=[];
0118 if (last-start)>M,
0119     for ind=start:M:last;
0120         e=ind+M-1;
0121         if e>last,e=last;end
0122         [x1,y1,tex,elec,cal,oth]=loadcnt(file,elec,ind,e);
0123         y=[y y1];
0124         x=[x x1];
0125     end
0126 else
0127     
0128     l=eval(oth(6,:));
0129     if isempty(last),last=l;end
0130     if size(elec)==[0,0];return;end;
0131     % read data
0132     
0133     %*** NEUROSCAN SYNAMPS ***
0134     if eval(oth(7,:))>1310000,    % ==1310720
0135         bs=10*nchannels;    % block size
0136         st=floor(start/bs)*bs;
0137         la=ceil(last/bs)*bs;
0138         
0139         x=1:(last-start)+1;
0140         fseek(file,900+nchannels*(75+st*2),-1);
0141         Yall=fread(file,[nchannels*10,(la-st)/10],'short');
0142         % only wanted
0143         y(nchannels,(la-st))=0;
0144         for i=1:size(elec,2),
0145             el=elec(i);
0146             a=Yall((el-1)*10+1:el*10,:);
0147             y(el,:)=a(:)';
0148         end
0149         s=x+start-st;
0150         %??? some problems with index ???
0151         if max(s)>size(y,2);s=s-1;end
0152         Yall=y(:,s);y=[];        % x+start-st
0153         I=ones(size(elec,2),size(x,2));
0154         y(1:size(elec,2),1:size(x,2))=sparse(diag(cal(elec,2)))*sparse(diag(cal(elec,3)))*...
0155             (Yall(elec,x)-sparse(diag(cal(elec,1)))*I)./204.8;
0156     else
0157         
0158         %*** NEUROSCAN FORMAT ***
0159         % fast but needs memory
0160         x=1:(last-start)+1;         
0161         fseek(file,900+nchannels*(75+(start-1)*2),-1);
0162         Yall=fread(file,[nchannels,(last-start+1)],'short');
0163         % only wanted channels
0164         I=ones(size(elec,2),size(x,2));
0165         y(1:size(elec,2),1:size(x,2))=sparse(diag(cal(elec,2)))*sparse(diag(cal(elec,3)))*...
0166             (Yall(elec,x)-sparse(diag(cal(elec,1)))*I)./204.8;
0167     end
0168     
0169     x=x+ones(1,size(x,2))*(start-1);
0170     x=x/eval(oth(5,:));         % xlabel in seconds
0171     tex=lab(elec,:);
0172 end
0173 
0174 
0175 %*** FILENUMBER OR NAME AS PARAMETER ***
0176 if isstr(filen),
0177     fclose(file);
0178 end;
0179 
0180 %END OF LOADCNT

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003