📄 main.m
字号:
% Title: RAAA EOG Correction Program GUI % Author: Tony Tanoyo% Year: Feb 2007 - Oct 2007% Brain Sciences Institute% -----------------------------------function varargout = main(varargin)% Last Modified by GUIDE v2.5 25-Oct-2007 23:51:37% main: Display the selection for loading files and channel selections,% correction for the EOG data. %% EOG Correction program is used to work out the amount of ocular% potential recorded by the electroencephalograph [EEG] (as a% proportion of the potentials recorded by the electrooculograph% [EOG]), and to subtract this from the EEG. By doing this we are able% to reduce the effect of ocular potentials on the EEG, and this in% turn allows us to increase the amount of usable data (we dont have% to discard data that correspond to eye movements), provides us with% greater confidence in data that correspond with small eye movements,% and reduces the restrictions that we place on participants' eye% movements.% % These proportions of EOG voltages that contaminate EEG recordings% are termed 'betas' or 'Bs'. We calculate separate Bs for vertical% (Bv), horizontal (Bh), and radial (Br) EOG channels, with separate% Bv, Bh, and Br values for EEG electrode. To increase accuracy of the% 'Bs', they are calculated from specifically designed calibration% data collected separate to the main experimental data, in general% 'Bs' remain constant across the EEG recording session. % % This program has been designed to interface with Neuroscan Edit % software, thus at present this will primarily be use to those with access% to this software. However, as the software uses the ascii ('.dat')% output from Neuroscan, if your data can be converted to that format% you will be able to use this correction algorithm. For example of% the ascii file format required are given in the package folder% /Extra Files/sample.... Note that the 'EOG Calibration' and% 'To-Be-Corrected' files must have the same channels, but filter% settings and digitisation rates may differ. % % Start the program by running the main file. % % For more information, please see the help file.% ---------------------------------------------------------------- % % H = MAIN returns the handle to a new MAIN or the handle to% the existing singleton*.% % MAIN('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in MAIN.M with the given input arguments.% % MAIN('Property','Value',...) creates a new MAIN or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before plotfig_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to plotfig_OpeningFcn via varargin.% % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".% % See also: GUIDE, GUIDATA, GUIHANDLES% % Programmed and Copyright by Tony Tanoyo: tony.tanoyo@gmail.com% $Revision: 01 $ $Date: 24/10/2007s$% % Files Contribution:% Yair Altman for the statusbar function, May 2007.% Daniel Claxton for the workbar function, March 2005.% Xiaoning (David) Yang for the keep function, 1998. % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @main_OpeningFcn, ... 'gui_OutputFcn', @main_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% ----------------------------------------------------------% --- Executes just before main is made visible.function main_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject; % Choose default command line output for mainguidata(hObject, handles); % Update handles structureinit_strings(handles); % initialisation of stringsetappdata(gcf,'pathname0',pwd); % set pathname0 to the current program directorysetappdata(0,'hMainGui',gcf); % set the hMainGui to the gcf(get current figure)newpushbutton_Callback(hObject, eventdata, handles);hMainGui = getappdata(0, 'hMainGui'); timeperchar=7e-7; % time taken per char to read data, found by experiment.run_id=0;setappdata(hMainGui,'run_id',run_id); starting_id=1; % starting_id to indicate that the program just started and has not been runsetappdata(hMainGui,'starting_id',starting_id); setappdata(hMainGui,'timeperchar',timeperchar); % set the timeperchar to hMainGui% set all the up, down, left, right, and blink popupmenu inactive at the startset(handles.up_popupmenu,'enable','inactive');set(handles.down_popupmenu,'enable','inactive');set(handles.left_popupmenu,'enable','inactive');set(handles.right_popupmenu,'enable','inactive');set(handles.blink_popupmenu,'enable','inactive');% set the editchannel1, 2 and 3 handlessetappdata(hMainGui,'edit_VE_main',handles.editchannel1);setappdata(hMainGui,'edit_HE_main',handles.editchannel2);setappdata(hMainGui,'edit_RE_main',handles.editchannel3);% --- Outputs from this function are returned to the command line.function varargout = main_OutputFcn(hObject, eventdata, handles)varargout{1} = handles.output; % Get default command line output from handles structure% --------------------------------------------% Push Button Callbacks% --------------------------------------------% --- Executes on button press in loadpushbutton1.function loadpushbutton1_Callback(hObject, eventdata, handles)hMainGui = getappdata(0, 'hMainGui'); % get the value of the hMainGUI from the root (handle 0) and assign it to hMainGui variable. timeperchar=getappdata(hMainGui,'timeperchar');pathname0=getappdata(hMainGui,'pathname0'); % root directorypathname1=getappdata(hMainGui,'pathname1'); % eog calibration file directorypathname2=getappdata(hMainGui,'pathname2'); % eog datapnts file directorypathname3=getappdata(hMainGui,'pathname3'); % tbc directorypathname1st2open=getappdata(hMainGui,'pathname1st2open'); % directory when the 1st file is openif ~isempty(pathname1)&&isempty(pathname2)&&isempty(pathname3) cd(pathname1);elseif isempty(pathname1)&&~isempty(pathname2)&&isempty(pathname3) cd(pathname2);elseif isempty(pathname1)&&isempty(pathname2)&&~isempty(pathname3) cd(pathname3);elseif ~isempty(pathname1st2open) cd(pathname1st2open);endselect=1; invalid=1; data_type='cnt'; while(invalid==1) while(select~=0) [fname1, pathname1] = uigetfile('*.dat', 'Pick "eog calibration" file'); if isempty(pathname2)&&isempty(pathname3) pathname1st2open=pathname1; end cd(pathname0); if isequal(fname1,0) || isequal(pathname1,0) return else select=0; invalid=0; % to catch if user does not select a file. end end try set(handles.figure1,'Pointer','watch'); [data,hdr]=read([pathname1 fname1],handles,timeperchar,data_type); % Reading the eog file set(handles.figure1,'Pointer','arrow'); catch statusbar; set(handles.figure1,'Pointer','arrow'); warn_push1=msgbox('Please Select Continouous Type EOG Calibration File','Warning','warn','modal'); waitfor(warn_push1); select=1; invalid=1; % to catch if user selected wrong file. endendsetappdata(hMainGui,'plot_id',0); % plot_id =0 -> cannot be plottedset(handles.editchannel1,'string','');set(handles.editchannel2,'string','');set(handles.editchannel3,'string','');set(handles.fname1,'string',fname1); % set the string of fname1 to fname1setappdata(hMainGui,'pathname1',pathname1);setappdata(hMainGui,'fname1',fname1); setappdata(hMainGui,'data',data); setappdata(hMainGui,'hdr',hdr);elec_label=hdr{9,1}; % get line 9 of the headerlab_idx=regexp(elec_label,'([)*(])');ch_label=cell(length(lab_idx),1); % create length(lab_idx),1 empty matricesfor i=1:length(lab_idx) ch_label{i,1}=elec_label((lab_idx(i)-9):lab_idx(i)); % read every electrode label using the index, including the square brackets, since the char length varies from one to another.endch_label=strrep(ch_label,'[','');ch_label=strrep(ch_label,']',''); ch_label=strtrim(ch_label); % get the channel labelsfor ch_idx=1:length(ch_label) % convert all the channel labels to capital try if isscalar(eval(ch_label{ch_idx})) ch_label{ch_idx}=['CH' ch_label{ch_idx}]; end catch for j=1:length(ch_label{ch_idx}) if ch_label{ch_idx}(j)>=97 && ch_label{ch_idx}(j)<=122 ch_label{ch_idx}(j)=ch_label{ch_idx}(j)-32; end end endendsetappdata(hMainGui,'ch_label',ch_label);option=1; vech1_idx=1; vech2_idx=2*vech1_idx+1; while(option<3) for i=1:length(ch_label) switch(option) case 1 if isequal('VE',ch_label{i})||isequal('VEOG',ch_label{i}) vech=ch_label{i}; % char type of variable ve_count=i; elseif isequal('HE',ch_label{i})||isequal('HEOG',ch_label{i}) hech=ch_label{i}; he_count=i; elseif isequal('RE',ch_label{i})||isequal('REOG',ch_label{i}) rech=ch_label{i}; re_count=i; end case 2 if isequal('E1',ch_label{i})||isequal('E2',ch_label{i}) % E1 & E2 try try if ~isequal(vech{vech1_idx-1},ch_label{i}) && vech1_idx<3 % check on the 2nd occurence possibility of double elect label pass; end catch if ~ischar(vech) && ~ischar(rech) rech{vech1_idx}=ch_label{i}; % cell type of variable vech{vech1_idx}=ch_label{i}; % vech1_idx takes the 1st and 3rd pos vech1_idx=vech1_idx+1; elseif ~ischar(vech) && ischar(rech) vech{vech1_idx}=ch_label{i}; vech1_idx=vech1_idx+1; elseif ischar(vech) && ~ischar(rech) rech{vech1_idx}=ch_label{i}; vech1_idx=vech1_idx+1; end end catch try if ischar(vech) rech{vech1_idx}=ch_label{i}; vech1_idx=vech1_idx+1; end catch try if ischar(rech) vech{vech1_idx}=ch_label{i}; vech1_idx=vech1_idx+1; end catch rech{vech1_idx}=ch_label{i}; vech{vech1_idx}=ch_label{i}; vech1_idx=vech1_idx+1; end end end elseif isequal('E3',ch_label{i})||isequal('E4',ch_label{i}) %E3 & E4 try try if ~isequal(vech{vech2_idx-1},ch_label{i}) && vech2_idx<5 % check on the 2nd occurence possibility of double elect label pass; end catch if ~ischar(vech) && ~ischar(rech) rech{vech2_idx}=ch_label{i}; vech{vech2_idx}=ch_label{i}; % vech2_idx takes the 2nd and 4th pos vech2_idx=vech2_idx+1; elseif ~ischar(vech) && ischar(rech) vech{vech2_idx}=ch_label{i}; vech2_idx=vech2_idx+1; elseif ischar(vech) && ~ischar(rech) rech{vech2_idx}=ch_label{i}; vech2_idx=vech2_idx+1; end end catch try if ischar(vech) rech{vech2_idx}=ch_label{i}; vech2_idx=vech2_idx+1; end catch try if ischar(rech) vech{vech2_idx}=ch_label{i}; vech2_idx=vech2_idx+1; end catch rech{vech2_idx}=ch_label{i}; vech{vech2_idx}=ch_label{i}; vech2_idx=vech2_idx+1; end end end elseif isequal('E5',ch_label{i}) % E5 try if ischar(hech)||ischar(hech{1}) && length(vech)<2 continue end catch hech{1}=ch_label{i}; end elseif isequal('E6',ch_label{i}) % E6 try if ischar(hech)||ischar(hech{2}) && length(vech)<2 continue end catch hech{2}=ch_label{i}; end end end end try if ischar(vech)&& ischar(hech) && ischar(rech) option=3; else option=option+1; end catch option=option+1; end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -