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

📄 makefig.m

📁 A MATLAB tool for analysis of Transient Otoacoustic Emission signals
💻 M
字号:
function handle = makefig(prsel, avgfile, dtafile, h, fmse, smme, sE, ipat, tabtit);

% makefig
%
%   in:   prsel     print all selected
%         avgfile   amp file for average data ([] if avg not wanted)
%         dtafile   full filename
%         h         handles of all graphics objects in the figure (struct)
%         fmse      [freq [Hz]; max; start; end] in milliseconds
%         smme      strings for the table
%         sE        strings for the table (energy)
%         ipat      number of the patient
%         tabtit    title for the table

% (c) Pekka Kumpulainen 9.9.1994 (P.K. Feb-95)

if nargin<2; h = []; end 
global STOP_ILOPRINT; 

load filters
% options
fs = 25000; % sampling frequency
t=(0:511)'/fs*1000; % time axis in ms
ttf=t(1:6:510);  % for T-F-plot
wstart = 2.4; % start point of the window (ms)
wrise = 2; % risetime of the window (ms)
lin = 0;
siisti = 0;
fhzgrid=[250;500;1000;1500;2000;3000;4000;6000];
fbgrid=hz2bark(fhzgrid);
flabels=['0.25';'0.5 ';'1.0 ';'1.5 ';'2.0 ';'3.0 ';'4.0 ';'6.0 '];
dB0=(20e-6)^2;
fhz=bark2hz(fb);
fbtf=2:.25:23; % for T-F-plot

% Absolute color & axis limits
colmin = -20; colmax = 10; maxllim = -10; 
resplim = 3;
zamin = colmin; zamax = colmax;
S_ymin = -35; S_ymax = 10;
Ssm_ymin = -40; Ssm_ymax = 10;

