Home > bioelectromagnetism > eeg_view_cnt.m

eeg_view_cnt

PURPOSE ^

eeg_view_cnt - Plot scan CNT data

SYNOPSIS ^

function [cnt] = eeg_view_cnt(filename,command,parent)

DESCRIPTION ^

 eeg_view_cnt - Plot scan CNT data
 
 eeg_view_cnt(filename,command,parent)
 
   filename    -   a string filename
   command     -   a string, 'init', 'hslider', 'vslider'
   parent      -   optional, for GUI parent
 
 Note: Works only with Scan 4.1+ data files

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [cnt] = eeg_view_cnt(filename,command,parent)
0002 
0003 % eeg_view_cnt - Plot scan CNT data
0004 %
0005 % eeg_view_cnt(filename,command,parent)
0006 %
0007 %   filename    -   a string filename
0008 %   command     -   a string, 'init', 'hslider', 'vslider'
0009 %   parent      -   optional, for GUI parent
0010 %
0011 % Note: Works only with Scan 4.1+ data files
0012 %
0013 
0014 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0015 
0016 % Licence:  GNU GPL, no express or implied warranties
0017 % History:  2002, Sean.Fitzgibbon@flinders.edu.au
0018 %           06/2002, Darren.Weber_at_radiology.ucsf.edu
0019 %                    adapted to eeg_toolbox
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 if ~exist('filename','var'),
0023   msg = sprintf('EEG_VIEW_CNT: No input filename\n');
0024   error(msg);
0025 end
0026 if ~exist('command','var'), command = 'init'; end
0027 
0028 
0029 switch command,
0030   
0031   case 'init',
0032     
0033     if exist('parent','var'),
0034       VIEWCNT = INIT(filename,parent);
0035     else
0036       VIEWCNT = INIT(filename);
0037     end
0038     
0039   case 'plot',
0040     
0041     VIEWCNT = get(gcbf,'userdata');
0042     
0043     % ------- Baseline parameters -------
0044     
0045     base = str2num(get(VIEWCNT.handles.baseline,'String'));
0046     
0047     % adjust baseline to multiple of sample rate
0048     minbase = (1/VIEWCNT.data.cnt.srate)*1000;
0049     base = floor(base / minbase) * minbase;
0050     % make sure baseline is within range of display
0051     if (base < minbase), base = minbase; end;
0052     maxbase = (VIEWCNT.data.dispNPoints/VIEWCNT.data.cnt.srate)*1000;
0053     if (base > maxbase), base = maxbase; end;
0054     % update baseline number displayed
0055     set(VIEWCNT.handles.baseline,'String',sprintf('%6.2f',base));
0056     VIEWCNT.data.base = 1:base;
0057     
0058     %  ------- Seconds displayed per page -------
0059     
0060     VIEWCNT.data.dispSeconds = str2num(get(VIEWCNT.handles.seconds,'String'));
0061     
0062     % must display at least 2 time points
0063     if (VIEWCNT.data.dispSeconds <= 0),
0064       minsec = (1000/VIEWCNT.data.cnt.srate) / 1000;
0065       VIEWCNT.data.dispSeconds = 2 * minsec;
0066     end;
0067     
0068     if (VIEWCNT.data.dispSeconds > VIEWCNT.data.points / VIEWCNT.data.cnt.srate ),
0069       % Request to display more seconds than currently loaded
0070       totalseconds = VIEWCNT.data.cnt.numSamples / VIEWCNT.data.cnt.srate;
0071       if(VIEWCNT.data.dispSeconds > totalseconds ),
0072         % Load ALL data
0073         VIEWCNT.data.dispSeconds = totalseconds;
0074         VIEWCNT.data.dispNPoints = floor(VIEWCNT.data.dispSeconds * VIEWCNT.data.cnt.srate);
0075         
0076         range = 'all';
0077       else,
0078         % Load more data
0079         VIEWCNT.data.dispNPoints = floor(VIEWCNT.data.dispSeconds * VIEWCNT.data.cnt.srate);
0080         VIEWCNT.data.dispEPoint = VIEWCNT.data.dispSPoint - 1 + VIEWCNT.data.dispNPoints;
0081         
0082         range(1) = VIEWCNT.data.dispSPoint;
0083         range(2) = VIEWCNT.data.dispEPoint;
0084       end;
0085       filename = [VIEWCNT.data.cnt.path,VIEWCNT.data.cnt.name];
0086       VIEWCNT.data.cnt = eeg_load_scan4_cnt(filename,'all',range);
0087       VIEWCNT.data.points = size(VIEWCNT.data.cnt.volt,1);
0088     else
0089       VIEWCNT.data.dispNPoints = floor(VIEWCNT.data.dispSeconds * VIEWCNT.data.cnt.srate);
0090       VIEWCNT.data.dispEPoint = VIEWCNT.data.dispSPoint - 1 + VIEWCNT.data.dispNPoints;
0091     end
0092     
0093     set(VIEWCNT.handles.seconds,'String',sprintf('%8.4f',VIEWCNT.data.dispSeconds));
0094     
0095     
0096     
0097     
0098     %  ------- Slider parameters -------
0099     
0100     slider = get(VIEWCNT.handles.Slider,'Value');
0101     
0102     sec = slider/VIEWCNT.data.cnt.srate;
0103     set(VIEWCNT.handles.Tslider,'String',sprintf('%8.4f sec',sec));
0104     
0105     point = floor(slider);
0106     if (point > VIEWCNT.data.dispEPoint),
0107       % Slider request for data beyond display range
0108       pointdif = point - VIEWCNT.data.dispEPoint;
0109       range(1) = VIEWCNT.data.dispSPoint -1 + pointdif;
0110       range(2) = range(1) + VIEWCNT.data.dispNPoints;
0111       
0112       if (range(2) > VIEWCNT.data.cnt.numSamples),
0113         % Ensure display range within data range
0114         range(1) = VIEWCNT.data.cnt.numSamples - VIEWCNT.data.dispNPoints;
0115         range(2) = VIEWCNT.data.cnt.numSamples;
0116       end;
0117       
0118       % Update display range and check whether or not to reload data
0119       if (VIEWCNT.data.dispSPoint < range(1)),
0120         filename = [VIEWCNT.data.cnt.path,VIEWCNT.data.cnt.name];
0121         VIEWCNT.data.cnt = eeg_load_scan4_cnt(filename,'all',range);
0122         VIEWCNT.data.dispSPoint = range(1);
0123       elseif (VIEWCNT.data.dispEPoint < range(2)),
0124         filename = [VIEWCNT.data.cnt.path,VIEWCNT.data.cnt.name];
0125         VIEWCNT.data.cnt = eeg_load_scan4_cnt(filename,'all',range);
0126         VIEWCNT.data.dispEPoint = range(2);
0127       end
0128       VIEWCNT.data.dispSPoint = range(1);
0129       VIEWCNT.data.dispEPoint = range(2);
0130       
0131     elseif (point < VIEWCNT.data.dispSPoint),
0132       % Slider request for data beyond display range
0133       pointdif = VIEWCNT.data.dispSPoint - point;
0134       range(1) = VIEWCNT.data.dispSPoint -1 - pointdif;
0135       if range(1) < 1, range(1) = 1; end;
0136       range(2) = range(1) + VIEWCNT.data.dispNPoints;
0137       
0138       if (range(2) > VIEWCNT.data.cnt.numSamples),
0139         % Ensure display range within data range
0140         range(1) = VIEWCNT.data.cnt.numSamples - VIEWCNT.data.dispNPoints;
0141         range(2) = VIEWCNT.data.cnt.numSamples;
0142       end;
0143       
0144       % Update display range and check whether or not to reload data
0145       if (VIEWCNT.data.dispSPoint > range(1)),
0146         filename = [VIEWCNT.data.cnt.path,VIEWCNT.data.cnt.name];
0147         VIEWCNT.data.cnt = eeg_load_scan4_cnt(filename,'all',range);
0148         VIEWCNT.data.dispSPoint = range(1);
0149       elseif (VIEWCNT.data.dispEPoint > range(2)),
0150         filename = [VIEWCNT.data.cnt.path,VIEWCNT.data.cnt.name];
0151         VIEWCNT.data.cnt = eeg_load_scan4_cnt(filename,'all',range);
0152         VIEWCNT.data.dispEPoint = range(2);
0153       end
0154       VIEWCNT.data.dispSPoint = range(1);
0155       VIEWCNT.data.dispEPoint = range(2);
0156     end;
0157     
0158     
0159     stime = (VIEWCNT.data.dispSPoint /VIEWCNT.data.cnt.srate) * 1000;
0160     etime = (VIEWCNT.data.dispEPoint /VIEWCNT.data.cnt.srate) * 1000;
0161     
0162     VIEWCNT.data.time = [stime:VIEWCNT.data.tstep:etime]';
0163     VIEWCNT.data.time = VIEWCNT.data.time(1:VIEWCNT.data.dispNPoints);
0164     
0165     volt = VIEWCNT.data.cnt.volt(1:VIEWCNT.data.dispNPoints,:);
0166     
0167     
0168     
0169     VIEWCNT.data.basemean = mean(VIEWCNT.data.cnt.volt(VIEWCNT.data.base,:));
0170     basemean = repmat(VIEWCNT.data.basemean,VIEWCNT.data.dispNPoints,1);
0171     
0172     % Now calculate voltage data and plot it
0173     volt = volt - basemean;
0174     plot(VIEWCNT.data.time,volt);
0175     set(VIEWCNT.axes,'XLim',[VIEWCNT.data.time(1) VIEWCNT.data.time(end)]);
0176     eeg_plot_metric;
0177     set(VIEWCNT.gui,'userdata',VIEWCNT);
0178     
0179   otherwise
0180     
0181     close gcbf;
0182   end
0183   
0184   cnt = VIEWCNT.data.cnt;
0185   
0186   return
0187   
0188   
0189   
0190   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0191   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0192   function [VIEWCNT] = INIT(filename,parent),
0193   
0194   % GUI General Parameters
0195   
0196   GUIwidth  = 150;
0197   GUIheight =  40;
0198   
0199   GUI = figure('Name','CNT View [alpha 1.0]','Tag','CNTVIEW',...
0200     'NumberTitle','off',...
0201     'units','characters',...
0202     'MenuBar','none','Position',[1 1 GUIwidth GUIheight]);
0203   movegui(GUI,'center');
0204   
0205   VIEWCNT.gui = GUI;
0206   
0207   VIEWCNT.axes = axes('Parent',GUI,'YDir','reverse');
0208   
0209   Font.FontName   = 'Helvetica';
0210   Font.FontUnits  = 'Pixels';
0211   Font.FontSize   = 12;
0212   Font.FontWeight = 'normal';
0213   Font.FontAngle  = 'normal';
0214   
0215   % ---- Display Parameters
0216   
0217   data.dispSeconds =  1; % seconds per screen
0218   data.chanPage =  4; % channels displayed per page (not used yet)
0219   
0220   % ---- Control Parameters
0221   
0222   % Load first 2 points of CNT file to check parameters
0223   data.cnt = eeg_load_scan4_cnt(filename,'all',[1 2]);
0224   
0225   data.dispNPoints = data.dispSeconds * data.cnt.srate;
0226   data.dispSPoint = 1;
0227   data.dispEPoint = data.dispNPoints;
0228   
0229   range(1) = data.dispSPoint;
0230   range(2) = data.dispEPoint;
0231   data.cnt = eeg_load_scan4_cnt(filename,'all',range);
0232   
0233   data.points = size(data.cnt.volt,1);
0234   data.nChan  = size(data.cnt.volt,2);
0235   
0236   data.totalsec  = data.cnt.numSamples / data.cnt.srate;
0237   data.totalmsec = data.totalsec * 1000;
0238   
0239   stime = (data.dispSPoint / data.cnt.srate) * 1000;
0240   etime = (data.dispEPoint / data.cnt.srate) * 1000;
0241   
0242   data.tstep = (1/data.cnt.srate) * 1000;
0243   
0244   data.time = [stime:data.tstep:etime]';
0245   
0246   set(VIEWCNT.axes,'XLim',[data.time(1) data.time(end)]);
0247   
0248   % Baseline data on first 10 msec
0249   data.base = data.dispSPoint:data.dispSPoint + (data.cnt.srate / 1000) * 10;
0250   data.basemean = mean(data.cnt.volt(data.base,:));
0251   basemean = repmat(data.basemean,data.dispNPoints,1);
0252   volt = data.cnt.volt(data.dispSPoint:data.dispEPoint,:);
0253   volt = volt - basemean;
0254   
0255   plot(data.time,volt);
0256   
0257   eeg_plot_metric;
0258   
0259   %dataSD   = std(data);
0260   %dataVar  = var(data);
0261   %dataMean = repmat(dataMean,points,1);
0262   %dataVar  = repmat(dataVar ,points,1);
0263   %data = (data - dataMean) ./ dataVar;
0264   %increment = [1:nChan];
0265   %data = data + repmat(increment,points,1);
0266   if isfield(data.cnt,'labels'),
0267     data.labels = data.cnt.labels;
0268   else
0269     data.labels = [];
0270   end
0271   if (length(data.labels) ~= data.nChan),
0272     data.labels = [];
0273   end
0274   %set(VIEWCNT.axes,'YTick',increment,'YTickLabel',labels);
0275   
0276   axpos = get(VIEWCNT.axes,'position');
0277   
0278   % Baseline data interface
0279   G.baseline = uicontrol(GUI,'style','edit','units','normalized',Font,...
0280     'Position',[.92 .8 .075 .05],...
0281     'TooltipString','Baseline (msec)',...
0282     'String',10,...
0283     'min',1,'max',(data.dispNPoints/data.cnt.srate)*1000,...
0284     'Callback','eeg_view_cnt('''',''plot'');');
0285   
0286   G.seconds = uicontrol(GUI,'style','edit','units','normalized',Font,...
0287     'Position',[.92 .7 .075 .05],...
0288     'TooltipString','Seconds / Page',...
0289     'String',sprintf('%8.4f',data.dispSeconds), ...
0290     'min',1,'max',data.points/data.cnt.srate,...
0291     'Callback','eeg_view_cnt('''',''plot'');');
0292   
0293   tpos = [ axpos(1,1)-.12 .01 .12        .05];
0294   spos = [ axpos(1,1)     .01 axpos(1,3) .05];
0295   
0296   hbuttonstep = .01; % move 1% of datafile
0297   hsliderstep = .05; % move 5% of datafile
0298   horizSliderStep = [ hbuttonstep hsliderstep ];
0299   
0300   G.Tslider = uicontrol(GUI,'style','text','units','normalized',Font,...
0301     'Position',tpos,...
0302     'TooltipString','% of CNT file',...
0303     'String',sprintf('%6.2f sec',1/data.cnt.srate),...
0304     'HorizontalAlignment', 'center');
0305   G.Slider = uicontrol(GUI,'style','slider','units','normalized',Font,...
0306     'Position',spos,...
0307     'sliderstep',horizSliderStep, ...
0308     'min',1,'max',data.cnt.numSamples,'value',1,...
0309     'Callback','eeg_view_cnt('''',''plot'');');
0310   
0311   
0312   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0313   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0314   Font.FontWeight = 'bold';
0315   
0316   G.exit = uicontrol(GUI,'style','pushbutton','units','normalized',Font,...
0317     'Position',[.925 .01 .07 .05],...
0318     'TooltipString','Close',...
0319     'String','EXIT',...
0320     'BackgroundColor',[0.75 0.0 0.0],...
0321     'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0322     'Callback','close gcbf;');
0323   
0324   VIEWCNT.data = data;
0325   VIEWCNT.handles = G;
0326   set(VIEWCNT.gui,'userdata',VIEWCNT);
0327   
0328   
0329   return

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