Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

function varargout = INSS_GUI_V4final(varargin)

% INSS_GUI_V4final MATLAB code for INSS_GUI_V4final.fig


% INSS_GUI_V4final, by itself, creates a new INSS_GUI_V4final or raises
the existing
% singleton*.
%
% H = INSS_GUI_V4final returns the handle to a new INSS_GUI_V4final or
the handle to
% the existing singleton*.
%
% INSS_GUI_V4final('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in INSS_GUI_V4final.M with the given input
arguments.
%
% INSS_GUI_V4final('Property','Value',...) creates a new INSS_GUI_V4final
or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before INSS_GUI_V4final_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to INSS_GUI_V4final_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

% Edit the above text to modify the response to help INSS_GUI_V4final

% Last Modified by GUIDE v2.5 11-Feb-2021 13:15:42

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @INSS_GUI_V4final_OpeningFcn, ...
'gui_OutputFcn', @INSS_GUI_V4final_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 INSS_GUI_V4final is made visible.


function INSS_GUI_V4final_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 INSS_GUI_V4final (see VARARGIN)

% Choose default command line output for INSS_GUI_V4final


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes INSS_GUI_V4final wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = INSS_GUI_V4final_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


varargout{1} = handles.output;

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_dir
[FileName,PathName] = uigetfile('*.edf','Select the EDF\EEG file');
file_dir=[PathName FileName];
handles.path=file_dir;
handles.pathname=PathName;
set(handles.edit1,'String',file_dir);
handles.channelNumber=1;
guidata(hObject,handles)

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (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 edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a
double

% --- Executes during object creation, after setting all properties.


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data;
file_dir=handles.path;
msgbox('Loading............................................','Load','modal')
[hdr,data]=edfread(file_dir);
handles.data=data;
handles.hdr=hdr;
mbhandles=msgbox('Load Complete','Load','modal');
delete(mbhandles)
set(handles.listbox1,'String',char(hdr.label))
handles.data=data;
handles.hdr=hdr;
%plotSummaryBox(handles,1)
%blah=get(gcf,'CurrentAxes')%matlab made new axis -useless
%fazul(handles)
orange(handles,data,256,0,'raw plot',200,3600,'b',0,0)
%blah2=get(gcf,'CurrentAxes')
EEG = eeg_emptyset;
comments="Patients Information";
%EEG.comments="nhejdif";
%EEG= pop_comments(handles,EEG,comments);

%g="bheregwyy"

guidata(hObject,handles)

file_dir=handles.path;
KKK=split(file_dir,["\"]);
kkkk=split(KKK{end},["b"]);
kk=split(kkkk{2},["_"]);
Subj=str2num(kk{1});
kkx=split(kk(2),["."]);
File=str2num(kkx{1});
sb=num2str(Subj);
fi=num2str(File);

try
load(['D:\INSS_GUI_V4\Marked Labels\' sb '_' fi '.mat']);

handles.Marked_Labels=Marked_Labels;
asx=['File already processed'];
set(handles.edit3,'String',asx);
channelNumber=1;
%blah=get(gcf,'CurrentAxes')
plotClassifiedProfileBox(handles,channelNumber)
%ax1=get(gcf,'CurrentAxes')
catch
asx=['File is not processed yet'];
handles.Marked_Labels=[];
set(handles.edit3,'String',asx);
end

fwrite(fopen([pwd '\lastVisitedAddress.txt'],
'w'),get(handles.edit1,'String'));
fwrite(fopen([ pwd '\lastSamplingFrequency.txt'],
'w'),get(handles.edit2,'String'));

asx=['Zoom Count'];
set(handles.edit4,'String',asx);

handles.flg=0;
handles.cnt=0;
handles.x=[];
handles.pluss=[];
handles.Marked_Labels=[];
guidata(hObject,handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55555
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pop_comments(handles, comments);

% limits,title,freqfaq, percent, 'key1',


'value1' ...);
%pop_eegplot( data, 1, 0, 0 )
%eegplot(data)

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=handles.data;
file_dir=handles.path;
KKK=split(file_dir,["\"]);
kkkk=split(KKK{end},["b"]);
kk=split(kkkk{2},["_"]);
Subj=str2num(kk{1});
kk=split(kk(2),["."]);
File=str2num(kk{1});
handles.File=File;
handles.Subj=Subj;
% channelNumber = get(hObject,'Value');
%{
%%multiple plotting processing!
[apple,mango] = size(data);
%%for i=1:len(apple) %loop through all chnannels

%}
channelNumber=handles.channelNumber;
Chan=channelNumber;
PathName=handles.pathname;
mbhandles =
msgbox('Processing............................................','Load');
%
[V,S_T,S_P,Accuracy]=Process_Test(data(channelNumber,:),Subj,File,channelNumbe
r);
%
[V,S_T,S_P,Accuracy]=Process_Test_Balanced(data(channelNumber,:),Subj,File,cha
nnelNumber,PathName);
hdr=handles.hdr;
[V,S_T,S_P,Accuracy]=Process(data,Subj,File,Chan,PathName,hdr);
% global S_P
% Accuracy
mbhandles = msgbox('Processing
completed............................................','Load');
msgbox('Function passed')

xxx=0;yyy=0;
for i=1:length(S_T)
if S_T(i)==1
xxx=xxx+1;
if S_P(i)==1
yyy=yyy+1;
end
end
end

handles.S_T=S_T;
handles.S_P=S_P;
handles.Marked_Labels=[];
guidata(hObject,handles)
handles.flg=0;

plotClassifiedProfileBox(handles,channelNumber)
msgbox('Plot passed')
mbhandles = msgbox('Plot
Passed............................................','Load');

set(handles.edit2, 'FontWeight', 'Bold');


set(handles.edit3, 'FontWeight', 'Bold');
%set(handles.edit4, 'FontWeight', 'Bold');
if sum(S_T)~=0
Accuracy=Accuracy*100;

asx=strcat('Channel Accuracy is : ','"',num2str(Accuracy),'"',' Percent');


asx=['Channel Accuracy is : ' ' ' num2str(Accuracy) ' ' 'Percent'];
set(handles.edit3,'String',asx);
mnb=strcat('Total',' ',num2str(sum(S_P)),' ','Seizures detected');
mnb=['Total' ' ' num2str(sum(S_P)) ' ' 'Siezures detected from which' ' '
num2str(yyy) ' ' 'are correct'];
% %set(handles.edit4,'String',mnb);
%plotSummaryBoxAcytualSeizure(handles,channelNumber)
else
set(handles.edit2,'String','No Seizure in file');
cla(handles.axes5)
asx=strcat('Channel Accuracy is : "100" Percent');
set(handles.edit3, 'FontWeight', 'Bold');
asx=['Channel Accuracy is : ' ' ' '100' ' ' 'Percent'];
set(handles.edit3,'String',asx);
% % set(handles.edit4, 'FontWeight', 'Bold');
% % set(handles.edit4,'String','No Seizure detected');
end

Label=handles.S_P;
tt=sum(Label);
asx=['Total' ' ' num2str(tt) ' ' ' Seizures Found'];
set(handles.edit2,'String',asx);

delete(mbhandles)

asx=['Zoom Count'];
set(handles.edit4,'String',asx);
handles.pluss=[];
handles.cnt=0;
guidata(hObject,handles)

%{
function plotSummaryBox(handles,channelNumber)
data=handles.data;
temp = data(channelNumber,:);
sampels = length(temp);
cla(handles.axes3)
plot(handles.axes3,temp)

title(handles.axes3,'Raw EEG','FontSize', 15);


xlabel(handles.axes3,'Epochs (Sec)')
ylabel(handles.axes3,'V (\mu v)')
%}
function plotClassifiedProfileBox(handles,channelNumber)
if isempty(handles.Marked_Labels)
S_P=handles.S_P;
else
S_P=handles.Marked_Labels;
end
data=handles.data;
% Group = GUI_DWT_SVM1(temp,sampFreq,channelNumber);
temp = data(channelNumber,:);

if handles.flg==0
Group=S_P;
else
x=handles.x;
Group=S_P(x(1):x(2),:);
% temp = data(channelNumber,x(1):x(2));
i1=x(1);i2=x(2);
end

j=1;
cla(handles.axes4)
sampFreq=256;
hold(handles.axes4,'on')%%%%%%%%%% process

for i=1:length(Group)

if handles.flg==0

if Group(j)==0
plot(handles.axes4,((i-1)*sampFreq+1:i*sampFreq)/sampFreq,temp(1,(i-
1)*sampFreq+1:i*sampFreq),'b')
else
plot(handles.axes4,((i-1)*sampFreq+1:i*sampFreq)/sampFreq,temp(1,(i-
1)*sampFreq+1:i*sampFreq),'r')
end
j=j+1;

else

if Group(j)==0
plot(handles.axes4,((i1-1)*sampFreq+1:i1*sampFreq)/sampFreq,temp(1,
(i1-1)*sampFreq+1:i1*sampFreq),'b')
else
plot(handles.axes4,((i1-1)*sampFreq+1:i1*sampFreq)/sampFreq,temp(1,
(i1-1)*sampFreq+1:i1*sampFreq),'r')
end
j=j+1;i1=i1+1;
end
end

if handles.flg==0
xlim(handles.axes4,[0 length(Group)])
else
xlim(handles.axes4,[x(1) x(2)])
end
hold(handles.axes4,'off')
title(handles.axes4,'Processed data','FontSize', 15);
xlabel(handles.axes4,'Epochs (Sec)')
ylabel(handles.axes4,'V (\mu v)')

function edit2_Callback(hObject, eventdata, handles)%%%%%%%%%%%% ACTUAL


SEIZURE
% hObject handle to edit2 (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 edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a
double

% --- Executes during object creation, after setting all properties.


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit3_Callback(hObject, eventdata, handles)%%%%%%%%%%%%%% PROCESSED


YET
% hObject handle to edit3 (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 edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a
double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in listbox1.


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

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents


as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
channelNumber = get(hObject,'Value')
handles.channelNumber=channelNumber;

pushbutton3_Callback(hObject, eventdata, handles)


%plotSummaryBox(handles,channelNumber)
%plotZoomBox(handles,channelNumber)
% mbhandles =
msgbox('Processing............................................','Load');
%plotClassifiedProfileBox(handles,channelNumber)
%delete(mbhandles)
guidata(hObject,handles)
fwrite(fopen([ pwd '\lastSamplingFrequency.txt'],
'w'),get(handles.edit2,'String'));

% --- Executes during object creation, after setting all properties.


function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)%%%%%%%%%%%%MARK
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[x,y] = ginput(2)
%[x,y] = getpts

x=floor(x);
y=floor(y);
% handles.x=x;
% handles.y=y;
if x(1)<x(2)
xa=x(1);xb=x(2);
else
xa=x(2);xb=x(1);
end
Marked_Labels=handles.Marked_Labels;
if isempty(Marked_Labels)
Labels=handles.S_P;
Marked_Labels=Labels;
Marked_Labels(xa:xb,:)=1;
else
Marked_Labels(xa:xb,:)=1;
end

handles.Marked_Labels=Marked_Labels;
channelNumber=handles.channelNumber;
plotClassifiedProfileBox(handles,channelNumber)

guidata(hObject,handles)

% --- Executes on button press in pushbutton5.%%%%%%%%%%%%%% UNMARK


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Marked_Labels=handles.Marked_Labels;
if isempty(handles.Marked_Labels)
S_P=handles.S_P;
else
S_P=handles.Marked_Labels;
end

[x,y] = ginput(2)
x=floor(x);
y=floor(y);

if x(1)<x(2)
xa=x(1);xb=x(2);
else
xa=x(2);xb=x(1);
end
if isempty(handles.Marked_Labels)
Labels=S_P;
Labels(xa:xb,:)=0;
Marked_Labels=Labels;
else
Marked_Labels(xa:xb,:)=0;
end
handles.Marked_Labels=Marked_Labels;
channelNumber=handles.channelNumber;
plotClassifiedProfileBox(handles,channelNumber)
guidata(hObject,handles)

% --- Executes on button press in pushbutton6.


function pushbutton6_Callback(hObject, eventdata, handles)%%%%%%%%% SAVE
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox('Saving............................................','Load','modal')

myfile1=num2str(handles.File);
myfile2=num2str(handles.Subj);
myfile=[myfile2 '_' myfile1];
x=handles.x;
% y=handles.y;
Marked_Labels=handles.Marked_Labels;
save(['D:\INSS_GUI_V4\Marked Labels/' myfile '.mat'],'x','Marked_Labels')

% S_P=handles.S_P;
% data=handles.data;
% hdrnew=handles.hdr;
% hdr=handles.hdr;
% hdrnew.channels=hdr.label;
% hdrnew.samplingrate=256;
% hdrnew.markk=S_P;
% % hdrnew.units=S_P;
% lab_write_edf('newedfsaveee',data,hdrnew);
mbhandles=msgbox('Save Complete','Load','modal');
delete(mbhandles)
guidata(hObject,handles)

function edit4_Callback(hObject, eventdata, handles)%%%%%%%%%%%%%


ZOOM COUNT
% hObject handle to edit4 (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 edit4 as text


% str2double(get(hObject,'String')) returns contents of edit4 as a
double

% --- Executes during object creation, after setting all properties.


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton7.


function pushbutton7_Callback(hObject, eventdata, handles)%%%%%%% PLUS
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cnt=handles.cnt;
cnt=cnt+1;
[x,y] = ginput(2)
x=floor(x);
y=floor(y);
handles.x=x;
handles.y=y;
handles.flg=1;

asx=[num2str(cnt)];
set(handles.edit4,'String',asx);

pluss=handles.pluss;
pluss(cnt).x=x;
handles.cnt=cnt;
handles.pluss=pluss;
channelNumber=handles.channelNumber;
plotClassifiedProfileBox(handles,channelNumber)

guidata(hObject,handles)

% --- Executes on button press in pushbutton8.


function pushbutton8_Callback(hObject, eventdata, handles)%%%%%%%%% MINUS
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cnt=handles.cnt;
cnt_m=cnt-1;
handles.cnt=cnt_m;
asx=[num2str(cnt_m)];
set(handles.edit4,'String',asx);

channelNumber=handles.channelNumber;
pluss=handles.pluss;
p=length(pluss);
if p<=1
handles.flg=0;
plotClassifiedProfileBox(handles,channelNumber)
else

handles.flg=1;
x=pluss(p-1).x;
p=p-1;
for i=1:p
pp(i).x=pluss(i).x;
end
pluss=pp;
handles.pluss=pluss;
handles.x=x;

plotClassifiedProfileBox(handles,channelNumber)
end

guidata(hObject,handles)

% --- Executes on button press in pushbutton13.


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

setappdata(0, 'function', handles);


INSS_GUI_Subband

% --- Executes on button press in pushbutton11.


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

% --- Executes on button press in pushbutton12.


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

% --- Executes on button press in pushbutton9.


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

% --- Executes on button press in pushbutton10.


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

function orange(handles,data, srate, channamefile, titleval, yscaling, epoch,


linecolor,xstart,vertmark)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define defaults
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
icadefs; % read MAXEEGPLOTCHANS, DEFAULT_SRATE, DEFAULT_EPOCH from icadefs.m

if nargin < 1
help eegplots % print usage message
PLOT_TIME = 10;
data = 0.5*randn(8,floor(DEFAULT_SRATE*PLOT_TIME*2));
titleval = ['eegplots() example - random noise']; % show example plot
end
%}
[chans,frames] = size(data); %size of data matrix

% set initial spacing


DEFAULT_SPACING = max(max(data')-min(data'));
% spacing_var/20 = microvolts/millimeter with 21 channels
% for n channels: 21/n * spacing_var/20 = microvolts/mm
% for clinical data.
DEFAULT_PLOTTIME = 10; % default 10 seconds per window
DEFAULT_TITLE = 'eegplots()';
errorcode=0; % initialize error indicator

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Allow for different numbers of arguments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin < 9,
vertmark = 0;
end
if nargin < 8,
xstart = 0;
end

if nargin < 7
linecolor = 'y'; % DEFAULT LINECOLOR
end
if linecolor == 0,
linecolor = 'y'; % DEFAULT LINECOLOR
end
if nargin < 6
PLOT_TIME = 0;
else
PLOT_TIME = epoch;
end
if nargin < 5
spacing_var = 0;
else
spacing_var = yscaling;
end
if spacing_var == 0
spacing_var = DEFAULT_SPACING;
end

if nargin < 4
titleval = DEFAULT_TITLE;
end
if ~isstr(titleval)
if titleval == 0
titleval = DEFAULT_TITLE;
else
help eegplots
return
end
end
if nargin < 3
channamefile = 0;
end
if nargin < 2
srate = DEFAULT_SRATE;
end
if srate == 0,
srate = DEFAULT_SRATE;
end;
if PLOT_TIME == 0
PLOT_TIME = ceil(frames/srate);
if PLOT_TIME > DEFAULT_EPOCH
PLOT_TIME = DEFAULT_EPOCH;
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define internal variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

maxtime = frames / srate; %size of matrix in seconds

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Read the channel names
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
if channamefile ~=0, % read file of channel names
chid = fopen(channamefile,'r');
if chid <3,
fprintf('_plotdata: cannot open file %s.\n',channamefile);
errorcode=2;
channamefile = 0;
else
% fprintf('Chan info file %s opened\n',channamefile);
end;
if errorcode==0,
channames = fscanf(chid,'%d %f %f %s',[7 MAXEEGPLOTCHANS]);
channames = channames';
channames = setstr(channames(:,4:7)); % convert ints to chars
[r c] = size(channames);
for i=1:r
for j=1:c
if channames(i,j)=='.',
channames(i,j)=' '; % convert dots to spaces
end;
end;
end;
% fprintf('%d channel names read from file.\n',r);
if (r>chans)
fprintf('Using first %d names.\n',chans);
channames = channames(1:chans,:);
end;
if (r<chans)
fprintf('Only %d channel names read.\n',r);
end;
end;
end
%}
if channamefile ==0, % plot channel numbers
channames = [];
for c=1:chans
if c<10,
numeric = [' ' int2str(c)]; % four-character fields
else
numeric = [' ' int2str(c)];
end
channames = [channames;numeric];
end;
end; % setting channames

channames = str2mat(channames, ' '); % add padding element to Y labels

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make matrix of x-tick labels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Xlab = num2str(0);
%for j = 1:1:PLOT_TIME
% Q = num2str(0+j);
% Xlab = str2mat(Xlab, Q);
%end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set Graph Characteristics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold( handles.axes3, 'on' );
%get(handles.axes4, 'xgrid', 'on')
cla(handles.axes3)
%orange=get(gcf,'CurrentAxes')%making a new matlab axis useless!
set (handles.axes3, 'xgrid', 'on') % Xaxis gridlines only
set (handles.axes3, 'GridLineStyle','-') % Solid grid lines
% set (gca, 'XTickLabel', Xlab) % Use Xlab for tick labels
%set (gca, 'XTick', 0*srate:1.0*srate:PLOT_TIME*srate)
set (handles.axes3, 'Box', 'on')
set (handles.axes3, 'Ytick', 0:spacing_var:chans*spacing_var) % ytick
spacing on channels
set (handles.axes3, 'TickLength', [0.02 0.02])
title(handles.axes3,titleval) % title is
titleval
axis([xstart xstart+PLOT_TIME 0 (chans+1)*spacing_var]);
set (handles.axes3, 'YTickLabels', flipud(channames),'FontSize',9) % write
channel names
% Matlab-5 requires YTickLabels

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot the EEG data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lastn=919040
%data = data(1:end-lastn,:);
refax=handles.axes3;
PLOT_TIME=3600;
xx = xstart:1/srate:xstart+PLOT_TIME-0.9/srate; % x-range values
% xx
% xx = xx(:,1:2560);% looks like the range again
for i = 1:chans
F = data(chans-i+1,:);% extracts the specific row with all columns
F = F - mean(F) + i*spacing_var; % add offset to y-values
ploh= plot(handles.axes3, xx,F);
end
hold(handles.axes3, 'off');
%clear xx F
%arbitrarily set the reference axes limits to small portion of the
%total X/Y data of the plot handle.
set(refax,'xlim',[0 80]);
%make an X axis and Y axis scroll bar
axeslist = {'X'};
superscroll_obj=superscroll(refax,axeslist);
%build scrollbar, add keypress and resize functions
autoscrollbar(superscroll_obj,ploh);
%make one scroll bar yellow
yellow(superscroll_obj.axdyn(1));
%title(refax,'pan and zoom using arrow keys, shift and control')

%{
if xstart<0 & xstart+PLOT_TIME > 0
linetime = round(-xstart/srate);
line ([linetime linetime],[1e10,-1e10]);
end

if vertmark ~= 0,
for mark = vertmark,
linetime = xstart + (mark-1)/srate;
line ([linetime linetime],[-1e10,1e10],'Color','y','LineStyle',':');
end
end

%}
%{
function fazul(handles)
hold( handles.axes3, 'on' )

x=0:1:10;
y=2:1:12;
ploth=plot(x,y)
ploh=plot(x,y,'-*r','linewidth',2,'parent',refax); clear x y
set(refax,'xlim',[0 80],'ylim',[-1 2]);
axeslist = {'X','Y'};
superscroll_obj=superscroll(refax,axeslist);

%build scrollbar, add keypress and resize functions


autoscrollbar(superscroll_obj,ploh);

%make one scroll bar yellow


yellow(superscroll_obj.axdyn(1));

title(refax,'pan and zoom using arrow keys, shift and control')


%}

% --- Executes during object creation, after setting all properties.

function axes3_CreateFcn(hObject, eventdata, handles)


% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes3

function EEG = iniset();

EEG.setname = '';
EEG.filename = '';
EEG.filepath = '';
EEG.pnts = 0;
EEG.nbchan = 0;
EEG.trials = 0;
EEG.srate = 1;
EEG.xmin = 0;
EEG.xmax = 0;
EEG.rt = [];
EEG.data = [];
EEG.icawinv = [];
EEG.icasphere = [];
EEG.icaweights = [];
EEG.icaact = [];
EEG.event = [];
EEG.epoch = [];
EEG.chanlocs = '';
EEG.comments = 'Patient Comments';
%EEG.reject.threshold = [1 0.8 0.85];
%EEG.reject.icareject = [];
%EEG.reject.compreject = [];
%EEG.reject.gcompreject= [];
%EEG.reject.comptrial = [];
%EEG.reject.sigreject = [];
%EEG.reject.elecreject = [];

%EEG.stats.kurta = [];
%EEG.stats.kurtr = [];
%EEG.stats.kurtd = [];
%EEG.stats.eegentropy = [];
%EEG.stats.eegkurt = [];
%EEG.stats.eegkurtg = [];
%EEG.stats.entropy = [];
%EEG.stats.kurtc = [];
%EEG.stats.kurtt = [];
%EEG.stats.entropyc = [];

return;

function [EEG, com] = pop_comments(handles, comments);

com = '';
if nargin < 1
help pop_comments;
return;
end;
%if nargin < 2
%figure('menubar', 'none', 'numbertitle', 'off', 'name', 'About this
dataset -- pop_comment()');
axes(handles.axes5);
pos = get(handles.axes5,'position'); % plot relative to current axes
q = [pos(1) pos(2) 0 0];
s = [pos(3) pos(4) pos(3) pos(4)]./100;
set(handles.axes5, 'userdata', 0);
title('Comments on current dataset');

axis off;

try, comments = EEG.comments;


catch, comments = [];
end;

% create the buttons


% ------------------
%{
uicontrol('Parent',gcf, ...
'Units','Normalized', ...
'Position', [0 0 20 10].*s+q, ...
'string','CANCEL', 'callback', ...
[ 'set(gcbf, ''userdata'', -1);' ]);
%}
uicontrol('Parent',gcf, ...
'Units','Normalized', ...
'Position', [30 0 20 10].*s+q, ...
'string','SAVE', 'callback', ...
[ 'set(gcbf, ''userdata'', ' ...
'get(findobj(''parent'', gcbf, ''tag'', ''edit''), ''string''));' ]);

%hh = text( q(1), 100*s(2)+q(2), comments, 'tag', 'edit');


%set( hh, 'editing', 'on', 'verticalalignment', 'top');

hh = uicontrol('Parent',gcf, ...
'Units','Normalized', ...
'style', 'edit', ...
'tag', 'edit', ...
'Position', [0 15 100 85].*s+q, ...
'string', comments, ...
'backgroundcolor', [ 1 1 1], ...
'horizontalalignment', 'left', ...
'max', 2, ...
'fontsize', 12);

waitfor(gcf, 'userdata');

if isstr(get(gcf, 'userdata'))
comments = get(gcf, 'userdata') % ok button
%fwrite(fopen([ pwd '\comms.txt'], 'w'),get(handles.axes5,'edit'));
end;

%close(gcf);
%else
%try, comments = char(eval(comments)); catch, end;
%end;

EEG.comments = comments;
fileID = fopen('Patient.txt','w');
%fprintf(fileID,'%6s %12s\n','x','exp(x)');
fprintf(fileID,comments);
fclose(fileID);

I = find( comments(:) == '''');


comments(I) = ' ';

com =sprintf('%s = pop_comments( %s, ''%s'');', inputname(1), inputname(1),


array2str(comments));
return;

function str = array2str( array )


str = '[';
for index = 1:size(array,1)
str = [ str '; [' num2str(double(array(index,:))) '] ' ];
end;
str = [ str ']' ];
return;
function axes5_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes5

% --- Executes on button press in pushbutton15.


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

figure('menubar', 'none', 'numbertitle', 'off', 'name', 'Spectral and Head


Plots');
pos = get(gca,'position'); % plot relative to current axes
q = [pos(1) pos(2) 0 0];
s = [pos(3) pos(4) pos(3) pos(4)]./100;
%set(gcf, 'userdata', 0);
%title('Comments on current dataset');
axis off
data=handles.data;
[spectra,freqs] = spectopo(handles,data,921600,256,25);

function [eegspecdB,freqs]=spectopo(handles, data,frames,srate,headfreqs,


limits,titl,freqfac, percent, varargin)

LOPLOTHZ = 1; % low Hz to plot


FREQFAC = 4; % approximate frequencies/Hz (default)

if nargin<5
help spectopo
return
end

if nargin<8
freqfac = FREQFAC;
end

if nargin<7
titl = []; % default no title
end

if nargin<6
limits = [nan nan nan nan nan nan]; % defaults from data
end

if nargin<9
percent = 1; % defaults sample 100% of the data
else
percent = max(percent, 0);
percent = min(percent, 1);
end

if frames == 0
frames = size(data,2); % assume one epoch
end

if min(headfreqs)<0
fprintf('spectopo(): freqs must be >=0 Hz\n');
return
end
nchans = size(data,1);
epochs = round(size(data,2)/frames);
if frames*epochs ~= size(data,2)
error('Spectopo: non-integer number of epochs');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute channel spectra using psd()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
epoch_subset = 1:epochs;
if percent ~= 1 & epochs > 1
nb = round( percent*epochs);
epoch_subset = zeros(1,epochs);
while nb>0
index = ceil(rand*epochs);
if ~epoch_subset(index)
epoch_subset(index) = 1;
nb = nb-1;
end;
end;
epoch_subset = find(epoch_subset == 1);
fprintf('Selecting randomly %d epochs\n', length(epoch_subset));
end;
fftlength = 2^round(log(srate)/log(2))*FREQFAC;
fprintf('Computing spectra: ')
for c=1:nchans
for e=epoch_subset
[tmpspec,freqs] = pwelch(matsel(data,frames,0,c,e),fftlength,...
srate,fftlength/2,fftlength/8);
if c==1 & e==epoch_subset(1)
eegspec = zeros(nchans,length(freqs));
end
eegspec(c,:) = eegspec(c,:) + tmpspec';
end
fprintf('.')
end
eegspecdB = 10*log10(eegspec/epochs); % convert power to dB
fprintf('\n')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute axis and caxis limits
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if length(limits)<1 | isnan(limits(1))
limits(1) = LOPLOTHZ;
end

if length(limits)<2 | isnan(limits(2))
maxheadfreq = max(headfreqs);
if rem(maxheadfreq,5) ~= 0
limits(2) = 5*ceil(maxheadfreq/5);
else
limits(2) = maxheadfreq*1.1;
end
end

headfreqs = sort(headfreqs); % Determine topoplot frequencies


freqidx = zeros(1,length(headfreqs)); % Do not interpolate between freqs
for f=1:length(headfreqs)
[tmp fi] = min(abs(freqs-headfreqs(f)));
freqidx(f)=fi;
end
[tmp maxfreqidx] = min(abs(limits(2)-freqs)); % adjust max frequency
[tmp minfreqidx] = min(abs(limits(1)-freqs)); % adjust min frequency

if length(limits)<3|isnan(limits(3))
limits(3) = min(min(eegspecdB(:,minfreqidx:maxfreqidx)));
end
if length(limits)<4|isnan(limits(4))
limits(4) = max(max(eegspecdB(:,minfreqidx:maxfreqidx)));
end
dBrange = limits(4)-limits(3); % expand range a bit beyond data limits
limits(3) = limits(3)-dBrange/7;
limits(4) = limits(4)+dBrange/7;

if length(limits)<5 % default caxis plotting limits


limits(5) = nan;
end
if length(limits)<6
limits(6) = nan;
end

if isnan(limits(5))+isnan(limits(6)) == 1
fprintf('spectopo(): limits 5 and 6 must either be given or nan\n');
return
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot spectrum of each channel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
specaxes = sbplot(3,4,[5 12]);
% plot(freqs(1:maxfreqidx),eegspecdB(:,1:maxfreqidx)','b','LineWidth',2);
pl=plot(freqs(1:maxfreqidx),eegspecdB(:,1:maxfreqidx)');
set(pl,'LineWidth',2);
set(gca,'TickLength',[0.02 0.02]);

axis([freqs(minfreqidx) freqs(maxfreqidx) limits(3) limits(4)]);

xl=xlabel('Frequency (Hz)');
set(xl,'fontsize',16);
yl=ylabel('Rel. Power (dB)');
set(yl,'fontsize',16);
set(gca,'fontsize',16)
box off;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot lines through channel trace bundle at each headfreq
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for f=1:length(headfreqs)
hold on;
plot([freqs(freqidx(f)) freqs(freqidx(f))], ...
[min(eegspecdB(:,freqidx(f))) max(eegspecdB(:,freqidx(f)))],...
'k','LineWidth',2.5);
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot connecting lines using changeunits()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
headax = zeros(1,length(headfreqs));
for f=1:length(headfreqs)
headax(f) = sbplot(3,length(headfreqs),f);
axis([-1 1 -1 1]);
end
large = sbplot(1,1,1);
for f=1:length(headfreqs)
from = changeunits([freqs(freqidx(f)),max(eegspecdB(:,freqidx(f)))],...
specaxes,large);
to = changeunits([0,0],headax(f),large);
hold on;
plot([from(1) to(1)],[from(2) to(2)],'k','LineWidth',2);
axis([0 1 0 1]);
axis off;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot heads using topoplot()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('Plotting scalp distributions: ')
chanlocs= 'chalocfile.loc';
for f=1:length(headfreqs)
axes(headax(f));
topodata = eegspecdB(:,freqidx(f))-mean(eegspecdB(:,freqidx(f)));
if isnan(limits(5)), maplimits = 'absmax';
else maplimits = [limits(5) limits(6)];
end;
if ~isempty(varargin)
topoplot(topodata,chanlocs,'maplimits',maplimits, varargin{:});
else
topoplot(topodata,chanlocs,'maplimits',maplimits);
end
if f<length(headfreqs)
tl=title([num2str(freqs(freqidx(f)), '%3.1f')]);
else
tl=title([num2str(freqs(freqidx(f)), '%3.1f') ' Hz']);
end
set(tl,'fontsize',16);
axis square;
drawnow
fprintf('.');
end;
fprintf('\n');

%%%%%%%%%%%%%%%%
% Plot color bar
%%%%%%%%%%%%%%%%
cb=colorbar;
pos = get(cb,'position');
set(cb,'position',[pos(1) pos(2) 0.03 pos(4)]);
set(cb,'fontsize',12);
if isnan(limits(5))
ticks = get(cb,'ytick');
[tmp zi] = find(ticks == 0);
ticks = [ticks(1) ticks(zi) ticks(end)];
% set(cb,'ytick',ticks);
set(cb,'yticklabel',{'-','0','+'});
end

%%%%%%%%%%%%%%%%
% Draw title
%%%%%%%%%%%%%%%%
if ~isempty(titl)
tl = textsc(titl,'title');
set(tl,'fontsize',15)
end

%%%%%%%%%%%%%%%%
% Turn on axcopy
%%%%%%%%%%%%%%%%
axcopy

function axcopy(fig, command)

if (exist('fig') == 1) & strcmp(fig,'noticks')


noticks = 1;
if nargin> 1
shift
else
fig = [];
end
end
if ~(exist('fig') ==1) | isempty(fig) | fig == 0
fig = gcf;
end

hndl= findobj('parent',fig,'type','axes');
offidx=[];
for a=1:length(hndl) % make all axes visible
if exist('command') ~= 1
set(findobj('parent',hndl(a)),'ButtonDownFcn','copyaxis');
else
set(findobj('parent',hndl(a)),'ButtonDownFcn',['copyaxis(''' command
''')']);
end;
end
figure(fig);
if exist('command') ~= 1
set(hndl(a),'ButtonDownFcn','copyaxis');
else
set(hndl,'ButtonDownFcn',['copyaxis(''' command ''')']);
end;

You might also like