image thumbnail

eogui – a software to analyze electro-oculogram (EOG) recordings

by

 

10 Aug 2011 (Updated )

detects blinks and saccadic eye movements in EOG recordings

uigetnoise.m
function varargout = uigetnoise(varargin)
% $Id: uigetnoise.m 6 2004-12-13 12:28:39Z maik $

%RS: called by \\private\eichen.m
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @uigetnoise_OpeningFcn, ...
                   'gui_OutputFcn',  @uigetnoise_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if 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 uigetnoise is made visible.
function uigetnoise_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to uigetnoise (see VARARGIN)


% Parameter1 = Matrix
% Parameter3 = Titel
% Parameter4 = Text


% prft zuerst ob wir auch eine gltige datenmatrix bekommen haben
if (nargin<3+3)
    return;
end


indim=size(varargin{1});

%ist die Eingabe auch eine Matrix ?
if(length(indim)~=2)   
    return;
end

%sind weniger als 2 Kanle vorhanden, kein Auswerten mglich
if(indim(2)<2)
    return;
end



% Wenn alles ok, sichere Matrix fr sptere zugriffe und setze
% Fensterbreite, ist diese zu gro ....


handles.data = varargin{1};
set(handles.figure1,'Name',varargin{2});
set(handles.text,'String',varargin{3});

handles.winsize=4000;
if(indim(1)<handles.winsize)
    handles.winsize=indim(1);
end


% Update handles structure
guidata(hObject, handles);

% Positioniere die GUI im Mittelpunkt
dlgRes=get(handles.figure1,'position');
monRes=get(0,'ScreenSize');
dlgRes(1)=(monRes(3)-dlgRes(3))/2;  %x-achse
dlgRes(2)=(monRes(4)/2)-(dlgRes(4)/2);  %x-achse
set(handles.figure1,'position',dlgRes);
%%-------------------------------------



% Position slider einstellen
width=indim(1);
if(handles.winsize<width)    
    %set(handles.slider,'Max',width-handles.winsize,'Min',0);
    
    %Schrittweite einstellen
    stepratio = .1;                
    steptrough=handles.winsize / (width - handles.winsize); % Fensterbreite        
    steparrow =stepratio * steptrough;    % 10 % der fensterbreite
    set(handles.slider,'sliderstep', [steparrow steptrough]);
else
    set(handles.slider,'Visible','off');    
end


% X Kanal darstellen, zeichne ersten teil
r=1:handles.winsize;

h=handles.Graph1;
axes(handles.Graph1);
plot(handles.data(r,1),handles.data(r,2)); %RS: /1000 to get seconds?
set(h,'xlim',[handles.data(1,1) handles.data(handles.winsize,1)]);
set(h,'ButtonDownFcn','uigetnoise(''Graph_ButtonDownFcn'',gcbo,[],guidata(gcbo))');
setminwinhigh(20);


% Calculate noise across the first 500ms

off=handles.data(1,1);
index=find(handles.data(:,1)>off+100 & handles.data(:,1)<off+600);

h=handles.Graph2;
axes(handles.Graph2);
plot(handles.data(index,1),handles.data(index,2));
setminwinhigh(5);

a=min(handles.data(index,2));
b=max(handles.data(index,2));
noise=(b-a)/2;
z=a+noise;

%threshold('init',noise,'click_object()',z); 
threshold('init',noise,'h=guidata(gcbo);set(h.editNoise,''String'',num2str(threshold(''getValue'')))',z);



set(handles.editNoise,'String',num2str(noise));


% UIWAIT makes uigetnoise wait for user response (see UIRESUME)
uiwait(handles.figure1);



% --- Outputs from this function are returned to the command line.
function varargout = uigetnoise_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

% gibt es das feld ?
if(isfield(handles,'output'))  
    varargout{1} = handles.output;  
    close();
else
    varargout{1} = -1;
end
   



% --- Executes on button press in bCancel.
function bCancel_Callback(hObject, eventdata, handles)
% hObject    handle to bCancel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.output=-1;  
guidata(hObject, handles);

uiresume(handles.figure1);


% --- Executes on button press in bNext.
function bNext_Callback(hObject, eventdata, handles)
% hObject    handle to bNext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% prfe Daten
noise=str2double(get(handles.editNoise,'String'));
if isnan(noise)
    return;
end


