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

📄 eegplot.m

📁 用于脑电信号特征提取的InfoMax Algorithm Based on ICA;也可以稍作改动用于其他信息提取。
💻 M
📖 第 1 页 / 共 2 页
字号:
function [outvar1] = eegplot(data,p1,p2,p3,p4,p5,p6)% EEGPLOT - display EEG%% usage: eegplot(data,Fs,spacing,eloc_file,windowlength,title)%        eegplot('noui',data,Fs,spacing,eloc_file,startpoint,color)%%    data         : (chans,timepoints) EEG data matrix%    Fs           : EEG sampling rate in Hz %    spacing      : Space between channels (Default: max(data)-min(data))%    eloc_file    : Electrode file (topoplot.m format)%                      [] - no labels, 0 - numbered%    windowlength : Number of seconds of EEG displayed%    color        : EEG plot color%%    options: 'noui' :  Display eeg in current axes without uicontrols%%        use 0 or [] for default values.%%    Version 2.0           % Written by Colin Humphries, Salk Institute % colin@salk.edu% Runs under Matlab 5.0/5.1/5.2% May, 1998 - fixed scaling bug%           - added +/- and units strings to scale I bar% Note: this program still has a few bugs.% user defined defaultsDEFAULT_ELOC_FILE = 0;            % Default electrode name file                                  %   [] - none, 0 - numbered, or filenameDEFAULT_SAMPLE_RATE = 256;        % Samplerate DEFAULT_PLOT_COLOR = 'k';         % EEG line colorDEFAULT_AXIS_BGCOLOR = [.8 .8 .8];% EEG Axes Background ColorDEFAULT_FIG_COLOR = [.8 .8 .8];   % Figure Background ColorDEFAULT_AXIS_COLOR = 'k';         % X-axis, Y-axis Color, text ColorDEFAULT_WINLENGTH = 10;           % Number of seconds of EEG displayedDEFAULT_GRID_SPACING = 1;         % Grid lines every n secondsDEFAULT_GRID_STYLE = '-';         % Grid line styleYAXIS_NEG = 'off';                % 'off' = positive up DEFAULT_NOUI_PLOT_COLOR = 'k';    % EEG line color for noui option                                  %   0 - 1st color in AxesColorOrderDEFAULT_TITLEVAL = 2;             % Default title                                  %   string, 2 - variable name, 0 - noneSPACING_EYE = 'off';              % spacing I on/offSPACING_UNITS_STRING = [];        % optional units for spacing I Ex. uVDEFAULT_AXES_POSITION = [0.0964286 0.15 0.842 0.788095];                                  % dimensions of main EEG axes				  % %%%%%%%%%%%%%%%%%%%%%%%%% Setup inputsif ~isstr(data)  if strcmp(YAXIS_NEG,'on')    data = -data;  end  if nargin < 6    titleval = 0;  else    titleval = p5;  end  if nargin < 5    winlength = 0;  else    winlength = p4;  end  if nargin < 4    eloc_file = DEFAULT_ELOC_FILE;  else    eloc_file = p3;  end  if nargin < 3    spacing = 0;  else    spacing = p2;  end  if nargin < 2    Fs = 0;  else    Fs = p1;  end  if isempty(titleval)    titleval = 0;  end  if isempty(winlength)    winlength = 0;  end  if isempty(spacing)    spacing = 0;  end  if isempty(Fs)    Fs = 0;  end      [chans,frames] = size(data);    if winlength == 0    winlength = DEFAULT_WINLENGTH;  % Set window length  end    if ~isempty(eloc_file)            % Read in electrode names    if eloc_file == 0      YLabels = num2str((1:chans)');  % Use numbers    else      fid = fopen(eloc_file);       % Read file      if fid < 1        error('error opening electrode file')      end      YLabels = fscanf(fid,'%d %f %f%s',[7 128]);      fclose(fid);      YLabels = char(YLabels(4:7,:)');      ii = find(YLabels == '.');      YLabels(ii) = ' ';    end    YLabels = flipud(str2mat(YLabels,' '));  else    YLabels = [];    % no labels used  end    if spacing == 0    spacing = (max(max(data')-min(data')));  % Set spacing to max/min data    if spacing > 10      spacing = round(spacing);    end  end    if titleval == 0      titleval = DEFAULT_TITLEVAL;  % Set title value  end    if Fs == 0    Fs = DEFAULT_SAMPLE_RATE;     % Set samplerate  end    % %%%%%%%%%%%%%%%%%%%%%%%%  % Prepare figure and axes    figh = figure('UserData',[winlength Fs],...      'Color',DEFAULT_FIG_COLOR,...      'MenuBar','none','tag','eegplot');    ax1 = axes('tag','eegaxis','parent',figh,...      'userdata',data,...      'Position',DEFAULT_AXES_POSITION,...      'Box','on','xgrid','on',...      'gridlinestyle',DEFAULT_GRID_STYLE,...      'Xlim',[0 winlength*Fs],...      'xtick',[0:Fs*DEFAULT_GRID_SPACING:winlength*Fs],...      'Ylim',[0 (chans+1)*spacing],...      'YTick',[0:spacing:chans*spacing],...      'YTickLabel',YLabels,...      'XTickLabel',num2str((0:DEFAULT_GRID_SPACING:winlength)'),...      'TickLength',[.005 .005],...      'Color',DEFAULT_AXIS_BGCOLOR,...      'XColor',DEFAULT_AXIS_COLOR,...      'YColor',DEFAULT_AXIS_COLOR);    if isstr(titleval)      % plot title    title(titleval)  elseif titleval == 2    title(inputname(1))  end    % %%%%%%%%%%%%%%%%%%%%%%%%%  % Set up uicontrols    u(1) = uicontrol('Parent',figh, ...	'Units','points', ...	'Position',[49.1294 12.7059 50.8235 16.9412], ...	'Tag','Pushbutton1',...	'string','<',...	'Callback','eegplot(''drawp'',1)');  u(2) = uicontrol('Parent',figh, ...	'Units','points', ...	'Position',[105.953 12.7059 33.0353 16.9412], ...	'Tag','Pushbutton2',...	'string','<<',...	'Callback','eegplot(''drawp'',2)');  u(3) = uicontrol('Parent',figh, ...	'Units','points', ...	'Position',[195.882 12.7059 33.8824 16.9412], ...	'Tag','Pushbutton3',...	'string','>>',...	'Callback','eegplot(''drawp'',3)');  u(4) = uicontrol('Parent',figh, ...	'Units','points', ...	'Position',[235.765 12.7059 50.8235 16.9412], ...	'Tag','Pushbutton4',...	'string','>',...	'Callback','eegplot(''drawp'',4)');  u(5) = uicontrol('Parent',figh, ...	'Units','points', ...	'BackgroundColor',[1 1 1], ...	'Position',[144.988 10.1647 44.8941 19.4824], ...	'Style','edit', ...	'Tag','EPosition',...	'string','0',...	'Callback','eegplot(''drawp'',0)');  u(6) = uicontrol('Parent',figh, ...	'Units','points', ...	'BackgroundColor',[1 1 1], ...	'Position',[379.482-30 11.8 46.5882 19.5], ...	'Style','edit', ...	'Tag','ESpacing',...	'string',num2str(spacing),...	'Callback','eegplot(''draws'',0)');  u(7) = uicontrol('Parent',figh, ...	'Units','points', ...	'Position',[435-30 22.9 22 13.5], ...	'Tag','Pushbutton5',...	'string','+',...	'FontSize',8,...	'Callback','eegplot(''draws'',1)');  u(8) = uicontrol('Parent',figh, ...	'Units','points', ...	'Position',[435-30 6.7 22 13.5], ...	'Tag','Pushbutton6',...	'string','-',...	'FontSize',8,...	'Callback','eegplot(''draws'',2)');  set(u,'Units','Normalized')    % %%%%%%%%%%%%%%%%%%%%%%%%%%%  % Set up uimenus    % Figure Menu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  m(7) = uimenu('Parent',figh,'Label','Figure');  m(8) = uimenu('Parent',m(7),'Label','Orientation');  uimenu('Parent',m(7),'Label','Close',...      'Callback','delete(gcbf)')    % Portrait %%%%%%%%  timestring = ['[OBJ1,FIG1] = gcbo;',...	        'PANT1 = get(OBJ1,''parent'');',...	        'OBJ2 = findobj(''tag'',''orient'',''parent'',PANT1);',...		'set(OBJ2,''checked'',''off'');',...		'set(OBJ1,''checked'',''on'');',...		'set(FIG1,''PaperOrientation'',''portrait'');',...		'clear OBJ1 FIG1 OBJ2 PANT1;'];		  uimenu('Parent',m(8),'Label','Portrait','checked',...      'on','tag','orient','callback',timestring)    % Landscape %%%%%%%  timestring = ['[OBJ1,FIG1] = gcbo;',...	        'PANT1 = get(OBJ1,''parent'');',...	        'OBJ2 = findobj(''tag'',''orient'',''parent'',PANT1);',...		'set(OBJ2,''checked'',''off'');',...		'set(OBJ1,''checked'',''on'');',...		'set(FIG1,''PaperOrientation'',''landscape'');',...		'clear OBJ1 FIG1 OBJ2 PANT1;'];    uimenu('Parent',m(8),'Label','Landscape','checked',...      'off','tag','orient','callback',timestring)    % Display Menu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  m(1) = uimenu('Parent',figh,...      'Label','Display');    % X grid %%%%%%%%%%%%  m(3) = uimenu('Parent',m(1),'Label','X Grid');    timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''xgrid'',''on'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(3),'Label','on','Callback',timestring)  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''xgrid'',''off'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(3),'Label','off','Callback',timestring)    % Y grid %%%%%%%%%%%%%  m(4) = uimenu('Parent',m(1),'Label','Y Grid');  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''ygrid'',''on'');',...		'clear FIGH AXESH;'];    uimenu('Parent',m(4),'Label','on','Callback',timestring)  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''ygrid'',''off'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(4),'Label','off','Callback',timestring)    % Grid Style %%%%%%%%%  m(5) = uimenu('Parent',m(1),'Label','Grid Style');  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''gridlinestyle'',''--'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(5),'Label','- -','Callback',timestring)  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''gridlinestyle'',''-.'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(5),'Label','_ .','Callback',timestring)  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''gridlinestyle'','':'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(5),'Label','. .','Callback',timestring)  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''gridlinestyle'',''-'');',...		'clear FIGH AXESH;'];  uimenu('Parent',m(5),'Label','__','Callback',timestring)    % Scale Eye %%%%%%%%%  timestring = ['[OBJ1,FIG1] = gcbo;',...	        'eegplot(''scaleeye'',OBJ1,FIG1);',...		'clear OBJ1 FIG1;'];  m(7) = uimenu('Parent',m(1),'Label','Scale I','Callback',timestring);    % Title %%%%%%%%%%%%  uimenu('Parent',m(1),'Label','Title','Callback','eegplot(''title'')')    % Settings Menu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  m(2) = uimenu('Parent',figh,...      'Label','Settings');     % Window %%%%%%%%%%%%  uimenu('Parent',m(2),'Label','Window',...      'Callback','eegplot(''window'')')    % Samplerate %%%%%%%%  uimenu('Parent',m(2),'Label','Samplerate',...      'Callback','eegplot(''samplerate'')')    % Electrodes %%%%%%%%  m(6) = uimenu('Parent',m(2),'Label','Electrodes');    timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'set(AXESH,''YTickLabel'',[]);',...		'clear FIGH AXESH;'];  uimenu('Parent',m(6),'Label','none','Callback',timestring)  timestring = ['FIGH = gcbf;',...	        'AXESH = findobj(''tag'',''eegaxis'',''parent'',FIGH);',...		'YTICK = get(AXESH,''YTick'');',...		'YTICK = length(YTICK);',...		'set(AXESH,''YTickLabel'',flipud(str2mat(num2str((1:YTICK-1)''),'' '')));',...		'clear FIGH AXESH YTICK;'];  uimenu('Parent',m(6),'Label','numbered','Callback',timestring)  uimenu('Parent',m(6),'Label','load file',...      'Callback','eegplot(''loadelect'');')  %  %  % %%%%%%%%%%%%%%%%%%%%%%%%%%  % Plot EEG Data  meandata = mean(data(:,1:round(min(frames,winlength*Fs)))');    axes(ax1)  hold on  for i = 1:chans    plot(data(chans-i+1,...	1:round(min(frames,winlength*Fs)))-meandata(chans-i+1)+i*spacing,...	'color',DEFAULT_PLOT_COLOR)  end    % %%%%%%%%%%%%%%%%%%%%%%%%%%  % Plot Spacing I  if strcmp(SPACING_EYE,'on')        YLim = get(ax1,'Ylim');    A = DEFAULT_AXES_POSITION;    axes('Position',[A(1)+A(3) A(2) 1-A(1)-A(3) A(4)],...	'Visible','off','Ylim',YLim,'tag','eyeaxes')    axis manual    Xl = [.3 .6 .45 .45 .3 .6];    Yl = [spacing*2 spacing*2 spacing*2 spacing*1 spacing*1 spacing*1];    line(Xl,Yl,'color',DEFAULT_AXIS_COLOR,'clipping','off',... 	'tag','eyeline')    text(.5,YLim(2)/23+Yl(1),num2str(spacing,4),...	'HorizontalAlignment','center','FontSize',10,...	'tag','thescale')    if strcmp(YAXIS_NEG,'off')      text(Xl(2)+.1,Yl(1),'+','HorizontalAlignment','left',...	  'verticalalignment','middle')      text(Xl(2)+.1,Yl(4),'-','HorizontalAlignment','left',...	  'verticalalignment','middle')    else      text(Xl(2)+.1,Yl(4),'+','HorizontalAlignment','left',...	  'verticalalignment','middle')      text(Xl(2)+.1,Yl(1),'-','HorizontalAlignment','left',...	  'verticalalignment','middle')    end    if ~isempty(SPACING_UNITS_STRING)      text(.5,-YLim(2)/23+Yl(4),SPACING_UNITS_STRING,...	  'HorizontalAlignment','center','FontSize',10)    end    set(m(7),'checked','on')    elseif strcmp(SPACING_EYE,'off')    YLim = get(ax1,'Ylim');    A = DEFAULT_AXES_POSITION;    axes('Position',[A(1)+A(3) A(2) 1-A(1)-A(3) A(4)],...	'Visible','off','Ylim',YLim,'tag','eyeaxes')    axis manual    set(m(7),'checked','off')      end % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End Main Function% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%else  switch data  case 'drawp'        % Redraw EEG and change position    figh = gcbf;                          % figure handle    if strcmp(get(figh,'tag'),'dialog')      figh = get(figh,'UserData');    end    ax1 = findobj('tag','eegaxis','parent',figh); % axes handle    EPosition = findobj('tag','EPosition','parent',figh); % ui handle    ESpacing = findobj('tag','ESpacing','parent',figh);   % ui handle            data = get(ax1,'UserData');             % Data (Note: this could also be global)    time = str2num(get(EPosition,'string')); % current position    spacing = str2num(get(ESpacing,'string')); % current spacing    winlength = get(figh,'UserData');           Fs = winlength(2);                      % samplerate    winlength = winlength(1);               % window length        [chans,frames] = size(data);            if p1 == 1      time = time-winlength;     % subtract one window length    elseif p1 == 2                     time = time-1;             % subtract one second    elseif p1 == 3      time = time+1;             % add one second    elseif p1 == 4      time = time+winlength;     % add one window length    end        time = max(0,min(time,ceil(frames/Fs)-winlength));        set(EPosition,'string',num2str(time))  % Update edit box    % keyboard    % Plot data and update axes    meandata = mean(data(:,round(time*Fs+1):round(min((time+winlength)*Fs,...	frames)))');      axes(ax1)    cla    for i = 1:chans      plot(data(chans-i+1,round(time*Fs+1):round(min((time+winlength)*Fs,...	  frames)))-meandata(chans-i+1)+i*spacing,...	  'color',DEFAULT_PLOT_COLOR,'clipping','off')    end    set(ax1,'XTickLabel',...	num2str((time:DEFAULT_GRID_SPACING:time+winlength)'),...	'Xlim',[0 winlength*Fs],...	'XTick',[0:Fs*DEFAULT_GRID_SPACING:winlength*Fs])    case 'draws'      % Redraw EEG and change scale    figh = gcbf;                                          % figure handle    ax1 = findobj('tag','eegaxis','parent',figh);         % axes handle    EPosition = findobj('tag','EPosition','parent',figh); % ui handle    ESpacing = findobj('tag','ESpacing','parent',figh);   % ui handle        data = get(ax1,'UserData');                % data    time = str2num(get(EPosition,'string'));   % current position    spacing = str2num(get(ESpacing,'string')); % current spacing    winlength = get(figh,'UserData');          if isempty(spacing) | isempty(time)      return  % return if valid numbers are not in the edit boxes    end        Fs = winlength(2);        % samplerate    winlength = winlength(1); % window length        orgspacing = round(max(max(data')-min(data'))); % original spacing        [chans,frames] = size(data);           if p1 == 1

⌨️ 快捷键说明

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