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

📄 topoplot.m

📁 用于脑电信号特征提取的InfoMax Algorithm Based on ICA;也可以稍作改动用于其他信息提取。
💻 M
字号:
% TOPOPLOT   - plot a topographic map of an EEG field as a 2-D%              circular view (looking down at the top of the head) %              using cointerpolation on a fine cartesian grid.% Usage:%        >>  topoplot(datavector,'eloc_file');%        >>  topoplot(datavector,'eloc_file', 'Param1','Value1', ...)% Inputs:%   'eloc_file' = name of an EEG electrode position file {0 -> 'chan_file'}%    datavector = vector of values at the corresponding locations.%% Optional Parameters & Values (in any order):%                  Param                         Value%                'colormap'         -  any sized colormap%                'interplimits'     - 'electrodes' to furthest electrode%                                     'head' to edge of head%                                        {default 'head'}%                'gridscale'        -  scaling grid size {default 67}%                'maplimits'        - 'absmax' +/- the absolute-max %                                     'maxmin' scale to data range%                                     [clim1,clim2] user-definined lo/hi%                                        {default = 'absmax'}%                'style'            - 'straight' colormap only%                                     'contour' contour lines only%                                     'both' both colormap and contour lines%                                     'fill' constant color between lines%                                     'blank' just head and electrodes%                                        {default = 'both'}%                'numcontour'       - number of contour lines%                                        {default = 6}%                'electrodes'       - 'on','off','labels','numbers'%                'shading'          - 'flat','interp'  {default = 'flat'}%                'headcolor','electcolor'%                'efsize','emsize'%                'emarker'%% Note: topoplot() only works when map limits are >= the max and min %                                     interpolated data values.% Eloc_file format:%         chan_number degrees radius reject_level amp_gain channel_name%        (Angle-0 = Cz-to-Fz; C3-angle =-90; Radius at edge of image = 0.5)%% Note: topoplot() will ignore any electrode with a position outside %       the head (radius > 0.5)%%       For a sample eloc file:     >> topoplot('example')% Topoplot Version 2.1% Andy Spydell, NHRC,  7-23-96% 8-96 Revised by Colin Humphries, CNL / Salk Institute, La Jolla CA%   -changed surf command to imagesc (faster)%   -can now handle arbitrary scaling of electrode distances%   -can now handle non integer angles in eloc_file% 4-4-97 Revised again by Colin Humphries, reformat by SM%   -added parameters%   -changed eloc_file format% 2-26-98 Revised by Colin%   -changed image back to surface command%   -added fill and blank styles%   -removed extra background colormap entry%   -added parameters for electrode colors and labels%   -now each topoplot axes use the caxis command again.%   -removed OUTPUT parameterfunction handle = topoplot(Vl,loc_file,p1,v1,p2,v2,p3,v3,p4,v4,p5,v5,p6,v6,p7,v7,p8,v8,p9,v9)% User Defined Defaults:MAXCHANS = 256;DEFAULT_ELOC = 'chan_file';INTERPLIMITS = 'head';  % head, electrodesMAPLIMITS = 'absmax';   % absmax, maxmin, [values]GRID_SCALE = 67;CONTOURNUM = 6;STYLE = 'both';       % both,straight,fill,contour,blankHCOLOR = [0 0 0];ECOLOR = [0 0 0];CONTCOLOR = [0 0 0];ELECTROD = 'on';      % ON OFF LABELEFSIZE = get(0,'DefaultAxesFontSize');HLINEWIDTH = 2;EMARKER = '.';EMARKERSIZE = 6;SHADING = 'flat';     % flat or interp%%%%%%%%%%%%%%%%%%%%%%%nargs = nargin;if nargs < 2  loc_file = DEFAULT_ELOC;endif nargs == 1  if isstr(Vl)    if any(strcmp(lower(Vl),{'example','demo'}))      fprintf(['This is an example electrode location file.\n',...               'A file should consist of the following parameters.\n\n',...               'channel_number degrees radius channel_name\n',...               ' 1                 -18    .352       Fp1.\n',...               ' 2                  18    .352       Fp2.\n',...               ' 3                 -39    .231       F3..\n',...               ' 4                  39    .231       F4..\n',...               ' 5                 -90    .181       C3..\n',...               ' 6                  90    .181       C4..\n',...               ' 7                 -90    .500       A1..\n',...               ' 8                  90    .500       A2..\n',...               ' 9                -142    .231       P3..\n',...               '10                 142    .231       P4..\n',...               '11                -162    .352       O1..\n',...               '12                 162    .352       O2..\n',...               '13                 -54    .352       F7..\n',...               '14                  54    .352       F8..\n',...               '15                 -90    .352       T3..\n',...               '16                  90    .352       T4..\n',...               '17                -126    .352       T5..\n',...               '18                 126    .352       T6..\n',...               '19                   0    .181       Fz..\n',...               '20                   0    0          Cz..\n',...               '21                 180    .181       Pz..\n\n',...               'The edge of the head has a radius of .5, and\n',...               '0 degrees is towards the nasion\n\n\n'])      return    end  endendif isempty(loc_file)  loc_file = 0;endif loc_file == 0  loc_file = DEFAULT_ELOC;endif nargs > 2  if ~(round(nargs/2) == nargs/2)    error('topoplot(): Incorrect number of inputs')  end  for i = 3:2:nargs    Param = eval(['p',int2str((i-3)/2 +1)]);    Value = eval(['v',int2str((i-3)/2 +1)]);    if ~isstr(Param)      error('topoplot(): Parameter must be a string')    end    Param = lower(Param);    switch lower(Param)      case 'colormap'        if size(Value,2)~=3          error('topoplot(): Colormap must be a n x 3 matrix')        end        colormap(Value)      case {'interplimits','headlimits'}        if ~isstr(Value)          error('topoplot(): interplimits value must be a string')        end        Value = lower(Value);        if ~strcmp(Value,'electrodes') & ~strcmp(Value,'head')          error('topoplot(): Incorrect value for interplimits')        end        INTERPLIMITS = Value;      case 'maplimits'        MAPLIMITS = Value;      case 'gridscale'        GRID_SCALE = Value;      case 'style'	STYLE = lower(Value);      case 'numcontour'        CONTOURNUM = Value;      case 'electrodes'	ELECTROD = lower(Value);      case 'emarker'	EMARKER = Value;      case {'headcolor','hcolor'}	HCOLOR = Value;      case {'electcolor','ecolor'}	ECOLOR = Value;      case {'emarkersize','emsize'}	EMSIZE = Value;      case {'efontsize','efsize'}	EFSIZE = Value;      case 'shading'	SHADING = lower(Value);	if ~any(strcmp(SHADING,{'flat','interp'}))	  error('Invalid Shading Parameter')	end      otherwise	error('Unknown parameter.')    end  endend[r,c] = size(Vl);if r>1 & c>1,  error('topoplot(): data should be a single vector\n');endfid = fopen(loc_file);if fid<1,  error('topoplot(): cannot open eloc_file (',loc_file,')')endA = fscanf(fid,'%d %f %f %s',[7 MAXCHANS]);fclose(fid);A = A';if length(Vl) ~= size(A,1),  error('topoplot(): data vector must be the same size as eloc_file')endlabels = setstr(A(:,4:7));idx = find(labels == '.');                       % some labels have dotslabels(idx) = setstr(abs(' ')*ones(size(idx)));  % replace them with spacesTh = pi/180*A(:,2);                               % convert degrees to radsRd = A(:,3);ii = find(Rd <= 0.5); % interpolate on-head channels onlyTh = Th(ii);Rd = Rd(ii);Vl = Vl(ii);[x,y] = pol2cart(Th,Rd);rmax = .5;ha = gca;clahold onif ~strcmp(STYLE,'blank')  % find limits for interpolation  if strcmp(INTERPLIMITS,'head')    xmin = min(-.5,min(x)); xmax = max(0.5,max(x));    ymin = min(-.5,min(y)); ymax = max(0.5,max(y));  else    xmin = max(-.5,min(x)); xmax = min(0.5,max(x));    ymin = max(-.5,min(y)); ymax = min(0.5,max(y));  end    xi = linspace(xmin,xmax,GRID_SCALE);   % x-axis description (row vector)  yi = linspace(ymin,ymax,GRID_SCALE);   % y-axis description (row vector)    [Xi,Yi,Zi] = griddata(y,x,Vl,yi',xi,'invdist'); % Interpolate data    % Take data within head  mask = (sqrt(Xi.^2+Yi.^2) <= rmax);  ii = find(mask == 0);  Zi(ii) = NaN;    % calculate colormap limits  m = size(colormap,1);  if isstr(MAPLIMITS)    if strcmp(MAPLIMITS,'absmax')      amin = -max(max(abs(Zi)));      amax = max(max(abs(Zi)));    elseif strcmp(MAPLIMITS,'maxmin')      amin = min(min(Zi));      amax = max(max(Zi));    end  else    amin = MAPLIMITS(1);    amax = MAPLIMITS(2);  end  delta = xi(2)-xi(1); % length of grid entry    % Draw topoplot on head  if strcmp(STYLE,'contour')    contour(Xi,Yi,Zi,CONTOURNUM,'k');  elseif strcmp(STYLE,'both')    surface(Xi-delta/2,Yi-delta/2,zeros(size(Zi)),Zi,'EdgeColor','none',...	'FaceColor',SHADING);    contour(Xi,Yi,Zi,CONTOURNUM,'k');  elseif strcmp(STYLE,'straight')    surface(Xi-delta/2,Yi-delta/2,zeros(size(Zi)),Zi,'EdgeColor','none',...	'FaceColor',SHADING);  elseif strcmp(STYLE,'fill')    contourf(Xi,Yi,Zi,CONTOURNUM,'k');  else    error('Invalid style')  end  caxis([amin amax]) % set coloraxisendset(ha,'Xlim',[-rmax*1.3 rmax*1.3],'Ylim',[-rmax*1.3 rmax*1.3])% %%% Draw Head %%%%l = 0:2*pi/100:2*pi;basex = .18*rmax;  tip = rmax*1.15; base = rmax-.004;EarX = [.497 .510 .518 .5299 .5419 .54 .547 .532 .510 .489];EarY = [.0555 .0775 .0783 .0746 .0555 -.0055 -.0932 -.1313 -.1384 -.1199];% Plot Electrodesif strcmp(ELECTROD,'on')   hp2 = plot(y,x,EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE);elseif strcmp(ELECTROD,'labels')  for i = 1:size(labels,1)    text(y(i),x(i),labels(i,:),'HorizontalAlignment','center',...	'VerticalAlignment','middle','Color',ECOLOR,...	'FontSize',EFSIZE)  endelseif strcmp(ELECTROD,'numbers')  for i = 1:size(labels,1)    text(y(i),x(i),int2str(i),'HorizontalAlignment','center',...	'VerticalAlignment','middle','Color',ECOLOR,...	'FontSize',EFSIZE)  endend% Plot Head, Ears, Noseplot(cos(l).*rmax,sin(l).*rmax,...    'color',HCOLOR,'Linestyle','-','LineWidth',HLINEWIDTH,...    'clipping','off');plot([.18*rmax;0;-.18*rmax],[base;tip;base],...    'Color',HCOLOR,'LineWidth',HLINEWIDTH,...    'clipping','off');   plot(EarX,EarY,'color',HCOLOR,'LineWidth',HLINEWIDTH)plot(-EarX,EarY,'color',HCOLOR,'LineWidth',HLINEWIDTH)   hold offaxis off

⌨️ 快捷键说明

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