% sichere result
handles.output=[noise 1];
guidata(hObject, handles);

%beende Dialog
uiresume(handles.figure1);



function editNoise_Callback(hObject, eventdata, handles)
% hObject    handle to editNoise (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editNoise as text
%        str2double(get(hObject,'String')) returns contents of editNoise as a double
    noise = str2double(get(hObject,'string'));
    if isnan(noise)
        errordlg('ungltige Eingabe fr Noise','Fehler','modal')
        return
    end  
    axes(handles.Graph2);
    threshold('update',noise);
    
    
    

% --- Executes during object creation, after setting all properties.
function editNoise_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editNoise (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function editR_Callback(hObject, eventdata, handles)
% hObject    handle to editR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editR as text
%        str2double(get(hObject,'String')) returns contents of editR as a double


% --- Executes during object creation, after setting all properties.
function editR_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on button press in bHelp.
function bHelp_Callback(hObject, eventdata, handles)
% hObject    handle to bHelp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on slider movement.
function slider_Callback(hObject, eventdata, handles)
% hObject    handle to slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of

%v2=fix(get(handles.slider,'Value'));
v2=1+fix(get(handles.slider,'Value')* (length(handles.data(:,1))-handles.winsize) );  % workaround matlab 7
r=v2:v2+handles.winsize-1;

h=handles.Graph1;
axes(handles.Graph1);
plot(handles.data(r,1),handles.data(r,2));
set(h,'xlim',[handles.data(r(1),1) handles.data(r(end),1)]);
set(h,'ButtonDownFcn','uigetnoise(''Graph_ButtonDownFcn'',gcbo,[],guidata(gcbo))');
setminwinhigh(20);


% --- Executes during object creation, after setting all properties.
function slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




% --- Executes on button press in tbSetL.
function tbSetL_Callback(hObject, eventdata, handles)
% hObject    handle to tbSetL (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of tbSetL

set(handles.tbSetR,'Value',get(handles.tbSetR,'Min'));
if(get(hObject,'Value') ~= get(hObject,'Max'))
    set(hObject,'Value',get(hObject,'Max'));    
end
    


% --- Executes on button press in tbSetR.
function tbSetR_Callback(hObject, eventdata, handles)
% hObject    handle to tbSetR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.tbSetL,'Value',get(handles.tbSetL,'Min'));
if(get(hObject,'Value') ~= get(hObject,'Max'))
    set(hObject,'Value',get(hObject,'Max'));    
end




% --- Executes on mouse press over axes background.
function Graph1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to Graph1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
point1 = get(gca,'CurrentPoint');    % button down detected
%finalRect = rbbox;                   % return figure units
rec=mousesel();
if(~isempty(rec))
    delete(rec);
end
point2 = get(gca,'CurrentPoint');    % button up detected
xrage=sort([point1(1,1) point2(1,1)]);

start=find(handles.data(:,1)>=xrage(1));   % suche startsample
start=start(1);

ende=find(handles.data(:,1)>=xrage(2));   % suche endsample
ende=ende(1);

value=median(handles.data(start:ende,2));

if(get(handles.tbSetL,'Value') == get(handles.tbSetL,'Max'))
    set(handles.editNoise,'String',num2str(value));
else
    set(handles.editR,'String',num2str(value));
end


% --- Executes on mouse press over axes background.
function Graph_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to Graph (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
point1 = get(gca,'CurrentPoint');    % button down detected
%finalRect = rbbox;                   % return figure units
rec=mousesel();
if(~isempty(rec))
    delete(rec);
end
point2 = get(gca,'CurrentPoint');    % button up detected
xrage=sort([point1(1,1) point2(1,1)]);

index=find(handles.data(:,1)>=xrage(1) & handles.data(:,1)<=xrage(2));
if(length(index)<2) return; end
    
h=handles.Graph2;
axes(handles.Graph2);
threshold('remove');


plot(handles.data(index,1),handles.data(index,2));
set(gca,'xlim',[handles.data(index(1),1) handles.data(index(end),1)]);
setminwinhigh(5);

a=min(handles.data(index,2));
b=max(handles.data(index,2));
noise=(b-a)/2;
z=a+noise;
set(handles.editNoise,'String',num2str(noise));

 
threshold('init',noise,'h=guidata(gcbo);set(h.editNoise,''String'',num2str(threshold(''getValue'')))',z);  


Contact us