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

📄 ilo.m

📁 A MATLAB tool for analysis of Transient Otoacoustic Emission signals
💻 M
字号:
function out = ilo(command, varargin);

%  ilo    TEOAE analysis tool
%
%

%  Pekka Kumpulainen (kumpu@ee.tut.fi) 


switch nargin,
  % Initialize
  case 0,
    localInitFig

  % Execute a callback
  otherwise,

    switch command,
      case 'ilo_call',
        localILO_call(varargin{:})

      otherwise,
        % do nothing

    end % switch command

end % switch nargin

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% localILO_call %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
function hc = localILO_call(command,varargin)

h = get(gcf,'Userdata');

switch command
  case 'pbut_quit'
  % Quit
    delete(gcf)

  case 'pbut_files'
  % Chance directory
    [str, Files, dtaPath] = popstr;
    set(h.pop.notsel,'String',str,...
             'UserData',Files,...
             'Value',1);
    set(h.pop.selected,'String',' ',...
             'UserData',[]);
    set(h.txt.dtapath,'String',dtaPath);
    ilo ilo_call pop_notsel

  case 'pbut_OK'
  % OK: do it all
    %ilocanc('initialize',size(get(pop_selected,'UserData'),1));
    avg = get(h.chkb.avg,'Value'); sel = get(h.chkb.selected,'Value');
    f_type = get(h.pop.filters,'Value');
    lin = 0;
    dtapath = get(h.txt.dtapath,'String');
    files = get(h.pop.selected,'UserData');
    iloanlys(dtapath, files, avg, sel, lin, f_type)
    %iloprint(dtapath,files,avg,sel,lin)
  
  case 'pbut_add'
  % Add patient to list
    N = get(h.pop.notsel,'Value');
    applyall = get(h.chkb.applyall,'Value');
    UD1 = get(h.pop.notsel,'UserData'); UD2 = get(h.pop.selected,'UserData');
    STR1 = get(h.pop.notsel,'String'); STR2 = get(h.pop.selected,'String');
    n1 = size(STR1,1); n2 = size(STR2,1);
    if STR2 == ' '; STR2 = []; n2 = 0; end
  
    if ~applyall; % add one
      STR2 = [STR2; STR1(N,:)];
      nums = zeros(4,(n2+1)); nums(:) = sprintf('%4g',(1:(n2+1))');
      STR2(:,1:4) = nums';
      
      if n1>1;
        STR1(N,:) = []; nums = zeros(4,(n1-1)); nums(:) = sprintf('%4g',(1:(n1-1))');
        STR1(:,1:4) = nums';
      else 
        STR1 = ' ';
      end % n1>1
      
      set(h.pop.notsel,'String',STR1); set(h.pop.selected,'String',STR2);
      set(h.pop.selected,'UserData',[UD2; UD1(N,:)]);
      UD1(N,:) = []; 
      set(h.pop.notsel,'Value',1,'UserData',UD1); set(h.pop.selected,'Value',n2+1);
    elseif applyall;  % add all
      set(h.pop.notsel,'String',' '); set(h.pop.selected,'String',[STR2;STR1]);
      set(h.pop.selected,'UserData',[UD2; UD1]); set(h.pop.notsel,'UserData',[]);
      set(h.pop.notsel,'Value',1); set(h.pop.selected,'Value',1);
    end

  case 'pbut_remove'
  % Remove patient from list
    N = get(h.pop.selected,'Value');
    applyall = get(h.chkb.applyall,'Value');
    UD1 = get(h.pop.notsel,'UserData'); UD2 = get(h.pop.selected,'UserData');
    STR1 = get(h.pop.notsel,'String'); STR2 = get(h.pop.selected,'String');
    n1 = size(STR1,1); n2 = size(STR2,1);
    if STR1 == ' '; STR1 = [];  n1 = 0;end
  
    if ~applyall; % remove one
  
      STR1 = [STR1; STR2(N,:)];
      if n2>1;
        STR2(N,:) = []; nums = zeros(4,(n2-1)); nums(:) = sprintf('%4g',(1:(n2-1))');
        %if ~isempty(nums); 
        STR2(:,1:4) = nums'; % end
      else 
        STR2 = ' ';
      end % n2>1     

      nums = zeros(4,(n1+1)); nums(:) = sprintf('%4g',(1:(n1+1))');
      STR1(:,1:4) = nums';
      set(h.pop.notsel,'String',STR1); set(h.pop.selected,'String',STR2);
      set(h.pop.notsel,'UserData',[UD1; UD2(N,:)]);
  
      UD2(N,:) = []; set(h.pop.selected,'UserData',UD2);
      set(h.pop.notsel,'Value',n1+1); set(h.pop.selected,'Value',1);
    elseif applyall; % remove all
      set(h.pop.notsel,'String',[STR1;STR2]); set(h.pop.selected,'String',' ');
      set(h.pop.notsel,'UserData',[UD1; UD2]); set(h.pop.selected,'UserData',[]);
      set(h.pop.notsel,'Value',1); set(h.pop.selected,'Value',1);
    end  % ~applyall
  
  case 'pop_selected'
  % Show patients data
    popval = get(h.pop.selected,'value');
    S_ymin = -35;
    S_ymax = 60;
    fs = 25000; t = (0:511)'/fs*1000;
    filelist = get(h.pop.selected,'UserData'); dtaPath = get(h.txt.dtapath,'String');
    [r, stim, name, m_case, ear, m_date] = loaddta([dtaPath char(filelist(popval,:))]);
    delete(findobj(get(h.ax.stim,'Children'),'flat','HandleVisibility','on'));
    hlstim = line(t(1:128),stim,'Color',[1 0 0], 'Parent', h.ax.stim);
    rm=mean(r')';
    if sum(rm(1:40).^2) > sum(rm(111:150).^2);
        w=dtawin(25000,2.4,2,512,2);
        r=[w w].*r;
    end
    [Sr, Sn,Ss, f]=otospe(r,stim,fs);
    delete(findobj(get(h.ax.spect,'Children'),'flat','HandleVisibility','on'));
    hlSstim = line(f, dbs(Ss),'Color',[1 0 0], 'Parent', h.ax.spect);
    nzd = max(size(Sr))+2;
    hlSr = patch(dupends(f),[S_ymin dbs(Sr) S_ymin],zeros(nzd,1),[.8 .8 .8], 'Parent', h.ax.spect);
    hlSn = patch(dupends(f),[S_ymin dbs(Sn) S_ymin],ones(nzd,1),[.5 .5 .5], 'Parent', h.ax.spect);
    delete(findobj(get(h.ax.resp,'Children'),'flat','HandleVisibility','on'));
    hlresp1 = line(t,r(:,1),'color',[1 0 0], 'Parent', h.ax.resp);
    hlresp2 = line(t,r(:,2),'color',[0 0 1], 'Parent', h.ax.resp);
    set(get(h.ax.resp,'Title'),'String',[name '', '' ear '', '' m_case '', '' m_date]);

  case 'pop_notsel'
  % Show patients data
    popval = get(h.pop.notsel,'value');
    S_ymin = -35;
    S_ymax = 60;
    fs = 25000; t = (0:511)'/fs*1000;
    filelist = get(h.pop.notsel,'UserData'); dtaPath = get(h.txt.dtapath,'String');
    [r, stim, name, m_case, ear, m_date] = loaddta([dtaPath char(filelist(popval,:))]);
    delete(findobj(get(h.ax.stim,'Children'),'flat','HandleVisibility','on'));
    hlstim = line(t(1:128),stim,'Color',[1 0 0], 'Parent', h.ax.stim);
    rm=mean(r')';
    if sum(rm(1:40).^2) > sum(rm(111:150).^2);
        w=dtawin(25000,2.4,2,512,2);
        r=[w w].*r;
    end
    [Sr, Sn,Ss, f]=otospe(r,stim,fs);
    delete(findobj(get(h.ax.spect,'Children'),'flat','HandleVisibility','on'));
    hlSstim = line(f, dbs(Ss),'Color',[1 0 0], 'Parent', h.ax.spect);
    nzd = max(size(Sr))+2;
    hlSr = patch(dupends(f),[S_ymin dbs(Sr) S_ymin],zeros(nzd,1),[.8 .8 .8], 'Parent', h.ax.spect);
    hlSn = patch(dupends(f),[S_ymin dbs(Sn) S_ymin],ones(nzd,1),[.5 .5 .5], 'Parent', h.ax.spect);
    delete(findobj(get(h.ax.resp,'Children'),'flat','HandleVisibility','on'));
    hlresp1 = line(t,r(:,1),'color',[1 0 0], 'Parent', h.ax.resp);
    hlresp2 = line(t,r(:,2),'color',[0 0 1], 'Parent', h.ax.resp);
    set(get(h.ax.resp,'Title'),'String',[name '', '' ear '', '' m_case '', '' m_date])
   
otherwise
  error('Error: ilo called with incorrect command.') 
end % switch command
  


%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% localInitFig %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
function localInitFig

hfig = figure(...
    'Position',[5 20 780 550],...
    'Resize','on',...
    'Name','ILO Tool',...
    'MenuBar','none',...
    'NumberTitle','off',...
    'Color',[1 1 .9]); 

% Default Axes properties
set(hfig,...
  'DefaultAxesBox','on',...
  'DefaultAxesXGrid','on',...
  'DefaultAxesYGrid','on',...
  'DefaultAxesColor',[1 1 1],...
  'DefaultAxesXColor',[0 0 0],...
  'DefaultAxesYColor',[0 0 0])
% Default Text properties
set(hfig,...
  'DefaultTextUnits','Normalized',...
  'DefaultTextColor',[0 0 0],...
  'DefaultTextFontSize',10,...
  'DefaultTextFontName','Times')

% Default Uicontrol properties
set(hfig,...
  'DefaultUicontrolUnits','Normalized',...
  'DefaultUicontrolBackgroundColor',[0.75 0.75 0.75 ],... 
  'DefaultUicontrolForegroundColor',[0 0 0 ],...
  'DefaultUicontrolHorizontalAlignment','center')

% Axes objects
ax.stim = axes(...
  'Position',[.07 .65 .25 .3],...
  'xlim',[0 7],...
  'ylim',[-.35 .35]); 
set(get(ax.stim,'XLabel'),'String','Time [ms]')
set(get(ax.stim,'YLabel'),'String','Pa')
set(get(ax.stim,'Title'),'String','Stimulus')
S_ymin = -35;
S_ymax = 60;
ax.spect = axes(...
  'Position',[.45 .65 .45 .3],...
  'xlim',[0 6000],...
  'ylim',[S_ymin S_ymax]); 
set(get(ax.spect,'XLabel'),'String','Frequency [Hz]')
set(get(ax.spect,'YLabel'),'String','dB')
set(get(ax.spect,'Title'),'String','Spectrum')

ax.resp = axes(...
  'Position',[.07 .2 .75 .3],...
  'xlim',[0 21],...
  'ylim',[-.4e-3 .4e-3]); 
set(get(ax.resp,'XLabel'),'String','Time [ms]')
set(get(ax.resp,'YLabel'),'String','Pa')
set(get(ax.resp,'Title'),'String','','FontSize',14,'FontWeight','Bold')

handles.ax = ax;

%  Uicontrol Object Creation 
frame.chekb = uicontrol(... 
  'Style','frame',...
  'Position',[.85 .41 .15 .15]); 
chkb.selected = uicontrol(... 
  'Style','checkbox',...
  'Position',[.86 .43 .13 .04],... 
  'String','Selected',... 
  'Value',0); 
chkb.avg = uicontrol(... 
  'Style','checkbox',...
  'Position',[.86 .47 .13 .04],... 
  'String','Average',... 
  'Enable','off',  ...
  'Value',0); 
pbut.quit = uicontrol(... 
  'Style','pushbutton',... 
  'BackgroundColor',[0.7 0.7 0.7 ],... 
  'CallBack','ilo ilo_call pbut_quit',... 
  'Position',[.85 .15 .15 .05],... 
  'String','Quit'); 
pbut.files = uicontrol(... 
  'Style','pushbutton',... 
  'BackgroundColor',[0.7 0.7 0.7 ],... 
  'CallBack','ilo ilo_call pbut_files',... 
  'Position',[.85 .2 .15 .05],... 
  'String','Files >>'); 
pbut.OK = uicontrol(... 
  'Style','pushbutton',... 
  'BackgroundColor',[0.7 0.7 0.7 ],... 
  'CallBack','ilo ilo_call pbut_OK',... 
  'Position',[.85 .25 .15 .05],... 
  'String','OK',... 
  'Interruptible','on'); 
pbut.add = uicontrol(... 
  'Style','pushbutton',... 
  'BackgroundColor',[0.7 0.7 0.7 ],... 
  'CallBack','ilo ilo_call pbut_add',... 
  'Position',[.5-.11 0 .11 .05],... 
  'String','Add >>'); 
chkb.applyall = uicontrol(... 
  'Style','checkbox',...
  'BackgroundColor',get(gcf,'color'),... 
  'Position',[.45 .05 .16 .05],... 
  'String','Apply to all'); 
pbut.remove = uicontrol(... 
  'Style','pushbutton',... 
  'BackgroundColor',[0.7 0.7 0.7 ],... 
  'CallBack','ilo ilo_call pbut_remove',... 
  'Position',[.5 0 .11 .05],... 
  'String','<< Remove');
pop.selected = uicontrol(... 
  'Style','popupmenu',...
  'CallBack','ilo ilo_call pop_selected',... 
  'Position',[.62 0 .38 .04],... 
  'String',' '); 
pop.notsel = uicontrol(... 
  'Style','popupmenu',...
  'CallBack','ilo ilo_call pop_notsel',... 
  'Position',[0 0 .38 .04 ],... 
  'String',' '); 
pop.filters = uicontrol(... 
  'Style','popupmenu',...
  'Position',[0.85 0.32 .15 0.04 ],... 
  'String',['1 Bark';'2 Bark';'3 Bark'],... 
  'Value',1);
  
handles.chkb = chkb;
handles.pbut = pbut;
handles.pop = pop;


%  Text Object Creation 
txt.printopt = uicontrol(... 
  'Style','text',... 
  'BackgroundColor',[0.75 0.75 0.75 ],... 
  'CallBack','ilo(''chkb_avg'');',... 
  'Position',[.86 .52 .13 .03],... 
  'String','Print Options'); 
txt.selected = uicontrol(... 
  'Style','text',... 
  'BackgroundColor',get(gcf,'color'),... 
  'Position',[.65 .045 .35 .03],... 
  'String','Selected'); 
txt.dtapath = uicontrol(... 
  'Style','text',... 
  'BackgroundColor',get(gcf,'color'),... 
  'Position',[0 .045 .35 .03],... 
  'String','Path'); 
txt.filters = uicontrol(... 
  'Style','text',... 
  'BackgroundColor',get(gcf,'color'),... 
  'Position',[.85 .36 .15 .025],... 
  'String','Filter Width'); 

handles.chkb = chkb;
handles.pbut = pbut;
handles.pop = pop;
handles.txt = txt;

set(hfig,'UserData',handles); 

% Select data directory and get the data
[str, Files, Path] = popstr;
set(pop.notsel,...
  'String',str,...
  'UserData',Files);
set(txt.dtapath,'String',Path);
ilo ilo_call pop_notsel

⌨️ 快捷键说明

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