if isempty(h); % create the figure, axes and other objects
  h.fig = figure(...
    'Units','Normal',...
    'Position',[.05 0.05 0.6 0.9],...
    'Visible','off',... 
    'Name','ILO analysis',...
    'Color',[1 1 1]);
  set(h.fig,...
    'InvertHardCopy','off',...
    'PaperType','a4letter',...
    'PaperUnits','inches',...
    'PaperPosition',[0.4 0.5 7.3 11],...
    'Colormap',flipud(gray),...
    'DefaultAxesXColor',[0 0 0],...
    'DefaultAxesYColor',[0 0 0],...
    'DefaultAxesColororder',[0 0 0],...
    'DefaultTextColor',[0 0 0],...
    'DefaultTextFontSize',10,...
    'DefaultTextFontName','Times',...
    'DefaultLineColor',[0 0 0]);

  % name etc.
  h.ax.title = axes(...
    'Parent',h.fig,...
    'Position',[.1 .95 .8 .05],...
    'Visible','off');
  h.text.title = text(...
    'Parent',h.ax.title,...
    'Position',[0.5 0.5],...
    'VerticalAlignment','middle',...
    'HorizontalAlignment','center',...
    'FontSize',14);

  % axis and line for the stimulus in time domain
  h.ax.stim = axes(...
    'Parent',h.fig,...
    'Position',[0.1 0.8 0.38 0.1],...
    'XLim',[0 5],...
    'XGrid','on',...
    'YLim',[-0.35 0.35],...
    'YGrid','on',...
    'Box','on');
  set(get(h.ax.stim,'XLabel'),'String','time [ms]','color',[0 0 0])
  set(get(h.ax.stim,'YLabel'),'String','Pa','color',[0 0 0])
  set(get(h.ax.stim,'Title'),'String','Stimulus','color',[0 0 0])
  h.line.stim = line('Parent',h.ax.stim);

 % % axis for the cochlear response in time domain
 % figure(h.fig)
 % haxr = axes(...
 %   'position',[0.43 0.8 0.55 0.1],...
 %   'xlim',[0 21],...
 %   'ylim',[-.4*10^(-3) .4*10^(-3)],...
 %   'xgrid','on',...
 %   'ygrid','on',...
 %   'box','on');
 % set(haxr,...
 %   'xlabel',text(0,0,'time [ms]'),...
 %   'ylabel',text(0,0,'Pa'),...
 %   'title',text(0,0,'Response'));

  % axis and patches for FFT-SPECTRA
  h.ax.fftspect = axes(...
    'Color',[1 1 1],...
    'XColor',[0 0 0],...
    'YColor',[0 0 0],...
    'XGrid','on',...
    'YGrid','on',...
    'Units','normalized',... 
    'Position',[.1 .65 .38 .2],...
    'XLim',[0 6000],...
    'YLim',[S_ymin S_ymax],...
    'Visible','on',... 
    'Box','on',...
    'UserData',[]); 
  set(get(h.ax.fftspect,'XLabel'),'String','Frequency [Hz]')
  set(get(h.ax.fftspect,'YLabel'),'String','dB')
  set(get(h.ax.fftspect,'Title'),'String','FFT-Spectra')
  h.patch.fftresp = patch('Parent',h.ax.fftspect,'FaceColor',[.8 .8 .8]);
  h.patch.fftnoise = patch('Parent',h.ax.fftspect,'FaceColor',[.5 .5 .5]);

  % axis and patches for the spectra of the stimulus and the response
  S_ymin = -35;
  S_ymax = 60;
  h.ax.spect1 = axes(...
    'Parent',h.fig,...
    'Position',[0.1 0.36 0.38 0.35],...
    'Box','on',...
    'XTickLabel',[],... 
    'XLim',[1.8 hz2bark(6000)],...
    'XTick',fbgrid,...
    'XGrid','on',...
    'YLim',[S_ymin S_ymax],...
    'YGrid','on');
  set(get(h.ax.spect1,'Title'),'String','Spectra')
  set(get(h.ax.spect1,'YLabel'),'String','dB')
  h.patch.resp = patch('Parent',h.ax.spect1,'FaceColor',[.8 .8 .8]);
  h.patch.noise = patch('Parent',h.ax.spect1,'FaceColor',[.5 .5 .5]);
  h.line.stimspec = line('Parent',h.ax.spect1);

  % axis & surfaces for the time-dependent spectrum of the response
  YTicks = [2.5 4 6 8 10 12 14 16 18 20];
  h.ax.timespect2d = axes(...
    'Parent',h.fig,...
    'Position',[0.1 0.1 0.38 0.25],...
    'Layer','top',...
    'XLim',[1.8 hz2bark(6000)],...
    'Xtick',fbgrid,...
    'XTickLabel',flabels,...
    'YLim',[2.5 21],...
    'YDir','reverse',...
    'YTick',YTicks,...
    'ZLim',[zamin zamax],...
    'CLim',[colmin colmax]);
  set(get(h.ax.timespect2d,'XLabel'),'String','Frequency [kHz]')
  set(get(h.ax.timespect2d,'YLabel'),'String','Time [ms]')
    
  h.surf.resp2d = surface(...
    'Parent',h.ax.timespect2d,...
    'FaceColor','flat',...
    'EdgeColor','none');
  h.surf.noise2d = surface(...
    'Parent',h.ax.timespect2d,...
    'FaceColor','none',...
    'EdgeColor',[0 0 0],...
    'LineStyle','--',...
    'Linewidth',0.1);
  h.line.maxline = line('Parent',h.ax.timespect2d,'Color',[1 1 1]);
  h.line.startline = line('Parent',h.ax.timespect2d,'Color',[1 1 1]);
  h.line.endline = line('Parent',h.ax.timespect2d,'Color',[1 1 1]);
  
  % axis & surfaces for the time-dependent spectrum of the response 3D-VIEW
  h.ax.timespect3d = axes(...
    'Parent',h.fig,...
    'Position',[.52 .05 .4 .25],...
    'XLim',[1.8 hz2bark(6000)],...
    'XTick',fbgrid,...
    'XTickLabel',flabels,...
    'YLim',[2.5 21],...
    'YDir','reverse',...
    'YTick',YTicks,...
    'ZLim',[zamin zamax],...
    'CLim',[colmin colmax],...
    'View',[45 55]);
  set(get(h.ax.timespect3d,'XLabel'),'String','Frequency [kHz]')
  set(get(h.ax.timespect3d,'YLabel'),'String','Time [ms]')
  set(get(h.ax.timespect3d,'ZLabel'),'String','dB')

  h.surf.resp3d = copyobj(h.surf.resp2d,h.ax.timespect3d);
  h.surf.noise3d = copyobj(h.surf.noise2d,h.ax.timespect3d);

%%%%% Layer top %%%%%
% % Gridlines over surface
% Od = [1 1]; gt = [2 22];
% lx = zeros(8,1);
% axes(h.ax.timespect2d);
% for k=1:8;
%   lx(k) = line(fbgrid(k)*Od,gt,10*Od,'linewidth',0.5);
% end
%
% gf = [2 23];
% ly = zeros(10,1);
% for k=1:10
%   ly(k) = line(gf,YTicks(k)*Od,10*Od,'linewidth',0.5);
% end
%%%%%% Layer top %%%%


  %  AXIS for SMOOTHED SPECTRA
  h.ax.smoothspect = axes(...
    'Parent',h.fig,...
    'Pos',[.6 .45 .38 .25],... 
    'Box','on',...
    'XLim',[1.8 hz2bark(6000)],...
    'XTick',fbgrid,...
    'XGrid','on',...
    'XTickLabel',flabels,...
    'YLim',[Ssm_ymin Ssm_ymax],...
    'YGrid','on');
  set(get(h.ax.smoothspect,'Title'),'String','Smoothed spectra')
  set(get(h.ax.smoothspect,'XLabel'),'String','Frequency [kHz]')
  set(get(h.ax.smoothspect,'YLabel'),'String','dB')
  h.patch.smoothresp = patch('Parent',h.ax.smoothspect,'FaceColor',[.8 .8 .8]);
  h.patch.smoothnoise = patch('Parent',h.ax.smoothspect,'FaceColor',[.5 .5 .5]);
 
  % Axis and text objects of the table --
  h.ax.table = axes(...
    'Parent',h.fig,...
    'Units','normal',...
    'Position',[.52 .1 .45 .25],...
    'Visible','off',...
    'DefaultTextVerticalAlignment','bottom');
  set(get(h.ax.table,'Title'),...
    'Visible','on',...
    'String',tabtit);

  nx = 6;ny = 8;
  x = zeros(nx,1);
  x = [0;[3:7]'/8];
  y = zeros(ny,1);
  y = 1-[1:ny]/ny;

  %gridlines
  for k=2:nx;
    line([x(k) x(k)],[0 1]);
  end    
  for k=1:ny;
    line([0 1],[y(k) y(k)]);
  end    

  x = x+0.01; % some space between lines and text

  %text objects
  h.tabletext = zeros(ny,nx);
  for xx=1:nx;
    for yy=1:ny;
      h.tabletext(yy,xx) = text('position',[x(xx) y(yy) 0]);
    end
  end
  
  Sep = setstr(124);
  strset(h.tabletext(1,:),...
    ['Frequency [kHz]' Sep ,...            
     '0.5' Sep ,...                        
     '1.0' Sep ,...                        
     '2.0' Sep ,...                        
     '4.0' Sep ,...                        
     '6.0'],...                            
     Sep,10,'Helvetica');                  
                                           
  strset(h.tabletext(2:8,1),...                
    ['Maximum [dB]' Sep ,...
     'Maximum [ms]' Sep ,...
     'Start [ms]' Sep ,...
     'End [ms]' Sep ,...
     'Max Deriv. [ms]' Sep ,...
     'Min Deriv. [ms]' Sep ,...
     'E [mPa^2 * ms]']);


  % save handles of the objects in figure's userdata
  set(h.fig,'userdata',h)

end % figure, axes and other objects created
handle = h; % export the handle of the figure

% Load patient's data
[r,stim,name,casetype,ear,date] = loaddta(dtafile);

%calculations
rm = mean(r')';
if sum(rm(1:40).^2) > sum(rm(111:150).^2);
  w = dtawin(fs,wstart,wrise,512,2);
  r = [w w].*r;
end

% Noise level  
n=r(:,1)-r(:,2); 
s2n=std(n)^2;
bwtot=diff(bark2hz([fll(1) ful(length(fll))]));
% Pband=s2n*bwhz(1:2:length(bwhz))/bwtot; 
Pband=s2n*bwhz(1:length(bwhz))/bwtot; % /sum(bwhz);
tn=ttf(1:2:85); fn=fb;
Pn=ones(43);
for ii=1:length(Pband);
  Pn(:,ii)=Pband(ii)*Pn(:,ii);
end
Pn=dbs(Pn/dB0);

%Spectra 
[Sr, Sn,Ss, f]=otospe(r,stim,fs);
[L] = spl(Sr, Sn, f);
% Scale spectra for bark frequencies
Srsc=zeros(1,43);
Sssc=zeros(1,43);
Snsc=zeros(1,43);
df=f(2)-f(1);
for ii=1:42;
  band=fhz([0 1]+ii); bw=band(2)-band(1);
  in= band(1)<=f & f<=band(2);
  Srsc(ii)=(sum(Sr(in))*df)/bw;
  Sssc(ii)=(sum(Ss(in))*df)/bw;
  Snsc(ii)=(sum(Sn(in))*df)/bw;
end
   
%T-F-surface
Prp = fspe(B,A,mean(r')',fs,bwhz);
Prp = Prp(1:6:510,:);

if siisti
  rzdata = dbs(fsmooth(Prp)/dB0);
else
  rzdata = dbs(Prp/dB0);
  fbtf = fbtf(1:2:length(fbtf));
end  

% start max and end lines
if siisti; lwin = 7; else lwin = 5; end
mme = limnums(rzdata, ttf, Pn(1,:), 3);
maxline = smooth(mme(2,:),gaussw(lwin));
startline = smooth(mme(3,:),gaussw(lwin));
endline = smooth(mme(4,:),gaussw(lwin));

% cut maximum values to colmax    
rcdata=colmax*ones(size(rzdata));
rcdata(rzdata<colmax)=rzdata(rzdata<colmax);  


if prsel
  % Create lines patches and surfaces
      
  %name
  set(h.text.title,'String',[int2str(ipat) '. ' name ', ' ear ', ' date])
  
  % Stimulus
  set(h.line.stim,...
    'XData',(0:127)/25,...
    'YData',stim);
  
  % % Response
  % set(0,'CurrentFigure',h.fig);
  % set(h.fig,'CurrentAxes',haxr);
  % delete(get(haxr,'Children'));
  % hr1=line(t,r(:,1),'linestyle','-');
  % hr2=line(t,r(:,2),'linestyle',':');
  
  % FFT-Spectra
  nzd = max(size(Sr))+2;
  set(h.patch.fftresp,'XData',dupends(f),'YData',[S_ymin dbs(Sr) S_ymin],'ZData',zeros(nzd,1));
  set(h.patch.fftnoise,'XData',dupends(f),'YData',[S_ymin dbs(Sn) S_ymin],'ZData',ones(nzd,1));
  
  % Spectra
  nzd = max(size(Srsc))+2;
  set(h.patch.resp,'XData',dupends(fb),'YData',[S_ymin dbs(Srsc) S_ymin],'ZData',zeros(nzd,1));  
  set(h.patch.noise,'XData',dupends(fb),'YData',[S_ymin dbs(Snsc) S_ymin],'ZData',ones(nzd,1)); 
  set(h.line.stimspec,'XData',fb,'YData',dbs(Sssc));                  
  
  % Smoothed spectra
  set(h.patch.smoothresp,'XData',dupends(fb),'YData',[Ssm_ymin smooth(dbs(Srsc),gaussw(7)) Ssm_ymin],'ZData',zeros(nzd,1));
  set(h.patch.smoothnoise,'XData',dupends(fb),'YData',[Ssm_ymin smooth(dbs(Snsc),gaussw(7)) Ssm_ymin],'ZData',ones(nzd,1));
  
  % T-F-Spectrum & Noise level
  infb = fbtf>=1.8 & fbtf<=hz2bark(6000); 
  infn = fn>=1.8 & fn<=hz2bark(6000); 
  int = ttf>=2.5 & ttf<=21;
  intn = tn>=2.5 & tn<=21;
  rzdata = rzdata(int,infb);
  rcdata = rcdata(int,infb);
  Pn = Pn(intn,infn);
  fbtf = fbtf(infb);
  fn = fn(infn);
  ttf = ttf(int);
  tn = tn(intn);
  rzdata(rzdata<zamin) = NaN*rzdata(rzdata<zamin);

  set(h.surf.resp2d,...
    'xdata',fbtf,...
    'ydata',ttf,...
    'zdata',rzdata,...
    'cdata',rcdata);
  set(h.surf.noise2d,...
    'xdata',fn,...
    'ydata',tn,...
    'zdata',Pn);
  
  % max, start & end lines over T-F-surface
  msezd = 20*ones(size(maxline(infb)));
  set(h.line.maxline,...
      'xdata',fbtf,...
      'ydata',maxline(infb),...
      'zdata',msezd);
  set(h.line.startline,...
      'xdata',fbtf,...
      'ydata',startline(infb),...
      'zdata',msezd);
  set(h.line.endline,...
      'xdata',fbtf,...
      'ydata',endline(infb),...
      'zdata',msezd);
  
  % Figures to the table
  for i1=2:7;
    strset(h.tabletext(i1,2:6),smme(i1-1,:));
  end % i1
  strset(h.tabletext(8,2:6),sE); 
  
  % 3D-surface
  set(h.surf.resp3d,...
    'xdata',fbtf,...
    'ydata',ttf,...
    'zdata',rzdata,...
    'cdata',rcdata);
  set(h.surf.noise3d,...
    'xdata',fn,...
    'ydata',tn,...
    'zdata',Pn);
    
  % ASETTELUN KOKEILUA-------------
    %delete(haxr);
    % axis for the stimulus in time domain
    set(h.ax.stim,'position',[0.1 0.83 0.4 0.07])
    % AXIS for FFT-SPECTRA
    set(h.ax.fftspect,'pos',[.1 .65 .38 .11])      
    %  AXIS for SMOOTHED SPECTRA
    set(h.ax.smoothspect,'pos',[.6 .65 .38 .25])
    % Axis and text objects of the table --
    set(h.ax.table,'pos',[.52 .36 .45 .2]) 
    % axis for the spectra of the stimulus and the response
    set(h.ax.spect1,'position',[0.1 0.31 0.38 0.25])
    % axis for the time-dependent spectrum of the response
    set(h.ax.timespect2d,'position',[0.1 0.05 0.38 0.25]);
    % axis for surface
    set(h.ax.timespect3d,...
        'pos',[.55 .05 .41 .25],...
        'view',[30 65]);
  
  % -------------------------------
  
  % print
  tempdir = getenv('temp');
  printfile = [tempdir '\ilo_' int2str(ipat) '.ps'];
  %printfile = [tempdir '\tmp.ps'];
  hardcopy(h.fig,printfile,'-dps');
  %lprcmd = printopt;
  %cmd = sprintf(lprcmd, printfile);
  
  ilopath = which('ilo');
  fbs = find(ilopath == '\');
  
  cmd = [ilopath(1:fbs(end)) 'tmpprint.bat ' printfile];
  dos(cmd);
  %delete printfile
  
  %dos('copy /B c:\tmp\tmp.ps LPT2: &');
end % if prsel

% Average not available -------------------------------------
% if ~isempty(avgfile);
%   if ipat == 1;
%     Mstim = stim;
%     MSr = Sr;
%     MSn = Sn;
%     MSssc = Sssc;
%     MSrsc = Srsc;
%     MSnsc = Snsc;
%     Mzdata = rzdata;
%     Mrzdatap = rzdatap;
%     NumPat = ipat;
%     eval(['save ' avgfile ' Mstim MSr MSn MSssc MSrsc MSnsc Mzdata NumPat']);
%   else
%     eval(['load ' avgfile])
%     Mstim = (stim+(ipat-1)*Mstim)/ipat;
%     MSr = (Sr+(ipat-1)*MSr)/ipat;
%     MSn = (Sn+(ipat-1)*MSn)/ipat;
%     MSssc = (Sssc+(ipat-1)*MSssc)/ipat;
%     MSrsc = (Srsc+(ipat-1)*MSrsc)/ipat;
%     MSnsc = (Snsc+(ipat-1)*MSnsc)/ipat;
%     Mzdata = (rzdata+(ipat-1)*Mzdata)/ipat;
%     Mrzdatap = (rzdatap+(ipat-1)*Mrzdatap)/ipat;
%     NumPat = ipat;
%     eval(['save ' avgfile ' Mstim MSr MSn MSssc MSrsc MSnsc Mzdata NumPat']);
%   end
% end
% ------------------------------------------------------------  

⌨️ 快捷键说明

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