# HG changeset patch # User tomwalters # Date 1305891151 -3600 # Node ID 74dedb26614dee8cbd1ce7ee45e00cb3c2f3277c Initial checkin of AIM-MAT version 1.5 (6.4.2011). diff -r 000000000000 -r 74dedb26614d README.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.html Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,71 @@ + + + +AIM-MAT Readme + + + + +

Getting started with AIM-MAT

+
+  AIM-MAT v 1.5
+$Date: 20011-04-06 $
+
+ +
+

System Requirements

+

AIM-MAT was developed using MATLAB 7 and above.

+

The package should work on any platform supporting MATLAB 6.5 or above, with + the Signal Processing Toolbox installed.

+

AIM-MAT has been tested while in development on the following platforms:

+ +
+

Tips for getting started

+ + + diff -r 000000000000 -r 74dedb26614d Sounds/CalSounds/cegc.wav Binary file Sounds/CalSounds/cegc.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/CalSounds/ct8ms.wav Binary file Sounds/CalSounds/ct8ms.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/CalSounds/ordinate_cal.wav Binary file Sounds/CalSounds/ordinate_cal.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/CalSounds/rdct.wav Binary file Sounds/CalSounds/rdct.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/Tones/ris/IRNd16i8.wav Binary file Sounds/Tones/ris/IRNd16i8.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/Tones/ris/makeIRNo.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sounds/Tones/ris/makeIRNo.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,96 @@ +% support file for 'aim-mat' +% +% This external file is included as part of the 'aim-mat' distribution package +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function irn = makeIRNo(Delay,NIt,Dur,Gate,RMS,TS,DelF1,HPF,LPF,DelF2) +% irn = makeIRNo(Delay,NIt,Dur,Gate,RMS,TS,DelF1,HPF,LPF,DelF2) +% +% Delay = IRN delay in ms; +% NIt = number of iterations; +% Dur = duration of IRN; +% Gate = duration of on- and offset ramps; +% RMS = RMS amplitude of IRN; +% TS = sampling period in ms; +% Delf1 = lower spectral ramp (we used 0.2 kHz); +% HPF = lower edge of stady-state portion +% (in the experiment, HPF was 0.8, 1.6, 3.2 or 6.4 kHz); +% LPF = upper edge of steady-state portion +% (in the experiment, LPF was always 1.6 kHz above HPF); +% DelF2 = upper lower spectral ramp (we used 1.6 kHz); +% +% irn = makeIRNo(16,8,100,10,.1,.05,.2,.5,2.0,1.6) + +TPts = round(Dur/TS); +FPts = lcfFPts(TPts); +cmbFilter = lcfFilter(Delay,NIt,TPts,FPts,TS,DelF1,HPF,LPF,DelF2); +array = real(ifft(cmbFilter.*fft(randn(1,FPts)))); +irn = lcfQWind(lcfSetI(array(1:TPts),RMS),Gate,TS); +irn = lcfSetI(irn,RMS); +wavwrite(irn,1000/TS,'testwave'); + +% ********** lcfFilter ********** +function cmbFilter = lcfFilter(Delay,NIt,TPts,FPts,TS,DelF1,HPF,LPF,DelF2) + +DF = 1/(TS*FPts); +SDelF1 = round(DelF1/DF); +SDelF2 = round(DelF2/DF); +SBW = round((LPF-HPF)/DF); +FL = max(HPF-DelF1,0); +FH = min(LPF+DelF2,1/(2*TS)); + +bpFilter = zeros(1,round(FL/DF)); +LEN = min(SDelF1,round(HPF/DF)-length(bpFilter)); +jwd = fliplr(cos((0:LEN-1)*pi/(2*SDelF1))); +bpFilter = [bpFilter jwd]; +bpFilter = [bpFilter ones(1,SBW)]; + +LEN = min(min(FPts/2,round(FH/DF))-length(bpFilter),SDelF2); +jwd = cos((0:(LEN-1))*pi/(2*SDelF2)); +bpFilter = [bpFilter jwd]; +bpFilter = [bpFilter zeros(1,FPts/2-length(bpFilter))]; + +frq = (0:FPts/2-1)*DF; +%Erb = sum(bpFilter.^2*DF); + +G = 1; +reH = ones(1,FPts/2); +imH = zeros(1,FPts/2); +for I = 1:NIt + reH = reH+G^I*cos(2*pi*I*Delay*frq); + imH = imH+G^I*sin(2*pi*I*Delay*frq); +end +cmbFilter = bpFilter.*(reH+i*imH); +cmbFilter = [cmbFilter fliplr(cmbFilter)]; + +% ************ lcfFPts *********** +function FPts = lcfFPts(TPts) + +FPts = 16384; +while FPts0 + out = in*RMS/S; +else + error('==> RMS: Devide by zero!') +end + +% ************ lcfQWind ************ +function out = lcfQWind(in,Gate,TS) + +GPts = round(Gate/TS); +APts = length(in); +if APts<2*GPts + error('==> ''Dur'' must be longer than two times ''Gate''!') +end +env = cos(pi*(0:GPts-1)/(2*(GPts-1))).^2; +out = [1-env ones(1,APts-2*GPts) env].*in; + diff -r 000000000000 -r 74dedb26614d Sounds/Tones/roys_vowels/roy_a_canon.wav Binary file Sounds/Tones/roys_vowels/roy_a_canon.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/Tones/roys_vowels/roy_e_canon.wav Binary file Sounds/Tones/roys_vowels/roy_e_canon.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/Tones/roys_vowels/roy_i_canon.wav Binary file Sounds/Tones/roys_vowels/roy_i_canon.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/Tones/roys_vowels/roy_o_canon.wav Binary file Sounds/Tones/roys_vowels/roy_o_canon.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/Tones/roys_vowels/roy_u_canon.wav Binary file Sounds/Tones/roys_vowels/roy_u_canon.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/aimmat.wav Binary file Sounds/aimmat.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/ct8ms.wav Binary file Sounds/ct8ms.wav has changed diff -r 000000000000 -r 74dedb26614d Sounds/freqprofile.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sounds/freqprofile.txt Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,50 @@ +1000 0.0003745 +2000 0.00032037 +3000 0.00090275 +4000 0.0029595 +5000 0.0059385 +6000 0.0078835 +7000 0.007494 +8000 0.0060847 +9000 0.0046621 +10000 0.0066574 +11000 0.01128 +12000 0.013275 +13000 0.012507 +14000 0.0098303 +15000 0.010794 +16000 0.013058 +17000 0.015763 +18000 0.027611 +19000 0.040498 +20000 0.045664 +21000 0.046239 +22000 0.049006 +23000 0.048659 +24000 0.041914 +25000 0.036679 +26000 0.028243 +27000 0.021026 +28000 0.017685 +29000 0.019133 +30000 0.02211 +31000 0.025596 +32000 0.02644 +33000 0.023552 +34000 0.019867 +35000 0.0161 +36000 0.012248 +37000 0.0099462 +38000 0.013779 +39000 0.017035 +40000 0.01648 +41000 0.013519 +42000 0.010507 +43000 0.0091298 +44000 0.0074301 +45000 0.0060468 +46000 0.0056208 +47000 0.0057545 +48000 0.0056186 +49000 0.005049 +50000 0.0041599 diff -r 000000000000 -r 74dedb26614d Sounds/singleclick.wav Binary file Sounds/singleclick.wav has changed diff -r 000000000000 -r 74dedb26614d aim-mat/gui/adaptedspecgramdemo.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/adaptedspecgramdemo.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,2862 @@ +function out=adaptedspecgramdemo(y,Fs,t_min,t_max) +%SPECGRAMDEMO Spectrogram Demo +% SPECGRAMDEMO(y,Fs) displays a spectrogram of signal y, assuming +% a sample rate of Fs Hz. If y is specified but Fs is not, +% a sample rate of 1 Hz is assumed. If no input arguments +% are supplied, y and Fs are taken from the default data file +% "mtlb.mat." +% +% Context menus and context-sensitive help are enabled throughout +% the GUI. Explore the visualization options by right-clicking +% on various GUI items including the spectrogram, the colorbar, +% etc. For example, the panner may be zoomed by dragging the +% mouse on the left- and right-hand edges of the highlighted +% zoom region. Right-clicking the highlighted zoom area brings +% up a menu for focusing in on the zoom region, and provides +% a link to context help. +% +% See also SPECGRAM, SPTOOL, FDATOOL. + +% Author: D. Orofino +% Copyright 1988-2002 The MathWorks, Inc. +% $orginal Revision: 1.11 $ $orginal Date: 2002/05/17 14:17:56 $ +% +% +% adapted by Stefan Bleeck 5.3.2003 to give back the selected time. +% Stefan@Bleeck.de + +%%%%%%%%%%%%%%%%%%%%%%%%%% +% inserted by S.Bleeck +global tmin; +global tmax; +if nargin<4 + t_max=length(y)/Fs; +end +if nargin<3 + t_min=0; +end +tmin=0; +tmax=length(y); +%%%%%%%%%%%%%%%%%%%%%%%%%% + +if nargin<1, + default_file = 'mtlb.mat'; + fprintf(['Loading demo file (%s).\n\n'],default_file); + s = load(default_file); + y = s.mtlb; % default dataset + Fs = s.Fs; +elseif nargin<2, + Fs=1; % default sample rate +end + +create_gui(y,Fs,t_min,t_max); + + +%%%%%%%%%%%%%%%%%%%%%%%%%% +% inserted by S.Bleeck +out.start=tmin/Fs; +out.duration=tmax/Fs-tmin/Fs; +%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%--------------------------------------------------------------- +function zoom_in(hco,eventStruct,hfig) + +if nargin<3, hfig=gcbf; end + +ud = get(hfig,'userdata'); + +% Get "pixel spacing" of image content +im_xdata = get(ud.himage,'xdata'); +im_dx = im_xdata(2)-im_xdata(1); + +% Get current axis limit +xlim = get(ud.hax(1),'xlim'); +xlim_ctr = sum(xlim)/2; +dxlim = diff(xlim); + +% If current axis limits will only show 1 pixel width, +% don't bother zooming in any further: +if dxlim <= im_dx, return; end + +% Shrink limits 50% toward center of current limits: +new_xlim = (xlim + xlim_ctr)/2; +% Update the spectrogram and time slice axes: +set(ud.hax(1),'xlim',new_xlim); % [1 3] xxxx + +% Update the thumbnail: +set(ud.hthumb,'xdata',new_xlim([1 2 2 1 1])); + +% update the audio selection to be played +set_audio_selection(hfig, new_xlim * ud.Fs); + +% Update zoom signal, if enabled: +% xxx plot_signal_zoom(hfig); + +%--------------------------------------------------------------- +function zoom_out(hco,eventStruct,hfig) + +% Zooming is relative to the current focus window +% We will not zoom out beyond the current focus window + +if nargin<3, hfig=gcbf; end +ud = get(hfig,'userdata'); + +% Get current spectrogram axis limit (= thumbnail limits) +thumb_xlim = get(ud.hax(1),'xlim'); % thumb limits = spectrogram limits +thumb_dx = diff(thumb_xlim); + +% If spectrogram axis limits >= focus window limits, +% don't bother zooming out any further: +hax_time = ud.hax(2); +focus_xlim = get(hax_time,'xlim'); % = panner xlim +focus_dx = focus_xlim(2)-focus_xlim(1); +if thumb_dx >= focus_dx, return; end + +% Grow limits 50% away from center of current limits: +new_xlim = thumb_xlim + [-thumb_dx thumb_dx]/2; +if new_xlim(1)focus_xlim(2), new_xlim(2)=focus_xlim(2); end + +% Update the thumbnail: +set(ud.hthumb,'xdata',new_xlim([1 2 2 1 1])); + +% Sync the spectrogram and time slice axes to the thumbnail: +set(ud.hax(1),'xlim',new_xlim); % [1 3] xxxx + +% update the audio selection to be played +set_audio_selection(hfig, new_xlim * ud.Fs); + +% Update zoom signal, if enabled: +% xxx plot_signal_zoom(hfig); + +%--------------------------------------------------------------- +function zoom_full(hco,eventStruct,hfig) + +if nargin<3, hfig=gcbf; end +ud = get(hfig,'userdata'); + +focusTimeReset(hfig); % reset focus window to full extent + +% Get time range of full spectrogram +im_xdata = get(ud.himage,'xdata'); + +% Grow limits 50% away from center of current limits: +new_xlim(1)=im_xdata(1); +new_xlim(2)=im_xdata(end); + +% Update the spectrogram and time slice axes: +set(ud.hax([1 3]),'xlim',new_xlim); + +% Update the thumbnail: +set(ud.hthumb,'xdata',new_xlim([1 2 2 1 1])); + +% update the audio selection to be played +set_audio_selection(hfig, new_xlim * ud.Fs); + +% Update zoom signal, if enabled: +% xxx plot_signal_zoom(hfig); + +%--------------------------------------------------------------- +function top_plot_toggle + +% XXX UNUSED? + +hfig=gcbf; +ud=get(hfig,'userdata'); + +if strcmp(ud.plot.top,'spectrogram_time_slice'), + newMode='signal_zoom'; +else + newMode='spectrogram_time_slice'; +end +ud.plot.top=newMode; +set(hfig,'userdata',ud); + +hax_tslice = ud.hax(3); + +if strcmp(newMode,'signal_zoom'), + t = (0:length(ud.y)-1)/ud.Fs; + set(ud.htslice_line,'xdata',t, 'ydata', ud.y); + set(hax_tslice,'xlim',[0 max(t)],'ylimmode','auto'); +else + % xxx + set(ud.htslice_line,'ydata', get_spec_tslice(hfig), ... + 'xdata',ud.t); + + b = get(ud.himage,'cdata'); + blim = [min(b(:)) max(b(:))]; + spec_xlim = [0 max(ud.t)]; + set(hax_tslice, 'xlim',spec_xlim, 'ylim',blim); +end + +% Update the top plot (Time slice) +%update_top_plot(hfig); + +%--------------------------------------------------------------- +function left_plot_toggle +% Define the newMode flag in ud.plot.left + +hfig = gcbf; +ud = get(hfig,'userdata'); + +if strcmp(ud.plot.left,'spectrogram_freq_slice'), + newMode = 'signal_psd'; +else + newMode = 'spectrogram_freq_slice'; +end +ud.plot.left = newMode; +set(hfig,'userdata',ud); + +% Update the left plot (Frequency slice and PSD) +update_left_plot(hfig); + +%--------------------------------------------------------------- +function set_crosshairs(hfig,x,y) + +% Get current point in axis ASAP: +%hfig = gcbf; +ud = get(hfig,'userdata'); + +% Update cache +ud.crosshair.xctr = x; +if nargin == 3, + ud.crosshair.yctr = y; +else + y = ud.crosshair.yctr; +end +set(hfig,'userdata',ud); + +% Update crosshairs +set([ud.hspec_y ud.htime_y ud.htslice_y], 'xdata',[x x]); +set([ud.hspec_x ud.hfreq_x], 'ydata',[y y]); + +% Update readouts +update_time_readout(hfig); +update_freq_readout(hfig); +update_dB_readout(hfig); +update_cmap_ptr(hfig); + +% For the VERTICAL and H/V crosshairs, +% update the freq slice display: +if strcmp(ud.plot.left,'spectrogram_freq_slice'), + set(ud.hfreq_line,'xdata', get_spec_freq(hfig)); +end + +% For the HORIZONTAL and H/V crosshairs, +% update the time slice display: +if strcmp(ud.plot.top,'spectrogram_time_slice'), + set(ud.htslice_line,'ydata', get_spec_tslice(hfig)); +end + +%--------------------------------------------------------------- +function center_cross(hco,eventStruct) + +hfig = gcbf; +ud = get(hfig,'userdata'); + +% Determine center of spectrogram axis: +xlim=get(ud.hax(1),'xlim'); +ylim=get(ud.hax(1),'ylim'); + +set_crosshairs(hfig,mean(xlim),mean(ylim)); +update_cmap_ptr(hfig); + +%--------------------------------------------------------------- +function wbmotion_thumb(hco,eventStruct) +% thumbnail motion + +% Get current point in axis ASAP: +hfig = gcbf; +ud = get(hfig,'userdata'); +hax = ud.hax(2); +cp = get(hax,'currentpoint'); +curr_x = cp(1,1); + +xdata = get(ud.hthumb,'xdata'); +xmotion = curr_x - ud.thumb.origPt; +width = ud.thumb.width; +xdata = ud.thumb.xdata + xmotion; + +% Constrain to axis limits, so we don't lose cursor: +xlim=get(hax,'xlim'); +min_xdata = min(xdata); +max_xdata = max(xdata); +if min_xdata < xlim(1), + xdata=[xlim(1) xlim([1 1])+width xlim([1 1])]; +elseif max_xdata > xlim(2), + xdata = [xlim(2)-width xlim([2 2]) xlim([2 2])-width]; +end + +% If the patch is larger than the zoom window +if min(xdata)<=xlim(1) & max(xdata)>=xlim(2), + % error('wbmotion_thumb: xdata is out of bounds'); + return +end + +% Update the thumbnail: +set(ud.hthumb,'xdata',xdata); + +% Scroll the spectrogram and time-slice axes: +% xxxx +set(ud.hax([1]),'xlim',xdata(1:2)); % [1 3] xxx + +% update the audio selection to be played +set_audio_selection(hfig, xdata(1:2) * ud.Fs); + +%if strcmp(ud.plot.top,'spectrogram_time_slice'), +% set(ud.htslice_line,'ydata', get_spec_tslice(hfig)); % xxxx +%end + +%--------------------------------------------------------------- +function wbmotion_thumbleft(hco,eventStruct) +% thumbnail LEFT motion + +% Get current point in axis ASAP: +hfig = gcbf; +ud = get(hfig,'userdata'); + +% current object may be either the patch, or the signal line +hax = ud.hax(2); +cp = get(hax,'currentpoint'); +curr_x = cp(1,1); + +xdata = get(ud.hthumb,'xdata'); +xmotion = curr_x - ud.thumb.origPt; +width = ud.thumb.width; +xdata = ud.thumb.xdata; +xdata([1 4 5]) = xdata([1 4 5]) + xmotion; + +% Constrain to axis limits, so we don't lose cursor: +xlim = get(hax,'xlim'); +min_xdata = min(xdata); +if min_xdata < xlim(1), + xdata=[xlim(1) xdata([2 3])' xlim([1 1])]; +elseif min_xdata >= xdata(2), + xdata = ud.thumb.xdata; +end + +% Update the thumbnail: +set(ud.hthumb,'xdata',xdata); + +% Scroll the spectrogram: +set(ud.hax(1),'xlim',xdata(1:2)); + +% update the audio selection to be played +set_audio_selection(hfig, xdata(1:2) * ud.Fs); + +%--------------------------------------------------------------- +function wbmotion_thumbright(hco,eventStruct) +% thumbnail RIGHT motion + +% Get current point in axis ASAP: +hfig = gcbf; +ud = get(hfig,'userdata'); + +hax = ud.hax(2); +cp = get(hax,'currentpoint'); +curr_x = cp(1,1); + +xdata = get(ud.hthumb,'xdata'); +xmotion = curr_x - ud.thumb.origPt; +width = ud.thumb.width; +xdata = ud.thumb.xdata; +xdata([2 3]) = xdata([2 3]) + xmotion; + +% Constrain to axis limits, so we don't lose cursor: +xlim = get(hax,'xlim'); +max_xdata = max(xdata); +if max_xdata > xlim(2), + xdata([2:3]) = xlim(2); +elseif max_xdata <= xdata(1), + xdata = ud.thumb.xdata; +end + +% Update the thumbnail: +set(ud.hthumb,'xdata',xdata); + +% Scroll the spectrogram: +set(ud.hax(1),'xlim',xdata(1:2)); + +% update the audio selection to be played +set_audio_selection(hfig, xdata(1:2) * ud.Fs); + +%--------------------------------------------------------------- +function wbup_thumb(hco,eventStruct) + +% set spectrogram and time-slice xlims +hfig = gcbf; +ud = get(hfig,'userdata'); +xdata = get(ud.hthumb,'xdata'); +xlim = [min(xdata) max(xdata)]; + +% Commented out, due to flash: +%set(ud.hax([1 3]),'xlim',xlim); +% +% This is fine: +%set(ud.hax(1),'xlim',xlim); +% +% xxx the following line causes flash in the spect image +% this is the time-slice axis: +% xxx xxx BAD NEWS! +% why does this affect the spectrogram axis? (overlap? clipping?) +%set(ud.hax(3),'xlim',xlim); + +changePtr(gcbf,'hand'); +install_cursorfcns(gcbf,'thumb'); + +% Turn back on image axis visibility, +% which was turned off during wbdown_thumb +% so that it does not flash while panning: +% xxx +% Leave off! +%set(ud.hax(1),'vis','on'); +% +% Turn on crosshair visibility, which was shut off +% during thumbnail panning (wbdown_thumb): +set([ud.hspec_y ud.hspec_x ud.htslice_y],'vis','on'); + +%--------------------------------------------------------------- +function wbup_thumbleft(hco,eventStruct) +% set spectrogram and time-slice xlims +hfig = gcbf; +ud = get(hfig,'userdata'); +xdata = get(ud.hthumb,'xdata'); +xlim = [min(xdata) max(xdata)]; + +% Commented out, due to flash: +%set(ud.hax([1 3]),'xlim',xlim); +% +% This is fine: +set(ud.hax(1),'xlim',xlim); +% +% xxx the following line causes flash in the spect image +% this is the time-slice axis: +% xxx xxx xxx +%set(ud.hax(3),'xlim',xlim); + +changePtr(gcbf,'ldrag'); +install_cursorfcns(gcbf,'thumbleft'); + +% Turn on crosshair visibility, which was shut off +% during thumbnail panning (wbdown_thumb): +set([ud.hspec_y ud.hspec_x],'vis','on'); + +%--------------------------------------------------------------- +function wbup_thumbright(hco,eventStruct) +% set spectrogram and time-slice xlims +hfig = gcbf; +ud = get(hfig,'userdata'); +xdata = get(ud.hthumb,'xdata'); +xlim = [min(xdata) max(xdata)]; + +% Commented out, due to flash: +%set(ud.hax([1 3]),'xlim',xlim); +% +% This is fine: +set(ud.hax(1),'xlim',xlim); +% +% xxx the following line causes flash in the spect image +% this is the time-slice axis: +% xxx xxx +%set(ud.hax(3),'xlim',xlim); + +changePtr(gcbf,'rdrag'); +install_cursorfcns(gcbf,'thumbright'); + +% Turn on crosshair visibility, which was shut off +% during thumbnail panning (wbdown_thumb): +set([ud.hspec_y ud.hspec_x],'vis','on'); + +%--------------------------------------------------------------- +function update_status(hfig,str) +% UPDATE_STATUS Update status text. + +% If str is not a string, skip +% -1 is often used to "skip" the update +if ischar(str), + ud = get(hfig,'userdata'); + set(ud.htext_status,'string',str); +end + +%--------------------------------------------------------------- +function play_sound(hco, eventStruct) +% PLAY_SOUND Play the selected sound segment + +hfig = gcbf; +ud = get(hfig,'userdata'); +y = get(ud.htime_plot,'ydata'); +Fs = ud.Fs; + +xdata=get(ud.hthumb,'xdata'); +xlim=[min(xdata) max(xdata)]; +xidx=floor(xlim*Fs)+1; +if xidx(1)<1, xidx(1)=1; end +if xidx(2)>length(y), xidx(2)=length(y); end + +% Normalize sound and play: +mx=max(abs(y)); +try + wavplay(y(xidx(1):xidx(2))./mx,Fs,'sync'); +catch + msg = lasterr; + errordlg(msg,'Audio Playback Error','modal'); +end + +%--------------------------------------------------------------- +% called by audioplayer during playback (if audioplayer enabled) +function update_audio_position(hco, eventStruct) +if hco.isplaying, % only do this if playback is in progress + currentPosition = get(hco, 'CurrentSample') / get(hco, 'SampleRate'); + set_crosshairs(get(hco, 'UserData'), currentPosition); +end + +%--------------------------------------------------------------- +% utility to easily set playback boundaries +function set_audio_selection(hfig, selectionPair) +%%%%%%%%%%%%%%%%%%%%%%%%%% +% inserted by S.Bleeck +global tmin; +global tmax; +%%%%%%%%%%%%%%%%%%%%%%%%%% +if ~ isempty(getappdata(hfig, 'audioSelection')), % only do this if audioplayer enabled + selection.inPoint = selectionPair(1); + if selection.inPoint < 1, selection.inPoint = 1; end + selection.outPoint = selectionPair(2); + setappdata(hfig, 'audioSelection', selection); + %%%%%%%%%%%%%%%%%%%%%%%%%% + % inserted by S.Bleeck + % set the global times, so that we can pick them up + tmin=selection.inPoint; + tmax=selection.outPoint; + %%%%%%%%%%%%%%%%%%%%%%%%%% +end + +%--------------------------------------------------------------- +% used to set the "put back position" of the vertical crosshair +function start_function(hobj, eventStruct) +hfig = get(hobj, 'UserData'); +ud = get(hfig,'userdata'); +set(hobj, 'StopFcn', {@stop_function, ud.crosshair.xctr}); + +%--------------------------------------------------------------- +% when playback has completed, puts back the vertical crosshair +% to where it was when playback was initiated +function stop_function(hobj, eventStruct, where) +while isplaying(hobj), pause(0); end % let playback complete +if get(hobj, 'CurrentSample') == 1, % if paused, don't put it back + set_crosshairs(get(hobj, 'UserData'), where); +end + +%--------------------------------------------------------------- +function set_cmap_limits(hfig, new_dr) +% Set new colormap limits + +ud = get(hfig,'userdata'); +hax_spec = ud.hax(1); +hax_cbar = ud.hax(5); +himage_cbar = ud.himage_cbar; + +% Set new dynamic range limits into spectrogram image +set(hax_spec,'clim',new_dr); + +% colorbar is 1:256 +% actual spectrogram dynamic range is orig_dr +% new spectrogram dynamic range is new_dr +orig_dr = get(himage_cbar,'ydata'); +diff_dr = new_dr - orig_dr; +cmapIndices_per_dB = 256./diff(orig_dr); % a constant +diff_clim = diff_dr .* cmapIndices_per_dB; +cbar_clim = [1 256] + diff_clim; +set(himage_cbar,'cdatamapping','scaled'); % do during creation +set(hax_cbar,'clim',cbar_clim); + +%--------------------------------------------------------------- +function reset_cmap_limits(hco,eventStruct) +% Reset colormap limits to dynamic range of spectrogram data + +hfig = gcbf; +ud = get(hfig,'userdata'); +orig_dr = get(ud.himage_cbar,'ydata'); +set_cmap_limits(hfig, orig_dr); + +%--------------------------------------------------------------- +function manual_cmap_limits(hco,eventStruct,hfig) +% manual_cmap_limits Manual change to colormap dynamic range limits + +if nargin<3, + hfig = gcbf; +end +ud = get(hfig,'userdata'); +hax_spec = ud.hax(1); + +% Prompt for changes to cmap limits: +clim = get(hax_spec,'clim'); +% 'dB value of first color in colormap:' +% 'dB value of last color in colormap:' +prompt={'Value of top color in colormap (dB):', ... + 'Value of bottom color in colormap (dB):'}; +def = {num2str(clim(2)), num2str(clim(1))}; +dlgTitle='Adjust dynamic range of colormap'; +lineNo=1; +strs=inputdlg(prompt,dlgTitle,lineNo,def); +if isempty(strs), + return +end +new_dr = [str2num(strs{2}) str2num(strs{1})]; + +set_cmap_limits(hfig,new_dr); + +%--------------------------------------------------------------- +function wbmotion_cmap(hco,eventStruct) +% WBMOTION_CMAP Graphical change to colormap dynamic range limits + +hfig = gcbf; +ud = get(hfig,'userdata'); +hax_spec = ud.hax(1); +hax_cbar = ud.hax(5); + +% Determine cursor starting and current points ASAP: +cp = get(hax_cbar,'CurrentPoint'); +newPt = cp(1,2); % y-coord only +dy = newPt - ud.cbar.origPt; + +% if SelectionType was normal, +% update top or bottom of colorbar, only, +% depending on whether user started drag +% in the top or bottom of bar, respectively. +% if SelectionType was extend, +% update both top AND bottom of bar simultaneously, +% translating colormap region. +if strcmp(ud.cbar.SelectionType,'extend'), + change_dr = [dy dy]; +else + if ud.cbar.StartInTop, + change_dr = [0 dy]; + else + change_dr = [dy 0]; + end +end +new_dr = ud.cbar.starting_dr + change_dr; +if diff(new_dr)<=0, + new_dr = ud.cbar.starting_dr; +end + +% Colorbar range is 1 to 256. +% Actual spectrogram dynamic range is orig_dr +% New spectrogram dynamic range is new_dr +orig_dr = get(ud.himage_cbar,'ydata'); % a constant +cmapIndices_per_dB = 256./diff(orig_dr); % a constant +diff_dr = new_dr - orig_dr; +diff_clim = diff_dr .* cmapIndices_per_dB; +cbar_clim = [1 256] + diff_clim; + +if diff(cbar_clim)>0, + % Protect against poor choice of values + set(hax_cbar,'clim',cbar_clim,'userdata',new_dr); +end + +% We defer setting the new dynamic range limits +% into the spectrogram image axis, as it will create +% too much flash. Instead, on button-up, the new +% limit is set. See wbup_cmap() for details. + +% Set new dynamic range limits into spectrogram image +% Note: userdata could be empty if this is the first entry... +% xxx +%set(ud.hax(1),'clim',new_dr); +set(hax_spec,'clim',new_dr); + +%--------------------------------------------------------------- +function isChange = changePtr(hfig, newPtr) + +% Get current pointer name: +ud = get(hfig,'userdata'); + +% Is this a change in pointer type? +isChange = ~strcmp(ud.currPtr,newPtr); +if isChange, + setptr(hfig, newPtr); + ud.currPtr = newPtr; + set(hfig,'userdata',ud); +end + +%--------------------------------------------------------------- +function wbmotion_general(hco,eventStruct,hfig) +% General button motion +% +% Determines if cursor is over a crosshair +% If so, changes pointer and installs crosshair buttondowns +% If not, changes back to normal cursor and general buttondowns +% as necessary. + +if nargin<3, + hfig = gcbf; +end +[isOverHV, isSegmentAxis, isCmapAxis,isTopHalfCmap, isThumb] = ... + over_crosshair(hfig); + +if ~any(isOverHV), + % Not hovering over a crosshair + + if isSegmentAxis, + % Over an axis in which we can get a delta-time measurement + if changePtr(hfig,'crosshair'), + install_cursorfcns(hfig,'segment'); + end + + elseif isCmapAxis, + % Over the colormap axes + % Install the up/down pointer: + if isTopHalfCmap, + if changePtr(hfig,'udrag'), + update_status(hfig,'Adjust upper dynamic range (shift to translate)'); + install_cursorfcns(hfig,'cmap'); + end + else + if changePtr(hfig,'ddrag'), + update_status(hfig,'Adjust lower dynamic range (shift to translate)'); + install_cursorfcns(hfig,'cmap'); + end + end + + elseif any(isThumb), + % Over thumbnail - isThumb is a 3-element vector, [left center right], + % indicating whether cursor is over left edge, right edge, or is over + % the general thumbnail patch itself. + + % Install appropriate pointer: + if isThumb(1), + % Over left edge + if changePtr(hfig,'ldrag'), + install_cursorfcns(hfig,'thumbleft'); + end + elseif isThumb(3), + % Over right edge + if changePtr(hfig,'rdrag'), + install_cursorfcns(hfig,'thumbright'); + end + else + % Over general patch region + if changePtr(hfig,'hand'), + install_cursorfcns(hfig,'thumb'); + end + end + + else + % Not over a special axes: + if changePtr(hfig,'arrow'), + install_cursorfcns(hfig,'general'); + end + end + +else + % Pointer is over a crosshair (vert or horiz or both) + if all(isOverHV), + % Over both horiz and vert (near crosshair center): + if changePtr(hfig,'fleur'), + install_cursorfcns(hfig,'hvcross'); + end + elseif isOverHV(1), + % Over H crosshair + if changePtr(hfig,'uddrag'), + install_cursorfcns(hfig,'hcross'); + end + else + % Over V crosshair + if changePtr(hfig,'lrdrag'), + install_cursorfcns(hfig,'vcross'); + end + end +end + +%--------------------------------------------------------------- +function [y,isSegmentAxis,isCmapAxis,... + isTopHalfCmap, isThumb] = over_crosshair(hfig) +% Is the cursor hovering over the crosshairs? +% There are two crosshairs, one an H-crosshair, the other +% a V-crosshair. The H and V crosshairs span several +% different axes. +% +% Function returns a 2-element vector, indicating whether +% the cursor is currently over the H- and/or V-crosshairs. +% y = [isOverH isOverV] + +y = [0 0]; +isSegmentAxis = 0; +isCmapAxis = 0; +isTopHalfCmap = 0; +isThumb = [0 0 0]; % left, middle, right regions + +% First, are we over any axes? +hax = overAxes(hfig); +if isempty(hax), return; end % not over an axis + +% Get current point in axis: +cp = get(hax,'currentpoint'); +ud = get(hfig,'userdata'); + +% Axis which are "segmentable" have a vertical crosshair +% e.g., spectrogram and time axes only +isCmapAxis = (hax==ud.hax(5)); +isSegmentAxis = (hax==ud.hax(1)); + +% Determine if any horiz or vert crosshairs are +% in this axis ... store as [anyHoriz anyVert]: +hasHVCrossHairs = [any(hax==ud.hax([1 4])) ... + any(hax==ud.hax(1:3))]; + +% Is cursor in colormap axis? +if (isCmapAxis), + % is cursor in top half of colormap axis? + orig_dr = get(ud.hax(1),'clim'); + isTopHalfCmap = (cp(1,2) >= sum(orig_dr)/2); +end + +if any(hasHVCrossHairs), + % Get cursor & crosshair positions: + crosshair_pos = [ud.crosshair.xctr ud.crosshair.yctr]; + cursor_delta = abs(crosshair_pos - cp(1,1:2)); + axis_dx = diff(get(hax,'xlim')); + axis_dy = diff(get(hax,'ylim')); + axis_delta = [axis_dx axis_dy]; + + % Is cursor within 1 percent of crosshair centers? + % Limit test uses the reciprocal of the percentage tolerance + % 1-percent -> 1 / 0.01 = 100 + % 1.5-percent -> 1 / 0.015 ~= 67 + % 2-percent -> 1 / 0.02 = 50 + % + % Finally, allow a true result only if the axis + % has a crosshair of the corresponding type + % + y = fliplr(cursor_delta * 67 < axis_delta) & hasHVCrossHairs; +end + +% Are we over the thumbnail patch? +% Check if we're over the time axis: +if (hax == ud.hax(2)), + % Get thumb patch limits: + xdata=get(ud.hthumb,'xdata'); + xlim=[min(xdata) max(xdata)]; + + % Is cursor over general patch area? + thumb_delta = xlim - cp(1,1); + isThumb(2) = thumb_delta(1)<=0 & thumb_delta(2)>=0; + + % Is cursor over left or right thumbnail edge? + % Use same tolerance as crosshair test: + axis_dx = diff(get(hax,'xlim')); + isThumb([1 3]) = (abs(thumb_delta) * 67 < axis_dx); +end + +%--------------------------------------------------------------- +function h=overAxes(hfig) +% overAxes Determine if pointer is currently over an +% axis of the figure; the axis list comes from the +% figure UserData (ud.hax). + +p = get(0,'PointerLocation'); +figPos = get(hfig,'Position'); +if ~isempty(figPos), + x = (p(1)-figPos(1))/figPos(3); + y = (p(2)-figPos(2))/figPos(4); + ud = get(hfig,'userdata'); + for h = ud.hax, + r = get(h,'Position'); + if (x > r(1)) & (x < r(1)+r(3)) & ... + (y > r(2)) & (y < r(2)+r(4)), + return; + end + end +end +h = []; +return + +%--------------------------------------------------------------- +function y=isLeftClick(hfig) + +% Keywords for key/button combinations: +% Left Right +% none: normal alt +% Shift: extend alt +% Ctrl: alt alt +% Double: open alt + +y=strcmp(get(hfig,'SelectionType'),'normal'); + +%--------------------------------------------------------------- +function wbdown_hcross(hco,eventStruct) +% window button down in h-crosshair mode +if ~isLeftClick(gcbf), return; end +install_cursorfcns(gcbf,'hcross_buttondown'); +wbmotion_cross([],[],'h'); + +%--------------------------------------------------------------- +function wbdown_vcross(hco,eventStruct) +% window button down in v-crosshair mode +if ~isLeftClick(gcbf), return; end +install_cursorfcns(gcbf,'vcross_buttondown'); +wbmotion_cross([],[],'v'); + +%--------------------------------------------------------------- +function wbdown_hvcross(hco,eventStruct) +% window button down in hv-crosshair mode +if ~isLeftClick(gcbf), return; end +install_cursorfcns(gcbf,'hvcross_buttondown'); +wbmotion_cross([],[],'hv'); + +%--------------------------------------------------------------- +function wbdown_segment(hco,eventStruct) +% window button down in segmentation mode +if ~isLeftClick(gcbf), return; end +install_cursorfcns(gcbf,'segment_buttondown'); +wbmotion_segment([],[],gcbf); + +%--------------------------------------------------------------- +function wbdown_thumb(hco,eventStruct) +% window button down in thumbnail mode +if ~isLeftClick(gcbf), return; end + +% cache y-coord of pointer +ud = get(gcbf,'userdata'); +hax_time = ud.hax(2); +cp = get(hax_time,'currentpoint'); +xdata = get(ud.hthumb,'xdata'); +width = max(xdata)-min(xdata); + +ud.thumb.origPt = cp(1,1); % x-coord only +ud.thumb.width = width; +ud.thumb.xdata = xdata; +set(gcbf,'userdata',ud); + +changePtr(gcbf,'closedhand'); +install_cursorfcns(gcbf,'thumb_buttondown'); + + +% Turn off image axis visibility, +% so that it does not flash while panning: +% +% xxx off permanently now: +%set(ud.hax(1),'vis','off'); +% +% Turn off crosshair visibility: +set([ud.hspec_y ud.hspec_x ud.htslice_y],'vis','off'); + +%--------------------------------------------------------------- +function wbdown_thumbleft(hco,eventStruct) + +% window button down in LEFT thumbnail mode +if ~isLeftClick(gcbf), return; end + +% cache y-coord of pointer +ud = get(gcbf,'userdata'); +hax_time = ud.hax(2); +cp = get(hax_time,'currentpoint'); +xdata = get(ud.hthumb,'xdata'); +width = max(xdata)-min(xdata); + +ud.thumb.origPt = cp(1,1); % x-coord only +ud.thumb.width = width; +ud.thumb.xdata = xdata; +set(gcbf,'userdata',ud); + +install_cursorfcns(gcbf,'thumbleft_buttondown'); + +% Turn off crosshair visibility: +set([ud.hspec_y ud.hspec_x],'vis','off'); + +%--------------------------------------------------------------- +function wbdown_thumbright(hco,eventStruct) + +% window button down in LEFT thumbnail mode +if ~isLeftClick(gcbf), return; end + +% cache y-coord of pointer +ud = get(gcbf,'userdata'); +hax_time = ud.hax(2); +cp = get(hax_time,'currentpoint'); +xdata = get(ud.hthumb,'xdata'); +width = max(xdata)-min(xdata); + +ud.thumb.origPt = cp(1,1); % x-coord only +ud.thumb.width = width; +ud.thumb.xdata = xdata; +set(gcbf,'userdata',ud); + +install_cursorfcns(gcbf,'thumbright_buttondown'); + +% Turn off crosshair visibility: +set([ud.hspec_y ud.hspec_x],'vis','off'); + +%---------------------------------------------------- +function wbdown_cmap(hco,eventStruct) +% window button down in colormap mode + +hfig = gcbf; + +% Only allow left (normal) or shift+left (extend) +st = get(hfig,'SelectionType'); +i=strmatch(st,{'normal','extend','open'}); +if isempty(i), return; end + +if i==3, + % open dynamic range menu + manual_cmap_limits([],[],hfig); + return +elseif i==2, + % Shift+left button = translate, + % show up/down cursor during drag + % NOTE: cannot update cursor when shift is pressed + % but no mouse button is pressed (no event!) + changePtr(hfig,'uddrag'); % xxx +end + +ud = get(hfig,'userdata'); + +% cache y-coord of pointer +hax_cbar = ud.hax(5); +cp = get(hax_cbar,'currentpoint'); +ud.cbar.origPt = cp(1,2); % y-coord only +ud.cbar.SelectionType = st; % normal or extend + +% The current clim is in the spectrogram image +% We want to know the midpoint of this +orig_dr = get(ud.hax(1),'clim'); +ud.cbar.midPt = sum(orig_dr)/2; + +% Determine if pointer went down in top or bottom +% half of colorbar: +ud.cbar.StartInTop = (ud.cbar.origPt >= ud.cbar.midPt); + +% Cache original dynamic range: +hax_spec = ud.hax(1); +ud.cbar.starting_dr = get(hax_spec,'clim'); +set(hfig,'userdata',ud); + +install_cursorfcns(hfig,'cmap_buttondown'); + +% Set initial clim into userdata in case motion +% callback not performed (motion updates userdata). +% wbup_cmap reads the userdata +% +% Turn off visibility during drag to prevent flash +set(hax_cbar, ... + 'userdata',ud.cbar.starting_dr, ... + 'vis','off'); + +%--------------------------------------------------------------- +function wbup_hcross(hco,eventStruct) +% window button up in h-crosshair mode +install_cursorfcns(gcbf,'hcross'); +update_cmap_ptr(gcbf); + +%--------------------------------------------------------------- +function wbup_vcross(hco,eventStruct) +% window button up in v-crosshair mode +install_cursorfcns(gcbf,'vcross'); +update_cmap_ptr(gcbf); + +%--------------------------------------------------------------- +function wbup_hvcross(hco,eventStruct) +% window button up in hv-crosshair mode +install_cursorfcns(gcbf,'hvcross'); +update_cmap_ptr(gcbf); + +%--------------------------------------------------------------- +function wbup_segment(hco,eventStruct) +% window button up in segmentation mode +install_cursorfcns(gcbf,'segment'); + +%--------------------------------------------------------------- +function wbup_cmap(hco,eventStruct) +% window button up in colormap mode +install_cursorfcns(gcbf,'cmap'); + +% Set new dynamic range limits into spectrogram image +% Note: userdata could be empty if this is the first entry... +ud = get(gcbf,'userdata'); +hax_cbar=ud.hax(5); +set(ud.hax(1),'clim',get(hax_cbar,'userdata')); +set(hax_cbar,'vis','on'); % re-enable axis vis + +% Set new status msg, since it doesn't update +% in the install_cursorfcns fcn for cmap callbacks +% Do this by calling the general mouse-motion fcn: +wbmotion_general([],[]); + +%--------------------------------------------------------------- +function update_cmap_ptr(hfig) +% Update colormap pointer: + +ud = get(hfig,'userdata'); +v = get_spec_val(hfig); % value in dB +dy_tri = ud.crosshair.cbar.dy_tri; +set(ud.hcmap_arrow,'ydata', [v+dy_tri v-dy_tri v]); + + +%--------------------------------------------------------------- +function [i,j] = get_adjusted_crosshair_idx(hfig) +% Find image matrix coordinate pair (j,i) under crosshair. +% Adjust crosshair for "half-pixel offset" implicit in image display + +ud=get(hfig,'userdata'); +xc=ud.crosshair.xctr; +yc=ud.crosshair.yctr; +himage=ud.himage; +im=get(himage,'cdata'); + +% Get image pixel size: +xdata=get(himage,'xdata'); +if length(xdata)>1, dx = xdata(2)-xdata(1); else dx=0; end + +ydata=get(himage,'ydata'); +if length(ydata)>1, dy = ydata(2)-ydata(1); else dy=0; end + +% Remove half a pixel size from apparent cursor position: +xc=xc-dx/2; +yc=yc-dy/2; + +% Find pixel coordinate under the crosshair: +i=find(xc>=xdata); +if isempty(i), i=1; +else i=i(end)+1; +end +j=find(yc>=ydata); +if isempty(j), j=1; +else j=j(end)+1; +end +sz=size(im); +if i>sz(2), i=sz(2); end +if j>sz(1), j=sz(1); end + +%--------------------------------------------------------------- +function v = get_spec_val(hfig) + +ud = get(hfig,'userdata'); +im = get(ud.himage,'cdata'); +[i,j] = get_adjusted_crosshair_idx(hfig); +v = double(im(j,i)); % Get pixel value in double-precision + +%--------------------------------------------------------------- +function v = get_spec_freq(hfig) + +ud = get(hfig,'userdata'); +im = get(ud.himage,'cdata'); +[i,j] = get_adjusted_crosshair_idx(hfig); +v = im(:,i); % Get pixel row in uint8 + +%--------------------------------------------------------------- +function v = get_spec_tslice(hfig) + +ud = get(hfig,'userdata'); +im = get(ud.himage,'cdata'); +[i,j] = get_adjusted_crosshair_idx(hfig); +v = im(j,:); % Get pixel column + +%--------------------------------------------------------------- +function update_time_readout(hfig,diffTime) + +% xxx + +ud = get(hfig,'userdata'); +if nargin<2, + t=ud.crosshair.xctr; + prefix=''; +else + t=diffTime - ud.crosshair.xctr; + prefix='\Deltat '; +end + +% Update time readout +[y,e,u] = engunits(t, 'latex','time'); +%str=[prefix num2str(y) ' ' u]; +str=[prefix sprintf('%.4f',y) ' ' u]; +set(ud.htext_time,'string',str); + +%--------------------------------------------------------------- +function update_freq_readout(hfig,diffFreq) + +ud=get(hfig,'userdata'); +if nargin<2, + f=ud.crosshair.yctr; + prefix=''; +else + f=diffFreq - ud.crosshair.yctr; + prefix='\Deltaf '; +end + +% Update freq readout +[y,e,u] = engunits(f,'latex'); +%str=[prefix num2str(y) ' ' u 'Hz']; +str=[prefix sprintf('%.4f',y) ' ' u 'Hz']; +set(ud.htext_freq,'string',str); + +%--------------------------------------------------------------- +function update_dB_readout(hfig,diffAmpl) + +ud = get(hfig,'userdata'); +if nargin<2, + a=get_spec_val(hfig); + prefix=''; +else + a=diffAmpl - get_spec_val(hfig); + prefix='\Deltaa='; +end + +% Update mag readout +%str=[prefix num2str(a) ' dB']; +str=[prefix sprintf('%.4f',a) ' dB']; +set(ud.htext_mag,'string',str); + +%--------------------------------------------------------------- +function clear_dB_readout(hfig) + +ud = get(hfig,'userdata'); +set(ud.htext_mag,'string',''); + +%--------------------------------------------------------------- +function wbmotion_cross(hco,eventStruct,sel) +% motion callback during horiz/vert-crosshair selection +% sel='h', 'v', or 'hv' + +% Get current point in axis ASAP: +hfig = gcbf; +hco = gco; +switch get(hco,'type') +case 'axes' + hax=hco; +otherwise + hax=get(hco,'parent'); +end + +cp = get(hax,'currentpoint'); +ud = get(hfig,'userdata'); +x = cp(1,1); +y = cp(1,2); + +switch sel +case 'h' + x=ud.crosshair.xctr; +case 'v' + y=ud.crosshair.yctr; +end + +% Constrain to axis limits, so we don't lose cursor: +if any(sel=='v'), + xlim=get(hax,'xlim'); + if xxlim(2), + x=xlim(2); + end +end + +if any(sel=='h'), + ylim=get(hax,'ylim'); + if yylim(2), + y=ylim(2); + end +end +set_crosshairs(hfig,x,y); + +%--------------------------------------------------------------- +function wbmotion_segment(hco,eventStruct,hfig) +% motion callback during segmentation selection + +% xxx +% Get current point in axis ASAP: +if nargin<3, + hfig = gcbf; +end + +hax=gco; +t=get(hax,'type'); +if ~strcmp(t,'axes'), + hax = get(hax,'parent'); +end +cp = get(hax,'currentpoint'); +ud = get(hfig,'userdata'); +x = cp(1,1); +y = cp(1,2); + +% Constrain to axis limits, so we don't lose cursor: +xlim=get(hax,'xlim'); +if xxlim(2), + x=xlim(2); +end +ylim=get(hax,'ylim'); +if yylim(2), + y=ylim(2); +end + +update_time_readout(hfig,x); +update_freq_readout(hfig,y); +clear_dB_readout(hfig); + +%--------------------------------------------------------------- +function install_cursorfcns(hfig,cursorType) + +switch lower(cursorType) +case 'none' + dn = []; + motion = []; + up = []; + status = ''; + +case 'general' + dn = []; + motion = @wbmotion_general; + up = []; + status = 'Ready'; + +case 'segment' + dn = @wbdown_segment; + motion = @wbmotion_general; + up = []; + status = 'Ready'; + +case 'segment_buttondown' + dn = []; + motion = @wbmotion_segment; + up = @wbup_segment; + status = 'Difference from crosshair'; + +case 'thumb' + % button not pushed, thumbnail highlighted + dn = @wbdown_thumb; + motion = @wbmotion_general; + up = []; + status = 'Pan zoom window'; + +case 'thumb_buttondown' + % button pushed, thumbnail highlighted + dn = []; + motion = @wbmotion_thumb; + up = @wbup_thumb; + status = 'Release to set zoom window'; + +case 'thumbleft' + % button not pushed, left thumbnail edge highlighted + dn = @wbdown_thumbleft; + motion = @wbmotion_general; + up = []; + status = 'Adjust zoom window left edge'; + +case 'thumbleft_buttondown' + % button pushed, thumbnail highlighted + dn = []; + motion = @wbmotion_thumbleft; + up = @wbup_thumbleft; + status = 'Release to set zoom window'; + +case 'thumbright' + % button not pushed, right thumbnail edge highlighted + dn = @wbdown_thumbright; + motion = @wbmotion_general; + up = []; + status = 'Adjust zoom window right edge'; + +case 'thumbright_buttondown' + % button pushed, right thumbnail edge highlighted + dn = []; + motion = @wbmotion_thumbright; + up = @wbup_thumbright; + status = 'Release to set zoom window'; + +case 'hcross' + % button not pushed, h-crosshair highlighted + dn = @wbdown_hcross; + motion = @wbmotion_general; + up = []; + status = 'Move horizontal cursor'; + +case 'hcross_buttondown' + % button pushed while over horiz cross-hair + dn = []; + motion = {@wbmotion_cross,'h'}; + up = @wbup_hcross; + status = 'Release to update cursor'; + +case 'vcross' + dn = @wbdown_vcross; + motion = @wbmotion_general; + up = []; + status = 'Move vertical cursor'; + +case 'vcross_buttondown' + dn = []; + motion = {@wbmotion_cross,'v'}; + up = @wbup_vcross; + status = 'Release to update cursor'; + +case 'hvcross' + dn = @wbdown_hvcross; + motion = @wbmotion_general; + up = []; + status = 'Move crosshair cursor'; + +case 'hvcross_buttondown' + dn = []; + motion = {@wbmotion_cross,'hv'}; + up = @wbup_hvcross; + status = 'Release to update cursor'; + +% Change dynamic range of colormap +case 'cmap' + dn = @wbdown_cmap; + motion = @wbmotion_general; + up = []; + % Status is set in wbmotion_general function + % since it depends on which pointer we're using + status = -1; + +case 'cmap_buttondown' + dn = []; + motion = @wbmotion_cmap; + up = @wbup_cmap; + status = 'Release to update colormap'; + +otherwise + error('Unrecognized cursorfcn'); +end + +set(hfig, ... + 'windowbuttondownfcn', dn, ... + 'windowbuttonmotionfcn',motion, ... + 'windowbuttonupfcn', up) + +update_status(hfig,status); + + +%--------------------------------------------------------------- +function resize_fig(hco,eventStruct) +% Callback to resize the figure + +update_axes_with_eng_units(gcbf); + + +%--------------------------------------------------------------- +function update_axes_with_eng_units(hfig) + +% Update the tick marks for axes that are using engineering units +% For example, a resize could have added or removed ticks, and the +% axes would no longer have the proper tick marks +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); +hax_freq = ud.hax(4); + +% Update freq-axis labels for engineering units, etc: +yy=get(hax_freq,'ytick'); +[cs,eu] = convert2engstrs(yy); +set(hax_freq,'yticklabel',cs); +set(get(hax_freq,'ylabel'),'string',['Frequency, ' eu 'Hz']); + +% Update time-axis labels for engineering units, etc: +yy=get(hax_time,'xtick'); +[cs,eu] = convert2engstrs(yy,'time'); +set(hax_time,'xticklabel',cs); +set(get(hax_time,'xlabel'),'string',['Time, ' eu]); + + +%--------------------------------------------------------------- +function update_gui(hco, eventStruct, hfig) + +if nargin<3, hfig=gcbf; end + +ptr.ptr = get(hfig,'pointer'); +ptr.shape = get(hfig,'pointershapecdata'); +ptr.hot = get(hfig,'pointershapehotspot'); +setptr(hfig,'watch'); % set user's expectations... + +ud = get(hfig,'userdata'); +hax_spec = ud.hax(1); +hax_time = ud.hax(2); +hax_tslice = ud.hax(3); +hax_freq = ud.hax(4); +hax_cbar = ud.hax(5); +hax_cbar_ind = ud.hax(6); + +% Get spectrogram parameters: +Nwin = str2double(get(ud.spect.nwin,'string')); +Nlap = str2double(get(ud.spect.nlap,'string')); +Nfft = str2double(get(ud.spect.nfft,'string')); + +% Recompute spectrogram +y = ud.y; +Fs = ud.Fs; +window = 'blackman'; +w = feval(window,Nwin,'periodic'); +try + [b,f,t]=specgram(y,Nfft,Fs,w,Nlap); + [Pxx, W] = pwelch(y,w,Nlap,Nfft,Fs); +catch + % Error occurred + % Put up modal error display, then + % get spectrogram params from cache (userdata) + msg = lasterr; + errordlg(msg,'Specgram Demo Error','modal'); + + % Reset Nwin/Nlap/Nfft: + Nwin = get(ud.spect.nwin,'userdata'); + Nlap = get(ud.spect.nlap,'userdata'); + Nfft = get(ud.spect.nfft,'userdata'); + set(ud.spect.nwin,'string',num2str(Nwin)); + set(ud.spect.nlap,'string',num2str(Nlap)); + set(ud.spect.nfft,'string',num2str(Nfft)); + return +end + +% Update new values into "old" cache (userdata field) +% Also, update strings themselves, in case spaces have +% been removed, etc: +set(ud.spect.nwin,'string',num2str(Nwin),'userdata',Nwin); +set(ud.spect.nlap,'string',num2str(Nlap),'userdata',Nlap); +set(ud.spect.nfft,'string',num2str(Nfft),'userdata',Nfft); + +ud.f = f; +ud.t = t; + +% Pxx is the distribution of power per unit frequency. +ud.Pxx = Pxx; + +% W is the vector of normalized frequencies at which the PSD is estimated. +ud.w = W; + +% Carefully execute log10: +wstate=warning; +warning off; +b = 20*log10(abs(b)); +warning(wstate); + +% Handle -inf's: +i_inf = find(isinf(b(:))); +if ~isempty(i_inf), + % Set all -inf points to next-lowest value: + b(i_inf)=inf; + min_val=min(b(:)); + b(i_inf)=min_val; +end + +blim = [min(b(:)) max(b(:))]; +spec_xlim = [0 max(t)]; +spec_ylim = [0 max(f)]; + +% Update spectrogram +% XXX UINT8 change: +set(ud.himage,'cdata',b, 'xdata',t, 'ydata',f); +%set(ud.himage,'cdata',uint8( (b-blim(1))./(blim(2)-blim(1))*255 + 1 ), 'xdata',t, 'ydata',f); +set(hax_spec,'xlim',spec_xlim, 'ylim', spec_ylim); + +% Update colorbar +%XXX UINT8 change: +set(ud.himage_cbar, 'ydata',blim, 'cdata', (1:256)'); +%set(ud.himage_cbar, 'ydata',[1 256], 'cdata', (1:256)'); +set(hax_cbar,'ylim',blim); +set(hax_cbar_ind, 'ylim',blim); + +% Update time slice +rows=size(b,1); +bi=floor(rows/2); if bi<1, bi=1; end +set(ud.htslice_line,'xdata',t, 'ydata',b(bi,:)); +set(hax_tslice, 'xlim',spec_xlim, 'ylim',blim); +% Use 2 ticks only +new_ticks = return2ticks(hax_tslice); +set(hax_tslice,'Ytick',new_ticks); + +% frequency slice +cols=size(b,2); +bj=floor(cols/2); if bj<1, bj=1; end +set(ud.hfreq_line, 'xdata',b(:,bj),'ydata',f); +set(hax_freq, 'ylim',spec_ylim,'xlim',blim); + +% Use 2 ticks only +new_xticks = return2ticks(ud.hax(4)); +set(ud.hax(4),'Xtick',new_xticks); + + +% full time trace +ylen=length(y); +half_nfft = ceil(Nfft/2); +t1=(0 : length(y)-half_nfft)/Fs; +set(ud.htime_plot,'xdata',t1,'ydata',y(half_nfft:end)); +set(hax_time, 'xlim',spec_xlim); + +update_axes_with_eng_units(hfig); + +% setup thumbnail patch +axylim = get(hax_time,'ylim'); +ymax = axylim(2); +ymin = axylim(1); +tmax = max(t); +tmin = min(t); +set(ud.hthumb, ... + 'xdata',[tmin tmax tmax tmin tmin], ... + 'ydata',[ymin ymin ymax ymax ymin]); + +% Reset crosshair positions +crosshair = ud.crosshair; +crosshair.xctr = mean(spec_xlim); +crosshair.yctr = mean(spec_ylim); +time_ylim = get(hax_time,'ylim'); +freq_xlim = get(hax_freq,'xlim'); +tslice_ylim = get(hax_tslice,'ylim'); + +% Crosshairs: +set(ud.hspec_x, ... + 'xdata',spec_xlim, ... + 'ydata',[crosshair.yctr crosshair.yctr]); +set(ud.hspec_y, ... + 'xdata',[crosshair.xctr crosshair.xctr], ... + 'ydata',spec_ylim); +set(ud.htime_y, ... + 'xdata',[crosshair.xctr crosshair.xctr], ... + 'ydata',time_ylim); +set(ud.htslice_y, ... + 'xdata',[crosshair.xctr crosshair.xctr], ... + 'ydata',tslice_ylim); +set(ud.hfreq_x, ... + 'xdata',freq_xlim, ... + 'ydata',[crosshair.yctr crosshair.yctr]); + +% Colormap indicator triangle: +dy_tri=.025*diff(blim); +yp=b(bi,bj); +ytri=[yp+dy_tri yp-dy_tri yp ]; +set(ud.hcmap_arrow, ... + 'erase','xor', ... + 'linestyle','none', ... + 'xdata',[0 0 1], ... + 'ydata',ytri); +crosshair.cbar.dy_tri = dy_tri; + +% Update user data: +ud.crosshair = crosshair; +set(hfig,'userdata',ud); + +% Text readouts: +update_time_readout(hfig); +update_freq_readout(hfig); +update_dB_readout(hfig); +%xxx +%str=[num2str(b(bi,bj)) ' dB']; +%set(ud.htext_mag,'string',str); + +% Re-establish pointer cursor, etc: +set(hfig,'pointer',ptr.ptr, ... + 'pointershapecdata',ptr.shape, ... + 'pointershapehotspot',ptr.hot); + +%--------------------------------------------------------------- +function printdlg_cb(hco,eventStruct) +printdlg(gcbf); + +%--------------------------------------------------------------- +function printpreview_cb(hco,eventStruct) +printpreview(gcbf); + +%--------------------------------------------------------------- +function close_cb(hco,eventStruct) +close(gcbf); + +%--------------------------------------------------------------- +function hfig=create_gui(y,Fs,tmin,tmax) +%CREATE_GUI Render the figure and all uicontrols. + +% freq, specgram and time +hfig = figure('numbertitle','off', ... + 'name','Spectrogram Demo', ... + 'menubar','none', ... + 'toolbar','none', ... + 'resizefcn',@resize_fig, ... + 'doublebuffer','off', ... + 'backingstore','off', ... + 'integerhandle','off', ... + 'vis','off', ... + 'pos',[50 15 550 450],... + 'PaperPositionMode','auto'); + +% Try to create audioplayer object for audio playback and tracking cursor +audioplayer_enabled = true; +try + player = audioplayer(y / abs(max(y)), Fs); %make a player for the normalized signal + set(player, 'UserData', hfig, 'TimerPeriod', 0.05, 'TimerFcn', @update_audio_position, ... + 'StartFcn', @start_function); + % the toolbar callback fcns look for these named bits of appdata + setappdata(hfig, 'theAudioPlayer', player); + setappdata(hfig, 'theAudioRecorder', []); + selection.inPoint = tmin*Fs; + selection.outPoint = tmax*Fs; + setappdata(hfig, 'audioSelection', selection); % selection starts as "full" +catch + audioplayer_enabled = false; +end + +% Load toolbar icons +icon_file = 'specgramdemoicons.mat'; +icon = load(icon_file); + +% Create toolbar: +htoolbar = uitoolbar(hfig); + +% Print: +uipushtool('parent',htoolbar, ... + 'tooltip','Print', ... + 'clickedcallback',@printdlg_cb, ... + 'cdata',icon.print); +% Print preview: +uipushtool('parent',htoolbar, ... + 'tooltip','Print Preview', ... + 'clickedcallback',@printpreview_cb, ... + 'cdata',icon.printpreview); + +if audioplayer_enabled, + % add Play/Pause/Stop audio toolbar buttons + [htoolbar, audiobuttons] = render_basicaudiotoolbar(htoolbar); + + % set play button to "active" version, because changing the button image + % causes the whole darn window to repaint! Ick. + play_button = audiobuttons(1); + audioIcons = getappdata(htoolbar, 'audioButtonIcons'); + set(play_button, 'cdata', audioIcons.play_on); +else + % Play icon + uipushtool('parent',htoolbar, ... + 'tooltip','Play', ... + 'clickedcallback',@play_sound, ... + 'cdata',icon.playsound); +end + +% Zoom in, out, full +uipushtool('parent',htoolbar, ... + 'separator','on', ... + 'tooltip','Zoom 100%', ... + 'clickedcallback', @zoom_full, ... + 'cdata',icon.fullview); +uipushtool('parent',htoolbar, ... + 'tooltip','Zoom In', ... + 'clickedcallback',@zoom_in, ... + 'cdata',icon.zoominx); +uipushtool('parent',htoolbar, ... + 'tooltip','Zoom Out', ... + 'clickedcallback',@zoom_out, ... + 'cdata',icon.zoomoutx); +% Center crosshairs +uipushtool('parent',htoolbar, ... + 'tooltip','Center Crosshair', ... + 'clickedcallback',@center_cross, ... + 'separator','on', ... + 'cdata',icon.center_crosshair); + +% What's this? +uipushtool('parent',htoolbar, ... + 'separator','on', ... + 'tooltip','What''s This?', ... + 'clickedcallback',@HelpWhatsThisCB, ... + 'cdata',icon.whatsthis); + +% specgram +% inputs: t, f, b +hax_spec = axes('pos',[.25 .275 .625 .525]); +himage=image; axis xy; colormap(jet) +set(himage,'erase','xor','cdatamapping','scaled'); +set(hax_spec, ... + 'box','on', ... + 'draw','fast', ... + 'xticklabel',''); +% xxx +% Shut off image axis visibility +set(hax_spec, 'vis','off'); + +% time slice +hax_tslice = axes('pos',[.25 .825 .625 .1]); +htslice_line=line('color','b'); +set(htslice_line,'erase','xor'); % xxx +set(hax_tslice, ... + 'box','on', ... + 'fontsize',8, ... + 'draw','fast', ... + 'xticklabel','', ... + 'xtick',[], ... + 'yaxisloc','right'); +ylabel('dB'); +sz=size(y); + +% Title of time slice plot +[ey,ee,eu]=engunits(Fs,'latex'); +str=['Data=[' num2str(sz(1)) 'x' num2str(sz(2)) '], Fs=' ... + num2str(ey) ' ' eu 'Hz']; +title(str); + +% colorbar +cmapLen = 256; +hax_cbar = axes('pos',[.91 .275 .03 .525]); +himage_cbar = image([0 1],[0 1],(1:cmapLen)'); +set(himage_cbar,'cdatamapping','scaled','erase','none'); +set(hax_cbar, ... + 'draw','fast', ... + 'fontsize',8, ... + 'box','on', ... + 'xticklabel','', ... + 'Ydir','normal', 'YAxisLocation','right', 'xtick',[]); + +% frequency slice +hax_freq = axes('pos',[.1 .275 .125 .525]); +hfreq_line=line('color','b'); +set(hfreq_line,'erase','xor'); +set(hax_freq, ... + 'fontsize',8, ... + 'box','on',... + 'draw','fast', ... + 'xdir','rev', ... + 'xaxisloc','top'); +ylabel('Frequency, Hz'); +xlabel('dB'); + +% colorbar indicator +hax_cbar_ind = axes('pos',[.885+.01 .275 .015 .525]); +set(hax_cbar_ind,'vis','off','xlim',[0 1],'ylim',[0 1], ... + 'draw','fast', ... + 'fontsize',8, ... + 'yaxisloc','right'); + +% full time trace +% inputs: y, Fs +hax_time = axes('pos',[.25 .15 .625 .1]); +htime_plot = line('color','b'); +set(hax_time, ... + 'box','on',... + 'fontsize',8, ... + 'draw','fast', ... + 'yaxisloc','right'); +xlabel('Time, secs'); ylabel('Ampl'); + +% thumbnail patch +%bgclr = get(0,'defaultuicontrolbackgr'); +%bgclr = get(0,'defaultfigurecolor'); +bgclr = 'b'; +hthumb = patch([0 0 1 1 0], [0 1 1 0 0], bgclr, ... + 'edgecolor','k', ... + 'erase','xor'); + +% Crosshairs: +hspec_x=line('parent',hax_spec, ... + 'erase','xor'); +hspec_y=line('parent',hax_spec, ... + 'erase','xor'); +htime_y=line('parent',hax_time, ... + 'linewidth',2, ... + 'erase','xor'); +htslice_y=line('parent',hax_tslice, ... + 'erase','xor'); +hfreq_x=line('parent',hax_freq, ... + 'erase','xor'); + +% Colormap indicator triangle: +hcmap_arrow=patch('parent',hax_cbar_ind, ... + 'xdata',[0 0 1], ... + 'ydata',[0 0 0]); + +% Text readouts: +% xxx +hax_readout = axes('pos',[0.02 .09 .185 .15],'vis','off'); +patch([0 1 1 0 0],[0 0 1 1 0],'w'); +htext_time = text('parent',hax_readout, 'pos',[0.075 .8], ... + 'erase','xor'); +htext_freq = text('parent',hax_readout, 'pos',[0.075 .5], ... + 'erase','xor'); +htext_mag = text('parent',hax_readout, 'pos',[0.075 .2], ... + 'erase','xor'); + +% Status bar +bgc=get(hfig,'color'); +hax_status = axes('pos',[0.005 0.01 .99 .04]); +set(hax_status,'vis','off','xlim',[0 1],'ylim',[0 1]); +% Main status: +h1=line([0 .45 .45],[0 0 1],'color','w'); +h2=line([0 0 .45],[0 1 1],'color',[1 1 1]*0); +htext_status = uicontrol('parent',hfig, ... + 'style','text', ... + 'units','norm', ... + 'pos',[.015 .012 .96-.55 .035], ... + 'horiz','left', ... + 'backgr',bgc, ... + 'string','Ready'); + +% Spectrogram controls: +% +% segment length +ylen = length(y); +Nfft = min(256,ylen); +Nwin = Nfft; +% Nlap = min(Nwin,ceil(Nwin/2)); +Nlap = min(Nwin,200); +ud.spect.nwin_text = uicontrol('parent',hfig, ... + 'style','text', ... + 'units','norm', ... + 'pos', [.45 .012 .07 .035], ... + 'backgr',bgc, ... + 'horiz','right', ... + 'string','Nwin:'); +ud.spect.nwin = uicontrol('parent',hfig, ... + 'style','edit', ... + 'units','norm', ... + 'pos', [.45+.07+.005 .01 .08 .04], ... + 'backgr','white', ... + 'horiz','left', ... + 'string',num2str(Nwin), ... + 'callback',@update_gui); +% overlap length +ud.spect.nlap_text = uicontrol('parent',hfig, ... + 'style','text', ... + 'units','norm', ... + 'pos', [.61 .012 .06 .035], ... + 'backgr',bgc, ... + 'horiz','right', ... + 'string','Nlap:'); +ud.spect.nlap = uicontrol('parent',hfig, ... + 'style','edit', ... + 'units','norm', ... + 'pos', [.61+.06+.005 .01 .08 .04], ... + 'backgr','white', ... + 'horiz','left', ... + 'string',num2str(Nlap), ... + 'callback',@update_gui); +% fft length +ud.spect.nfft_text = uicontrol('parent',hfig, ... + 'style','text', ... + 'units','norm', ... + 'pos', [.76 .012 .05 .035], ... + 'backgr', bgc, ... + 'horiz','right', ... + 'string','Nfft:'); +ud.spect.nfft = uicontrol('parent',hfig, ... + 'style','edit', ... + 'units','norm', ... + 'pos', [.75+.06+.005 .01 .08 .04], ... + 'backgr','white', ... + 'horiz','left', ... + 'string',num2str(Nfft), ... + 'callback',@update_gui); + +% Window + +% Menus +mFile = uimenu('parent',hfig,'label','&File'); +uimenu('parent',mFile,'label','&Print','callback',@printdlg_cb); +uimenu('parent',mFile,'label','&Close', ... + 'callback',@close_cb,'separator','on'); + +uimenu('parent',hfig, 'label','&Window', ... + 'tag','winmenu', ... + 'callback', winmenu('callback')); +% +% Help menu: +% +mHelp = uimenu('parent',hfig,'label','&Help'); + +% Help -> Specgramdemo Help +uimenu('parent',mHelp, ... + 'Label','Spectrogram Demo &Help', ... + 'Callback',@HelpSpecgramdemoCB); + +% Help -> Signal Processing Toolbox Help +uimenu('parent',mHelp, ... + 'Label','Signal Processing &Toolbox Help', ... + 'Callback',@HelpProductCB); + +% Help -> What's This? +uimenu('parent',mHelp, ... + 'Label','&What''s This?', ... + 'Callback', @HelpWhatsThisCB,... + 'Separator','On'); + +% Help -> Demos +uimenu('parent',mHelp, ... + 'Label','&Demos', ... + 'Callback',@HelpDemosCB,... + 'Separator','On'); + +% Help -> About Signal Processing Toolbox +uimenu('parent',mHelp, ... + 'Label','&About Signal Processing Toolbox', ... + 'Callback',@HelpAboutCB,... + 'Separator','On'); + +set(hfig,'colormap',jet(256)); + +% Retain info in figure userdata: +ud.hfig = hfig; +ud.hax = [hax_spec hax_time hax_tslice hax_freq hax_cbar hax_cbar_ind]; +ud.hspec_x = hspec_x; +ud.hspec_y = hspec_y; +ud.htime_y = htime_y; +ud.htslice_y = htslice_y; +ud.hfreq_x = hfreq_x; +ud.hcmap_arrow = hcmap_arrow; +ud.hfreq_line = hfreq_line; +ud.htslice_line = htslice_line; +ud.htime_plot = htime_plot; +ud.htext_time = htext_time; +ud.htext_freq = htext_freq; +ud.htext_mag = htext_mag; +ud.htext_status= htext_status; +ud.crosshair = []; +ud.himage = himage; +ud.himage_cbar = himage_cbar; +ud.hthumb = hthumb; +ud.f=[]; +ud.t=[]; +ud.y=y; +ud.Fs=Fs; +ud.currPtr = ''; % current pointer +ud.Pxx = []; +ud.w = []; + +% Set plot default modes: +ud.plot.top = 'spectrogram_time_slice'; +ud.plot.left = 'spectrogram_freq_slice'; + +set(hfig,'userdata',ud); + +winmenu(hfig); % Initialize the submenu, after ud is installed + +% Protect GUI from user plots, etc: +set([hfig ud.hax],'handlevis','callback'); + +% After GUI has all elements in it, install context help: +install_context_help(hfig); +install_context_menus(hfig); + +% Populate GUI with data, limits, etc: +update_gui([],[],hfig); + +% Enable general (non-segmenting) mouse functions: +install_cursorfcns(hfig,'general'); +set(hfig,'vis','on'); + +%%%%%%%%%%%%%%%%%%%%%%%%%% +% inserted by S.Bleeck +% switch to modal +uiwait(hfig); +%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +return + +% --------------------------------------------------------------- +% H E L P S Y S T E M +% -------------------------------------------------------------- +% +% General rules: +% - Context menus that launch the "What's This?" item have their +% tag set to 'WT?...', where the '...' is the "keyword" for the +% help lookup system. +% + +%-------------------------------------------------------------- +function HelpWhatsThisBDown(hco,eventStruct) +% HelpWhatsThisBDown Button-down function called from either +% the menu-based "What's This?" function, or the toolbar icon. + +hfig = gcbf; +hOver = gcbo; % overobj('uicontrol'); % handle to object under pointer + +% Restore pointer icon quickly: +setptr(hfig,'arrow'); + +% Shut off button-down functions for uicontrols and the figure: +hChildren = findobj(hfig); +set(hChildren, 'ButtonDownFcn',''); +set(hfig,'WindowButtonDownFcn',''); + +% Restore GUI pointers, etc: +wbmotion_general(hfig); + +% Dispatch to context help: +hc = get(hOver,'uicontextmenu'); +hm = get(hc,'children'); % menu(s) pointed to by context menu + +% Multiple entries (children) of context-menu may be present +% Tag is a string, but we may get a cell-array of strings if +% multiple context menus are present: +% Find 'What's This?' help entry +tag = get(hm,'tag'); +helpIdx = find(strncmp(tag,'WT?',3)); +if ~isempty(helpIdx), + % in case there were accidentally multiple 'WT?' entries, + % take the first (and hopefully, the only) index: + if iscell(tag), + tag = tag{helpIdx(1)}; + end + HelpGeneral([],[],tag); +end + +%-------------------------------------------------------------- +function HelpWhatsThisCB(hco, eventStruct) +% HelpWhatsThisCB Get "What's This?" help +% This mimics the context-menu help selection, but allows +% cursor-selection of the help topic + +% NOTE: Enabling context-help "destroys" the enable-state +% of all uicontrols in the GUI. When the callback completes, +% we must restore the enable states. + +hfig = gcbf; + +% Change pointer icon: +setptr(hfig,'help'); + +% Install button-down functions on all uicontrols, +% plus the figure itself: +% uicontrol, axes, line, patch, text +hChildren = findobj(hfig); +% No need to set enable states, etc. +set(hChildren, ... + 'ButtonDownFcn',@HelpWhatsThisBDown); +set(hfig, ... + 'WindowButtonMotionFcn','', ... + 'WindowButtonUpFcn','', ... + 'WindowButtonDownFcn',''); + +%-------------------------------------------------------------- +function HelpSpecgramdemoCB(hco,eventStruct) +%HELPSPECGRAMDEMO Get specgramdemo reference-page help + +helpwin(mfilename); + +%-------------------------------------------------------------- +function HelpProductCB(hco,eventStruct) +%HELPRPODUCTCB Opens the Help window with the online doc Roadmap +% page (a.k.a. "product page") displayed. +doc signal/ + +%-------------------------------------------------------------- +function HelpDemosCB(hco,eventStruct) +%HELPDEMOSCB Starts Demo window, with the appropriate product's +% demo highlighted in the Demo window contents pane. +demo toolbox signal + +%-------------------------------------------------------------- +function HelpAboutCB(hco,eventStruct) +%HELPABOUTCB Displays version number of product, and copyright. + +aboutsignaltbx; + +%-------------------------------------------------------------- +function HelpGeneral(hco,eventStruct,tag) +% HelpGeneral Define CSH text for specgramdemo + +hfig = gcbf; +hco = gcbo; + +if nargin<3, + % Testing purposes only: + tag = get(hco,'tag'); +end + +% Check for legal tag string: +if ~ischar(tag), + error('Invalid context-sensitive help tag.'); +end + +% Remove 'WT?' prefix; +if strncmp(tag,'WT?',3), + tag(1:3) = []; +else + error('Help tag must be a string beginning with "WT?" prefix.'); +end + +ud = get(hfig,'UserData'); + +% Define text for CSH system +title = ['Help: ' tag]; +msg = ''; +switch tag +case '' + msg = {''; + 'No help available on selected item.'}; + +case 'Spectrogram image' + msg = {''; + 'This image displays the spectrogram for the signal currently loaded '; + 'in the viewer. The spectrogram presents the magnitude of the short-time '; + 'Fourier transform.'; + ''; + 'Calculate the spectrogram as follows:'; + ''; + '1. Split the signal into overlapping sections and apply the'; + 'window specified by the window parameter to each section.'; + ''; + '2. Compute the discrete-time Fourier transform of each'; + 'section with a length Nfft FFT to estimate the short-term '; + 'frequency content of the signal. These transforms '; + 'make up the columns of B. The quantity (length(Nwin) - Nlap)' + 'specifies by how many samples the window will be shifted.'; + ''; + '3. For real input, truncate the spectrogram to the'; + 'first (Nfft/2 + 1) points when Nfft is even and (Nfft + 1)/2 when '; + 'Nfft is odd.'}; + +case 'Zoom Window Panner' + msg = {''; + 'Shows a panoramic view of the signal which is loaded in the viewer. '; + 'When you zoom in the spectrogram, the corresponding time domain '; + 'portion is highlighed.'; + ''; + 'You can zoom the panner by dragging the mouse on the left- and '; + 'right-hand edges of the highlighted zoom region. Right-click the '; + 'highlighted zoom area to bring up a menu for focusing in on the zoomed '; + 'region'}; + +case 'Spectrogram Frequency Slice' % Left axes + if strcmp(ud.plot.left,'spectrogram_freq_slice'), + msg = {''; + 'This view displays a frequency slice for the current spectrogram. The '; + 'view is updated as you move the crosshair cursor along the frequency ' + 'axes (horizontally).'}; + else + % Change the helpwin title for the PSD case. + title = ['Help: Signal Power Spectral Density']; + + msg = {''; + 'Displays the Power Spectral Density (PSD) estimate calculated '; + 'using Welch''s averaged modified periodogram method.'}; + + end + +case 'Spectrogram Time Slice', % Top axes + msg = {''; + 'This view displays a time slice for the current spectrogram. The'; + 'view is updated as you move the crosshair cursor along the time' + 'axes (vertically).'}; + +case 'Colorbar' + msg = {''; + 'The colorbar shows the color scale for the current spectrogram.'; + ''}; + +case 'Status Bar', + msg = {''; + 'The Status Bar displays information about the state of the '; + 'Spectrogram Demo, the current operation of the tool, and operation'; + 'of the crosshair cursor.'}; + +case 'Magnitude Readout', + msg = {''; + 'Displays the magnitude (in dB) of a spectrogram slice.'; + ''}; + +case 'Frequency Readout', + msg = {''; + 'Displays frequency values in Hz.'; + ''}; + +case 'Time Readout', + msg = {''; + 'Displays time measurements in seconds for the Time Plot '; + 'and the Time Slice'}; + +case 'Time Plot', % Bottom axes + msg = {''; + 'Time Plot displays the original signal in its entirety.'}; + +case 'Colorbar Indicator', + msg = {''; + 'The colorbar indicator points to the level of the spectrogram.'}; + +case 'Frequency Crosshair', + msg = {''; + 'Move the frequency crosshair cursor to pin-point a particular '; + 'frequency location on the spectrogram''s frequency slice axes.'}; + +case 'Time Crosshair', + msg = {''; + 'Move the time crosshair cursor to pin-point a particular '; + 'time instance on the spectrogram''s time slice axes.'}; + +case 'Spectrogram Demo', + msg = {''; + 'This is the Spectrogram Demo which displays a spectrogram, '; + 'a time plot, and a frequency slice of an input signal'; + ''; + 'SPECGRAMDEMO(y,Fs) displays a spectrogram of signal y, assuming a sample '; + 'rate of Fs Hz. If y is specified but Fs is not, a sample rate of 1 '; + 'Hz is assumed. If no input arguments are supplied, y and Fs are '; + 'taken from the default data file "mtlb.mat."'}; + +case 'Spectrogram Window Size', + msg = {''; + 'Nwin specifies the length of the Periodic Blackman window used in '; + 'this demo. The default value is 256.'}; + +case 'Spectrogram FFT Size', + msg = {''; + 'Nfft specifies the FFT length used to calculate the spectrogram. '; + 'This value determines the frequencies at which the discrete-time '; + 'Fourier transform is computed. These values are typically powers '; + 'of two, such as 256 or 512.'}; + +case 'Spectrogram Overlap' + msg = {''; + 'Use Nlap to specify the number of samples to overlap the windowed sections.'}; +end + +% If no text is defined, simply display the tag. +if isempty(msg), + msg = {''; + ['This is the ' tag '.']}; +end + +% Put up message box for help: +%hmsg = msgbox(msg,title, 'help','modal'); +%CenterFigOnFig(hfig, hmsg); + +helpwin(char(msg),title); + +%-------------------------------------------------------------- +function CenterFigOnFig(hfig,hmsg) +% CenterFigOnFig Center hMsg figure on top of hFig figure + +set(hfig,'units','pix'); +figPos = get(hfig,'pos'); +figCtr = [figPos(1)+figPos(3)/2 figPos(2)+figPos(4)/2]; + +set(hmsg,'units','pix'); +msgPos = get(hmsg,'position'); +msgCtr = [msgPos(1)+msgPos(3)/2 msgPos(2)+msgPos(4)/2]; + +movePos = figCtr - msgCtr; + +new_msgPos = msgPos; +new_msgPos(1:2) = msgPos(1:2) + movePos; +set(hmsg,'Position',new_msgPos); + +return + +%-------------------------------------------------------------- +function install_context_help(hfig) + +ud = get(hfig,'userdata'); + +main = {'label','&What''s This?', ... + 'callback',@HelpGeneral, 'parent'}; + +setWTC(hfig,main, [ud.himage ud.hax(1)], 'Spectrogram image'); +setWTC(hfig,main, ud.hthumb, 'Zoom Window Panner'); +setWTC(hfig,main, [ud.himage_cbar ud.hax(5)], 'Colorbar'); +setWTC(hfig,main, ud.htext_status, 'Status Bar'); +setWTC(hfig,main, ud.htext_mag, 'Magnitude Readout'); +setWTC(hfig,main, ud.htext_freq, 'Frequency Readout'); +setWTC(hfig,main, ud.htext_time, 'Time Readout'); +setWTC(hfig,main, [ud.htime_plot ud.hax(2)], 'Time Plot'); +setWTC(hfig,main, [ud.htslice_line ud.hax(3)], 'Spectrogram Time Slice'); +setWTC(hfig,main, [ud.hfreq_line ud.hax(4)], 'Spectrogram Frequency Slice'); +setWTC(hfig,main, [ud.hcmap_arrow ud.hax(6)], 'Colorbar Indicator'); + +setWTC(hfig,main, [ud.hfreq_x ud.hspec_x], 'Frequency Crosshair'); +setWTC(hfig,main, [ud.htime_y ud.htslice_y ud.hspec_y], 'Time Crosshair'); +setWTC(hfig,main, ud.hfig, 'Spectrogram Demo'); + +setWTC(hfig,main, [ud.spect.nwin ud.spect.nwin_text], 'Spectrogram Window Size'); +setWTC(hfig,main, [ud.spect.nfft ud.spect.nfft_text], 'Spectrogram FFT Size'); +setWTC(hfig,main, [ud.spect.nlap ud.spect.nlap_text], 'Spectrogram Overlap'); + +% xxx set context for: +% - readout axis +% - uitoolbar + +%-------------------------------------------------------------- +function setWTC(hfig,main,hItem,tagStr) +% setWT Set the "What's This?" context menu and callback: +hc = uicontextmenu('parent',hfig); +uimenu(main{:},hc, 'tag',['WT?' tagStr]); +set(hItem,'uicontextmenu',hc); + + +% --------------------------------------------------------------- +% C O N T E X T M E N U S +% -------------------------------------------------------------- + +%----------------------------------------------------------------- +function install_context_menus(hfig) + +install_specgram_mode_menus(hfig); +install_colorbar_menus(hfig); +install_freq_slice_menus(hfig); +install_time_slice_menus(hfig); +install_time_panner_menus(hfig); + +%----------------------------------------------------------------- +function install_specgram_mode_menus(hfig) + +% Additional menus to prepend to the spectrogram context menu: + +ud = get(hfig,'userdata'); +hc = get(ud.himage,'uicontext'); % ud.hax(1) also? + +hEntry=[]; % holds handles to each colormap menu item +opts={hc,'2-D Image',@changeSpecgramMode, 'checked','on'}; +hEntry(end+1) = createContext(opts); +opts={hc,'3-D Magnitude Plot',@changeSpecgramMode}; +hEntry(end+1) = createContext(opts); +% xxx disable last menu until feature implemented: +set(hEntry(end),'enable','off'); +opts={hc,'3-D dB Plot',@changeSpecgramMode}; +hEntry(end+1) = createContext(opts); +% xxx disable last menu until feature implemented: +set(hEntry(end),'enable','off'); + +% Give each menu item a vector of handles to all peer menus +set(hEntry,'userdata',hEntry); + +fixup_context_order(hc); + +%----------------------------------------------------------------- +function install_colorbar_menus(hfig) +% Additional menus to prepend to the colorbar context menu: + +ud = get(hfig,'userdata'); +hc = get(ud.himage_cbar,'uicontext'); % ud.hax(1) also? + +opts={hc,'Colormap',''}; +hCmap = createContext(opts); + +hEntry=[]; % holds handles to each colormap menu item +opts={hCmap,'Jet',@changeCMap, 'checked','on'}; +hEntry(end+1) = createContext(opts); +opts={hCmap,'Hot',@changeCMap}; +hEntry(end+1) = createContext(opts); +opts={hCmap,'Gray',@changeCMap}; +hEntry(end+1) = createContext(opts); +opts={hCmap,'Bone',@changeCMap}; +hEntry(end+1) = createContext(opts); +opts={hCmap,'Copper',@changeCMap}; +hEntry(end+1) = createContext(opts); +opts={hCmap,'Pink',@changeCMap}; +hEntry(end+1) = createContext(opts); + +opts={hc,'Set Limits',@manual_cmap_limits, 'separator','on'}; +createContext(opts); + +opts={hc,'Reset Limits',@reset_cmap_limits}; +createContext(opts); + +% Give each menu item a vector of handles to all peer menus +set(hEntry,'userdata',hEntry); + +fixup_context_order(hc); + +%----------------------------------------------------------------- +function install_freq_slice_menus(hfig) + +% Additional menus to prepend to the spectrogram context menu: + +ud = get(hfig,'userdata'); +hax_freq = ud.hax(4); +hc = get(hax_freq,'uicontext'); % ud.hax(1) also? + +hEntry=[]; % holds handles to each colormap menu item +opts={hc,'Marginal (specgram slice)',@changeFreqSliceMode, 'checked','on'}; +hEntry(end+1) = createContext(opts); +%opts={hc,'Integrated (freq PSD)',@changeFreqSliceMode}; +opts={hc,'Power Spectral Density',@changeFreqSliceMode}; +hEntry(end+1) = createContext(opts); +set(hEntry(end),'enable','on'); + +% Give each menu item a vector of handles to all peer menus +set(hEntry,'userdata',hEntry); + +fixup_context_order(hc); + +%----------------------------------------------------------------- +function install_time_slice_menus(hfig) + +% Additional menus to prepend to the spectrogram context menu: + +ud = get(hfig,'userdata'); +hax_tslice = ud.hax(3); +hc = get(hax_tslice,'uicontext'); % ud.hax(1) also? + +hEntry=[]; % holds handles to each colormap menu item +opts={hc,'Marginal (specgram slice)',@changeTimeSliceMode, 'checked','on'}; +hEntry(end+1) = createContext(opts); +opts={hc,'Integrated (time zoom)',@changeTimeSliceMode}; +hEntry(end+1) = createContext(opts); + +% disable last menu until feature implemented: +set(hEntry(end),'enable','off'); + +% Give each menu item a vector of handles to all peer menus +set(hEntry,'userdata',hEntry); + +fixup_context_order(hc); + +%----------------------------------------------------------------- +function install_time_panner_menus(hfig) + +% Additional menus to prepend to the time-panner context menu: + +ud = get(hfig,'userdata'); +hthumb = ud.hthumb; % XXX add to time axis as well? +hc = get(hthumb, 'uicontext'); + +% Update the menu on-the-fly: +set(hc,'callback', @focus_menu_render_callback); + +hEntry=[]; % holds handles to each colormap menu item + +opts={hc,'Focus In',@focusTimeIn}; +hEntry(end+1) = createContext(opts); + +opts={hc,'Previous Focus',@focusTimePrev}; +hEntry(end+1) = createContext(opts); + +opts={hc,'Reset Focus',@focusTimeReset}; +hEntry(end+1) = createContext(opts); + +% Give each menu item a vector of handles to all peer menus +set(hEntry,'userdata',hEntry); + +fixup_context_order(hc); + +update_focus_history_menu(hfig); % pass any focus context menu + +%----------------------------------------------------------------- +function hMenu=createContext(opts) +% Helper function to append additional context menus +args = {'parent',opts{1}, 'label',opts{2}, 'callback',opts{3:end}}; +hMenu=uimenu(args{:}); + +%----------------------------------------------------------------- +function fixup_context_order(hContext) +% Put the first context menu entry (the "What's This?" entry) +% last in the context menu list, and turn on the separator +% for the "What's This?" entry +childList = get(hContext,'children'); +childList = childList([end 1:end-1]); +set(hContext,'children',childList); +set(childList(1),'separator','on'); + +%--------------------------------------------------------------- +function changeCMap(hco,eventStruct) + +hco=gcbo; hfig=gcbf; +% Reset checks on all colormap menu items: +set(get(hco,'userdata'),'checked','off'); +set(hco,'checked','on'); + +% Update figure colormap: +cmapStr = lower(get(hco,'label')); +cmap = feval(cmapStr); +set(hfig,'colormap',cmap); + +%--------------------------------------------------------------- +function changeSpecgramMode(hco,eventStruct) + +hco=gcbo; hfig=gcbf; +% Reset checks on all menu items: +set(get(hco,'userdata'),'checked','off'); +set(hco,'checked','on'); + +% Update userdata cache: +% Update display: + +%--------------------------------------------------------------- +function changeFreqSliceMode(hco,eventStruct) + +hco=gcbo; hfig=gcbf; +% Reset checks on all menu items +set(get(hco,'userdata'),'checked','off'); +set(hco,'checked','on'); + +% Update userdata cache: +% Update display: +left_plot_toggle; + +%--------------------------------------------------------------- +function changeTimeSliceMode(hco,eventStruct) + +hco=gcbo; hfig=gcbf; +% Reset checks on all menu items +set(get(hco,'userdata'),'checked','off'); +set(hco,'checked','on'); + +% Update userdata cache: +% Update display: + + +% --------------------------------------------------------------- +% F O C U S S Y S T E M +% -------------------------------------------------------------- + +%--------------------------------------------------------------- +function push_curr_to_focus_history(hfig) + +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); + +% focus history is stored in userdata of time-panner axis +% as either an empty vector or cell, or as +% a cell-array of 2-element x-lim vector. + +% get current time-axis limits +curr_xlim = get(hax_time,'xlim'); + +curr_history = get(hax_time,'userdata'); +if isempty(curr_history), + updated_focus_history = {curr_xlim}; +else + updated_focus_history = [curr_history {curr_xlim}]; +end +set(hax_time,'userdata',updated_focus_history); + +update_focus_history_menu(hfig); + +%--------------------------------------------------------------- +function hist_xlim = pop_from_focus_history(hfig) + +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); +curr_xlim = get(hax_time,'xlim'); % get current time-axis limits + +curr_history = get(hax_time,'userdata'); +if isempty(curr_history), + % no prev focus info recorded + warning('Attempt to pop empty focus stack'); + hist_xlim = curr_xlim; + + %im_xdata = get(ud.himage,'xdata'); + %hist_xlim = [min(im_xdata) max(im_xdata)]; +else + % Pop last history xlim + hist_xlim = curr_history{end}; + curr_history(end) = []; + set(hax_time,'userdata',curr_history); +end + +update_focus_history_menu(hfig); + +%--------------------------------------------------------------- +function clear_focus_history(hfig) +% Remove all previous focus entries + +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); +set(hax_time,'userdata',[]); + +update_focus_history_menu(hfig); + +%--------------------------------------------------------------- +function update_focus_history_menu(hfig) + +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); + +% Update 'Previous Focus' context menu label: +% +curr_history = get(hax_time,'userdata'); +histLen = length(curr_history); +str = 'Previous Focus'; +if histLen>0, + str = [str ' (' num2str(histLen) ')']; + ena = 'on'; +else + ena = 'off'; +end + +% Get panner context menu handle: +hmenu = findobj( get(get(ud.hthumb, 'uicontext'),'children'),'label','Focus In'); +hAllMenus = get(hmenu,'userdata'); % vector of handles to context menus +hFocusPrev = hAllMenus(2); +set(hFocusPrev, 'label',str); +set(hAllMenus(2:3), 'enable',ena); % Prev and Reset Focus menus + +%--------------------------------------------------------------- +function focus_menu_render_callback(hco, eventStruct) +% Used to update the enable of the "Focus In" menu item +% Only enabled if thumb_xlim ~= curr_xlim + +hfig=gcbf; hparent=gcbo; +ud = get(hfig,'userdata'); +hAllMenus = get(hparent,'children'); % vector of handles to context menus + +% Enable 'Focus on Window' if zoom window is less than entire panner +% +hFocusIn = hAllMenus(end); % 'Focus on Zoom' entry +hax_time = ud.hax(2); +curr_xlim = get(hax_time,'xlim'); % get current time-axis limits +% Get thumbnail xlim vector: +thumb_xdata = get(ud.hthumb,'xdata'); % current thumbnail patch coords +thumb_xlim = [min(thumb_xdata) max(thumb_xdata)]; % convert to xlim +if ~isequal(curr_xlim, thumb_xlim), + ena='on'; +else + ena='off'; +end +set(hFocusIn,'enable',ena); + +%--------------------------------------------------------------- +function focusTimeIn(hco,eventStruct) + +hfig=gcbf; + +% get current time-axis (panner) limits +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); +curr_xlim = get(hax_time,'xlim'); + +% Get thumbnail xlim vector: +thumb_xdata = get(ud.hthumb,'xdata'); % current thumbnail patch coords +thumb_xlim = [min(thumb_xdata) max(thumb_xdata)]; % convert to xlim + +if ~isequal(curr_xlim, thumb_xlim), + push_curr_to_focus_history(hfig); + + % Zoom in to thumb limits + hax_time = ud.hax(2); + + if 0 + xidx = round(1+thumb_xlim*ud.Fs); + yfocus = ud.y(xidx(1):xidx(2)); + ylim = [min(yfocus) max(yfocus)]; + set(hax_time, 'ylim',ylim); + end + + set(hax_time,'xlim', thumb_xlim); + update_axes_with_eng_units(gcbf); +end + +%--------------------------------------------------------------- +function focusTimePrev(hco,eventStruct) + +hfig=gcbf; +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); + +% Reset to last focus +xlim = pop_from_focus_history(hfig); + +if 0 + xidx = round(1+xlim*ud.Fs); + yfocus = ud.y(xidx(1):xidx(2)); + ylim = [min(yfocus) max(yfocus)]; + set(hax_time, 'ylim',ylim); +end + +set(hax_time, 'xlim',xlim); +update_axes_with_eng_units(gcbf); + +%--------------------------------------------------------------- +function focusTimeReset(hco,eventStruct,hfig) +% Remove all previous focus entries + +if nargin<3, hfig=gcbf; end +clear_focus_history(hfig); + +% Reset focus zoom: +ud = get(hfig,'userdata'); +hax_time = ud.hax(2); +im_xdata = get(ud.himage,'xdata'); +xlim = [min(im_xdata) max(im_xdata)]; + +if 0 + xidx = round(1+xlim*ud.Fs); + yfocus = ud.y(xidx(1):xidx(2)); + ylim = [min(yfocus) max(yfocus)]; + set(hax_time,'ylim',ylim); +end + +set(hax_time,'xlim',xlim); +update_axes_with_eng_units(gcbf); + +% --------------------------------------------------------------- +% PARAMETER WINDOW +% -------------------------------------------------------------- +% function create_param_gui +% XXX UNUSED + + +% --------------------------------------------------------------- +% AXES UPDATE FUNCTIONS +% -------------------------------------------------------------- +function update_left_plot(hfig) +% UPDATE_LEFT_PLOT Updates the frequency plot with the appropriate analysis + +ud = get(hfig,'UserData'); +mode = ud.plot.left; +if strcmp(mode,'spectrogram_freq_slice'), + update_freqslice(hfig); +else + update_psdplot(hfig); +end + +% -------------------------------------------------------------- +function update_freqslice(hfig) +% UPDATE_FREQSLICE Update the Frequency Slice (on the left axes) + +ud = get(hfig,'UserData'); +set(ud.hfreq_line, 'xdata',get_spec_freq(hfig),'ydata',ud.f); +hax_freq = ud.hax(4); + +b = get(ud.himage,'cdata'); +blim = [min(b(:)) max(b(:))]; +spec_ylim = [0 max(ud.f)]; +xlabel('dB'); +set(hax_freq, ... + 'YLim',spec_ylim, ... + 'XLim',blim,... + 'XtickMode','auto'); +set(hax_freq, 'Xtick', return2ticks(hax_freq)); + +% Update extent of horizontal crosshair: +set(ud.hfreq_x, 'xdata',blim); + + +% -------------------------------------------------------------- +function update_psdplot(hfig) +% UPDATE_PSDPLOT Update the PSD plot (on the left axes) + +ud = get(hfig,'UserData'); +wstate = warning; +warning off; +density = 10*log10(ud.Pxx); +warning(wstate); + +hax_freq = ud.hax(4); + +% Update the PSD plot with data and limits +set(ud.hfreq_line,'Xdata',density,'Ydata',ud.w); +xlim = [min(density(:)) max(density(:))]; +xlabel('dB/Hz'); +set(hax_freq, ... + 'YLim', [0 ud.Fs/2],'XLim',xlim,... + 'XTickMode','auto'); +set(hax_freq, 'Xtick', return2ticks(hax_freq)); + +% Update extent of horizontal crosshair: +set(ud.hfreq_x, 'xdata',xlim); + + +% --------------------------------------------------------------- +% UTILITY FUNCTIONS +% -------------------------------------------------------------- +function new_xtick = return2ticks(haxes) +% RETURN2TICKS Utility to return two tick marks +x = get(haxes,'Xtick'); +if length(x)>2, + new_xtick = [x(1) x(end)]; +else + new_xtick = x; +end + +%-------------------------------------------------------------- +% [EOF] specgramdemo.m diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,62 @@ +% main procedure for aim +% +% INPUT VALUES: either a wave-file, a m-file or nothing +% +% RETURN VALUE: +% for the nongraphic version, the result, otherwise non +% +% load the signal file and all files, that are in this directory +% set the project variables accordingly. +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +function result=aim(varargin) + +nrparams=length(varargin); +switch nrparams + case 0 % no argument, load a wave file and go to graphic version + [signame,dirname]=uigetfile('*.wav'); + if isnumeric(signame) + return + end + cd(dirname); + aim_gui(signame); + return + case 1 % only one parameter, this can be the structure of parameters, or a wavefile + cname=varargin{1}; + if isstruct(cname); % called with an struct +% result=aim_gui(cname); + result=aim_ng(cname); + return + end + + % calling with a wavefile - open the graphic version + [pathstr,filename,ext] = fileparts(cname); %#ok + if strcmp(ext,'.wav') % + if fexist(cname) % yes, the wavefile is there! Is there also a directory? + aim_gui(cname); + return + else + str=sprintf('The wave-file %s does not exist in the current working directory %s',cname,pwd); + er=errordlg(str,'File Error'); + set(er,'WindowStyle','modal'); + return + end + else % called with a m-file + if strcmp(ext,'.m') % calling with a m-file? + if fexist(cname) % yes, the m-file is there, we call the nographic version: + result=aim_ng(cname); + return + else + str=sprintf('file %s does not exist in the current working directory %s',cname,pwd); + er=errordlg(str,'File Error'); + set(er,'WindowStyle','modal'); + return + end + end + end +end + +disp('call ''aim'' with with a sound file or a m-parameter file'); diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_define_plot_areas.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_define_plot_areas.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,167 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% load the signal file and all files, that are in this directory +% set the project variables accordingly. +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function [myaxes1,myaxes2,myaxes3,myaxes4]=aim_define_plot_areas(handles,relative_axis,options) + +withtime=options.withtime; +withfre=options.withfre; +withsignal=options.withsignal; + +current_plot=handles.info.current_plot; + +% calculate the position of the axes according to the tick-settings +% find out, which graphic we want: +if ~withtime && ~withfre && ~withsignal + graphiccase=1; +else if ~withtime && ~withfre && withsignal + if current_plot==1 + graphiccase=8; + else + graphiccase=2; + end + else if withtime && ~withfre && withsignal + graphiccase=3; + else if withtime && withfre && withsignal + graphiccase=4; + else if ~withtime && withfre && ~withsignal + graphiccase=5; + else if ~withtime && withfre && withsignal + graphiccase=6; + else if withtime && withfre && ~withsignal + graphiccase=7; + else if withtime && ~withfre && ~withsignal + graphiccase=9; + end + end + end + end + end + end + end +end + + +off=0.002; % between graphics +% width without frequency profile: +b11=0.96; +% width left and right with frequency profile: +b21=0.87-off; +b22=0.12; boff22=0.87-off; + +% height signal without main or temp profile +h11=1; +% height signal with main window +h21=0.2; hoff21=0.8+off; +h22=0.8; +% height temp profile with main window +h21a=0.8; hoff21a=0.2+off; +h22a=0.2; + +% height signal with main window and temporal profile +h31=0.15; hoff31=0.85+off+off+off; +h32=0.7; hoff32=0.15+off; +h33=0.15; + +if strcmp(handles.screen_modus,'paper') + off=0.001; % between graphics + % width without frequency profile: + b11=0.95; + % width left and right with frequency profile: + b21=0.83-off; + b22=0.12; boff22=0.83-off; + + % height signal without main or temp profile + h11=1; + % height signal with main window + h21=0.2; hoff21=0.75+off; + h22=0.75; + % height temp profile with main window + h21a=0.8; hoff21a=0.2+off; + h22a=0.2; + + % height signal with main window and temporal profile + h31=0.15; hoff31=0.83+off+off+off; + h32=0.68; hoff32=0.15+off; + h33=0.15; +end + + +switch graphiccase + case 1 + axpos2=[0,0,b11,h11]; + case 2 + axpos1=[0,hoff21,b11,h21]; + axpos2=[0,0,b11,h22]; + case 3 + axpos1=[0,hoff31,b11,h31]; + axpos2=[0,hoff32,b11,h32]; + axpos3=[0,0,b11,h33]; + case 4 + axpos1=[0,hoff31,b21,h31]; + axpos2=[0,hoff32,b21,h32]; + axpos3=[0,0,b21,h33]; + axpos4=[boff22,hoff32+off,b22,h32]; + case 5 + axpos2=[0,0,b21,h11]; + axpos4=[boff22,0,b22,h11]; + case 6 + axpos1=[0,hoff21,b21,h21]; + axpos2=[0,0,b21,h22]; + axpos4=[boff22,0 ,b22,h22]; + case 7 + axpos2=[0,hoff21a,b21,h21a]; + axpos3=[0,0,b21,h22a]; + axpos4=[boff22,hoff21a,b22,h21a]; + case 9 + axpos2=[0,hoff21a,b11,h21a]; + axpos3=[0,0,b11,h22a]; + otherwise + axpos1=[0,hoff21,b11,h21]; +end + +ra=relative_axis; +% put a little space to the left side: +ra(1)=ra(1)+0.015; +if strcmp(handles.screen_modus,'paper') + ra(2)=ra(2)+0.015; +end +if exist('axpos1','var') + myaxes1=subplot('Position',[ra(1)+(axpos1(1)*ra(3)) ra(2)+(axpos1(2)*ra(4)) ra(3)*axpos1(3) ra(4)*axpos1(4)] ); + set(myaxes1,'Visible','on'); + cla; +else + myaxes1=[]; +end +if exist('axpos2','var') + myaxes2=subplot('Position',[ra(1)+(axpos2(1)*ra(3)) ra(2)+(axpos2(2)*ra(4)) ra(3)*axpos2(3) ra(4)*axpos2(4)] ); + set(myaxes2,'Visible','on'); +% cla; +else + myaxes2=[]; +end +if exist('axpos3','var') + myaxes3=subplot('Position',[ra(1)+(axpos3(1)*ra(3)) ra(2)+(axpos3(2)*ra(4)) ra(3)*axpos3(3) ra(4)*axpos3(4)] ); + set(myaxes3,'Visible','on'); +% cla; +else + myaxes3=[]; +end +if exist('axpos4','var') + myaxes4=subplot('Position',[ra(1)+(axpos4(1)*ra(3)) ra(2)+(axpos4(2)*ra(4)) ra(3)*axpos4(3) ra(4)*axpos4(4)] ); + set(myaxes4,'Visible','on'); + cla; +else + myaxes4=[]; +end \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_deletefile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_deletefile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,55 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% handles: +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_deletefile(handles,type) +% deletes the file, if it is there + +switch type + case 'bmm' + todelete=handles.info.bmmname; + handles.info.bmm_loaded=0; + case 'nap' + todelete=handles.info.napname; + handles.info.nap_loaded=0; + case 'strobes' + todelete=handles.info.strobesname; + handles.info.strobes_loaded=0; + case 'sai' + todelete=handles.info.sainame; + handles.info.sai_loaded=0; + case 'pitch_image' + todelete=handles.info.pitch_imagename; + handles.info.pitch_image_loaded=0; + case 'usermodule' + todelete=handles.info.usermodulename; + handles.info.usermodule_loaded=0; + case 'movie' + handles.info.movie_loaded=0; + mnames=handles.info.moviename; + for i=1:length(mnames) + todelete=handles.info.moviename{i}; + if ~fexist(todelete) + return + end + delete(todelete); + end + return + %otherwise + % todelete=''; % Stops it crashing if given junk, left out as this + % is a good indicator that there's something wrong. +end + +if ~fexist(todelete) + return +end + +delete(todelete); diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_display_versions.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_display_versions.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,166 @@ +% procedure for 'aim-mat' +% function aim_display_versions(handles) +% INPUT VALUES: +% RETURN VALUE: +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function aim_display_versions(handles) + +%PCP +pcpnames=get(handles.listbox0,'String'); +for i=1:length(pcpnames) + str=sprintf('ver=handles.all_options.pcp.%s.revision;',pcpnames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{1}{i}.columname='PCP'; + text{1}{i}.modulename=pcpnames{i}; + text{1}{i}.version=ver; +end +%BMM +bmmnames=get(handles.listbox1,'String'); +for i=1:length(bmmnames) + str=sprintf('ver=handles.all_options.bmm.%s.revision;',bmmnames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{2}{i}.columname='BMM'; + text{2}{i}.modulename=bmmnames{i}; + text{2}{i}.version=ver; +end +%NAP +napnames=get(handles.listbox2,'String'); +for i=1:length(napnames) + str=sprintf('ver=handles.all_options.nap.%s.revision;',napnames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{3}{i}.columname='NAP'; + text{3}{i}.modulename=napnames{i}; + text{3}{i}.version=ver; +end +%STROBES +strobesnames=get(handles.listbox3,'String'); +for i=1:length(strobesnames) + str=sprintf('ver=handles.all_options.strobes.%s.revision;',strobesnames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{4}{i}.columname='STROBES'; + text{4}{i}.modulename=strobesnames{i}; + text{4}{i}.version=ver; +end +%SAI +sainames=get(handles.listbox4,'String'); +for i=1:length(sainames) + str=sprintf('ver=handles.all_options.sai.%s.revision;',sainames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{5}{i}.columname='SAI'; + text{5}{i}.modulename=sainames{i}; + text{5}{i}.version=ver; +end +%USER +usernames=get(handles.listbox6,'String'); +for i=1:length(usernames) + str=sprintf('ver=handles.all_options.user.%s.revision;',usernames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{6}{i}.columname='USER'; + text{6}{i}.modulename=usernames{i}; + text{6}{i}.version=ver; +end +%MOVIES +movienames=get(handles.listbox5,'String'); +for i=1:length(movienames) + str=sprintf('ver=handles.all_options.movie.%s.revision;',movienames{i}); + try + eval(str); + catch + ver='Revision not known'; + end + text{7}{i}.columname='MOVIES'; + text{7}{i}.modulename=movienames{i}; + text{7}{i}.version=ver; +end + + +figure; +win=get(gca,'Parent'); +set(win,'Name','All models and all versions'); +set(win,'NumberTitle','off'); +set(win,'MenuBar','none'); +movegui(win,'center'); +pos=get(win,'Position'); +set(win,'Visible','on'); +box = uicontrol('Style', 'ListBox','Position', [0,0,pos(3),pos(4)],'HorizontalAlignment','left'); +set(box,'Parent',win); +set(box,'FontSize',10); + +str=[]; +counter=1; +for i=1:7 + nr_modules=length(text{i}); + str{counter}=text{i}{1}.columname ; + counter=counter+1; +% str=[str text{i}{1}.columname '\n']; + for j=1:nr_modules + ver=strrep(text{i}{j}.version,'$',''); + str{counter}=[' ' text{i}{j}.modulename ' ' ver]; + counter=counter+1; +% str=[str text{i}{j}.modulename '\t' text{i}{j}.version '\n']; + end +end + + +% display the conflicts + +str{counter}='' ; +counter=counter+1; +str{counter}='' ; +counter=counter+1; +% conflicts: +if isfield(handles.info,'conflicts') + conflicts=handles.info.conflicts; +else + return +end + + +if isempty(conflicts) + str{counter}='no conflicts'; +% counter=counter+1;%#ok +else + str{counter}='conflicts:'; + counter=counter+1; + for i=1:length(conflicts) + str{counter}=conflicts{i}; + counter=counter+1; + end +end + + + +set(box,'String',str); +set(box,'max',length(str)); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_displayaboutbox.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_displayaboutbox.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,65 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function retfig=aim_displayaboutbox(handles) + +% h = dialog('title','about'); + +if isfield(handles,'abouttexttodisplay') + withtext=1; + abtext=handles.abouttexttodisplay; +else + withtext=0; +end + +logoname=sprintf('%s/logo.gif',handles.info.columnpath); +[logo,colmap]=imread(logoname); + +retfig=figure('Visible','off'); +h=image(logo); +colormap(colmap); +h2=get(h,'Parent'); +retfig=get(h2,'Parent'); + +% set(win,'Visible','off'); +set(h2,'YTick',[]); +set(h2,'XTick',[]); +set(h2,'Position',[0 0 1 1]); + +if withtext==1 + a=axis; + text(20,a(4)/2,abtext,'FontSize',18,'Color','r','Interpreter','none'); +end + +a=axis; +text(20,0.91.*a(4),release('ver'),'FontSize',12,'Color','b','Interpreter','none'); +% text(20,0.95.*a(4),release('rev'),'FontSize',9,'Color','b','Interpreter','none'); +text(20,0.98.*a(4),release('date'),'FontSize',12,'Color','b','Interpreter','none'); + +set(retfig,'Name','About aim-mat'); +set(retfig,'NumberTitle','off'); +set(retfig,'MenuBar','none'); +movegui(retfig,'center'); +pos=get(retfig,'Position'); +sis=size(logo); +pos(3)=sis(2); +pos(4)=sis(1); +set(retfig,'Position',pos); +set(retfig,'Visible','on'); +% but = uicontrol('Style', 'pushbutton', 'String', 'OK','Position', [390 0 70 60]); +% set(but,'Parent',win); +% set(but,'FontSize',20); +% set(but,'Callback', 'close'); +% set(but,'FontWeight','bold'); + +a=0; + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_exchange_sound_file.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_exchange_sound_file.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,229 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% the new soundfilename +% RETURN VALUE: +% the updated handles +% +% changes the soundfile and updates +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_exchange_sound_file(handles,signame) +% exchanges the sound file and keeps the parameters +% this works by deleting the directory +% saving the parameter file under new name +% recalculation of all stages up to the chosen one + +% save some old values +oldhandles=handles; +slider_start=handles.slideredit_start; +slider_duration=handles.slideredit_duration; +slider_scale=handles.slideredit_scale; +slider_combi=handles.currentslidereditcombi; +slider_frames=handles.slideredit_frames; + + +handles=setupnames(handles,signame); +dirname=handles.info.directoryname; + + +loadswitch=0; +if exist(dirname)~=7 % is not a directory so far + % load the project + handles=init_aim_parameters(handles,signame); + loadswitch=1; +end + +% if exist(dirname)==7 % is a directory with a project in (hopefully) +wave_switch=get(handles.checkbox10,'Value'); +spectral_switch=get(handles.checkbox6,'Value'); +temporal_switch=get(handles.checkbox7,'Value'); + +% copy the project-file to the new directory: +oldpfile=fullfile(pwd,oldhandles.info.projectfilename); +newpfile=fullfile(pwd,handles.info.projectfilename); +try + copyfile(oldpfile,newpfile); +catch + what=0; +end + +if loadswitch==0 + % load the project + handles=init_aim_parameters(handles,signame); +end + +tempinfo=handles.info; +% the signal options have been overwritten, so set them back: +handles.all_options.signal.start_time=oldhandles.all_options.signal.start_time; +handles.all_options.signal.duration=oldhandles.all_options.signal.duration; +handles.all_options.signal.samplerate=oldhandles.all_options.signal.samplerate; +handles=init_aim_gui(handles); + +tempoptions=handles.all_options; +% tempinfo=handles.info; + +% copy the parameter file to the new directory +oldpfile=fullfile(pwd,oldhandles.info.parameterfilename); +newpfile=fullfile(pwd,handles.info.parameterfilename); +try + copyfile(oldpfile,newpfile); +catch + disp('error in aim_exchange_sound_file: parameter file could not be copied'); +end + +% handles.info.current_pcp_module= +handles=do_aim_updateparameters(handles); + +% set the current modules to the new ones, and set ticks if neccessary: +handles=setselection(handles,'pcp',oldhandles.info.current_pcp_module); +handles=setselection(handles,'bmm',oldhandles.info.current_bmm_module); +handles=setselection(handles,'nap',oldhandles.info.current_nap_module); +handles=setselection(handles,'strobes',oldhandles.info.current_strobes_module); +handles=setselection(handles,'sai',oldhandles.info.current_sai_module); +handles=setselection(handles,'usermodule',oldhandles.info.current_usermodule_module); +handles=setselection(handles,'movie',oldhandles.info.current_movie_module); + +% handles=init_aim_gui(handles); + +changepcp=get(handles.checkbox0,'Value') || handles.info.calculate_pcp; +changebmm=get(handles.checkbox1,'Value')|| handles.info.calculate_bmm; +changenap=get(handles.checkbox2,'Value')|| handles.info.calculate_nap; +changestrobes=get(handles.checkbox3,'Value')|| handles.info.calculate_strobes; +changesai=get(handles.checkbox4,'Value')|| handles.info.calculate_sai; +changeusermodule=get(handles.checkbox8,'Value')|| handles.info.calculate_usermodule; +changemovie=get(handles.checkbox5,'Value')|| handles.info.calculate_movie; +if oldhandles.info.pcp_loaded==1 && (handles.info.pcp_loaded==0 || changepcp==1) + handles.info.calculate_pcp=1; + changepcp=1; + set(handles.checkbox0,'Value',1); +end +if oldhandles.info.bmm_loaded==1 && (handles.info.bmm_loaded==0 || changebmm==1 || (handles.info.bmm_loaded==1 && changepcp==1)) + handles.info.calculate_bmm=1; + changebmm=1; + set(handles.checkbox1,'Value',1); +end +if oldhandles.info.nap_loaded==1 && (handles.info.nap_loaded==0 || changenap==1 || (handles.info.nap_loaded==1 && changebmm==1)) + handles.info.calculate_nap=1; + changenap=1; + set(handles.checkbox2,'Value',1); +end +if oldhandles.info.strobes_loaded==1 && (handles.info.strobes_loaded==0 || changestrobes==1|| (handles.info.strobes_loaded==1 && changenap==1)) + handles.info.calculate_strobes=1; + changestrobes=1; + set(handles.checkbox3,'Value',1); +end +if oldhandles.info.sai_loaded==1 && (handles.info.sai_loaded==0 || changesai==1|| (handles.info.sai_loaded==1 && changestrobes==1)) + handles.info.calculate_sai=1; + changesai=1; + set(handles.checkbox4,'Value',1); +end +if oldhandles.info.usermodule_loaded==1 && (handles.info.usermodule_loaded==0 || changeusermodule==1 || (handles.info.usermodule_loaded==1 && changesai==1)) + handles.info.calculate_usermodule=1; + changeusermodule=1; + set(handles.checkbox8,'Value',1); +end +if oldhandles.info.movie_loaded==1 && (handles.info.movie_loaded==0 || changemovie==1 || (handles.info.movie_loaded==1 && changesai==1)) + handles.info.calculate_movie=1; + changemovie=1; + set(handles.checkbox5,'Value',1); +end + +% if the new project has more columns active then the old one, then +% delete the surplus +if oldhandles.info.pcp_loaded ==0 + handles=aim_deletefile(handles,'pcp'); +end +if oldhandles.info.bmm_loaded ==0 + handles=aim_deletefile(handles,'bmm'); +end +if oldhandles.info.nap_loaded ==0 + handles=aim_deletefile(handles,'nap'); +end +if oldhandles.info.strobes_loaded==0 + handles=aim_deletefile(handles,'strobes'); +end +if oldhandles.info.sai_loaded==0 + handles=aim_deletefile(handles,'sai'); +end +if oldhandles.info.usermodule_loaded==0 + handles=aim_deletefile(handles,'usermodule'); +end + + +handles=do_aim_calculate(handles); + +% reset the signal options to the new ones: +handles.all_options.signal=tempoptions.signal; +handles=aim_saveparameters(handles,handles.info.parameterfilename,1); + + +% force the sliders to the same values as before: +handles.slideredit_start=slider_start; +handles.slideredit_duration=slider_duration; +handles.slideredit_scale=slider_scale; +handles.currentslidereditcombi=slider_combi; +handles.slideredit_frames=slider_frames; + +set(handles.checkbox10,'Value',wave_switch); +set(handles.checkbox6,'Value',spectral_switch); +set(handles.checkbox7,'Value',temporal_switch); + +return + + +function handles=setselection(handles,selstr,curmod) +switch selstr + case('pcp') + hand=handles.listbox0; + hand2=handles.checkbox0; + oldnam=handles.info.current_pcp_module; + handles.info.current_pcp_module=curmod; + case('bmm') + hand=handles.listbox1; + hand2=handles.checkbox1; + oldnam=handles.info.current_bmm_module; + handles.info.current_bmm_module=curmod; + case('nap') + hand=handles.listbox2; + hand2=handles.checkbox2; + oldnam=handles.info.current_nap_module; + handles.info.current_nap_module=curmod; + case('strobes') + hand=handles.listbox3; + hand2=handles.checkbox3; + oldnam=handles.info.current_strobes_module; + handles.info.current_strobes_module=curmod; + case('sai') + hand=handles.listbox4; + hand2=handles.checkbox4; + oldnam=handles.info.current_sai_module; + handles.info.current_sai_module=curmod; + case('usermodule') + hand=handles.listbox6; + hand2=handles.checkbox8; + oldnam=handles.info.current_usermodule_module; + handles.info.current_usermodule_module=curmod; + case('movie') + hand=handles.listbox5; + hand2=handles.checkbox5; + oldnam=handles.info.current_movie_module; + handles.info.current_movie_module=curmod; +end +% it the new module is different from the old one, then set the tick +if ~strcmp(oldnam,curmod) + set(hand2,'Value',1); +end + +names=get(hand,'String'); +for i=1:length(names) + if strcmp(names{i},curmod) + set(hand,'Value',i); + return + end +end +return diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_getcurrent_module.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_getcurrent_module.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,77 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% column number +% RETURN VALUE: +% +% +% helping function, that gives back the current selected module for a given +% column number +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,columnnr) + + +switch columnnr + case 2 + options=handles.all_options.pcp; + generating_module=handles.info.current_pcp_module; % this one is selected by the user + handles.info.calculated_pcp_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.pcp',generating_module); + eval(optline); + case 3 + options=handles.all_options.bmm; + generating_module=handles.info.current_bmm_module; + handles.info.calculated_bmm_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.bmm',generating_module); + eval(optline); + case 4 + options=handles.all_options.nap; + generating_module=handles.info.current_nap_module; + handles.info.calculated_nap_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.nap',generating_module); + eval(optline); + case 5 + options=handles.all_options.strobes; + generating_module=handles.info.current_strobes_module; + handles.info.calculated_strobes_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.strobes',generating_module); + eval(optline); + case 6 + options=handles.all_options.sai; + generating_module=handles.info.current_sai_module; + handles.info.calculated_sai_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.sai',generating_module); + eval(optline); + case 7 + options=handles.all_options.usermodule; + generating_module=handles.info.current_usermodule_module; + handles.info.calculated_usermodule_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.usermodule',generating_module); + eval(optline); + case 8 + options=handles.all_options.movie; + generating_module=handles.info.current_movie_module; + handles.info.calculated_movie_module=generating_module; % this one is really calculated + generating_functionline=['options.' generating_module '.generatingfunction']; + eval(sprintf('generating_function=%s;',generating_functionline')); + optline=sprintf('coptions=%s.%s;','handles.all_options.movie',generating_module); + eval(optline); +end \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_getwindowtitle.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_getwindowtitle.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,51 @@ +% procedure for 'aim-mat' +% function namestr=aim_getwindowtitle(handles) +% +% INPUT VALUES: +% RETURN VALUE: +% a string with the current graphics window title +% +% plots the current graphic in the GUI or in the current windowhandle +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function namestr=aim_getwindowtitle(handles) + +modus=[];modul=[]; +str=[handles.info.completesoundfilename]; +op=handles.info.current_plot; +if op>1 + modus='PCP'; + modul=handles.info.current_pcp_module; + str=[str ' - ' modus ': ' modul]; +end +if op>2 + modus='BMM'; + modul=handles.info.current_bmm_module; + str=[str ' - ' modus ': ' modul]; +end +if op>3 + modus='NAP'; + modul=handles.info.current_nap_module; + str=[str ' - ' modus ': ' modul]; +end +if op>4 + modus='STROBES'; + modul=handles.info.current_strobes_module; + str=[str ' - ' modus ': ' modul]; +end +if op>5 + modus='SAI'; + modul=handles.info.current_sai_module; + str=[str ' - ' modus ': ' modul]; +end +if op>6 + modus='USER'; + modul=handles.info.current_usermodule_module; + str=[str ' - ' modus ': ' modul]; +end + +namestr=str; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_gui.fig Binary file aim-mat/gui/aim_gui.fig has changed diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_gui.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_gui.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,717 @@ +% procedure for 'aim-mat' +% function varargout = aim(varargin) +% INPUT VALUES: +% varargin: either a wave-file, a parameter file (m-file) or an +% parameter struct +% RETURN VALUE: +% with a parameter file, the result of the processing, otherwise none +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function varargout = aim(varargin) + +% check the version + +gui_Singleton = 0; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @aim_OpeningFcn, ... + 'gui_OutputFcn', @aim_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); +if nargin && isstr(varargin{1}) + fistletter=varargin{1}(1); +% if ~isempty(str2num(fistletter)) +% disp('matlab does not like wave files that start with numbers. Please change first letter!'); +% return +% end + gui_State.gui_Callback = str2func(varargin{1}); +end + +% something for the eye: +if length(varargin)==1 % only at the first call + fpa=which('gen_gtfb'); % ugly hack to get the graphics... sorry! + [a,b,c]=fileparts(fpa); + where=strfind(a,'modules'); + if ~isempty(where) + columnpath=fpa(1:where+7); + handles.info.columnpath=columnpath; + if ~isstruct(varargin{1})% no box for call with struct + prname=varargin{1}; + prname=prname(1:end-4); + if exist(prname)==7 % is there a directory with the same name? + handles.abouttexttodisplay=sprintf('loading existing project ''%s'' ...',prname); + else + handles.abouttexttodisplay=sprintf('creating new project ''%s'' ...',prname); + end + f=aim_displayaboutbox(handles); + end + end +end +%%%%%%%%%%%%%%%%%%%%%%%%%% +% Aufruf des guis: +if nargout + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); +else + gui_mainfcn(gui_State, varargin{:}); +end +%%%%%%%%%%%%%%%%%%%%%%%%%% +%close the annoying about-box +if exist('f','var') && ishandle(f) + name=get(f,'name'); + if ~isempty(strfind(name,'About')) + close(f); + end +end + + +function aim_OpeningFcn(hObject, eventdata, handles, varargin) +handles.output = hObject; + +verstrst=ver; +nrproducts=length(verstrst); +for i=1:nrproducts + verstr=verstrst(i); + if strcmp(verstr.Name,'MATLAB') % just making sure... + vernr=str2num(verstr.Version); + if vernr<6.5 + str='aim-mat requires MATLAB version 6.5 or higher!'; + disp(str); + er=errordlg(str,'Version error'); + set(er,'WindowStyle','modal'); + return + end + end +end + +% per default we work with graphic +handles.with_graphic=1; +% no error so far +handles.error=0; + + +% handles.screen_modus='paper'; % can be 'screen' or 'paper' - chooses the colors and styles +handles.screen_modus='screen'; % + +if isstruct(varargin{1}) + all_options=varargin{1}; + filename=all_options.signal.signal_filename; + handles.autorun=1; % start running after loading + handles.initial_options=all_options; % start with these options +else + filename=varargin{1}; + handles.autorun=0; % dont start running after loading +end + +% initiate the parameters from an old version or do it new: +handles=init_aim_parameters(handles,filename); +if handles.error==1 + close(handles.figure1); + return +end + +% reset the graphic to standart values: +handles=init_aim_gui(handles); +movegui(handles.figure1,'south'); + +% set the close function to my own +set(handles.figure1,'CloseRequestFcn',{@quitprogram,handles}) + +if handles.autorun==1 + if isfield(handles.initial_options,'pcp') + set(handles.checkbox0,'Value',1); + end + if isfield(handles.initial_options,'bmm') + set(handles.checkbox1,'Value',1); + end + if isfield(handles.initial_options,'nap') + set(handles.checkbox2,'Value',1); + end + if isfield(handles.initial_options,'strobes') + set(handles.checkbox3,'Value',1); + end + if isfield(handles.initial_options,'sai') + set(handles.checkbox4,'Value',1); + end + if isfield(handles.initial_options,'usermodule') + set(handles.checkbox8,'Value',1); + end +end + +% do the changes and go on! +handles=update(hObject, eventdata, handles,2); + +if handles.autorun==1 + old_all_options=handles.all_options; + handles.all_options=all_options; + handles.info.no_automatic_parameter_update=1; + % now tell the info, which modules we want. This is the same routine as + % in the no-grafic version: + + handles.info.calculate_signal=0; + handles.info.calculate_pcp=0; + handles.info.calculate_bmm=0; + handles.info.calculate_nap=0; + handles.info.calculate_strobes=0; + handles.info.calculate_sai=0; + handles.info.calculate_usermodule=0; + handles.info.calculate_movie=0; + % now find out, which column we want to calculate: + if isfield(all_options,'pcp') + handles.info.calculate_pcp=1; + module_names=fieldnames(all_options.pcp); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_pcp_module=module_name; % this one is the current one + handles.all_options.pcp=all_options.pcp; % copy the parameters in place + end + if isfield(all_options,'bmm') + handles.info.calculate_bmm=1; + module_names=fieldnames(all_options.bmm); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_bmm_module=module_name; % this one is the current one + handles.all_options.bmm=all_options.bmm; % copy the parameters in place + end + if isfield(all_options,'nap') + handles.info.calculate_nap=1; + module_names=fieldnames(all_options.nap); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_nap_module=module_name; % this one is the current one + handles.all_options.nap=all_options.nap; % copy the parameters in place + end + if isfield(all_options,'strobes') + handles.info.calculate_strobes=1; + module_names=fieldnames(all_options.strobes); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_strobes_module=module_name; % this one is the current one + handles.all_options.strobes=all_options.strobes; % copy the parameters in place + end + if isfield(all_options,'sai') + handles.info.calculate_sai=1; + module_names=fieldnames(all_options.sai); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_sai_module=module_name; % this one is the current one + handles.all_options.sai=all_options.sai; % copy the parameters in place + end + if isfield(all_options,'usermodule') + handles.info.calculate_usermodule=1; + module_names=fieldnames(all_options.usermodule); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_usermodule_module=module_name; % this one is the current one + handles.all_options.usermodule=all_options.usermodule; % copy the parameters in place + end + if isfield(all_options,'movie') + handles.info.calculate_movie=1; + module_names=fieldnames(all_options.movie); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_movie_module=module_name; % this one is the current one + handles.all_options.movie=all_options.movie; % copy the parameters in place + end + + % up to here copy of nowgrafic. If I ever have time, I think of something + % more elegant + + handles=do_aim_calculate(handles); + handles.all_options=old_all_options; + + if isfield(all_options,'pcp') + result=handles.data.pcp; + end + if isfield(all_options,'bmm') + result=handles.data.bmm; + end + if isfield(all_options,'nap') + result=handles.data.nap; + end + if isfield(all_options,'strobes') + result=handles.data.strobes; + end + if isfield(all_options,'sai') + result=handles.data.sai; + end + if isfield(all_options,'pitch_image') + result=handles.data.pitch_image; + end + if isfield(all_options,'usermodule') + result=handles.data.usermodule; + end + + handles.output=result; + handles=update(hObject, eventdata, handles,2); +end + +function varargout = aim_OutputFcn(hObject, eventdata, handles) +if isfield(handles,'output') + result.result=handles.output; + result.error=0; + result.all_options=handles.all_options; + result.info=handles.info; + % copy all data to the output, it is usefull sometimes! + if isfield(handles.info,'no_automatic_parameter_update') + if isfield(handles.all_options,'pcp') + result.result=handles.data.pcp; + end + if isfield(handles.all_options,'bmm') + result.result=handles.data.bmm; + end + if isfield(handles.all_options,'nap') + result.result=handles.data.nap; + end + if isfield(handles.all_options,'strobes') + result.result=handles.data.strobes; + end + if isfield(handles.all_options,'sai') + result.result=handles.data.sai; + end + if isfield(handles.all_options,'usermodule') + result.result=handles.data.usermodule; + end + end + + varargout{1} = result; +end + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Menufunktions %%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function exit_Callback(hObject, eventdata, handles) +quitprogram(hObject, eventdata, handles); +function about_Callback(hObject, eventdata, handles) +aim_displayaboutbox(handles); +function file_Callback(hObject, eventdata, handles) +function help_Callback(hObject, eventdata, handles) + +% load a new sound +function loadsound_Callback(hObject, eventdata, handles) +[signame,dirname]=uigetfile('*.wav'); +if ~isnumeric(dirname) + cd(dirname); + if fexist(signame) + handles=init_aim_parameters(handles,signame); + handles=init_aim_gui(handles); + else + return + end +else + return +end +handles=update(hObject, eventdata, handles,2); + +% exchange the soundfile and keep the rest +function exchange_Callback(hObject, eventdata, handles) +[signame,dirname]=uigetfile('*.wav'); +if ~isnumeric(dirname) + cd(dirname); + if fexist(signame) + handles=aim_exchange_sound_file(handles,signame); + % handles=init_aim_gui(handles); + else + return + end +else + return +end +handles=update(hObject, eventdata, handles,2); + + + +function edit_Callback(hObject, eventdata, handles) +function opencool_Callback(hObject, eventdata, handles) +wavename=sprintf('%s/%s',pwd,handles.info.signalwavename); +if ispc + winopen(wavename); +else + disp('sorry, cant open external file in unix...'); +end + +function internethelp_Callback(hObject, eventdata, handles) +helpname=sprintf('%shelp.html',handles.info.columnpath); +if ispc + winopen(helpname); +else + disp('sorry, cant open external file in unix...'); +end + +function Untitled_1_Callback(hObject, eventdata, handles) +function sptool_Callback(hObject, eventdata, handles) +sig=handles.data.signal; +adaptedspecgramdemo(getvalues(sig),getsr(sig)); + + + +%%%%%%% save standalone parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function saveasparameters_Callback(hObject, eventdata, handles) +[fname,dirname]=uiputfile('*.m','Save stand alone parameter file'); +if isempty(strfind(fname,'.m')) + fname=[fname '.m']; +end +filename=fullfile(dirname,fname); +aim_saveparameters(handles,filename,0); % the 0 indicates, that only the relevant parameters are important + +%%%%%%% open personal default file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function open_personal_Callback(hObject, eventdata, handles) +edit('personal_defaults.m'); + +%%%%%%% open current generating function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function edit_genfunc_Callback(hObject, eventdata, handles) +[generating_module,generating_function,coptions]=aim_getcurrent_module(handles,handles.info.current_plot); +edit(generating_function); + + +%%%%%%% edit parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function edit_params_Callback(hObject, eventdata, handles) +dir=handles.info.original_soundfile_directory; +filename=fullfile(dir,handles.info.parameterfilename); +edit(filename); +%%%%%%% diaplay versions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function version_Callback(hObject, eventdata, handles) +aim_display_versions(handles); + +function copydata_Callback(hObject, eventdata, handles) +assignin('base','data',handles.data); +assignin('base','info',handles.info); + +% select the start point and the end point of the signal +function select_time_Callback(hObject, eventdata, handles) +oldoptions=handles.all_options.signal; +sig=handles.data.original_signal; +% out=adaptedspecgramdemo(getvalues(sig),getsr(sig),oldoptions.start_time,oldoptions.start_time+oldoptions.duration); +% handles.all_options.signal.start_time=out.start; +% handles.all_options.signal.duration=out.duration; + +current_start=handles.all_options.signal.start_time; +current_duration=handles.all_options.signal.duration; +allowed_duration=handles.all_options.signal.original_duration; +text{1}=''; +text{2}=''; + +[start,duration]=length_questionbox(current_start,current_duration,allowed_duration,text); +handles.all_options.signal.start_time=start; +handles.all_options.signal.duration=duration; + +if ~structisequal(oldoptions,handles.all_options.signal) + aim_saveparameters(handles,handles.info.parameterfilename,1); % save the new parameters to the file + % handles.info.calculate_signal=1; + handles.all_options.signal=oldoptions; % tell him to use the new ones! + handles=do_aim_updateparameters(handles); + % handles=do_aim_calculate(handles); + handles=update(hObject, eventdata, handles,4); +end + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% PushButtons %%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%% play sound %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function pushbutton23_Callback(hObject, eventdata, handles) +play(handles.data.signal); +% signal +function pushbutton22_Callback(hObject, eventdata, handles) +handles.info.current_plot=1; +handles=update(hObject, eventdata, handles,4); +%pcp +function pushbutton0_Callback(hObject, eventdata, handles) +handles.info.current_plot=2; +if get(handles.checkbox0,'Value')==1 + handles=do_aim_calculate(handles); +end +handles=update(hObject, eventdata, handles,4); +% bmm +function pushbutton2_Callback(hObject, eventdata, handles) +handles.info.current_plot=3; +if get(handles.checkbox1,'Value')==1 + handles=do_aim_calculate(handles); +end +handles=update(hObject, eventdata, handles,4); +% nap +function pushbutton3_Callback(hObject, eventdata, handles) +handles.info.current_plot=4; +if get(handles.checkbox2,'Value')==1 + handles=do_aim_calculate(handles); +end +handles=update(hObject, eventdata, handles,4); +% strobes +function pushbutton4_Callback(hObject, eventdata, handles) +handles.info.current_plot=5; +if get(handles.checkbox3,'Value')==1 + handles=do_aim_calculate(handles); +end +handles=update(hObject, eventdata, handles,4); +% sai +function pushbutton5_Callback(hObject, eventdata, handles) +handles.info.current_plot=6; +if get(handles.checkbox4,'Value')==1 + handles=do_aim_calculate(handles); +end +sai=handles.data.sai; +nr_chan=getnrchannels(sai{1}); +if nr_chan==1 + set(handles.checkbox6,'Value',0); %switch off frequency profile + set(handles.checkbox7,'Value',0); %switch off temporal profile +else + set(handles.checkbox6,'Value',1); %switch on frequency profile + set(handles.checkbox7,'Value',1); %switch on temporal profile +end +handles=update(hObject, eventdata, handles,4); +% usermodule +function pushbutton21_Callback(hObject, eventdata, handles) +handles.info.current_plot=7; +if get(handles.checkbox8,'Value')==1 + handles=do_aim_calculate(handles); +end +handles=update(hObject, eventdata, handles,2); +% movie +function pushbutton6_Callback(hObject, eventdata, handles) +if get(handles.checkbox5,'Value')==1 + handles=do_aim_calculate(handles); +end +% generating_module_string=get(handles.listbox5,'String'); +% generating_module=generating_module_string(get(handles.listbox5,'Value')); +% generating_module=generating_module{1}; +% uniqueworkingname=handles.info.uniqueworkingname; +directoryname=handles.info.directoryname; +% moviename=sprintf('%s/%s/%s.%s.mov',pwd,directoryname,uniqueworkingname,generating_module); + +handles=update(hObject, eventdata, handles,2); + +moviename=fullfile(pwd,directoryname,handles.info.last_movie_name_generated); +if ispc + winopen(moviename); +else + disp('sorry, cant open external file in unix...'); +end + +% autoscale +function pushbuttonautoscale_Callback(hObject, eventdata, handles) +handles=do_aim_autoscale(handles); +handles=update(hObject, eventdata, handles,1); + +% update +function pushbutton25_Callback(hObject, eventdata, handles) +handles=do_aim_updateparameters(handles); +handles=update(hObject, eventdata, handles,2); + + + +% single channel +function pushbutton24_Callback(hObject, eventdata, handles) +if ~isfield(handles.info,'children') + fig=figure; + handles.info.children.single_channel.windowhandle=fig; +else + figure(handles.info.children.single_channel.windowhandle) +end + +single_channel_gui(handles); +guidata(hObject, handles); + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Listboxes %%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function listbox0_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function listbox1_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function listbox2_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function listbox3_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function listbox4_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function listbox5_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function listbox6_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end + +% pcp +function listbox0_Callback(hObject, eventdata, handles) +% TODO: +% oldmodule=handles.info.current_pcp_module; +set(handles.checkbox0,'Value',1); % set the tick to indicate, that it has changed +handles=update(hObject, eventdata, handles,3); +% newmodule=handles.info.current_pcp_module; +% if strcmp(oldmodule,newmodule) +% set(handles.checkbox0,'Value',0); % remove the tick again +% end +% bmm +function listbox1_Callback(hObject, eventdata, handles) +set(handles.checkbox1,'Value',1); +handles=update(hObject, eventdata, handles,5); +% nap +function listbox2_Callback(hObject, eventdata, handles) +set(handles.checkbox2,'Value',1); +handles=update(hObject, eventdata, handles,5); +% strobes +function listbox3_Callback(hObject, eventdata, handles) +set(handles.checkbox3,'Value',1); +handles=update(hObject, eventdata, handles,5); +% sai +function listbox4_Callback(hObject, eventdata, handles) +set(handles.checkbox4,'Value',1); +handles=update(hObject, eventdata, handles,5); +%usermodule +function listbox6_Callback(hObject, eventdata, handles) +set(handles.checkbox8,'Value',1); +handles=update(hObject, eventdata, handles,5); +% movie +function listbox5_Callback(hObject, eventdata, handles) +set(handles.checkbox5,'Value',1); +handles=update(hObject, eventdata, handles,5); + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Checkboxes %%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%pcp +function checkbox0_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,1); +handles=update(hObject, eventdata, handles,3); +%bmm +function checkbox1_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,2); +handles=update(hObject, eventdata, handles,3); +%nap +function checkbox2_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,3); +handles=update(hObject, eventdata, handles,3); +%strobes +function checkbox3_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,4); +handles=update(hObject, eventdata, handles,3); +%sai +function checkbox4_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,5); +handles=update(hObject, eventdata, handles,3); +% usermodule +function checkbox8_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,6); +handles=update(hObject, eventdata, handles,3); +%movies +function checkbox5_Callback(hObject, eventdata, handles) +handles=aim_updatecheckboxes(hObject, eventdata, handles,7); +handles=update(hObject, eventdata, handles,3); + +% show the time waveform on top +function checkbox10_Callback(hObject, eventdata, handles) +handles=update(hObject, eventdata, handles,2); +function checkbox6_Callback(hObject, eventdata, handles) +handles=update(hObject, eventdata, handles,2); +%show interval profile +function checkbox7_Callback(hObject, eventdata, handles) +handles=update(hObject, eventdata, handles,2); + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Sliders %%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function slider1_CreateFcn(hObject, eventdata, handles) +usewhitebg = 1;if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]);else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function slider2_CreateFcn(hObject, eventdata, handles) +usewhitebg = 1;if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]);else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function slider3_CreateFcn(hObject, eventdata, handles) +usewhitebg = 1;if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]);else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end + +function slider1_Callback(hObject, eventdata, handles) +handles=slider_scale(hObject, eventdata, handles); +handles=update(hObject, eventdata, handles,1); + +function slider2_Callback(hObject, eventdata, handles) +handles=slider_start(hObject, eventdata, handles); +handles=update(hObject, eventdata, handles,1); + +function slider3_Callback(hObject, eventdata, handles) +handles=slider_duration(hObject, eventdata, handles); +handles=update(hObject, eventdata, handles,1); + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Edits %%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function edit1_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function edit2_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function edit3_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end + +function edit1_Callback(hObject, eventdata, handles) +handles=edit_scale(hObject, eventdata, handles); +handles=update(hObject, eventdata, handles,1); +function edit2_Callback(hObject, eventdata, handles) +handles=edit_start(hObject, eventdata, handles); +handles=update(hObject, eventdata, handles,1); +function edit3_Callback(hObject, eventdata, handles) +handles=edit_duration(hObject, eventdata, handles); +handles=update(hObject, eventdata, handles,1); + + +function handles=update(hObject, eventdata, handles,action) + +% check, if the singlechannel window was closed: (this is here, because it +% is checked most often +if isfield(handles.info,'children') + if ~ishandle(handles.info.children.single_channel.windowhandle) + rmfield(handles.info.children,'single_channel'); + end +end + +handles.calling_object=hObject; + +if action>1 + handles=aim_updategui(handles); +end + +% if we want to see the interval profile: + +if get(handles.checkbox7,'Value')==1 + options.withtime=true; +else + options.withtime=false; +end +% and if we want to see the frequency profile: +if get(handles.checkbox6,'Value')==1 + options.withfre=islogical(true); +else + options.withfre=islogical(0); +end +% do we want to see the signal? +if get(handles.checkbox10,'Value')==1 + options.withsignal=islogical(true); +else + options.withsignal=islogical(0); +end +% if there has never been a figure, create a new one +if ~isfield(handles.info,'current_figure') + handles.info.current_figure=figure; +end +options.figure_handle=handles.info.current_figure; + +switch action + case {1,2} + handles=aim_replotgraphic(handles,options); + aim_savecurrentstate(handles);% save the state of the project and the window to a file + guidata(hObject, handles); + case 3 + aim_savecurrentstate(handles);% save the state of the project and the window to a file + guidata(hObject, handles); + case 4 % everything with autoscale (for click on button) + handles=do_aim_autoscale(handles); + handles=aim_replotgraphic(handles,options); + aim_savecurrentstate(handles);% save the state of the project and the window to a file + guidata(hObject, handles); + case 5 + guidata(hObject, handles); +end + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_loadcurrentstate.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_loadcurrentstate.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,97 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_loadcurrentstate(handles) +% save some crucial information to a file + +% standart setting, that prevent followup errors: +handles.info.init.start_time=0; +handles.info.init.duration=0.04; +handles.info.init.scale=1; +handles.info.current_figure=1; +handles.info.current_plot=1; +handles.info.init.hastime=0; +handles.info.init.hasfreq=0; +handles.info.init.hassignal=0; + +if isfield(handles.info,'projectfilename') + projectfilename=handles.info.projectfilename; + if exist(projectfilename)==2 + olddir=pwd; + cd(handles.info.directoryname); + [pathstr,name,ext] = fileparts(projectfilename); + eval(name); + cd(olddir); + + try + % test if the current plot can be presented, or if it was maybe + % deleted in between. In this case set the current_plot to + % something resonable + if current_plot >6 && ~handles.info.usermodule_loaded + current_plot=6; start_time=0; + end + if current_plot > 5 && ~handles.info.sai_loaded + current_plot=5; start_time=0; + end + if current_plot > 4 && ~handles.info.strobes_loaded + current_plot=4; start_time=0; + end + if current_plot > 3 && ~handles.info.nap_loaded + current_plot=3; start_time=0; + end + if current_plot > 2 && ~handles.info.bmm_loaded + current_plot=2; start_time=0; + end + handles.info.current_plot=current_plot; + + handles.info.init.start_time=start_time; + handles.info.init.duration=duration; + handles.info.init.scale=scale; + + oldsize=get(handles.figure1,'Position'); + pos(1)=winx; + pos(2)=winy; + pos(3)=oldsize(3); + pos(4)=oldsize(4); + set(handles.figure1,'Position',pos); + + gpos(1)=grafixwinx; + gpos(2)=grafixwiny; + gpos(3)=grafixwinb; + gpos(4)=grafixwinh; + gnr=grafixwinnr; + figure(gnr); + clf; + set(gnr,'Position',gpos); + handles.info.current_figure=gnr; + + + if exist('hastime','var') + handles.info.init.hastime=hastime; + else + handles.info.init.hastime=0; + end + if exist('hasfreq','var') + handles.info.init.hasfreq=hasfreq; + else + handles.info.init.hasfreq=0; + end + if exist('hassignal','var') + handles.info.init.hassignal=hassignal; + else + handles.info.init.hassignal=0; + end + catch + disp('non fatal problem in reading the project file. Continue...'); + end + end +end diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_loadfile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_loadfile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,69 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function [loadobject,type,options]=aim_loadfile(name) +% load the nap and its options + + +load(name); +whodir=who; +loadobject=[]; +for i=1:length(whodir) + if ~strcmp(whodir(i),'name') + eval(sprintf('classstruct=%s.data;',whodir{i})); + eval(sprintf('options=%s.options;',whodir{i})); + try + eval(sprintf('type=%s.type;',whodir{i})); + catch + type=[]; + end + if strcmp(whodir(i),'strobes') | strcmp(whodir(i),'strobestruct') | strcmp(whodir(i),'usermodule') + loadobject=classstruct; + else + % construct the frame from whatever (sometimes the object is not recognised + % as object due to the version ??) + if isobject(classstruct) + loadobject=classstruct; + else + nr=length(classstruct); + if nr==1 + switch type + case 'sai' + loadobject=frame(classstruct); + case 'frame' + loadobject=frame(classstruct); + case 'spiral' + loadobject=spiral(classstruct); + otherwise + loadobject=classstruct; + end + else + for i=1:nr + switch type + case 'sai' + loadobject{i}=frame(classstruct{i}); + case 'frame' + loadobject{i}=frame(classstruct{i}); + case 'spiral' + loadobject{i}=spiral(classstruct{i}); + otherwise + loadobject{i}=classstruct{i}; + end + end + end + end + end + end +end + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_loadpersonal_defaults.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_loadpersonal_defaults.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,105 @@ +% procedure for 'aim-mat' +%function handles=aim_loadpersonal_defaults(handles) +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_loadpersonal_defaults(handles) +% loads the file 'personal_defaults' from the current directory +% each personal default setting for a parameter must come in the complete +% parameter format +% e.g. +% + +if exist('personal_defaults.m','file') + + all_options=handles.all_options; + + try + personal_defaults; % evaluates the file and overwrites the + catch + disp('aim_loadpersonal_defaults: errors in reading in the personal_defaults.m'); + return + end + % if OK, then overwrite the parameters: + handles.all_options=all_options; + + + if exist('default_module_pcp','var')==1 + handles=setselection(handles,'pcp',default_module_pcp); + handles.info.default_start_module_pcp=default_module_pcp; + end + if exist('default_module_bmm','var')==1 + handles=setselection(handles,'bmm',default_module_bmm); + handles.info.default_start_module_bmm=default_module_bmm; + end + if exist('default_module_nap','var')==1 + handles=setselection(handles,'nap',default_module_nap); + handles.info.default_start_module_nap=default_module_nap; + end + if exist('default_module_strobes','var')==1 + handles=setselection(handles,'strobes',default_module_strobes); + handles.info.default_start_module_strobes=default_module_strobes; + end + if exist('default_module_sai','var')==1 + handles=setselection(handles,'sai',default_module_sai); + handles.info.default_start_module_sai=default_module_sai; + end + if exist('default_module_usermodule','var')==1 + handles=setselection(handles,'usermodule',default_module_usermodule); + handles.info.default_start_module_usermodule=default_module_usermodule; + end + if exist('default_module_movie','var')==1 + handles=setselection(handles,'pcp',default_module_pcp); + handles.info.default_start_module_pcp=default_module_pcp; + end + if exist('default_module_pcp','var')==1 + handles=setselection(handles,'movie',default_module_movie); + handles.info.default_start_module_movie=default_module_movie; + end +end + +function handles=setselection(handles,selstr,curmod) +switch selstr + case('pcp') + hand=handles.listbox0; + handles.info.current_pcp_module=curmod; + case('bmm') + hand=handles.listbox1; + handles.info.current_bmm_module=curmod; + case('nap') + hand=handles.listbox2; + handles.info.current_nap_module=curmod; + case('strobes') + hand=handles.listbox3; + handles.info.current_strobes_module=curmod; + case('sai') + hand=handles.listbox4; + handles.info.current_sai_module=curmod; + case('usermodule') + hand=handles.listbox6; + handles.info.current_usermodule_module=curmod; + case('movie') + hand=handles.listbox5; + handles.info.current_movie_module=curmod; +end + +names=get(hand,'String'); +for i=1:length(names) + if strcmp(names{i},curmod) + set(hand,'Value',i); + return + end +end +return + + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_loadproject.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_loadproject.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,214 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% load the signal file and all files, that are in this directory +% set the project variables accordingly. +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function handles=aim_loadproject(handles,signame); + + +signalname=handles.info.signalname; +signalwavename=handles.info.signalwavename; +oldsignalwavename=handles.info.oldsignalwavename; +pcpname=handles.info.pcpname; +bmmname=handles.info.bmmname; +napname=handles.info.napname; +strobesname=handles.info.strobesname; +thresholdsname=handles.info.thresholdsname; +sainame=handles.info.sainame; +usermodulename=handles.info.usermodulename; + + +was_conflict=0; +% load the parameterfile (and apply the parameters) +if exist(handles.info.parameterfilename,'file') + workdir=pwd; + cd(handles.info.directoryname); + [a,parfile,c,d]=fileparts(handles.info.parameterfilename); + clear all_options; + new_options=handles.all_options; + + try % desperate... + eval(parfile); % this produces all_options as 'all_options' + [new_options,conflicts]=aim_mixstruct(all_options,new_options); + + handles.info.conflicts=conflicts; + handles.all_options=new_options; + cd(workdir); + if ~structisequal(new_options,all_options) + aim_saveparameters(handles,handles.info.parameterfilename); + end + catch + %lasterror + disp('problems with reading in old parameter file. Check parameters manually!'); + disp('A common reason for this error is that you have included a new module without a ''revision'' parameter:'); + disp('See the parameters file of one of the distributed modules for a template'); + % new_options=all_options; + conflicts='problem reading in parameter file. Check parameters!'; + cd(workdir); + was_conflict=1; + end +else + was_conflict=1; +end + +if exist(signalname,'var') + [sig,type,sigoptions]=aim_loadfile(signalname); + handles.data.signal=sig; + if ~isempty(sigoptions) + handles.all_options.signal=sigoptions; + handles.data.original_signal=loadwavefile(signal,handles.info.signalwavename); + else + handles.all_options.signal.start_time=0; + handles.all_options.signal.duration=getlength(sig); + handles.all_options.signal.samplerate=getsr(sig); + handles.all_options.signal.original_start_time=0; + handles.all_options.signal.original_duration=getlength(sig); + handles.all_options.signal.original_samplerate=getsr(sig); + % for old projects + if exist(handles.info.originalwavename) + handles.data.original_signal=loadwavefile(signal,handles.info.originalwavename); + else + handles.data.original_signal=loadwavefile(signal,handles.info.signalwavename); + end + end + + % put the original signal in its place: +else + % cant continue without signal! + str=sprintf('No signal-object found in the project %s',signalname); + er=errordlg(str,'File Error'); + set(er,'WindowStyle','modal'); + handles.error=1; + return +end + +if fexist(pcpname) + [pcp,type,options]=aim_loadfile(pcpname); + handles.data.pcp=pcp; + handles.info.pcp_loaded=1; + handles.info.calculated_pcp_module=type; % this one is really calculated +% select(handles.listbox0,type); + if ~isempty(type) + str=sprintf('handles.all_options.pcpoptions.%s=options;',type); + eval(str); + else % old style + type='ELC'; + handles.all_options.pcpoptions=options; + sai_savefile(pcp,pcpname,type,options,handles.all_options); + end + handles.info.init.calculated_pcp_module=type; +else + handles.info.pcp_loaded=0; +end + +if fexist(bmmname) + [bmm,type,options]=aim_loadfile(bmmname); + handles.data.bmm=bmm; + handles.info.bmm_loaded=1; + handles.info.calculated_bmm_module=type; % this one is really calculated + +% select(handles.listbox1,type); + handles.info.init.calculated_bmm_module=type; + +else + handles.info.bmm_loaded=0; +end +if fexist(napname) + [nap,type,options]=aim_loadfile(napname); + handles.data.nap=nap; + handles.info.nap_loaded=1; +% select(handles.listbox2,type); + handles.info.init.calculated_nap_module=type; + +else + handles.info.nap_loaded=0; +end +if fexist(strobesname) + [strobes,type,options]=aim_loadfile(strobesname); + if fexist(thresholdsname) + thresholds=aim_loadfile(thresholdsname); + handles.data.thresholds=thresholds; + end + handles.data.strobes=strobes; + handles.info.strobes_loaded=1; + handles.info.calculated_strobes_module=type; % this one is really calculated +% select(handles.listbox3,type); + handles.info.init.calculated_strobes_module=type; +else + handles.info.strobes_loaded=0; +end + +if fexist(sainame) + [sai,type,options]=aim_loadfile(sainame); + handles.data.sai=sai; + handles.info.sai_loaded=1; + handles.info.calculated_sai_module=type; % this one is really calculated +% select(handles.listbox4,type); + handles.info.init.calculated_sai_module=type; + + nr_frames=length(sai); + handles.slideredit_frames.minvalue=1; + handles.slideredit_frames.maxvalue=nr_frames; + % set the framecounter +% handles.slideredit_frames=slidereditcontrol_set_value(handles.slideredit_frames,nr_frames); % set to the end +% handles.slideredit_frames=slidereditcontrol_set_range(handles.slideredit_frames,nr_frames); % the duration + +else + handles.info.sai_loaded=0; +end + +if fexist(usermodulename) + [usermodule,type,options]=aim_loadfile(usermodulename); + handles.data.usermodule=usermodule; + handles.info.usermodule_loaded=1; + handles.info.calculated_usermodule_module=type; % this one is really calculated + handles.info.init.calculated_usermodule_module=type; + +% select(handles.listbox6,type); + handles.info.usermodule_loaded=1; +else + handles.info.usermodule_loaded=0; +end + +% TODO: only the first available movie is loaded. The others not +handles.info.movie_loaded=0; +% if length(moviename)>1 +% for i=1:length(moviename) +% cname=moviename{i}; +% if fexist(cname) +% handles.info.movie_loaded=1; +% handles.info.calculated_movie_module=cname; % this one is really calculated +% handles.info.init.calculated_movie_module=type; +% break +% end +% end +% end + + +if was_conflict==1 + disp('parameter file does not exist. Taking standart parameters. Check parameters manually!'); + disp('saving standart parameters as new parameter file'); + handles=aim_saveparameters(handles,handles.info.parameterfilename,1); +end + + +function select(hand,what) +str=get(hand,'String'); +for i=1:length(str) + if strcmp(str,what) + set(hand,'Value',i); + return + end +end +return + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_loadsignalfile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_loadsignalfile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,99 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% load the signal file and all files, that are in this directory +% set the project variables accordingly. +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_loadsignalfile(handles,signalwavename) + +% load the signal file (we know, that it is there +sig=loadwavefile(signal,signalwavename); + +% first save the original signal as a copy +savewave(sig,handles.info.originalwavename,0); + + +len=getlength(sig); +if len<0.04 + disp('Signal is too short (<40ms)! padding it with zeros automatically'); + sig=expand(sig,0.04,0) +end + + +handles.info.signal_loaded=1; % it is now loaded! + +if handles.autorun==0 % only, when not called with a data structure + % we add these parameters to the parameter file + handles.all_options.signal.signal_filename=handles.info.oldsignalwavename; + handles.all_options.signal.start_time=0; + handles.all_options.signal.duration=getlength(sig); + handles.all_options.signal.samplerate=getsr(sig); + +% % prevent user to choose too long singals, because they are too slow +% % usually we only want a part of the signal +% max_allowed_duration=0.2; +% if getlength(sig) > max_allowed_duration +% text{1}='The signal is longer then 200 ms'; +% text{2}='So the model will run rather slowly.'; +% current_start=0; +% current_duration=getlength(sig); +% allowed_duration=getlength(sig); +% [new_start_time,new_duration]=length_questionbox(current_start,current_duration,allowed_duration,text); +% if new_start_time~=0; +% handles.all_options.signal.start_time=new_start_time; +% end +% if new_duration~=getlength(sig); +% handles.all_options.signal.duration=new_duration; +% end +% end +% + + handles.all_options.signal.original_start_time=0; + handles.all_options.signal.original_duration=getlength(sig); + handles.all_options.signal.original_samplerate=getsr(sig); + +end + +% save it to the data structure +name=handles.info.signalname; +aim_savefile(handles,sig,name,'signal','signal',handles.all_options.signal,handles.all_options) +handles.data.original_signal=sig; +handles.data.signal=sig; + + +if handles.autorun==0 % only, when not called with a data structure + % if the samplerate is too high, sample it down per default + max_allowed_sr=25000; + if getsr(sig) > max_allowed_sr + new_sr=sr_questionbox(getsr(sig)); + if new_sr~=getsr(sig); + sig=changesr(sig,new_sr); % this does the resampling + handles.all_options.signal.samplerate=new_sr; + signalstruct.data=sig; + handles.data.original_signal=sig; + handles.data.signal=sig; + end + + % % ask user if he wants that hi sample rate + % srneu=input('The samplerate of the specified signal \nis higher then 22050 Hz. \nPlease insert a smaller samperate \n(or return for keeping the old one): '); + % if ~isempty(srneu) + % end + end +end + +% the signal must not be changed at the moment +handles.info.calculate_signal=0; + +% and save the signal in the new directory +savewave(sig,handles.info.signalwavename,0); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_mixstruct.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_mixstruct.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,145 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% mix the parts of old_struct with the parts of add_struct +% old entries in old_struct with identical names are overwritten with the entries +% from add_struct +% works recursive up to the second layer +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function [new_struct,conflicts]=mixstruct(old_struct,add_struct) +% old_struct is the original structure +% add_struct is the new struct, that can have new options +% a warning is given, if a module doesnt exist any more +% and these options are removed from the parameter file. +% +% new parameters are added to the old parameters for each module + + +conflicts=[]; +conflict_counter=1; + +newcolumns=fieldnames(add_struct); + +new_struct=old_struct; + +for i=1:length(newcolumns) + curr_col=newcolumns{i}; + if ~strcmp(curr_col,'signal') + if ~isfield(old_struct,curr_col) % add whole new fields from the new struct + est=sprintf('new_struct.%s=add_struct.%s;',curr_col,curr_col); + eval(est); + else % its already there, but not neccessarily up to date + eval(sprintf('old_columns=old_struct.%s;',curr_col)); + eval(sprintf('new_columns=add_struct.%s;',curr_col)); + old_modules=fieldnames(old_columns); + new_modules=fieldnames(new_columns); + + + for j=1:length(new_modules) + if ~isfield(old_columns,new_modules{j}) % add whole new module + est=sprintf('new_struct.%s.%s=new_columns.%s;',curr_col,new_modules{j},new_modules{j}); + eval(est); + constr=sprintf('conflicts{%d}=''new module added: %s %s'';',conflict_counter,newcolumns{i},new_modules{j}); + eval(constr);conflict_counter=conflict_counter+1; + else % both are there, but check the versions + if ~strcmp(newcolumns{i},'signal') && ~strcmp(newcolumns{i},'graphics') + ver1str=sprintf('ver1=old_struct.%s.%s.revision;',newcolumns{i},new_modules{j}); + try % old version + eval(ver1str); + ver11=ver2num(ver1); + catch + constr=sprintf('conflicts{%d}=''old module had no revision number: module: %s.%s'';',conflict_counter,newcolumns{i},new_modules{j}); + eval(constr);conflict_counter=conflict_counter+1; +% ver11='no version'; + ver11=-1; + %ver12=-1; + end + ver2str=sprintf('ver2=add_struct.%s.%s.revision;',newcolumns{i},new_modules{j}); + try % new version + eval(ver2str); + ver21=ver2num(ver2); + catch + ver2='no version'; + constr=sprintf('conflicts{%d}=''loaded newer version on module: %s.%s (current version: no version)'';',conflict_counter,newcolumns{i},new_modules{j}); + eval(constr);conflict_counter=conflict_counter+1; + end +% if isnumeric(ver11) && isnumeric(ver12) && isnumeric(ver21) && isnumeric(ver22) + if ver21>ver11 %|| (ver21==ver11 && ver22>ver12) + constr=sprintf('conflicts{%d}=''module %s.%s loaded with higher version number (old: %d.%d new: %d.%d)'';',conflict_counter,newcolumns{i},new_modules{j},ver11,ver12,ver21,ver22); + eval(constr);conflict_counter=conflict_counter+1; + end + if ver21=6 + sai=handles.data.sai; + if handles.with_graphic==0 + current_frame_number=handles.current_frame_nr; + else + current_frame_number=round(slidereditcontrol_get_value(handles.currentslidereditcombi)); + end + if current_frame_number<=length(sai) && current_frame_number>0 + start_time=getcurrentframestarttime(sai{current_frame_number}); + else + start_time=getminimumtime(sig); + current_frame_number=1; % error! + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,length(sai)); + end + duration=getlength(sai{current_frame_number}); +else + start_time=slidereditcontrol_get_value(handles.currentslidereditcombi); + duration=slidereditcontrol_get_value(handles.slideredit_duration); +end +stop_time=start_time+duration; + +% in case of auditory image, we simply want the last part of the signal: +if stop_time>getmaximumtime(sig); + start_time=getmaximumtime(sig)-duration; + stop_time=getmaximumtime(sig); +end +if start_time < getminimumtime(sig) + start_time =getminimumtime(sig); +end +% sig=getpart(sig,start_time,stop_time); + + +% The signal window +if withsignal + set(myaxes1,'Visible','on'); + axes(myaxes1); + % sig=getpart(sig,start_time,stop_time); + if strcmp(handles.screen_modus,'paper') + h=plot(sig,[start_time stop_time],myaxes1); + set(h,'Color','k'); + set(h,'LineWidth',1.5); + else + plot(sig,[start_time stop_time],myaxes1); + end + if min(sig)==0 % for niceness: Clicktrains are cut away otherwise + ax=axis; + ax(3)=-0.1; + axis(ax); + end + title('');set(gca,'XTick',[]);set(gca,'YTick',[]);xlabel('');ylabel(''); +end + + + +% from here: plot in axes2: +% axes(myaxes2); +set(myaxes2,'XDir','normal') +set(myaxes2,'XScale','lin'); +if handles.with_graphic==1 + current_scale=slidereditcontrol_get_value(handles.slideredit_scale); +else + current_scale=options.data_scale; +end + +switch current_plot + case {-1,0,1} % signal + set(myaxes2,'Visible','off'); + case 2% pcp + sig=handles.data.pcp; +% current_frame=getpart(sig,start_time,stop_time); + ca=plot(sig,[start_time stop_time]); + set(gca,'YTick',[]); + ax=axis; + ax(3)=ax(3)/current_scale; + ax(4)=ax(4)/current_scale; + axis(ax); + title('');xlabel('');ylabel(''); + case 3% bmm + current_frame=handles.data.bmm; + str=get_graphics_options(handles,handles.info.current_bmm_module); + str.minimum_time_interval=start_time; + str.maximum_time_interval=stop_time; + nrchan=getnrchannels(handles.data.bmm); + if do_single_channel || nrchan==1 + sig=getsinglechannel(current_frame,options.display_single_channel); +% sig=getpart(sig,start_time,stop_time); + ymin=min(current_frame)*1.1;ymax=max(current_frame)*1.1; + plot(sig,[start_time stop_time ymin ymax]); + set(gca,'Ylim',[ymin,ymax]);set(gca,'YAxisLocation','right'); + xlabel('time (ms)');ylabel('amplitude');title(''); + else + hand=plot(current_frame,str); + zmin=min(current_frame)/current_scale;zmax=max(current_frame)/current_scale; + + %set(gca,'Zlim',[zmin,zmax]); + + %TCW AIM 2006 + if hand_scaling == 1 + set(gca,'Zlim',[0,1/current_scale]); + else + %TCW AIM 2006 to get this frequency axis correct, this lower + %limit of the z axis really needs to be zero + set(gca,'Zlim',[0,zmax]); + end + + xlabel('time (ms)');ylabel('Frequency (kHz)');title(''); + if strcmp(handles.screen_modus,'paper') + par=get(hand,'parent'); + set(par,'FontSize',12);xlab=get(par,'xlabel');set(xlab,'FontSize',12);ylab=get(par,'ylabel');set(ylab,'FontSize',12); + end + end + case 4% nap + current_frame=handles.data.nap; + str=get_graphics_options(handles,handles.info.current_nap_module); + str.minimum_time_interval=start_time; + str.maximum_time_interval=stop_time; + nrchan=getnrchannels(current_frame); + if do_single_channel || nrchan==1 + sig=getsinglechannel(current_frame,options.display_single_channel); +% sig=getpart(sig,start_time,stop_time); + ymin=0; + ymax=max(current_frame)*1.1; + plot(sig,[start_time stop_time]); + set(gca,'Ylim',[ymin,ymax]);set(gca,'YAxisLocation','right'); + xlabel('time (ms)');ylabel('amplitude');title(''); + else + hand=plot(current_frame,str); + zmin=0;zmax=max(current_frame)/current_scale; + + %TCW AIM 2006 + if hand_scaling == 1 + set(gca,'Zlim',[zmin,1/current_scale]); + else + set(gca,'Zlim',[zmin,zmax]); + end + + %set(gca,'Zlim',[zmin,zmax]); + + + xlabel('time (ms)');ylabel('Frequency (kHz)');title(''); + + if strcmp(handles.screen_modus,'paper') + par=get(hand,'parent'); + set(par,'FontSize',12);xlab=get(par,'xlabel');set(xlab,'FontSize',12);ylab=get(par,'ylabel');set(ylab,'FontSize',12); + end + end + case 5% strobes + current_frame=handles.data.nap; + strobes=handles.data.strobes; + str=get_graphics_options(handles,handles.info.current_strobes_module); + str.minimum_time_interval=start_time; + str.maximum_time_interval=stop_time; + nrchan=getnrchannels(current_frame); + temp_scale=1; % for debugging + % make the dots of a size of constant ratio to the window size + axpos=get(gcf,'Position'); + marker_dot_size=axpos(3)/168; + if do_single_channel || nrchan==1 % only one channel + + chan_nr=options.display_single_channel; +% chan_nr = [chan_nr-2 chan_nr-1 chan_nr chan_nr+1]; +% chan_nr = [chan_nr-1 chan_nr]; + chan_nr = chan_nr; + chan_nr=chan_nr(find(chan_nr>0 & chan_nr < getnrchannels(current_frame))); + options.display_single_channel=chan_nr; + + plot_single_channel_strobes(current_frame,options,handles,str,strobes,current_scale,duration); + else %several channels + hand=plot(current_frame/temp_scale,str);hold on + xlabel('time (ms)');ylabel('Frequency (kHz)');title(''); + colscale=length(hsv)/nrchan; + for i=1:nrchan + if isfield(strobes,'grouped') + nr_sources=size(strobes.cross_strobes{1}.source_cross_channel_value,2); + cols=hsv; + % first plot the originals +% herestrobes=strobes.original{i}; +% nr_here=length(herestrobes.strobes); +% col=cols(round(i*colscale),:); +% xoffs=-0.001; +% for j=1:nr_here +% time=herestrobes.strobes(j); +% if time>start_time & time1 + colnr=round(k*length(hsv)/nr_sources); + colnr=min(colnr,length(hsv)); + colnr=max(colnr,1); + col=cols(colnr,:); + cursize=target_chan_act/100; + else + continue + end + time=herestrobes(j); + if time>start_time & timestart_time & time1 && withtime +% axes(myaxes2); + set(myaxes2,'XTick',[]); + set(get(myaxes2,'xlabel'),'string',''); + +% axes(myaxes3); +% cla + if current_plot<6 + str.minimum_time_interval=start_time; + str.maximum_time_interval=start_time+duration; + str.is_log=0; + str.time_reversed=0; + str.time_profile_scale=-1; % decide on your own! + else + if current_plot==6 + str=get_graphics_options(handles,handles.info.calculated_sai_module); + str.time_profile_scale=-1; %variable scaling + % TCW AIM2006 WAS: + %str.time_profile_scale=1; %fixed scaling + else + str=get_graphics_options(handles,handles.info.calculated_usermodule_module); + end + end + hand=plottemporalprofile(current_frame,str,myaxes3); + if current_plot<6 + set(get(myaxes3,'xlabel'),'string','time (ms)'); +% xlabel('time (ms)') + elseif getxaxis(current_frame)=='0' + set(get(myaxes3,'xlabel'),'string','Time-Interval, Peak-Frequency product, \ith'); +% xlabel('Time-Interval, Peak-Frequency product, \ith') %brute force method change by Rich + elseif strcmp(getxaxis(current_frame),'harmonic ratio') + set(get(myaxes3,'xlabel'),'string','harmonic ratio'); +% xlabel('harmonic ratio') %brute force method change by Stefan we must do something about this!! + else + set(get(myaxes3,'xlabel'),'string','time interval (ms)'); +% xlabel('time interval (ms)') + end + title(''); + set(gca,'XMinorTick','off'); + if strcmp(handles.screen_modus,'paper') + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + set(xlab,'FontSize',12); + end + +else + set(myaxes2,'TickLength',[0.01,0.01]); +end + +if current_plot>1 && withfre + set(myaxes2,'YTick',[]); + set(get(myaxes2,'ylabel'),'string',''); +% ylabel(''); +% axes(myaxes4); +% cla + + + if current_plot<6 + str.minimum_time_interval=start_time; + str.maximum_time_interval=start_time+duration; + str.frequency_profile_scale=-1; % decide on your own according to momentan state + else + str.frequency_profile_scale=1; % fixed scaling + + end + + if getxaxis(current_frame)=='0' + hand=plotfrequencyprofile(current_frame,str,myaxes4); + set(get(myaxes4,'xlabel'),'string','Mellin variable, \it{c/2\pi'); +% xlabel('Mellin variable, \it{c/2\pi}'); %brute force change by Rich + str.shrink_range=-1; + elseif strcmp(getxaxis(current_frame),'harmonic ratio') + str.frequency_profile_scale=-1; + hand=plotfrequencyprofile(current_frame,str,myaxes4); + set(get(myaxes4,'xlabel'),'string','scale variable'); +% xlabel('scale variable'); % + else + str.shrink_range=1/0.85; + hand=plotfrequencyprofile(current_frame,str,myaxes4); + set(get(myaxes4,'xlabel'),'string','Frequency (kHz)'); +% xlabel('Frequency (kHz)'); + end + if strcmp(handles.screen_modus,'paper') + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + set(xlab,'FontSize',12); + % set(get(hand, + end + +else + set(myaxes2,'TickLength',[0.01,0.01]); +end + +if isfield(handles.info,'domovie') % no more actions! + return +end + + +% handles potential other windows +if isfield(handles.info,'children') && ~isfield(handles.info,'iscallfromchild') && current_plot <7 + % first check, whether the child is still there: + if ~ishandle(handles.info.children.single_channel.windowhandle) + rmfield(handles.info,'children'); + return + end + channr=single_channel_gui('getchannelnumber'); + handles.info.children.single_channel.channelnumber=channr; + single_channel_gui(handles); + +end + + + + +function str=get_graphics_options(handles,module_name) +% returns the graphic options, if they exist + +str=[]; +if isfield(handles.all_options.graphics,module_name) + str=getfield(handles.all_options.graphics,module_name); +else + % disp(sprintf('graphics part for module %s not found. Check version',module_name)); + switch handles.info.current_plot + case {1,2,3,4,5} + opstr.is_log=0; + opstr.time_reversed=0; + opstr.plotstyle='waterfall'; + opstr.plotcolor='k'; + opstr.display_time=0; + case {6} + opstr.is_log=1; + opstr.time_reversed=1; + opstr.plotstyle='waterfall'; + opstr.plotcolor='k'; + opstr.minimum_time=0.001; + opstr.maximum_time=0.032; + opstr.display_time=0; + end +end + + +function plot_single_channel_strobes(current_frame,options,handles,str,strobes,current_scale,duration) +start_time=str.minimum_time_interval; +stop_time=str.maximum_time_interval; + +nr_channels=length(options.display_single_channel); + +count=0; +for channr=options.display_single_channel + count=count+1; + sig=getsinglechannel(current_frame,channr); + sigpart=getpart(sig,start_time,stop_time); + ymin=0;ymax=max(current_frame)*1.2; + if strcmp(handles.screen_modus,'paper') +% hand=plot(sigpart,[getminimumtime(sigpart),getminimumtime(sigpart)+getlength(sigpart)]); + hand=plot(sig,[start_time stop_time]); + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + ylabel('NAP amplitude'); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + set(xlab,'FontSize',12); + set(gca,'Ytick',[]); + set(gca,'YAxisLocation','right'); + else + switch count + case 1 + color='b'; + case 2 + color='m'; + end + plot(sigpart,[getminimumtime(sigpart),getminimumtime(sigpart)+getlength(sigpart)],color); + end + hold on + + athres=handles.data.thresholds;%*current_scale/getallmaxvalue(current_frame); + thres=getsinglechannel(athres,channr); + thres=getpart(thres,start_time,stop_time); + hand=plot(thres,[start_time stop_time 0 max(current_frame)/current_scale],'g'); + if strcmp(handles.screen_modus,'paper') + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + ylabel('NAP amplitude'); + set(xlab,'FontSize',12); + else + xlabel('time (ms)');ylabel('amplitude');title('');set(gca,'YAxisLocation','right'); + end + herestrobes=strobes{channr}; + nr_here=length(herestrobes.strobes); + for j=1:nr_here + time=herestrobes.strobes(j); + if time>start_time & time=6 + sai=handles.data.sai; + if handles.with_graphic==0 + current_frame_number=handles.current_frame_nr; + else + current_frame_number=round(slidereditcontrol_get_value(handles.currentslidereditcombi)); + end + if current_frame_number<=length(sai) && current_frame_number>0 + start_time=getcurrentframestarttime(sai{current_frame_number}); + else + start_time=getminimumtime(sig); + current_frame_number=1; % error! + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,length(sai)); + end + duration=getlength(sai{current_frame_number}); +else + start_time=slidereditcontrol_get_value(handles.currentslidereditcombi); + duration=slidereditcontrol_get_value(handles.slideredit_duration); +end +stop_time=start_time+duration; + +% in case of auditory image, we simply want the last part of the signal: +if stop_time>getmaximumtime(sig); + start_time=getmaximumtime(sig)-duration; + stop_time=getmaximumtime(sig); +end +if start_time < getminimumtime(sig) + start_time =getminimumtime(sig); +end +% sig=getpart(sig,start_time,stop_time); + + +% The signal window +if withsignal + set(myaxes1,'Visible','on'); +% axes(myaxes1); + % sig=getpart(sig,start_time,stop_time); + if strcmp(handles.screen_modus,'paper') + h=plot(sig,[start_time stop_time],myaxes1); + set(h,'Color','k'); + set(h,'LineWidth',1.5); + else + plot(sig,[start_time stop_time],myaxes1); + end + if min(sig)==0 % for niceness: Clicktrains are cut away otherwise + ax=axis; + ax(3)=-0.1; + axis(ax); + end + title('');set(gca,'XTick',[]);set(gca,'YTick',[]);xlabel('');ylabel(''); +end + + + +% from here: plot in axes2: +% axes(myaxes2); +set(myaxes2,'XDir','normal') +set(myaxes2,'XScale','lin'); +if handles.with_graphic==1 + current_scale=slidereditcontrol_get_value(handles.slideredit_scale); +else + current_scale=options.data_scale; +end + +switch current_plot + case {-1,0,1} % signal + set(myaxes2,'Visible','off'); + case 2% pcp + sig=handles.data.pcp; +% current_frame=getpart(sig,start_time,stop_time); + ca=plot(sig,[start_time stop_time]); + set(gca,'YTick',[]); + ax=axis; + ax(3)=ax(3)/current_scale; + ax(4)=ax(4)/current_scale; + axis(ax); + title('');xlabel('');ylabel(''); + case 3% bmm + current_frame=handles.data.bmm; + str=get_graphics_options(handles,handles.info.current_bmm_module); + str.minimum_time_interval=start_time; + str.maximum_time_interval=stop_time; + nrchan=getnrchannels(handles.data.bmm); + if do_single_channel || nrchan==1 + sig=getsinglechannel(current_frame,options.display_single_channel); +% sig=getpart(sig,start_time,stop_time); + ymin=min(current_frame)*1.1;ymax=max(current_frame)*1.1; + plot(sig,[start_time stop_time ymin ymax]); + set(gca,'Ylim',[ymin,ymax]);set(gca,'YAxisLocation','right'); + xlabel('time (ms)');ylabel('amplitude');title(''); + else + hand=plot(current_frame,str,myaxes2); + zmin=min(current_frame)/current_scale;zmax=max(current_frame)/current_scale; + + %set(gca,'Zlim',[zmin,zmax]); + + %TCW AIM 2006 + if hand_scaling == 1 + set(gca,'Zlim',[0,1/current_scale]); + else + %TCW AIM 2006 to get this frequency axis correct, this lower + %limit of the z axis really needs to be zero + set(gca,'Zlim',[0,zmax]); + end + + xlabel('time (ms)');ylabel('Frequency (kHz)');title(''); + if strcmp(handles.screen_modus,'paper') + par=get(hand,'parent'); + set(par,'FontSize',12);xlab=get(par,'xlabel');set(xlab,'FontSize',12);ylab=get(par,'ylabel');set(ylab,'FontSize',12); + end + end + case 4% nap + current_frame=handles.data.nap; + str=get_graphics_options(handles,handles.info.current_nap_module); + str.minimum_time_interval=start_time; + str.maximum_time_interval=stop_time; + nrchan=getnrchannels(current_frame); + if do_single_channel || nrchan==1 + sig=getsinglechannel(current_frame,options.display_single_channel); +% sig=getpart(sig,start_time,stop_time); + ymin=0; + ymax=max(current_frame)*1.1; + plot(sig,[start_time stop_time]); + set(gca,'Ylim',[ymin,ymax]);set(gca,'YAxisLocation','right'); + xlabel('time (ms)');ylabel('amplitude');title(''); + else + hand=plot(current_frame,str); + zmin=0;zmax=max(current_frame)/current_scale; + + %TCW AIM 2006 + if hand_scaling == 1 + set(gca,'Zlim',[zmin,1/current_scale]); + else + set(gca,'Zlim',[zmin,zmax]); + end + + %set(gca,'Zlim',[zmin,zmax]); + + + xlabel('time (ms)');ylabel('Frequency (kHz)');title(''); + + if strcmp(handles.screen_modus,'paper') + par=get(hand,'parent'); + set(par,'FontSize',12);xlab=get(par,'xlabel');set(xlab,'FontSize',12);ylab=get(par,'ylabel');set(ylab,'FontSize',12); + end + end + case 5% strobes + current_frame=handles.data.nap; + strobes=handles.data.strobes; + str=get_graphics_options(handles,handles.info.current_strobes_module); + str.minimum_time_interval=start_time; + str.maximum_time_interval=stop_time; + nrchan=getnrchannels(current_frame); + temp_scale=1; % for debugging + % make the dots of a size of constant ratio to the window size + axpos=get(gcf,'Position'); + marker_dot_size=axpos(3)/168; + if do_single_channel || nrchan==1 % only one channel + + chan_nr=options.display_single_channel; +% chan_nr = [chan_nr-2 chan_nr-1 chan_nr chan_nr+1]; +% chan_nr = [chan_nr-1 chan_nr]; + chan_nr = chan_nr; + chan_nr=chan_nr(chan_nr>0 & chan_nr < getnrchannels(current_frame)); + options.display_single_channel=chan_nr; + + plot_single_channel_strobes(current_frame,options,handles,str,strobes,current_scale,duration); + else %several channels + hand=plot(current_frame/temp_scale,str,myaxes2);hold on + xlabel('time (ms)');ylabel('Frequency (kHz)');title(''); + colscale=length(hsv)/nrchan; + for i=1:nrchan + if isfield(strobes,'grouped') + nr_sources=size(strobes.cross_strobes{1}.source_cross_channel_value,2); + cols=hsv; + % first plot the originals +% herestrobes=strobes.original{i}; +% nr_here=length(herestrobes.strobes); +% col=cols(round(i*colscale),:); +% xoffs=-0.001; +% for j=1:nr_here +% time=herestrobes.strobes(j); +% if time>start_time & time1 + colnr=round(k*length(hsv)/nr_sources); + colnr=min(colnr,length(hsv)); + colnr=max(colnr,1); + col=cols(colnr,:); + cursize=target_chan_act/100; + else + continue + end + time=herestrobes(j); + if time>start_time && timestart_time && time1 && withtime +% axes(myaxes2); + set(myaxes2,'XTick',[]); + set(get(myaxes2,'xlabel'),'string',''); + + if current_plot<6 + str.minimum_time_interval=start_time; + str.maximum_time_interval=start_time+duration; + str.is_log=0; + str.time_reversed=0; + str.time_profile_scale=-1; % decide on your own! + else + if current_plot==6 + str=get_graphics_options(handles,handles.info.calculated_sai_module); + str.time_profile_scale=-1; %variable scaling + % TCW AIM2006 WAS: + %str.time_profile_scale=1; %fixed scaling + else + str=get_graphics_options(handles,handles.info.calculated_usermodule_module); + end + end + hand=plottemporalprofile(current_frame,str,myaxes3); + if current_plot<6 + set(get(myaxes3,'xlabel'),'string','time (ms)'); +% xlabel('time (ms)') + elseif getxaxis(current_frame)=='0' + set(get(myaxes3,'xlabel'),'string','Time-Interval, Peak-Frequency product, \ith'); +% xlabel('Time-Interval, Peak-Frequency product, \ith') %brute force method change by Rich + elseif strcmp(getxaxis(current_frame),'harmonic ratio') + set(get(myaxes3,'xlabel'),'string','harmonic ratio'); +% xlabel('harmonic ratio') %brute force method change by Stefan we must do something about this!! + else + set(get(myaxes3,'xlabel'),'string','time interval (ms)'); +% xlabel('time interval (ms)') + end + title(''); + set(gca,'XMinorTick','off'); + if strcmp(handles.screen_modus,'paper') + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + set(xlab,'FontSize',12); + end + +else + set(myaxes2,'TickLength',[0.01,0.01]); +end + +if current_plot>1 && withfre + set(myaxes2,'YTick',[]); + set(get(myaxes2,'ylabel'),'string',''); +% ylabel(''); +% axes(myaxes4); +% cla + + + if current_plot<6 + str.minimum_time_interval=start_time; + str.maximum_time_interval=start_time+duration; + str.frequency_profile_scale=-1; % decide on your own according to momentan state + else + str.frequency_profile_scale=1; % fixed scaling + + end + + if getxaxis(current_frame)=='0' + hand=plotfrequencyprofile(current_frame,str,myaxes4); + set(get(myaxes4,'xlabel'),'string','Mellin variable c'); +% set(get(myaxes4,'xlabel'),'string','Mellin variable, \it{c/2\pi'); +% xlabel('Mellin variable, \it{c/2\pi}'); %brute force change by Rich + str.shrink_range=-1; + elseif strcmp(getxaxis(current_frame),'harmonic ratio') + str.frequency_profile_scale=-1; + hand=plotfrequencyprofile(current_frame,str,myaxes4); + set(get(myaxes4,'xlabel'),'string','scale variable'); +% xlabel('scale variable'); % + else +% str.shrink_range=1/0.85; + str.shrink_range=1; + hand=plotfrequencyprofile(current_frame,str,myaxes4); + set(get(myaxes4,'xlabel'),'string','Frequency (kHz)'); +% xlabel('Frequency (kHz)'); + end + if strcmp(handles.screen_modus,'paper') + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + set(xlab,'FontSize',12); + % set(get(hand, + end + +else + set(myaxes2,'TickLength',[0.01,0.01]); +end + +if isfield(handles.info,'domovie') % no more actions! + return +end + + +% handles potential other windows +if isfield(handles.info,'children') && ~isfield(handles.info,'iscallfromchild') && current_plot <7 + % first check, whether the child is still there: + if ~ishandle(handles.info.children.single_channel.windowhandle) + rmfield(handles.info,'children'); + return + end + channr=single_channel_gui('getchannelnumber'); + handles.info.children.single_channel.channelnumber=channr; + single_channel_gui(handles); + +end + + + + +function str=get_graphics_options(handles,module_name) +% returns the graphic options, if they exist + +str=[]; +if isfield(handles.all_options.graphics,module_name) + str=getfield(handles.all_options.graphics,module_name); +else + % disp(sprintf('graphics part for module %s not found. Check version',module_name)); + switch handles.info.current_plot + case {1,2,3,4,5} + opstr.is_log=0; + opstr.time_reversed=0; + opstr.plotstyle='waterfall'; + opstr.plotcolor='k'; + opstr.display_time=0; + case {6} + opstr.is_log=1; + opstr.time_reversed=1; + opstr.plotstyle='waterfall'; + opstr.plotcolor='k'; + opstr.minimum_time=0.001; + opstr.maximum_time=0.032; + opstr.display_time=0; + end +end + + +function plot_single_channel_strobes(current_frame,options,handles,str,strobes,current_scale,duration) +start_time=str.minimum_time_interval; +stop_time=str.maximum_time_interval; + +nr_channels=length(options.display_single_channel); + +count=0; +for channr=options.display_single_channel + count=count+1; + sig=getsinglechannel(current_frame,channr); + sigpart=getpart(sig,start_time,stop_time); + ymin=0;ymax=max(current_frame)*1.2; + if strcmp(handles.screen_modus,'paper') +% hand=plot(sigpart,[getminimumtime(sigpart),getminimumtime(sigpart)+getlength(sigpart)]); + hand=plot(sig,[start_time stop_time]); + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + ylabel('NAP amplitude'); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + set(xlab,'FontSize',12); + set(gca,'Ytick',[]); + set(gca,'YAxisLocation','right'); + else + switch count + case 1 + color='b'; + case 2 + color='m'; + end + plot(sigpart,[getminimumtime(sigpart),getminimumtime(sigpart)+getlength(sigpart)],color); + end + hold on + + athres=handles.data.thresholds;%*current_scale/getallmaxvalue(current_frame); + thres=getsinglechannel(athres,channr); + thres=getpart(thres,start_time,stop_time); + hand=plot(thres,[start_time stop_time 0 max(current_frame)/current_scale],'g'); + if strcmp(handles.screen_modus,'paper') + set(hand,'Color','k'); + set(hand,'LineWidth',1.5); + par=get(hand,'parent'); + set(par,'FontSize',12); + xlab=get(par,'xlabel'); + ylabel('NAP amplitude'); + set(xlab,'FontSize',12); + else + xlabel('time (ms)');ylabel('amplitude');title('');set(gca,'YAxisLocation','right'); + end + herestrobes=strobes{channr}; + nr_here=length(herestrobes.strobes); + for j=1:nr_here + time=herestrobes.strobes(j); + if time>start_time & time0 +% figpos(3)=640; +% set(fig,'Position',figpos); +% end +% +% if figpos(4) < 400 +% figpos(4)=400; +% set(fig,'Position',figpos); +% end + + cur_axis=gca; % this is the full size axis with the full size area + set(cur_axis,'units','pixel'); + fax=get(gcf,'Position'); % the size of the figure + relative_axis(1)=10/fax(3); % bottom fixed + relative_axis(2)=111/fax(4); % bottom right fixed + relative_axis(3)=(fax(3)-40)/fax(3); % height + relative_axis(4)=(fax(4)-220)/fax(4); % height + +[myaxes1,myaxes2,myaxes3,myaxes4]=aim_define_plot_areas(handles,relative_axis); + +% screens=get(0,'ScreenSize'); +% if figpos(1)+figpos(3)>screens(3) +% figpos(1)=screens(3)-figpos(3)-5; +% set(fig,'Position',figpos); +% end +% if figpos(2)+figpos(4)>screens(4) +% figpos(2)=screens(4)-figpos(4)-30; +% set(fig,'Position',figpos); +% end + +% keep everything on top +dist1=46; +dist3=74; +dist4=104; +dist5=110; + +distr1=107; +keepontop('frame7',dist5); +keepontop('frame10',dist5); +% keepontopright('frame10',dist5,distr1+10); + +% keepontop('pushbutton10',dist1-1); +keepontop('pushbutton0',dist1); +keepontop('pushbutton2',dist1); +keepontop('pushbutton3',dist1); +keepontop('pushbutton4',dist1); +keepontop('pushbutton5',dist1); +keepontop('pushbutton6',dist1); +% keepontopright('pushbutton6',dist1,distr1); +keepontop('pushbutton21',dist1); + +% keepontop('pushbutton11',dist3+2); +% keepontop('pushbutton8',dist4+3); +% keepontopright('pushbutton9',179,distr1-6); + +keepontop('listbox1',dist3); +keepontop('listbox2',dist3); +keepontop('listbox0',dist3); +keepontop('listbox3',dist3); +keepontop('listbox4',dist3); +keepontop('listbox5',dist3); +% keepontopright('listbox5',dist3,distr1-1); +keepontop('listbox6',dist3); + +keepontop('checkbox0',dist4-5); +keepontop('checkbox1',dist4-5); +keepontop('checkbox2',dist4-5); +keepontop('checkbox3',dist4-5); +keepontop('checkbox4',dist4-5); +keepontop('checkbox8',dist4-5); +keepontop('checkbox5',dist4-5); +% keepontopright('checkbox5',dist4-5,distr1-38); + + +distr2=101; +distr3=85; +distr4=95; + +% keeponbottomright('text13',distr2); +% keeponbottomright('edit1',distr2); +% keeponbottomright('pushbuttonautoscale',distr2); +% keeponbottomright('slider1',distr3); +% keeponbottomright('frame5',distr4); + + +% set the axes to nice sizes: +hoben=107; % soviel muss oben freibleiben +hunten=110; % soviel muss unten freibleiben +hv=figpos(4)-hunten-hoben; % soviel ist verfügbar in der Mitte +% davon bekommen das Profile und das signal je 14% und das SAI 72%: +h1=hv*0.14; +h2=hv*0.72; +h3=hv*0.14; + + +b1=20; % soweit weg vom linken Rand +b2=38;% soweit weg vom rechten Rand +bv=figpos(3)-b1-b2; % soviel Breite ist verfügbar +% davon bekommen die linken 89% und das Profile 11% +b3=bv*0.11; +b4=bv*0.89; + +ax1 = findobj('Tag','axes1'); +ax2 = findobj('Tag','axes2'); +ax3 = findobj('Tag','axes3'); +ax4 = findobj('Tag','axes4'); +set(ax1,'Position',[b1-1 hunten+h1+h2+2 b4 h1]); +set(ax2,'Position',[b1 hunten+h1+1 b4 h2]); +set(ax3,'Position',[b1 hunten b4 h3]); +set(ax4,'Position',[b1+b4+1 hunten+h1+1 b3 h2]); + + + +set(fig,'Units',old_units); + +aim_savecurrentstate(handles);% save the state of the project and the window to a file +% handles=replotgraphic(handles); + + +function keepontop(name,dist) +global figpos +u = findobj('Tag',name); +correct=+9; +upos=get(u,'Position'); +upos = [upos(1), figpos(4) - dist+correct, upos(3), upos(4)]; +set(u,'Position',upos); + +function keepontopright(name,disttop,distright) +global figpos +u = findobj('Tag',name); +correct=+9; +upos=get(u,'Position'); +upos = [figpos(3)-distright, figpos(4) - disttop+correct, upos(3), upos(4)]; +set(u,'Position',upos); + +function keeponbottomright(name,distright) +global figpos +u = findobj('Tag',name); +upos=get(u,'Position'); +upos = [figpos(3)-distright, upos(2), upos(3), upos(4)]; +set(u,'Position',upos); diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_savecurrentstate.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_savecurrentstate.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,84 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function aim_savecurrentstate(handles) +% save some crucial information to a file + +nam=handles.info.projectfilename; + +% in which directory is the wavefile? users could have changed it! +dirname=handles.info.original_soundfile_directory; + +rnam=fullfile(dirname,nam); +id=fopen(rnam,'wt'); + +fprintf(id,'\n%% Project information'); +fprintf(id,'\n%% for the project: \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); +fprintf(id,'\n%%'); +filename=sprintf(' %s\n',handles.info.uniqueworkingname); +fprintf(id,filename); +fprintf(id,'%% %s',date); +fprintf(id,'\n%% produced by '); +result = license('inuse'); +cuser=result(1).user; +fprintf(id,'%s',cuser); +fprintf(id,'\n%% Dont write anything in this file'); +fprintf(id,'\n%%%%%%%%%%%%%%%%%%%%%%%%%%\n'); + +% infos about the setup of the project itself +% fprintf(id,'current_pcp_module=''%s'';\n',handles.info.calculated_pcp_module); +% fprintf(id,'current_bmm_module=''%s'';\n',handles.info.calculated_nap_module); +% fprintf(id,'current_nap_module=''%s'';\n',handles.info.calculated_bmm_module); +% fprintf(id,'current_strobes_module=''%s'';\n',handles.info.calculated_strobes_module); +% fprintf(id,'current_sai_module=''%s'';\n',handles.info.calculated_sai_module); +% fprintf(id,'current_usermodule=''%s'';\n',handles.info.calculated_usermodule_module); +% fprintf(id,'current_movie_module=''%s'';\n',handles.info.calculated_movie_module); + + +% and infos about the grapical display +fprintf(id,'current_plot=%d;\n',handles.info.current_plot); + +start_time=slidereditcontrol_get_value(handles.currentslidereditcombi); +if handles.info.current_plot<6 + fprintf(id,'start_time=%f;\n',start_time); +else + fprintf(id,'start_time=%d;\n',round(start_time)); +end + +duration=slidereditcontrol_get_value(handles.slideredit_duration); +fprintf(id,'duration=%f;\n',duration); +scale=slidereditcontrol_get_value(handles.slideredit_scale); +fprintf(id,'scale=%f;\n',scale); + + +hastime=get(handles.checkbox6,'Value'); +hasfreq=get(handles.checkbox7,'Value'); +hassignal=get(handles.checkbox10,'Value'); +fprintf(id,'hastime=%d;\n',hastime); +fprintf(id,'hasfreq=%d;\n',hasfreq); +fprintf(id,'hassignal=%d;\n',hassignal); + +pos=get(handles.figure1,'Position'); +if isfield(handles.info,'current_figure') + fprintf(id,'winx=%d;\n',pos(1)); + fprintf(id,'winy=%d;\n',pos(2)); + if ishandle(handles.info.current_figure) + gpos=get(handles.info.current_figure,'Position'); + fprintf(id,'grafixwinnr=%d;\n',handles.info.current_figure); + fprintf(id,'grafixwinx=%d;\n',gpos(1)); + fprintf(id,'grafixwiny=%d;\n',gpos(2)); + fprintf(id,'grafixwinb=%d;\n',gpos(3)); + fprintf(id,'grafixwinh=%d;\n',gpos(4)); + end +end +fclose(id); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_savefile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_savefile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,26 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function aim_savefile(handles,fr,name,type,modul,options,all_options) + +str.type=modul; +str.data=fr; +str.options=options; +str.all_options=all_options; + +eval(sprintf('%s=str;',type)); + +lookpath=fullfile(handles.info.original_soundfile_directory,name); + +str5=sprintf('save(''%s'',''%s'');',lookpath,type); +eval(str5); + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_saveparameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_saveparameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,270 @@ +% procedure for 'aim-mat' +% +% function handles=aim_saveparameters(handles,filename,all_parameters) +% +% INPUT VALUES: +% handles: all relevant information +% filename: which file +% all_parameters: switch, whether all parameters shell be saved or only the relevant ones +% RETURN VALUE: +% handles: the updated handles +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_saveparameters(handles,filename,all_parameters) + +if nargin < 3 + all_parameters=1; % save all parameters, not only the project relevant +end + + +id=fopen(filename,'wt'); +lines=struct2stringarray(handles.all_options.bmm,'all_options.bmm'); +fprintf(id,'\n%% Parameters'); +fprintf(id,'\n%% for the project: \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); +fprintf(id,'\n%%'); +filename=sprintf(' %s\n',handles.info.uniqueworkingname); +fprintf(id,filename); +fprintf(id,'%% %s',date); +fprintf(id,'\n%% produced by '); +result = license('inuse'); +cuser=result(1).user; +fprintf(id,'%s',cuser); +fprintf(id,'\n'); +fprintf(id,'\n\n%% Dont write anything in this file except for parameter values, \n%% since all other changes will be lost'); +fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); +% fprintf(id,'\nclear all_options; %% clear the options initially to remove any old entries'); +% fprintf(id,'\n'); + +if all_parameters==1 % save all parameters + lines=struct2stringarray(handles.all_options.signal,'all_options.signal'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% Signaloptions\n'); + for i=1:length(lines) + fprintf(id,lines{i}); + fprintf(id,';\n'); + end + + lines=struct2stringarray(handles.all_options.pcp,'all_options.pcp'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% outer/middle ear filter function\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + + lines=struct2stringarray(handles.all_options.bmm,'all_options.bmm'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% bmm\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + lines=struct2stringarray(handles.all_options.nap,'all_options.nap'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% nap\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + lines=struct2stringarray(handles.all_options.strobes,'all_options.strobes'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% strobes\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + lines=struct2stringarray(handles.all_options.sai,'all_options.sai'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% sai\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + lines=struct2stringarray(handles.all_options.usermodule,'all_options.usermodule'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% user defined module\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + lines=struct2stringarray(handles.all_options.movie,'all_options.movie'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% movies\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + + +else % save only the parameters, that are relevant for the current project + + % if handles.info.signal_loaded==1 + lines=struct2stringarray(handles.all_options.signal,'all_options.signal'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% Signaloptions\n'); + for i=1:length(lines) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + % end + + if handles.info.pcp_loaded==1 + lines=struct2stringarray(handles.all_options.pcp,'all_options.pcp'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% outer/middle ear filter function\n'); + module_name=['.pcp.' handles.info.current_pcp_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + if handles.info.bmm_loaded==1 + lines=struct2stringarray(handles.all_options.bmm,'all_options.bmm'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% bmm\n'); + module_name=['.bmm.' handles.info.current_bmm_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + if handles.info.nap_loaded==1 + lines=struct2stringarray(handles.all_options.nap,'all_options.nap'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% nap\n'); + module_name=['.nap.' handles.info.current_nap_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + if handles.info.strobes_loaded==1 + lines=struct2stringarray(handles.all_options.strobes,'all_options.strobes'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% strobes\n'); + module_name=['.strobes.' handles.info.current_strobes_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + if handles.info.sai_loaded==1 + lines=struct2stringarray(handles.all_options.sai,'all_options.sai'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% sai\n'); + module_name=['.sai.' handles.info.current_sai_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + + if handles.info.usermodule_loaded==1 + lines=struct2stringarray(handles.all_options.usermodule,'all_options.usermodule'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% user defined module\n'); + module_name=['.usermodule.' handles.info.current_usermodule_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + if handles.info.movie_loaded==1 + lines=struct2stringarray(handles.all_options.movie,'all_options.movie'); + fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); + fprintf(id,'\n%% movies\n'); + module_name=['.movie.' handles.info.current_movie_module '.']; + for i=1:length(lines) + if ~isempty(strfind(lines{i},module_name)) + text=lines{i}; + % if isempty(strfind(text,'generatingfunction')) && isempty(strfind(text,'displayname')) && isempty(strfind(text,'displayfunction')) + fprintf(id,text); + fprintf(id,';\n'); + % end + end + end + end + + +end + +% and the graphic options. Important for the movies +lines=struct2stringarray(handles.all_options.graphics,'all_options.graphics'); +fprintf(id,'\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%'); +fprintf(id,'\n%% graphics\n'); +for i=1:length(lines) + text=lines{i}; + fprintf(id,text); + fprintf(id,';\n'); +end + +err=fclose(id); +if err~=0 + ferror(id) +end +% pause(1) + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_set_current_slider.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_set_current_slider.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,205 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% helping function, that sets the sliders to their current values. This is +% a little bit preliminary, since I unfortunatly hadnt time to do this +% properly. Mercy!! If anyone has a few hours, he can fix this. Otherwise +% it works in most circumstances, however not very elegant... +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function handles=aim_set_current_slider(handles) +% sets the slider values and range according to the settings in handles + + +sig=handles.data.signal; +len=getlength(sig); +% if we switched from pre-sai to sai the slider has to change from time to +% frame number +if handles.info.old_current_plot<6 & handles.info.current_plot>=6 && handles.info.old_current_plot~=0 + % fiddle with the sliders % the frame number is the default + handles.slideredit_start=handles.currentslidereditcombi; % save for later + handles.currentslidereditcombi=handles.slideredit_frames; + nr_frames=length(handles.data.sai); + + handles.currentslidereditcombi.maxvalue=nr_frames; + handles.currentslidereditcombi.minvalue=1; + handles.currentslidereditcombi.nreditdigits=0; + handles.currentslidereditcombi.editscaler=1; + + % calculate the current frame number: + current_start_time=slidereditcontrol_get_value(handles.slideredit_start); + framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1}); + current_frame_nr=round((current_start_time-getminimumtime(sig))/framelen)+1; + current_frame_nr=min(nr_frames,current_frame_nr); + current_frame_nr=max(1,current_frame_nr); + + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_frame_nr); + handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration + handles.info.old_current_plot=handles.info.current_plot; + +% and set the duration slider to a start time slider + handles.info.oldduration=slidereditcontrol_get_value(handles.slideredit_duration); % save for later + handles.slideredit_duration.minvalue=0; + handles.slideredit_duration.maxvalue=framelen*(nr_frames-1)+getminimumtime(sig); + handles.slideredit_duration.current_value=getcurrentframestarttime(handles.data.sai{current_frame_nr}); + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,current_frame_nr*framelen); +end +% other way: if switched from to sai pre-sai : go from frame number to time +if handles.info.old_current_plot>=6 & handles.info.current_plot<6 + % the start time is the default + handles.slideredit_frames=handles.currentslidereditcombi; % save for later + if isfield(handles.info,'oldduration') + dur=handles.info.oldduration; + else + dur=0.04; + end + dur=min(dur,handles.slideredit_duration.maxvalue); + + siglen=getlength(sig); + start_time=handles.all_options.signal.start_time; + duration=handles.all_options.signal.duration; + curdur=slidereditcontrol_get_value(handles.slideredit_duration); + current_start_time=slidereditcontrol_get_value(handles.slideredit_start); + handles.slideredit_start.minvalue=start_time; + handles.slideredit_start.maxvalue=start_time+siglen-curdur; +% handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,curstart); +% handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,curdur); + + + handles.slideredit_duration.minvalue=0.001; + handles.slideredit_duration.maxvalue=siglen; + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,curdur); + handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration/10); + + + % dur=slidereditcontrol_get_value(handles.slideredit_duration); % thats the starttime at the moment +% current_frame_number=round(handles.currentslidereditcombi.current_value); +% current_start_time=getcurrentframestarttime(handles.data.sai{current_frame_number}); + % set the new control to the floating control + handles.currentslidereditcombi=handles.slideredit_start; + +% handles.currentslidereditcombi.maxvalue=len; +% handles.currentslidereditcombi.minvalue=0; +% handles.currentslidereditcombi.nreditdigits=1; +% handles.currentslidereditcombi.editscaler=1000; + + handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,dur); % the duration + current_start_time=min(current_start_time,len-dur); + current_start_time=max(current_start_time,0); + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_start_time); + + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,dur); + handles.info.old_current_plot=handles.info.current_plot; + + % and set the duration slider back to the duration + handles.slideredit_duration.minvalue=0.001; + handles.slideredit_duration.maxvalue=len; + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,dur); + +end + +% second run +if handles.info.old_current_plot==0 + cstart=slidereditcontrol_get_value(handles.currentslidereditcombi); + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,cstart); + cdur=slidereditcontrol_get_value(handles.slideredit_duration); + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,cdur); + cscale=slidereditcontrol_get_value(handles.slideredit_scale); + handles.slideredit_scale=slidereditcontrol_set_value(handles.slideredit_scale,cscale); + if handles.info.current_plot>=6 + handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration + else + handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,cdur); % the duration + end +end + + +% checking for unforseen errors. Can happen in unlucky circumstances: +if handles.info.current_plot>=6 % this should be in frame mode: check limits + nr_frames=length(handles.data.sai); + cur_nr=slidereditcontrol_get_value(handles.currentslidereditcombi); + if cur_nr > nr_frames + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,nr_frames); + handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration + framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1}); + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,nr_frames*framelen); + end + handles.currentslidereditcombi.maxvalue=nr_frames; + handles.currentslidereditcombi.minvalue=1; + +else + stval=slidereditcontrol_get_value(handles.currentslidereditcombi); + if stvalgetmaximumtime(sig)-0.001; + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,getmaximumtime(sig)-0.04); + end + handles.slideredit_duration.minvalue=0; + handles.slideredit_duration.maxvalue=getlength(sig); + + durval=slidereditcontrol_get_value(handles.slideredit_duration); + if durval<0.001 + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.001); + end + if durval>getlength(sig); + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,getlength(sig)-stval); + end + + +end + + +% set the text over the sliders accordingly + +duration=handles.all_options.signal.duration; +start_time=handles.all_options.signal.start_time; +sr=handles.all_options.signal.samplerate; + +if duration>1 + set(handles.displayduration,'String',num2str(fround(duration,2))); + set(handles.text20,'String','sec'); +else + set(handles.displayduration,'String',num2str(fround(duration*1000,0))); + set(handles.text20,'String','ms'); +end +% samplerate +set(handles.text25,'String',num2str(fround(sr/1000,1))); +% offset +if start_time>0 + set(handles.text29,'String',num2str(fround(start_time*1000,1))); + set(handles.text28,'Visible','on'); + set(handles.text29,'Visible','on'); + set(handles.text30,'Visible','on'); +else + set(handles.text28,'Visible','off'); + set(handles.text29,'Visible','off'); + set(handles.text30,'Visible','off'); +end + + + +% if handles.info.current_plot>=6 + + +% handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,start_time); +% handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,duration/10); +% +% handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.04); +% handles.slideredit_duration.maxvalue=duration; +% handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration/10); +% +% handles.currentslidereditcombi=handles.slideredit_start; + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_updatecheckboxes.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_updatecheckboxes.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,65 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_updatecheckboxes(hObject, eventdata, handles,nr); + + +% curval=get(hObject,'Value'); +% handles.info.calculate(nr)=curval; + +loadstatus(1)=handles.info.pcp_loaded; +loadstatus(2)=handles.info.bmm_loaded; +loadstatus(3)=handles.info.nap_loaded; +loadstatus(4)=handles.info.strobes_loaded; +loadstatus(5)=handles.info.sai_loaded; +loadstatus(6)=handles.info.usermodule_loaded; +loadstatus(7)=handles.info.movie_loaded; + + +curval=get(hObject,'Value'); +if curval==1 + for num=nr:-1:1 + if loadstatus(num)==0 +% handles.info.calculate(num)=curval; + hand=getcheckboxhandle(handles,num); + set(hand,'Value',curval); + else + break + end + end +else + for num=nr:7 +% handles.info.calculate(num)=curval; + hand=getcheckboxhandle(handles,num); + set(hand,'Value',curval); + end +end + + + +function hand=getcheckboxhandle(handles,nr) +switch nr + case 1 + hand=handles.checkbox0; + case 2 + hand=handles.checkbox1; + case 3 + hand=handles.checkbox2; + case 4 + hand=handles.checkbox3; + case 5 + hand=handles.checkbox4; + case 6 + hand=handles.checkbox8; + case 7 + hand=handles.checkbox5; +end diff -r 000000000000 -r 74dedb26614d aim-mat/gui/aim_updategui.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/aim_updategui.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,389 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=aim_updategui(handles) + +% enable / disable the buttons +loadstatus(1)=handles.info.pcp_loaded; +loadstatus(2)=handles.info.bmm_loaded; +loadstatus(3)=handles.info.nap_loaded; +loadstatus(4)=handles.info.strobes_loaded; +loadstatus(5)=handles.info.sai_loaded; +loadstatus(6)=handles.info.usermodule_loaded; +loadstatus(7)=handles.info.movie_loaded; + +for i=1:7 + but=getbuttonhandle(handles,i); + frame_hand=getframehandle(handles,i); + if loadstatus(i)==1 + set(but,'Enable','on'); + set(frame_hand,'BackgroundColor',handles.colors.green1); + else + set(but,'Enable','off'); + set(frame_hand,'BackgroundColor',handles.colors.background); + end +end + + +% default settings for all but the sai +set(handles.frame28,'BackgroundColor',handles.colors.green1); +set(handles.checkbox6,'Enable','on'); +set(handles.checkbox7,'Enable','on'); +set(handles.checkbox10,'Enable','on'); +set(handles.edit3,'Enable','on'); +set(handles.slider3,'Enable','on'); +set(handles.edit3,'Visible','on'); %switch on duration +set(handles.slider3,'Visible','on'); +set(handles.text7,'Visible','on'); +set(handles.text10,'Visible','on'); +set(handles.text9,'String','ms'); +set(handles.text8,'String','start time'); +set(handles.pushbutton24,'Enable','on'); + +sig=handles.data.signal; +len=getlength(sig); + +handles=aim_set_current_slider(handles); + +% the new one is now the old one: +handles.info.old_current_plot=handles.info.current_plot; + +% calculate dependencies TCW AIM2006 +% enumerate list boxes +for i=1:7 + listboxen(i)=getlisthandle(handles, i); +end +% if it was a list box that called +if (find(listboxen==handles.calling_object)) + current_listbox=handles.calling_object; + current_listbox_number=find(listboxen==handles.calling_object); + generating_module_string=get(current_listbox,'String'); + generating_module=generating_module_string(get(current_listbox,'Value')); + generating_module=generating_module{1}; + generating_section=getsectionnames(current_listbox_number); + generating_functionline=['handles.all_options.' generating_section '.' generating_module '.default_nextmodule']; + try + setdefault=1; + eval(sprintf('default_gen=%s;',generating_functionline')); + catch + setdefault=0; + end + if setdefault==1 && current_listbox_number<7 + next_listbox=getlisthandle(handles,current_listbox_number+1); + generating_module_string=get(next_listbox,'String'); + chosen_option=strmatch(default_gen,generating_module_string); + try + set(next_listbox,'Value', chosen_option); + catch + % never mind, the necessary module doesn't exist + end + end +end +% + +% set the colors according to the button setting +switch handles.info.current_plot + case 1 % signal + set(handles.checkbox6,'Value',0); % switch off profiles + set(handles.checkbox7,'Value',0); + set(handles.checkbox6,'Enable','off'); + set(handles.checkbox7,'Enable','off'); + set(handles.pushbutton24,'Enable','off'); + case 2 % pcp + set(handles.frame20,'BackgroundColor',handles.colors.green2); + set(handles.checkbox6,'Value',0); + set(handles.checkbox7,'Value',0); + set(handles.checkbox6,'Enable','off'); + set(handles.checkbox7,'Enable','off'); + set(handles.pushbutton24,'Enable','off'); + case 3 %bmm + %set(handles.checkbox10,'Value',0); + set(handles.checkbox6,'Value',0); % switch off profiles by default + set(handles.checkbox7,'Value',0); + set(handles.checkbox6,'Enable','off'); + set(handles.checkbox7,'Enable','off'); + set(handles.frame21,'BackgroundColor',handles.colors.green2); + case 4 % nap + %set(handles.checkbox10,'Value',0); + set(handles.checkbox10, 'Enable', 'on'); + set(handles.checkbox7,'Value',0); + set(handles.checkbox7,'Enable','off'); + set(handles.frame22,'BackgroundColor',handles.colors.green2); + case 5 % strobes + %set(handles.checkbox10,'Value',0); + set(handles.checkbox7,'Value',0); + set(handles.checkbox7,'Enable','off'); + set(handles.frame23,'BackgroundColor',handles.colors.green2); + case 6 % sai + set(handles.frame24,'BackgroundColor',handles.colors.green2); + set(handles.slider3,'Visible','off'); + set(handles.text7,'Visible','off'); + set(handles.text9,'String',''); + set(handles.text8,'String','frame #'); + set(handles.checkbox10,'Value',0); + set(handles.checkbox10, 'Enable', 'off'); + case 7 % user defined + % special: if usermodule is "none", then ignore it and set + if strcmp(handles.info.current_usermodule_module,'none') + set(handles.frame24,'BackgroundColor',handles.colors.green2); + set(handles.slider3,'Visible','off'); + set(handles.text7,'Visible','off'); + set(handles.text9,'String',''); + set(handles.text8,'String','frame #'); + set(handles.checkbox10,'Value',0); + set(handles.checkbox10, 'Enable', 'off'); + handles.info.current_plot=6; + handles=aim_updategui(handles); + else + set(handles.frame25,'BackgroundColor',handles.colors.green2); + set(handles.slider3,'Visible','off'); + set(handles.text7,'Visible','off'); + set(handles.text9,'String','frame #'); + set(handles.pushbutton24,'Enable','off'); + set(handles.checkbox10,'Value',0); + set(handles.checkbox10, 'Enable', 'off'); + end + if strcmp(handles.info.current_usermodule_module,'dualprofile') + set(handles.checkbox6,'Value',0); % switch of profiles + set(handles.checkbox7,'Value',0); + set(handles.checkbox6,'Enable','off'); + set(handles.checkbox7,'Enable','off'); + set(handles.pushbutton24,'Enable','off'); + set(handles.checkbox10,'Value',0); + set(handles.checkbox10, 'Enable', 'off'); + + end + case 8 % movie + set(handles.frame26,'BackgroundColor',handles.colors.green2); +end + + +% indicate by a blue color, that these ones are to be regenerated or to be +% deleted +for i=1:7 + checkhand=getcheckboxhandle(handles,i); + texthand=getbuttonhandle(handles,i); + framehand=getframehandle(handles,i); + if get(checkhand,'Value')==1 + set(framehand,'BackgroundColor',handles.colors.blue2); + set(texthand,'Enable','on'); + for j=i+1:7 + checkhand=getcheckboxhandle(handles,j); + texthand=getbuttonhandle(handles,j); + if loadstatus(j)==1 + set(framehand,'BackgroundColor',handles.colors.blue1); + end + cd1=getcheckboxhandle(handles,j-1); % left of + if get(cd1,'Value')==0 + % and uncheck + cd=getcheckboxhandle(handles,j); + set(cd,'Value',0); + end + end + end +end + + + +% set all commands accordingly, so that "calculate" can work with it +handles.info.calculate_pcp=0; +handles.info.calculate_bmm=0; +handles.info.calculate_nap=0; +handles.info.calculate_strobes=0; +handles.info.calculate_sai=0; +handles.info.calculate_usermodule=0; +handles.info.calculate_movie=0; +if get(handles.checkbox0,'Value')==1 + handles.info.calculate_pcp=1; +end +if get(handles.checkbox1,'Value')==1 + handles.info.calculate_bmm=1; +end +if get(handles.checkbox2,'Value')==1 + handles.info.calculate_nap=1; +end +if get(handles.checkbox3,'Value')==1 + handles.info.calculate_strobes=1; +end +if get(handles.checkbox4,'Value')==1 + handles.info.calculate_sai=1; +end +if get(handles.checkbox8,'Value')==1 + handles.info.calculate_usermodule=1; +end +if get(handles.checkbox5,'Value')==1 + handles.info.calculate_movie=1; +end + +% set the tooltip for each listbox: +settooltip(handles.all_options.pcp,handles.listbox0); +settooltip(handles.all_options.bmm,handles.listbox1); +settooltip(handles.all_options.nap,handles.listbox2); +settooltip(handles.all_options.strobes,handles.listbox3); +settooltip(handles.all_options.sai,handles.listbox4); +settooltip(handles.all_options.usermodule,handles.listbox6); +settooltip(handles.all_options.movie,handles.listbox5); + +% set the current info in handles to the current values +generating_module_string=get(handles.listbox0,'String'); +generating_module=generating_module_string(get(handles.listbox0,'Value')); +generating_module=generating_module{1}; +handles.info.current_pcp_module=generating_module; +generating_module_string=get(handles.listbox1,'String'); +generating_module=generating_module_string(get(handles.listbox1,'Value')); +generating_module=generating_module{1}; +handles.info.current_bmm_module=generating_module; +generating_module_string=get(handles.listbox2,'String'); +generating_module=generating_module_string(get(handles.listbox2,'Value')); +generating_module=generating_module{1}; +handles.info.current_nap_module=generating_module; +generating_module_string=get(handles.listbox3,'String'); +generating_module=generating_module_string(get(handles.listbox3,'Value')); +generating_module=generating_module{1}; +handles.info.current_strobes_module=generating_module; +generating_module_string=get(handles.listbox4,'String'); +generating_module=generating_module_string(get(handles.listbox4,'Value')); +generating_module=generating_module{1}; +handles.info.current_sai_module=generating_module; +generating_module_string=get(handles.listbox6,'String'); +generating_module=generating_module_string(get(handles.listbox6,'Value')); +generating_module=generating_module{1}; +handles.info.current_usermodule_module=generating_module; +generating_module_string=get(handles.listbox5,'String'); +generating_module=generating_module_string(get(handles.listbox5,'Value')); +generating_module=generating_module{1}; +handles.info.current_movie_module=generating_module; + +% special: if the sai-module is set to "ams" (auditory image model), then +% all buttons before that are set to disable and the settings are set to +% "none" +if strcmp(handles.info.current_sai_module,'ams') && handles.info.sai_loaded==1 && ~get(handles.checkbox0,'Value')==1 + set(handles.pushbutton0,'Enable','off'); + set(handles.frame20,'BackgroundColor',handles.colors.background); +% % set(handles.listbox0,'String','none'); + set(handles.pushbutton2,'Enable','off'); + set(handles.frame21,'BackgroundColor',handles.colors.background); +% % set(handles.listbox1,'String','none'); + set(handles.pushbutton3,'Enable','off'); + set(handles.frame22,'BackgroundColor',handles.colors.background); +% set(handles.listbox2,'String','none'); + set(handles.pushbutton4,'Enable','off'); + set(handles.frame23,'BackgroundColor',handles.colors.background); +% set(handles.listbox3,'String','none'); +end + + + +return + + +%%%%%%%%%%%%%%%%%%%%%%%% finished + +function settooltip(options,hand) +generating_module_string=get(hand,'String'); +generating_module=generating_module_string(get(hand,'Value')); +generating_module=generating_module{1}; +generating_functionline=['options.' generating_module '.displayname']; +eval(sprintf('displayname=%s;',generating_functionline')); +set(hand,'Tooltip',displayname); + +function hand=getcheckboxhandle(handles,nr) +switch nr + case 1 + hand=handles.checkbox0; + case 2 + hand=handles.checkbox1; + case 3 + hand=handles.checkbox2; + case 4 + hand=handles.checkbox3; + case 5 + hand=handles.checkbox4; + case 6 + hand=handles.checkbox8; + case 7 + hand=handles.checkbox5; +end + +function hand=getbuttonhandle(handles,nr) +switch nr + case 1 + hand=handles.pushbutton0; + case 2 + hand=handles.pushbutton2; + case 3 + hand=handles.pushbutton3; + case 4 + hand=handles.pushbutton4; + case 5 + hand=handles.pushbutton5; + case 6 + hand=handles.pushbutton21; + case 7 + hand=handles.pushbutton6; +end + + +function hand=getlisthandle(handles,nr) +switch nr + case 1 + hand=handles.listbox0; + case 2 + hand=handles.listbox1; + case 3 + hand=handles.listbox2; + case 4 + hand=handles.listbox3; + case 5 + hand=handles.listbox4; + case 6 + hand=handles.listbox6; + case 7 + hand=handles.listbox5; +end + + +function hand=getframehandle(handles,nr) +switch nr + case 1 + hand=handles.frame20; + case 2 + hand=handles.frame21; + case 3 + hand=handles.frame22; + case 4 + hand=handles.frame23; + case 5 + hand=handles.frame24; + case 6 + hand=handles.frame25; + case 7 + hand=handles.frame26; +end + +function name=getsectionnames(nr); +switch nr + case 1 + name='pcp'; + case 2 + name='bmm'; + case 3 + name='nap'; + case 4 + name='strobes'; + case 5 + name='sai'; + case 6 + name='usermodule'; + case 7 + name='movie'; +end diff -r 000000000000 -r 74dedb26614d aim-mat/gui/createparameterfile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/createparameterfile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,114 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=createparameterfile(handles,paramname) +% create parameters from that file +% when no second parameter is given, then load it using the standart way: +% go through all directories and call the single module-parameterfiles + + +if nargin==1 % if no parameter file is given, then take the standart one + % first load the default values from the default parameter file: + handles=loadallparameterfiles(handles); + if handles.error==1 + return + end + + if isfield(handles,'initial_options') % aim was called with initial parameters + % overwrite the parameters accordingly: + handles=aim_loadpersonal_defaults(handles); % take these anyhow + + % the signal in any case: + handles.all_options.signal=handles.initial_options.signal; + + if isfield(handles.initial_options,'pcp') + handles.info.calculate_pcp=1; + module_names=fieldnames(handles.initial_options.pcp); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_pcp_module=module_name; % this one is the current one + str=sprintf('handles.all_options.pcp%s=handles.initial_options.pcp.%s;',module_name,module_name); + eval(str); + end + if isfield(handles.initial_options,'bmm') + handles.info.calculate_bmm=1; + module_names=fieldnames(handles.initial_options.bmm); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_bmm_module=module_name; % this one is the current one + str=sprintf('handles.all_options.bmm.%s=handles.initial_options.bmm.%s;',module_name,module_name); + eval(str); + end + if isfield(handles.initial_options,'nap') + handles.info.calculate_nap=1; + module_names=fieldnames(handles.initial_options.nap); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_nap_module=module_name; % this one is the current one + str=sprintf('handles.all_options.nap.%s=handles.initial_options.nap.%s;',module_name,module_name); + eval(str); + end + if isfield(handles.initial_options,'strobes') + handles.info.calculate_strobes=1; + module_names=fieldnames(handles.initial_options.strobes); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_strobes_module=module_name; % this one is the current one + str=sprintf('handles.all_options.strobes.%s=handles.initial_options.strobes.%s;',module_name,module_name); + eval(str); + end + if isfield(handles.initial_options,'sai') + handles.info.calculate_sai=1; + module_names=fieldnames(handles.initial_options.sai); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_sai_module=module_name; % this one is the current one + str=sprintf('handles.all_options.sai.%s=handles.initial_options.sai.%s;',module_name,module_name); + eval(str); + end + if isfield(handles.initial_options,'usermodule') + handles.info.calculate_usermodule=1; + module_names=fieldnames(handles.initial_options.usermodule); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_usermodule_module=module_name; % this one is the current one + str=sprintf('handles.all_options.usermodule.%s=handles.initial_options.usermodule.%s;',module_name,module_name); + eval(str); + end + if isfield(handles.initial_options,'movie') + handles.info.calculate_movie=1; + module_names=fieldnames(handles.initial_options.movie); % find out, which module name + module_name=module_names{1}; % only the first one is relevant! + handles.info.current_movie_module=module_name; % this one is the current one + str=sprintf('handles.all_options.movie.%s=handles.initial_options.movie.%s;',module_name,module_name); + eval(str); + end + + else + % fill in some parameters for the signal: + handles.all_options.signal.signal_filename=''; + handles.all_options.signal.start_time=0; + handles.all_options.signal.duration=1; + handles.all_options.signal.samplerate=16000; + handles=aim_loadpersonal_defaults(handles); + handles=aim_loadpersonal_defaults(handles); + return + end +else % the parameter file is given as a paramter. So load it! + + olddir=pwd; + [pathstr,name,ext] = fileparts(paramname) + cd(pathstr); + eval(name); % here it is evaluated + cd olddir; + + + handles.all_options=all_options; + handles=aim_saveparameters(handles,handles.info.parameterfilename); +end + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/do_aim_autoscale.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/do_aim_autoscale.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,142 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=do_aim_autoscale(handles) + +hand_scaling=handles.hand_scaling; + +maxscalenumber=1; % this is the value to which the highest point is scaled to -> should look ok +multiplier=1; + +start_time=slidereditcontrol_get_value(handles.currentslidereditcombi); +% start_time=start_time+getminimumtime(handles.data.signal); +duration=slidereditcontrol_get_value(handles.slideredit_duration); +stop_time=start_time+duration; +scale=slidereditcontrol_get_value(handles.slideredit_scale); + +% TCW - in preparing aim-2006 I decided that this multiplier stuff is +% near-pointless +switch handles.info.current_plot + case {-1,0,1} + return + case 2 % pcp + data=handles.data.pcp; +% data=getpart(data,start_time,stop_time); + %TCW AIM2006 + %multiplier=0.01; + + multiplier=0.8; + + case 3 % bmm + data=handles.data.bmm; + data=getpart(data,start_time,stop_time); + nr_channels=getnrchannels(data); + + %TCW AIM2006 + if hand_scaling==1 + multiplier=1./max(data); + else + if nr_channels==1 + multiplier=0.8; + else + multiplier=30/nr_channels; + end + end + %% + + case {4,5} + data=handles.data.nap; +% data=getpart(data,start_time,stop_time); + nr_channels=getnrchannels(data); + nr_channels=getnrchannels(data); + + %TCW AIM2006 + if hand_scaling==1 + multiplier=1./max(data); + else + if nr_channels==1 + multiplier=0.8; + else + multiplier=30/nr_channels; + end + end + %% + +% if nr_channels==1 +% multiplier=0.8; +% else +% multiplier=30/nr_channels; +% end + case 6 + sai=handles.data.sai; + nr_frames=length(sai); + current_frame_number=round(slidereditcontrol_get_value(handles.currentslidereditcombi)); + current_frame=sai{current_frame_number}; + nr_channels=getnrchannels(current_frame); + data=current_frame; + + % TCW AIM 2006 + if hand_scaling==1 + m=max(data); + if m>0 + multiplier=1./max(data); + else + multiplier=1; + end + else + if nr_channels>1 + multiplier=50/nr_channels; + multiplier=multiplier*max(data)/getallmaxvalue(data); + else + multiplier=1; + end + end + +% if nr_channels>1 +% multiplier=50/nr_channels; +% % multiplier=multiplier*max(data)/getallmaxvalue(data); +% else +% multiplier=1; +% end + case 7 + return; + case 8 + return; +end + +%multiplier=1; + +if handles.info.current_plot < 6 + %TCW AIM2006 + %maxdata=max(data); + maxdata=1; + if maxdata>0 + newscale=maxscalenumber*multiplier/maxdata; + newscale=min(newscale,handles.slideredit_scale.maxvalue); + newscale=max(newscale,handles.slideredit_scale.minvalue); + else + newscale=1; + end +else + %TCW AIM2006 + %maxdata=getallmaxvalue(data); + maxdata=1; + if maxdata>0 + newscale=maxscalenumber*multiplier/maxdata; + newscale=min(newscale,handles.slideredit_scale.maxvalue); + newscale=max(newscale,handles.slideredit_scale.minvalue); + else + newscale=1; + end +end +%newscale=1; +handles.slideredit_scale=slidereditcontrol_set_value(handles.slideredit_scale,newscale); diff -r 000000000000 -r 74dedb26614d aim-mat/gui/do_aim_calculate.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/do_aim_calculate.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,417 @@ +% procedure for 'aim-mat' +% +% function handles=do_aim_calculate(handles) +% +% INPUT VALUES: +% handles: all relevant data and information in a struct +% RETURN VALUE: +% handles: the updated data +% +% this function does all relevant calculation (can be called with or +% without graphic. +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function handles=do_aim_calculate(handles) +% +% % if in the graphic version, then we take the parameters from the parameter +% % file. If in the nographic version, all parameters come in handles. + +% save for later +oldoptions=handles.all_options; + +if handles.with_graphic==1 + set(handles.figure1,'Pointer','watch'); % set the mousepointer to the busy-sign + + if ~isfield(handles.info,'no_automatic_parameter_update') + no_automatic_parameter_update=1; + else + no_automatic_parameter_update=handles.info.no_automatic_parameter_update; + end + + if no_automatic_parameter_update==0 + % first read in the new parameter values and see, which ones have changed + parfile=handles.info.parameterfilename; + [pathstr,parfilename,ext] = fileparts(parfile); + old=pwd; + lookpath=fullfile(handles.info.original_soundfile_directory,pathstr); + cd(lookpath); + eval(parfilename); + cd(old); + newoptions=all_options; + handles.all_options=newoptions; + end +end + + +% first calculate the signal +% check, if the signal has been changed: +sigopts=handles.all_options.signal; +sig=handles.data.signal; +changesig=0; +if sigopts.duration~=getlength(sig); + changesig=1; +end +if sigopts.start_time~=getminimumtime(sig); + changesig=1; +end +if structisequal(oldoptions.signal,handles.all_options.signal) + changesig=1; +end + +if changesig + %|| handles.info.calculate_signal==1 + start=handles.all_options.signal.start_time; + duration=handles.all_options.signal.duration; + orgsig=handles.data.original_signal; + + % do some error checking, just in case: + sigdur=getlength(orgsig); + start=max(start,0); + start=min(start,sigdur-0.001); + duration=max(0,duration); + duration=min(duration,sigdur-start); + + sig=getpart(orgsig,start,start+duration); + handles.data.signal=sig; + name=handles.info.signalname; + lookpath=fullfile(handles.info.original_soundfile_directory,name); + graphic_dir=fullfile(handles.info.original_soundfile_directory,handles.info.directoryname); + + if exist(graphic_dir)==7 % only, if not in ne graphic mode + aim_savefile(handles,sig,name,'signal','signal',[],handles.all_options); + signame= fullfile(handles.info.original_soundfile_directory,handles.info.signalwavename); + savewave(sig,signame,0); + end + +% handles.info.calculate_signal=0; + +end + + + +% calculate outerear /middle ear transfere function +% if get(handles.checkbox0,'Value')==1 +if handles.info.calculate_pcp==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,2); + handles.info.calculated_pcp_module=generating_module; % this one is really calculated + sig=handles.data.signal; + callline=sprintf('res=%s(sig,coptions);',generating_function); + eval(callline); % evaluate the generating function + % store the result + handles.data.pcp=res; + + if handles.info.save_pcp==1 + aim_savefile(handles,res,handles.info.pcpname,'pcp',generating_module,coptions,handles.all_options); + end + if handles.with_graphic==1 + handles.info.pcp_loaded=1; + handles.info.current_plot=2; % display the new data + set(handles.checkbox0,'Value',0); + handles=aim_deletefile(handles,'bmm'); + handles=aim_deletefile(handles,'nap'); + handles=aim_deletefile(handles,'strobes'); + handles=aim_deletefile(handles,'sai'); + handles=aim_deletefile(handles,'usermodule'); + end +end + +% calculate outer ear middle ear transfere functin +% if get(handles.checkbox1,'Value')==1 +if handles.info.calculate_bmm==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,3); + handles.info.calculated_bmm_module=generating_module; % this one is really calculated + sig=handles.data.pcp; + callline=sprintf('res=%s(sig,coptions);',generating_function); + eval(callline); + % store the result + handles.data.bmm=res; + if handles.info.save_bmm==1 + aim_savefile(handles,res,handles.info.bmmname,'bmm',generating_module,coptions,handles.all_options); + end + if handles.with_graphic==1 + handles.info.bmm_loaded=1; + handles.info.current_plot=3; % display the new data + % if this one is calculated new, then the further part has no relevance any more: + set(handles.checkbox1,'Value',0); + handles=aim_deletefile(handles,'nap'); + handles=aim_deletefile(handles,'strobes'); + handles=aim_deletefile(handles,'sai'); + handles=aim_deletefile(handles,'usermodule'); + end +end + +% calculate NAP +% if get(handles.checkbox2,'Value')==1 +if handles.info.calculate_nap==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,4); + handles.info.calculated_nap_module=generating_module; % this one is really calculated + bmm=handles.data.bmm; + callline=sprintf('res=%s(bmm,coptions);',generating_function); + eval(callline); + % store the result + handles.data.nap=res; + if handles.info.save_nap==1 + aim_savefile(handles,res,handles.info.napname,'nap',generating_module,coptions,handles.all_options); + end + if handles.with_graphic==1 + handles.info.nap_loaded=1; + handles.info.current_plot=4; % display the new data + % if this one is calculated new, then the further part has no relevance any more: + set(handles.checkbox2,'Value',0); + handles=aim_deletefile(handles,'strobes'); + handles=aim_deletefile(handles,'sai'); + handles=aim_deletefile(handles,'usermodule'); + end +end + +% calculate Strobes +% if get(handles.checkbox3,'Value')==1 +if handles.info.calculate_strobes==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,5); + handles.info.calculated_strobes_module=generating_module; % this one is really calculated + nap=handles.data.nap; + callline=sprintf('[res,thres]=%s(nap,coptions);',generating_function); + eval(callline); + % store the result + handles.data.strobes=res; + if handles.info.save_strobes==1 + aim_savefile(handles,res,handles.info.strobesname,'strobes',generating_module,coptions,handles.all_options); +% if isoftype(handles.data.bmm,'frame') && getnrchannels(handles.data.bmm)==1 + aim_savefile(handles,thres,handles.info.thresholdsname,'thresholds',generating_module,coptions,handles.all_options); +% end + end + if handles.with_graphic==1 + % if we only have one channel, then it is useful also to have the + % thresholds: + + handles.data.thresholds=thres; + handles.info.strobes_loaded=1; + handles.info.current_plot=5; % display the new data + + % if this one is calculated new, then the further part has no relevance any more: + set(handles.checkbox3,'Value',0); + handles=aim_deletefile(handles,'sai'); + handles=aim_deletefile(handles,'usermodule'); + + %TCW AIM2006 + handles=aim_deletefile(handles,'pitch_image'); + % This cleans up after pitchresonance and other dual output SAI + % modules but will log an error to the command window if the + % previous SAI module wasn't dual output. This is a bug and needs fixing. + end +end + +% calculate SAI +% if get(handles.checkbox4,'Value')==1 +if handles.info.calculate_sai==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,6); + handles.info.calculated_sai_module=generating_module; % this one is really calculated + nap=handles.data.nap; + strobes=handles.data.strobes; + callline=sprintf('res=%s(nap,strobes,coptions);',generating_function); + + % add the soundfilename in case for ams + if strcmp(generating_module,'ams') % for one channel we additionally pass the threshold: + coptions.soundfile=handles.info.oldsignalwavename; + else + if getnrchannels(handles.data.bmm)==1 % for one channel we additionally pass the threshold: + coptions.single_channel_threshold=handles.data.thresholds; + end + end + + eval(callline); + + % This module is a special case, as we can have two sorts of output + % from it, either the straight SAI (as seen in AIM 2003), or a pair of images: the pitch + % image and resonance image. If the dual_output option is set to 1 in + % the parameters file, then the module is taken to have two outputs. + % One of these outputs, the resonance image, gets put in the old 'sai' + % part of the structure, and the pitch image is placed in a new + % structure, 'pitch_image'. + if ~isfield(coptions, 'dual_output') + coptions.dual_output=0; + end + + % store the result + if (coptions.dual_output==1) + handles.data.sai=res{1}; + handles.data.pitch_image=res{2}; + else + handles.data.sai=res; + end + + + %handles.data.sai=res; + + if handles.info.save_sai==1 + if (coptions.dual_output==1) + aim_savefile(handles,res{1},handles.info.sainame,'sai',generating_module,coptions,handles.all_options); + aim_savefile(handles,res{2},handles.info.pitch_imagename,'pitch_image',generating_module,coptions,handles.all_options); + else + aim_savefile(handles,res,handles.info.sainame,'sai',generating_module,coptions,handles.all_options); + end + end + + if handles.with_graphic==1 + handles.info.sai_loaded=1; + handles.info.current_plot=6; % display the new data + % if this one is calculated new, then the further part has no relevance any more: + set(handles.checkbox4,'Value',0); + handles=aim_deletefile(handles,'usermodule'); + end +end + + +% calculate user module +% if get(handles.checkbox8,'Value')==1 +if handles.info.calculate_usermodule==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,7); + handles.info.calculated_usermodule_module=generating_module; % this one is really calculated + + sai=handles.data.sai; + + % TCW AIM2006 - to cary through pitch-resonance output to the latter + % stages + if ~isfield(coptions, 'dual_input') + coptions.dual_input=0; + end + + + if coptions.dual_input==1 + if isfield(handles.data, 'pitch_image') + pitch_image=handles.data.pitch_image; + callline=sprintf('res=%s(sai,pitch_image,coptions);',generating_function); + else + error(['The module ' generating_module ' is dual input, but the SAI module used before it'... + ' was not dual output, please use a compatible module at this stage'... + ' for more information, see the documentation at'... + ' http://www.pdn.cam.ac.uk/cnbh/aim2006/']); + end + else + if isfield(handles.data, 'pitch_image') + error(['The module ' generating_module ' is not dual input, but the SAI module used before it'... + ' was dual output, please use a compatible module at this stage'... + ' for more information, see the documentation at'... + ' http://www.pdn.cam.ac.uk/cnbh/aim2006/']); + else + callline=sprintf('res=%s(sai,coptions);',generating_function); + end + + end + + + eval(callline); + + % store the result + handles.data.usermodule=res; + if handles.info.save_usermodule==1 + aim_savefile(handles,res,handles.info.usermodulename,'usermodule',generating_module,coptions,handles.all_options); + end + if handles.with_graphic==1 + handles.info.usermodule_loaded=1; + handles.info.current_plot=7; % display the new data + % if this one is calculated new, then the further part has no relevance any more: + set(handles.checkbox8,'Value',0); + end +end + +% calculate movies +% if get(handles.checkbox5,'Value')==1 +if handles.info.calculate_movie==1 + [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,8); + handles.info.calculated_movie_module=generating_module; % this one is really calculated +% if strcmp(handles.info.current_usermodule_module,'none') +% data=handles.data.sai; +% else +% data=handles.data.usermodule; +% end + +% % if we dont know about the framerate, then get the framerate from the +% % sai-module +% if ~isfield(coptions,'frames_per_second') +% [mod,func,opts]=aim_getcurrent_module(handles,7); % try in the usermodule +% if ~isfield(opts,'frames_per_second') +% [mod,func,opts2]=aim_getcurrent_module(handles,6); % try in the sai-module +% if ~isfield(opts2,'frames_per_second') +% disp('dont know about the framerate! Assuming 20'); +% coptions.frames_per_second=20; % dont know about it +% else +% coptions.frames_per_second=opts2.frames_per_second; +% end +% else +% coptions.frames_per_second=opts.frames_per_second; +% end +% end + + + % in case of the screen-movie, we need some additional information: +% if strcmp(handles.info.current_movie_module,'screen') + if handles.with_graphic==1 + if get(handles.checkbox7,'Value')==1 + handles.all_options.movie.screen.withtime=1; + coptions.withtime=1; + else + handles.all_options.movie.screen.withtime=0; + coptions.withtime=0; + end + % and if we want to see the frequency profile: + if get(handles.checkbox6,'Value')==1 + handles.all_options.movie.screen.withfre=1; + coptions.withfre=1; + else + handles.all_options.movie.screen.withfre=0; + coptions.withfre=0; + end + % do we want to see the signal? + if get(handles.checkbox10,'Value')==1 + handles.all_options.movie.screen.withsignal=1; + coptions.withsignal=1; + else + handles.all_options.movie.screen.withsignal=0; + coptions.withsignal=0; + end + % scaling properties + data_scale=slidereditcontrol_get_value(handles.slideredit_scale); + handles.all_options.movie.screen.data_scale=data_scale; + coptions.data_scale=data_scale; + end +% end + + % give the movie access to all data, which is useful for bmm, etc + data=handles.data; + + + % add a few names to the options, so that the movie can be saved + if handles.with_graphic==1 + uniqueworkingname=handles.info.uniqueworkingname; + directoryname=handles.info.directoryname; + % find out the name of this movie. Movies are numberd in their + % order, so that no one is lost + moviename=generate_new_movie_name(handles); + newname=fullfile(handles.info.uniqueworkingname,moviename); + coptions.moviename=newname; + coptions.soundfilename=handles.info.signalwavename; + coptions.handles=handles; + callline=sprintf('%s(data,coptions);',generating_function); + eval(callline); + handles.info.movie_loaded=1; + handles.info.last_movie_name_generated=moviename; + set(handles.checkbox5,'Value',0); + else + coptions.moviename=sprintf('%s.%s.mov',handles.info.uniqueworkingname,handles.info.current_movie_module); + coptions.soundfilename=handles.all_options.signal.signal_filename; + coptions.handles=handles; + callline=sprintf('%s(sai,coptions);',generating_function); + eval(callline); + end +end + +% return the pointer shape +if handles.with_graphic==1 + set(handles.figure1,'Pointer','arrow'); +end diff -r 000000000000 -r 74dedb26614d aim-mat/gui/do_aim_updateparameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/do_aim_updateparameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,285 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=do_aim_updateparameters(handles) +% return the pointer shape +if handles.with_graphic==1 + set(handles.figure1,'Pointer','watch'); + wbh=waitbar(0,'Updating Parameters... Please Wait'); +end + + +% set the checkboxes according to the changes in the parameterfile. If +% changes have occured from the parameterfile relativ to the options in +% handles, the associated checkbox is checked. A further call to +% aim_calculate then does the rest + +oldoptions=handles.all_options; +parfile=handles.info.parameterfilename; + +olddir=pwd; +[pathstr,name,ext] = fileparts(parfile); +cd(pathstr); +eval(name); % here it is evaluated +cd(olddir); +if handles.with_graphic==1 + waitbar(0.2,wbh); +end +% +% wo=strfind(parfile,'.m'); +% if ~isempty(wo) +% parfile=parfile(1:wo-1); +% end +% +% [a,b,c]=fileparts(parfile); +% cd(a); +% parfile=parfile(strfind(parfile,'/')+1:end); +% eval(parfile); +% cd .. +newoptions=all_options; + +% compare the old and the new parameters to see, what must be changed +if ~structisequal(oldoptions.pcp,newoptions.pcp) + set(handles.checkbox0,'Value',1); + handles.info.calculate_pcp=1; +else + set(handles.checkbox0,'Value',0); + handles.info.calculate_pcp=0; +end +if handles.with_graphic==1 + waitbar(0.3,wbh); +end +if ~structisequal(oldoptions.bmm,newoptions.bmm) + set(handles.checkbox1,'Value',1); + handles.info.calculate_bmm=1; +else + set(handles.checkbox1,'Value',0); + handles.info.calculate_bmm=0; +end +if handles.with_graphic==1 + waitbar(0.4,wbh); +end +if ~structisequal(oldoptions.nap,newoptions.nap) + set(handles.checkbox2,'Value',1); + handles.info.calculate_nap=1; +else + set(handles.checkbox2,'Value',0); + handles.info.calculate_nap=0; +end +if handles.with_graphic==1 + waitbar(0.5,wbh); +end +if ~structisequal(oldoptions.strobes,newoptions.strobes) + set(handles.checkbox3,'Value',1); + handles.info.calculate_strobes=1; +else + set(handles.checkbox3,'Value',0); + handles.info.calculate_strobes=0; +end +if handles.with_graphic==1 + waitbar(0.6,wbh); +end +if ~structisequal(oldoptions.sai,newoptions.sai) + set(handles.checkbox4,'Value',1); + handles.info.calculate_sai=1; +else + set(handles.checkbox4,'Value',0); + handles.info.calculate_sai=0; +end +if handles.with_graphic==1 + waitbar(0.7,wbh); +end +if ~structisequal(oldoptions.usermodule,newoptions.usermodule) + set(handles.checkbox8,'Value',1); + handles.info.calculate_usermodule=1; +else + set(handles.checkbox8,'Value',0); + handles.info.calculate_usermodule=0; +end +% if ~structisequal(oldoptions.movie,newoptions.movie) +% set(handles.checkbox5,'Value',1); +% handles.info.calculate_movie=1; +% else +% set(handles.checkbox5,'Value',0); +% handles.info.calculate_movie=0; +% end + +if handles.with_graphic==1 + waitbar(0.8,wbh); +end +% check, if the signal time has changed, if, redo everything! +changesig=0; +if oldoptions.signal.start_time~=newoptions.signal.start_time + changesig=1; +end +if oldoptions.signal.duration~=newoptions.signal.duration + changesig=1; +end +if oldoptions.signal.samplerate~=newoptions.signal.samplerate + changesig=1; +end + +% if ~structisequal(oldoptions.signal,newoptions.signal) +if changesig==1 + new_duration=newoptions.signal.duration; + new_start_time=newoptions.signal.start_time; + new_sr=newoptions.signal.samplerate; + +% if new_start_time+new_duration>handles.all_options.signal.original_duration +% error('fehler in do_aim_updateparameters '); +% end + + + if handles.info.pcp_loaded==1 + set(handles.checkbox0,'Value',1); + handles.info.calculate_pcp=1; + end + if handles.info.bmm_loaded==1 + set(handles.checkbox1,'Value',1); + handles.info.calculate_bmm=1; + end + if handles.info.nap_loaded==1 + set(handles.checkbox2,'Value',1); + handles.info.calculate_nap=1; + end + if handles.info.strobes_loaded==1 + set(handles.checkbox3,'Value',1); + handles.info.calculate_strobes=1; + end + if handles.info.sai_loaded==1 + set(handles.checkbox4,'Value',1); + handles.info.calculate_sai=1; + end + if handles.info.usermodule_loaded==1 + set(handles.checkbox8,'Value',1); + handles.info.calculate_usermodule=1; + end + if handles.info.movie_loaded==1 + set(handles.checkbox5,'Value',1); + handles.info.calculate_movie=1; + end + handles.info.calculate_signal=1; + + + % change the slider etc... + if new_duration>1 + set(handles.displayduration,'String',num2str(fround(new_duration,2))); + set(handles.text20,'String','sec'); + else + set(handles.displayduration,'String',num2str(fround(new_duration*1000,0))); + set(handles.text20,'String','ms'); + end + % samplerate + set(handles.text25,'String',num2str(fround(new_sr/1000,1))); + % offset + if new_start_time>0 + set(handles.text29,'String',num2str(fround(new_start_time*1000,1))); + set(handles.text29,'Visible','on'); + set(handles.text30,'Visible','on'); + else + set(handles.text29,'Visible','off'); + set(handles.text30,'Visible','off'); + end + handles.slideredit_start.minvalue=new_start_time; + handles.slideredit_start.maxvalue=new_start_time+new_duration-0.04; + handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,new_start_time); + handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,new_duration/10); + + handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.04); + handles.slideredit_duration.maxvalue=new_duration; + handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,new_duration/10); + + handles.currentslidereditcombi=handles.slideredit_start; + +else + handles.info.calculate_signal=0; +end + +if handles.with_graphic==1 + waitbar(0.9,wbh); +end +% set the current info in handles to the current values +generating_module_string=get(handles.listbox0,'String'); +generating_module=generating_module_string(get(handles.listbox0,'Value')); +if ~isfield(handles.info,'current_pcp_module') || ~strcmp(handles.info.current_pcp_module,generating_module{1}) + handles.info.calculate_pcp=1; + set(handles.checkbox0,'Value',1); +end +handles.info.current_pcp_module=generating_module{1}; + +generating_module_string=get(handles.listbox1,'String'); +generating_module=generating_module_string(get(handles.listbox1,'Value')); +if ~isfield(handles.info,'current_bmm_module') || ~strcmp(handles.info.current_bmm_module,generating_module{1}) + handles.info.calculate_bmm=1; + set(handles.checkbox1,'Value',1); +end +handles.info.current_bmm_module=generating_module{1}; + +generating_module_string=get(handles.listbox2,'String'); +generating_module=generating_module_string(get(handles.listbox2,'Value')); +if ~isfield(handles.info,'current_nap_module') || ~strcmp(handles.info.current_nap_module,generating_module{1}) + handles.info.calculate_nap=1; + set(handles.checkbox2,'Value',1); +end +handles.info.current_nap_module=generating_module{1}; + +generating_module_string=get(handles.listbox3,'String'); +generating_module=generating_module_string(get(handles.listbox3,'Value')); +if ~isfield(handles.info,'current_strobes_module') || ~strcmp(handles.info.current_strobes_module,generating_module{1}) + handles.info.calculate_strobes=1; + set(handles.checkbox3,'Value',1); +end +handles.info.current_strobes_module=generating_module{1}; + +generating_module_string=get(handles.listbox4,'String'); +generating_module=generating_module_string(get(handles.listbox4,'Value')); +if ~isfield(handles.info,'current_sai_module') || ~strcmp(handles.info.current_sai_module,generating_module{1}) + handles.info.calculate_sai=1; + set(handles.checkbox4,'Value',1); +end +handles.info.current_sai_module=generating_module{1}; + +generating_module_string=get(handles.listbox6,'String'); +generating_module=generating_module_string(get(handles.listbox6,'Value')); +if ~isfield(handles.info,'current_usermodule_module') || ~strcmp(handles.info.current_usermodule_module,generating_module{1}) + handles.info.calculate_usermodule=1; + set(handles.checkbox8,'Value',1); +end +handles.info.current_usermodule_module=generating_module{1}; + +generating_module_string=get(handles.listbox5,'String'); +generating_module=generating_module_string(get(handles.listbox5,'Value')); +if ~isfield(handles.info,'current_movie_module') || ~strcmp(handles.info.current_movie_module,generating_module{1}) + handles.info.calculate_movie=1; + set(handles.checkbox5,'Value',1); +end +handles.info.current_movie_module=generating_module{1}; + + +% put some additional information in the info-domain +handles.info.save_pcp=1; +handles.info.save_bmm=1; +handles.info.save_nap=1; +handles.info.save_sai=1; +handles.info.save_strobes=1; +handles.info.save_usermodule=1; +handles.info.save_movie=1; + + +% and update the new parameters +handles.all_options=newoptions; + +if handles.with_graphic==1 + waitbar(1,wbh); + close(wbh); + set(handles.figure1,'Pointer','arrow'); +end \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/edit_duration.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/edit_duration.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,53 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=edit_duration(hObject, eventdata, handles) + + +curval=get(hObject,'String'); +curval=str2num(curval); + +handles.slideredit_duration=... + slidereditcontrol_set_raweditvalue(handles.slideredit_duration,curval); + +sig=handles.data.signal; + +if handles.info.current_plot>=6 %sai has additionally the start time below: + current_start_time=slidereditcontrol_get_value(handles.slideredit_duration); % the new value + framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1}); + + nr_frames=length(handles.data.sai); + current_frame_nr=round((current_start_time-getminimumtime(sig))/framelen)+1; % plus 1 because of the duration of the frame itself + current_frame_nr=min(nr_frames,current_frame_nr); + current_frame_nr=max(1,current_frame_nr); + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_frame_nr); + realval=(current_frame_nr-1)*framelen+getminimumtime(sig); + handles.slideredit_duration=... + slidereditcontrol_set_value(handles.slideredit_duration,realval); +else + % check range + start=slidereditcontrol_get_value(handles.currentslidereditcombi); + dur=slidereditcontrol_get_value(handles.slideredit_duration); + siglen=getmaximumtime(sig); + if start+dur>siglen + dur=siglen-start; + end + + + handles.slideredit_duration=... + slidereditcontrol_set_value(handles.slideredit_duration,dur); + + % set the range of the start_slider accordingly + len=slidereditcontrol_get_value(handles.slideredit_duration); + handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,len); % the duration + +end diff -r 000000000000 -r 74dedb26614d aim-mat/gui/edit_scale.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/edit_scale.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,36 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=edit_scale(hObject, eventdata, handles) + + +curval=get(hObject,'String'); +curval=str2num(curval); +handles.slideredit_scale=... + slidereditcontrol_set_raweditvalue(handles.slideredit_scale,curval); + + +return + + + +% strval=str2double(get(hObject,'String')); +% von=handles.data.min_scale; +% bis=handles.data.max_scale; +% if strval>bis +% strval=bis; +% end +% if strval=6 %sai has additionally the start time below: + sai=handles.data.sai; + cval=slidereditcontrol_get_value(handles.currentslidereditcombi); + cval=round(cval); + start_time=getcurrentframestarttime(sai{cval}); + set(handles.edit2,'String',num2str(cval)); + set(handles.edit3,'String',num2str(fround(start_time*1000,1))); +else + % range check: + start=slidereditcontrol_get_value(handles.currentslidereditcombi); + start=max(start,0); + dur=slidereditcontrol_get_value(handles.slideredit_duration); + sig=handles.data.signal; + siglen=getmaximumtime(sig); + if start+dur>siglen + start=siglen-dur; + end + handles.currentslidereditcombi=... + slidereditcontrol_set_value(handles.currentslidereditcombi,start); +% % and set a new range +% handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,dur); % the duration + +end \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/generate_new_movie_name.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/generate_new_movie_name.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,26 @@ +% procedure for 'aim-mat' +% +% function handles=do_aim_calculate(handles) +% +% INPUT VALUES: +% RETURN VALUE: +% a new unique movie name +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + + +function new_name=generate_new_movie_name(handles) +% looks through the directory and decides, what name a new movie should get + +dirname=handles.info.directoryname; +cd(dirname); + +allmovies=dir('*.mov'); +nr_movies=length(allmovies); +newnumber=nr_movies+1; +new_name=sprintf('%s.movie%d.mov',handles.info.uniqueworkingname,newnumber); +cd .. diff -r 000000000000 -r 74dedb26614d aim-mat/gui/init_aim_gui.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/init_aim_gui.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,615 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% handles : all relevant parameters +% +% RETURN VALUE: +% +% reset the graphic and everything in the GUI +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function handles=init_aim_gui(handles) + +% TCW AIM2006 +handles.hand_scaling=1; + +modus=handles.screen_modus; + +switch modus + case 'screen' + % set some colors: (green for display) + %handles.colors.background=[0 .502 0]; %Old AIM + handles.colors.background=[236/255 233/255 240/255]; + handles.colors.green1=[0 0.75 0]; + handles.colors.green2=[0 1 0]; + handles.colors.blue2=[0 0 1]; + handles.colors.blue1=[0.5 0 0]; + handles.colors.white=[1 1 1]; + handles.colors.black=[0 0 0]; + handles.colors.blue3=[0 0.5 0.5]; + handles.colors.textonbackground=handles.colors.black; + handles.colors.textonbuttons=handles.colors.black; + handles.colors.buttoncolor=[0.831 0.816 0.784]; + case 'paper' +% set some colors: (gray for publication) + handles.colors.background=[0.83 0.83 0.83]; + handles.colors.green1=[0.75 0.75 0.75]; + handles.colors.green2=[0.6 0.6 0.6]; + handles.colors.blue2=[0.5 0.5 0.5]; + handles.colors.blue1=[0.4 0.4 0.4]; + handles.colors.white=[1 1 1]; + handles.colors.black=[0 0 0]; + handles.colors.blue3=[0.8 0.8 0.8]; + handles.colors.textonbackground=handles.colors.black; + handles.colors.textonbuttons=handles.colors.white; + handles.colors.buttoncolor=handles.colors.green1; +end + +set(handles.figure1,'Color',handles.colors.background); +set(handles.text23,'BackgroundColor',handles.colors.background); +set(handles.text23,'ForegroundColor',handles.colors.textonbackground); +set(handles.text19,'BackgroundColor',handles.colors.background); +set(handles.text19,'ForegroundColor',handles.colors.textonbackground); +set(handles.text17,'BackgroundColor',handles.colors.background); +set(handles.text17,'ForegroundColor',handles.colors.textonbackground); +set(handles.displayduration,'BackgroundColor',handles.colors.background); +set(handles.displayduration,'ForegroundColor',handles.colors.textonbackground); +set(handles.text20,'BackgroundColor',handles.colors.background); +set(handles.text20,'ForegroundColor',handles.colors.textonbackground); +set(handles.text28,'BackgroundColor',handles.colors.background); +set(handles.text28,'ForegroundColor',handles.colors.textonbackground); +set(handles.text29,'BackgroundColor',handles.colors.background); +set(handles.text29,'ForegroundColor',handles.colors.textonbackground); +set(handles.text30,'BackgroundColor',handles.colors.background); +set(handles.text30,'ForegroundColor',handles.colors.textonbackground); +set(handles.text27,'BackgroundColor',handles.colors.background); +set(handles.text27,'ForegroundColor',handles.colors.textonbackground); +set(handles.text25,'BackgroundColor',handles.colors.background); +set(handles.text25,'ForegroundColor',handles.colors.textonbackground); +set(handles.text24,'BackgroundColor',handles.colors.background); +set(handles.text24,'ForegroundColor',handles.colors.textonbackground); +set(handles.text9,'BackgroundColor',handles.colors.background); +set(handles.text9,'ForegroundColor',handles.colors.textonbackground); +set(handles.text10,'BackgroundColor',handles.colors.background); +set(handles.text10,'ForegroundColor',handles.colors.textonbackground); +set(handles.text8,'BackgroundColor',handles.colors.background); +set(handles.text8,'ForegroundColor',handles.colors.textonbackground); +set(handles.text7,'BackgroundColor',handles.colors.background); +set(handles.text7,'ForegroundColor',handles.colors.textonbackground); +set(handles.text21,'BackgroundColor',handles.colors.background); +set(handles.text21,'ForegroundColor',handles.colors.textonbackground); +set(handles.text22,'BackgroundColor',handles.colors.background); +set(handles.text22,'ForegroundColor',handles.colors.textonbackground); +set(handles.text13,'BackgroundColor',handles.colors.background); +set(handles.text13,'ForegroundColor',handles.colors.textonbackground); + +set(handles.frame16,'BackgroundColor',handles.colors.background); +set(handles.frame15,'BackgroundColor',handles.colors.background); +set(handles.frame18,'BackgroundColor',handles.colors.background); +set(handles.frame17,'BackgroundColor',handles.colors.background); +set(handles.frame17,'ForegroundColor',handles.colors.black); +set(handles.frame14,'BackgroundColor',handles.colors.background); +set(handles.frame14,'ForegroundColor',handles.colors.black); +set(handles.frame19,'BackgroundColor',handles.colors.background); +set(handles.frame19,'ForegroundColor',handles.colors.background); + +set(handles.frame7,'BackgroundColor',handles.colors.background); +set(handles.frame10,'BackgroundColor',handles.colors.blue3); + +set(handles.checkbox10,'BackgroundColor',handles.colors.background); +set(handles.checkbox10,'ForegroundColor',handles.colors.textonbackground); +set(handles.checkbox6,'BackgroundColor',handles.colors.background); +set(handles.checkbox6,'ForegroundColor',handles.colors.textonbackground); +set(handles.checkbox7,'BackgroundColor',handles.colors.background); +set(handles.checkbox7,'ForegroundColor',handles.colors.textonbackground); + +set(handles.checkbox0,'BackgroundColor',handles.colors.background); +set(handles.checkbox1,'BackgroundColor',handles.colors.background); +set(handles.checkbox2,'BackgroundColor',handles.colors.background); +set(handles.checkbox3,'BackgroundColor',handles.colors.background); +set(handles.checkbox4,'BackgroundColor',handles.colors.background); +set(handles.checkbox8,'BackgroundColor',handles.colors.background); +set(handles.checkbox5,'BackgroundColor',handles.colors.blue3); + +set(handles.pushbutton24,'BackgroundColor',handles.colors.buttoncolor); +set(handles.pushbutton25,'BackgroundColor',handles.colors.buttoncolor); +set(handles.pushbuttonautoscale,'BackgroundColor',handles.colors.buttoncolor); +set(handles.slider1,'BackgroundColor',handles.colors.buttoncolor); +set(handles.slider2,'BackgroundColor',handles.colors.buttoncolor); +set(handles.slider3,'BackgroundColor',handles.colors.buttoncolor); + + +% % % first load the default values from the default parameter file: +% handles=loadallparameterfiles(handles); +all_options=handles.all_options; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% PCP +pcpnames = fieldnames(all_options.pcp); +finalpcpnames=[]; +finddefault=1; +findold=-1; + +% TCW AIM2006 Reorder the list so that the default value comes first +for i=1:length(pcpnames) + if strcmp(pcpnames{i},handles.info.default_start_module_pcp) + finalpcpnames=[pcpnames(i) finalpcpnames]; + else + finalpcpnames=[finalpcpnames pcpnames(i)]; + end +end +%%% + +for i=1:length(finalpcpnames) + if strcmp(finalpcpnames{i},handles.info.default_start_module_pcp) + finddefault=i; + end + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_pcp_module') + if strcmp(finalpcpnames{i},handles.info.init.calculated_pcp_module) + findold=i; + end + end + end +end +set(handles.listbox0,'String',finalpcpnames); +if findold>0 + handles.info.current_pcp_module=finalpcpnames{findold}; + set(handles.listbox0,'Value',findold); +else + handles.info.current_pcp_module=finalpcpnames{finddefault}; + set(handles.listbox0,'Value',finddefault); +end +handles.info.defaults.default_pcp_module=finddefault; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% BMM +bmmnames = fieldnames(all_options.bmm); +finalbmmnames=[]; +finddefault=1; +findold=-1; +% TCW AIM2006 Reorder the list so that the default value comes first +for i=1:length(bmmnames) + if strcmp(bmmnames{i},handles.info.default_start_module_bmm) + finalbmmnames=[bmmnames(i) finalbmmnames]; + else + finalbmmnames=[finalbmmnames bmmnames(i)]; + end +end +%%% + +for i=1:length(finalbmmnames) + if strcmp(finalbmmnames{i},handles.info.default_start_module_bmm) + finddefault=i; + end + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_bmm_module') + if strcmp(finalbmmnames{i},handles.info.init.calculated_bmm_module) + findold=i; + end + end + end +end +set(handles.listbox1,'String',finalbmmnames); +if findold>0 + handles.info.current_bmm_module=finalbmmnames{findold}; + set(handles.listbox1,'Value',findold); +else + handles.info.current_bmm_module=finalbmmnames{finddefault}; + set(handles.listbox1,'Value',finddefault); +end +handles.info.defaults.default_bmm_module=finddefault; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% NAP +napnames = fieldnames(all_options.nap); +finalnapnames=[]; +finddefault=1; +findold=-1; +% TCW AIM2006 Reorder the list so that the default value comes first +for i=1:length(napnames) + if strcmp(napnames{i},handles.info.default_start_module_nap) + finalnapnames=[napnames(i) finalnapnames]; + else + finalnapnames=[finalnapnames napnames(i)]; + end +end +%%% + +for i=1:length(finalnapnames) + if strcmp(finalnapnames{i},handles.info.default_start_module_nap) + finddefault=i; + end + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_nap_module') + if strcmp(finalnapnames{i},handles.info.init.calculated_nap_module) + findold=i; + end + end + end +end +set(handles.listbox2,'String',finalnapnames); +if findold>0 + handles.info.current_nap_module=finalnapnames{findold}; + set(handles.listbox2,'Value',findold); +else + handles.info.current_nap_module=finalnapnames{finddefault}; + set(handles.listbox2,'Value',finddefault); +end +handles.info.defaults.default_nap_module=finddefault; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% STROBES +strobesnames = fieldnames(all_options.strobes); +finalstrobesnames=[]; +finddefault=1; +findold=-1; + +% TCW AIM2006 Reorder the list so that the default value comes first +for i=1:length(strobesnames) + if strcmp(strobesnames{i},handles.info.default_start_module_strobes) + finalstrobesnames=[strobesnames(i) finalstrobesnames]; + else + finalstrobesnames=[finalstrobesnames strobesnames(i)]; + end +end + +for i=1:length(finalstrobesnames) + %finalstrobesnames=[finalstrobesnames strobesnames(i)]; + % default value is sf2003: + if strcmp(finalstrobesnames{i},handles.info.default_start_module_strobes) + finddefault=i; + end + % if loaded from a project, set the settings to the loaded ones + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_strobes_module') + if strcmp(finalstrobesnames{i},handles.info.init.calculated_strobes_module) + findold=i; + end + end + end +end +set(handles.listbox3,'String',finalstrobesnames); +if findold>0 + handles.info.current_strobes_module=finalstrobesnames{findold}; + set(handles.listbox3,'Value',findold); +else + handles.info.current_strobes_module=finalstrobesnames{finddefault}; + set(handles.listbox3,'Value',finddefault); +end +handles.info.defaults.default_strobes_module=finddefault; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% SAI +sainames = fieldnames(all_options.sai); +finalsainames=[]; +finddefault=1; +findold=-1; + +% TCW AIM2006 Reorder the list so that the default value comes first +for i=1:length(sainames) + if strcmp(sainames{i},handles.info.default_start_module_sai) + finalsainames=[sainames(i) finalsainames]; + else + finalsainames=[finalsainames sainames(i)]; + end +end + +for i=1:length(finalsainames) + if strcmp(finalsainames{i},handles.info.default_start_module_sai) + finddefault=i; + end + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_sai_module') + if strcmp(finalsainames{i},handles.info.init.calculated_sai_module) + findold=i; + end + end + end +end +set(handles.listbox4,'String',finalsainames); +if findold>0 + handles.info.current_sai_module=finalsainames{findold}; + set(handles.listbox4,'Value',findold); +else + handles.info.current_sai_module=finalsainames{finddefault}; + set(handles.listbox4,'Value',finddefault); +end +handles.info.defaults.default_sai_module=finddefault; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% USERMODULES +usermodulenames = fieldnames(all_options.usermodule); +finalusermodulenames=[]; +finddefault=1; +findold=-1; + +% TCW AIM2006 Reorder the list so that the default value comes first +for i=1:length(usermodulenames) + if strcmp(usermodulenames{i},handles.info.default_start_module_usermodule) + finalusermodulenames=[usermodulenames(i) finalusermodulenames]; + else + finalusermodulenames=[finalusermodulenames usermodulenames(i)]; + end +end + +for i=1:length(finalusermodulenames) + %finalusermodulenames=[finalusermodulenames usermodulenames(i)]; + % default value is dualprofile: + if strcmp(finalusermodulenames{i},handles.info.default_start_module_usermodule) + finddefault=i; + end + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_usermodule_module') + if strcmp(finalusermodulenames{i},handles.info.init.calculated_usermodule_module) + findold=i; + end + end + end + +end +set(handles.listbox6,'String',finalusermodulenames); +if findold>0 + handles.info.current_usermodule_module=finalusermodulenames{findold}; + set(handles.listbox6,'Value',findold); +else + handles.info.current_usermodule_module=finalusermodulenames{finddefault}; + set(handles.listbox6,'Value',finddefault); +end +handles.info.defaults.default_usermodule_module=finddefault; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%% MOVIES +movienames = fieldnames(all_options.movie); +finalmovienames=[]; +finddefault=1; +findold=-1; +for i=1:length(movienames) + finalmovienames=[finalmovienames movienames(i)]; + % default value is dpai: + if strcmp(finalmovienames{i},handles.info.default_start_module_movie) + finddefault=i; + end + if isfield(handles.info,'init') + if isfield(handles.info.init,'calculated_movie_module') + if strcmp(finalmovienames{i},handles.info.init.calculated_movie_module) + findold=i; + end + end + end + +end +set(handles.listbox5,'String',finalmovienames); +if findold>0 + handles.info.current_movie_module=finalmovienames{findold}; + set(handles.listbox5,'Value',findold); +else + handles.info.current_movie_module=finalmovienames{finddefault}; + set(handles.listbox5,'Value',finddefault); +end +handles.info.defaults.default_movie_module=finddefault; + + + + + + +% set all calculation orders to false +handles.info.calculate_signal=0; +handles.info.calculate_pcp=0; +handles.info.calculate_bmm=0; +handles.info.calculate_nap=0; +handles.info.calculate_strobes=0; +handles.info.calculate_sai=0; +handles.info.calculate_usermodule=0; +handles.info.calculate_movie=0; + +% in the graphic version, store the results +handles.info.save_signal=1; +handles.info.save_pcp=1; +handles.info.save_bmm=1; +handles.info.save_nap=1; +handles.info.save_strobes=1; +handles.info.save_sai=1; +handles.info.save_usermodule=1; +handles.info.save_movie=1; + + + + +if isfield(handles.info,'init') + set(handles.checkbox6,'Value',handles.info.init.hastime); + set(handles.checkbox7,'Value',handles.info.init.hasfreq); + set(handles.checkbox10,'Value',handles.info.init.hassignal); + handles.info.old_current_plot=0; + +else + % set the frequency profile off + set(handles.checkbox6,'Value',0); + % set the temporal profile off + set(handles.checkbox7,'Value',0); + % set the signal on + set(handles.checkbox10,'Value',1); + % set the current visible plot (the signal alone) + handles.info.current_plot=-1; + handles.info.old_current_plot=0; +end + + + +if isfield(handles.info,'init') + duration=handles.info.init.duration; + start_time=handles.info.init.start_time; + scale=handles.info.init.scale; +else + duration=0.04; + start_time=0; + scale=1; +end + + +sig=handles.data.signal; + + +% set up the combicontrols +handles.slideredit_start=slidereditcontrol_setup(... + handles.slider2,... % handle of the slider + handles.edit2,...% handle of the edit control + getminimumtime(sig), ... % min value + getmaximumtime(sig), ... % max value + max(start_time,getminimumtime(sig)), ... % current value + 0, ... % islog + 1000, ...% multiplier on the edit control + 1); % nr digits in the edit control after comma +handles.slideredit_duration=slidereditcontrol_setup(... + handles.slider3,... % handle of the slider + handles.edit3,...% handle of the edit control + 0.001, ... % min value + getlength(sig), ... % max value + duration, ... % current value + 0, ... % islog + 1000, ...% multiplier on the edit control + 1); % nr digits in the edit control after comma +handles.slideredit_scale=slidereditcontrol_setup(... + handles.slider1,... % handle of the slider + handles.edit1,...% handle of the edit control + 0.001, ... % min value + 1000, ... % max value + scale, ... % current value + 1, ... % islog + 1, ...% multiplier on the edit control + 3); % nr digits in the edit control after comma +handles.slideredit_frames=slidereditcontrol_setup(... + handles.slider2,... % handle of the slider + handles.edit2,...% handle of the edit control + 1, ... % min value + 100, ... % max value + start_time, ... % current value + 0, ... % islog + 1, ...% multiplier on the edit control + 0); % nr digits in the edit control after comma + +current_plot=handles.info.current_plot; +if current_plot<6 + handles.currentslidereditcombi=handles.slideredit_start; +else + handles.slideredit_frames.maxvalue=length(handles.data.sai); + handles.currentslidereditcombi=handles.slideredit_frames; +% handles.currentslidereditcombi= +end +% handles.slideredit_scale=slidereditcontrol_set_value(handles.slideredit_scale,scale); +% handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,duration); +handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,duration); + +handles=aim_set_current_slider(handles); + +% display the signal lenght and samplerate +len=getlength(sig); +if len>1 + set(handles.displayduration,'String',num2str(fround(getlength(sig),2))); + set(handles.text20,'String','sec'); +else + set(handles.displayduration,'String',num2str(fround(getlength(sig)*1000,0))); + set(handles.text20,'String','ms'); +end +% samlerate +set(handles.text25,'String',num2str(fround(getsr(sig)/1000,1))); + +% offset +if start_time>0 + set(handles.text29,'String',num2str(fround(start_time*1000,1))); + set(handles.text29,'Visible','on'); + set(handles.text30,'Visible','on'); +else + set(handles.text29,'Visible','off'); + set(handles.text30,'Visible','off'); +end + + +set(handles.edit1,'Enable','on'); +set(handles.slider1,'Enable','on'); +set(handles.edit2,'Enable','on'); +set(handles.slider2,'Enable','on'); +set(handles.edit3,'Enable','on'); +set(handles.slider3,'Enable','on'); + + +% set the displayed module name to the one that was loaded +if handles.info.pcp_loaded + setstring(handles.listbox0,handles.info.current_pcp_module);end +if handles.info.bmm_loaded + setstring(handles.listbox1,handles.info.current_bmm_module);end +if handles.info.nap_loaded + setstring(handles.listbox2,handles.info.current_nap_module);end +if handles.info.strobes_loaded + setstring(handles.listbox3,handles.info.current_strobes_module);end +if handles.info.sai_loaded + setstring(handles.listbox4,handles.info.current_sai_module);end +if handles.info.usermodule_loaded + setstring(handles.listbox6,handles.info.current_usermodule_module);end +if handles.info.movie_loaded + setstring(handles.listbox5,handles.info.current_movie_module);end + +if isfield(handles.info,'init') + set(handles.checkbox6,'Value',handles.info.init.hastime); + set(handles.checkbox7,'Value',handles.info.init.hasfreq); + set(handles.checkbox10,'Value',handles.info.init.hassignal); + handles.info.old_current_plot=0; + +else + % set the frequency profile off + set(handles.checkbox6,'Value',0); + % set the temporal profile off + set(handles.checkbox7,'Value',0); + % set the signal on + set(handles.checkbox10,'Value',1); + % set the current visible plot (the signal alone) + handles.info.current_plot=-1; + handles.info.old_current_plot=0; +end + + + + + +handles.audioplayer_enabled = true; +try + y=getvalues(sig); + Fs=getsr(sig); + player = audioplayer(y / abs(max(y)), Fs); %make a player for the normalized signal + set(player, 'UserData', handles.figure1, 'TimerPeriod', 0.05, 'TimerFcn', @update_audio_position, ... + 'StartFcn', @start_function); + % the toolbar callback fcns look for these named bits of appdata + setappdata(hfig, 'theAudioPlayer', player); + setappdata(hfig, 'theAudioRecorder', []); + selection.inPoint = 1; + selection.outPoint = length(y); + setappdata(hfig, 'audioSelection', selection); % selection starts as "full" +catch + audioplayer_enabled = false; +end + + + + + +return + +function handles=setstring(hand,name) +strings=get(hand,'String'); +nrstring=size(strings); +for i=1:nrstring + if strcmp(strings{i},name) + set(hand,'Value',i); + return + end +end +return \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/init_aim_parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/init_aim_parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,80 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% handles : all relevant parameters +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function handles=init_aim_parameters(handles,filename) + +% reset program: +handles.info=[]; +handles.data=[]; +handles.slideredit_start=[]; +handles.slideredit_duration=[]; +handles.slideredit_scale=[]; +handles.slideredit_frames=[]; +handles.currentslidereditcombi=[]; +handles.all_options=[]; + +handles.info.default_start_module_pcp='gm2002'; +handles.info.default_start_module_bmm='dcgc'; +handles.info.default_start_module_nap='hl'; +handles.info.default_start_module_strobes='sf2003'; +handles.info.default_start_module_sai='ti2003'; +handles.info.default_start_module_usermodule='mellin'; +handles.info.default_start_module_movie='screen'; + +% set up all names, that we need in this project +handles=setupnames(handles,filename); + +% check, wheter there is an existing project, if yes, load it +directoryname=handles.info.directoryname; +% if directory is empty, delete it +if exist(lower(directoryname))==7 || exist(directoryname)==7 + cd(directoryname); + dir_struct = dir; + if length(dir_struct)<=2 + cd .. +% ELN fix: + ELNmessage=rmdir(directoryname); + else + cd .. + end +end + +if exist(lower(directoryname))==7 || exist(directoryname)==7 + % first load the standart parameters. Maybe some new modules are added. + % Old data is overwritten in the process. + handles=createparameterfile(handles); + if handles.error==1 + return + end + handles=aim_loadproject(handles,handles.info.signalwavename); + handles=aim_loadcurrentstate(handles); +else + % otherwise create a new project + % ELN fix: + ELNmessage=mkdir(directoryname); + handles.info.pcp_loaded=0; + handles.info.bmm_loaded=0; + handles.info.nap_loaded=0; + handles.info.strobes_loaded=0; + handles.info.sai_loaded=0; + handles.info.usermodule_loaded=0; + handles.info.movie_loaded=0; + handles=createparameterfile(handles); % create standart parameters + handles=aim_loadsignalfile(handles,filename); % load the signal file and set up + handles=aim_saveparameters(handles,handles.info.parameterfilename); % and save them again in case, they are overwritten +end + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/loadallparameterfiles.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/loadallparameterfiles.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,114 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=loadallparameterfiles(handles) +% go through all directories and call the single module-parameterfiles + +% first find the directory, where all modules are saved. This directory +% should usually be next to the \aim\matlab - directory: \aim\ +% find a module, that is always there: +fpa=which('gen_gtfb'); +[a,b,c]=fileparts(fpa); +where=strfind(a,'modules'); +if isempty(where) + str=sprintf('loadallparameterfiles: Cant locate the module path (file gen_gtfb not found)'); + disp(str); + % TODO: a better solution for this. + er=errordlg(str,'File Error'); + set(er,'WindowStyle','modal'); + handles.error=1; + return +end +columnpath=fpa(1:where+7); +handles.info.columnpath=columnpath; % save it for later + +% save these for later, all other are overwritten +addsig=0; +if isfield(handles,'all_options') + if isfield(handles.all_options,'signal') + addsig=1; + signaloptions=handles.all_options.signal; + end +end +% now go recurse through all directories in columnpath +allcols=dir(columnpath); +nr_files=size(allcols); +completepath=path; +olddir=pwd; +for i=3:nr_files + current_column_name=allcols(i).name; + if ~strcmpi(current_column_name(1),'.') % we dont want hidden files + current_column_path=[columnpath current_column_name]; + allmodules=dir(current_column_path); + nr_modules=size(allmodules); + if ~strcmp(current_column_name,'signal') + % cd(current_module_path) + for j=3:nr_modules + current_module_name=lower(allmodules(j).name); + if ~strcmpi(current_module_name(1),'.') + current_module_path=fullfile(current_column_path,current_module_name); + + % if the path is not in the matlab search path, add it + % to it and print a notice! + if isempty(strfind(completepath,current_module_path)) % the module is not in the path + addpath(current_module_path); + disp(sprintf('Directory %s was added to the path!',current_module_path)); + end + + cd(current_module_path) + try + eval('parameters'); % call the standart parameters. Then we have a struct + str=sprintf('all_options.%s.%s=%s;',current_column_name,current_module_name,current_module_name); + eval(str); + cstr=sprintf('allo=all_options.%s.%s;',current_column_name,current_module_name); + eval(cstr); + if isfield(allo,'displayfunction')==1 + dstr=sprintf('all_options.%s.%s.displayfunction=''%s'';',current_column_name,current_module_name,allo.displayfunction); + eval(dstr); + else if strcmp(current_column_name,'usermodule') && ~strcmp(current_column_name,'graphics') + dstr=sprintf('all_options.%s.%s.displayfunction='''';',current_column_name,current_module_name); + eval(dstr); + end + end + + eval(sprintf('clear %s',current_module_name)); + catch + % either pop up a window +% str=sprintf('The parameter file for the module: %s produced errors!',current_module_path); +% er=errordlg(str,'File Error'); +% set(er,'WindowStyle','modal'); + % or just plot a warning message on the screen + str=sprintf('The parameter file for the module: %s produced errors!',current_module_path); + disp(str); + +% stop program +% handles.error=1; +% cd(olddir); +% return +% +% or continue: + end + end + end + end + end +end +cd(olddir); +handles.all_options=all_options; +if addsig==1 + handles.all_options.signal=signaloptions; +end + + +% save the new path +allpath=path; +path(allpath); diff -r 000000000000 -r 74dedb26614d aim-mat/gui/loadsignalfile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/loadsignalfile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,262 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% load the signal file and all files, that are in this directory +% set the project variables accordingly. +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + +function handles=loadsignalfile(handles,signame); + + +signalname=handles.info.signalname; +signalwavename=handles.info.signalwavename; +oldsignalwavename=handles.info.oldsignalwavename; +pcpname=handles.info.pcpname; +bmmname=handles.info.bmmname; +napname=handles.info.napname; +strobesname=handles.info.strobesname; +thresholdsname=handles.info.thresholdsname; +sainame=handles.info.sainame; +usermodulename=handles.info.usermodulename; +moviename=handles.info.moviename; + + +% load the parameterfile: +if fexist(handles.info.parameterfilename) + workdir=pwd; + cd(handles.info.directoryname); + [a,parfile,c,d]=fileparts(handles.info.parameterfilename); + clear all_options; + eval(parfile); + cd(workdir); +end + + + +if fexist(signalname) + [sig,sigoptions]=aim_loadfile(signalname); +else + if fexist(signalwavename) + sig=loadwavefile(signal,signalwavename); + % and save the wavefile hinterher: + % nsf=sprintf('%s\\%s',handles.info.directoryname,signalwavename); + % copyfile(signalwavename,nsf); + % delete(signalwavename); + % signalwavename=nsf; + elseif fexist(oldsignalwavename) + sig=loadwavefile(signal,oldsignalwavename); + % and save the wavefile hinterher: + nsf=sprintf('%s\\%s',handles.info.directoryname,oldsignalwavename); + copyfile(oldsignalwavename,nsf); + % delete(oldsignalwavename); + signalwavename=nsf; + else + % handles=0; + return + end +end +handles.data.sig=sig; +len=getlength(sig); +if len<0.04 + str=sprintf('Signal %s too short',signame); + er=errordlg(str,'File Error'); + set(er,'WindowStyle','modal'); + pause; + handles=0; + return +end + + +handles.info.signal_loaded=1; +% we add these parameters to the parameter file (for the future) +handles.all_options.signal.signal_filename=handles.info.oldsignalwavename; +handles.all_options.signal.start_time=0; +handles.all_options.signal.duration=getlength(sig); +handles.all_options.signal.samplerate=getsr(sig); +signalstruct.data=sig; +signalstruct.options=handles.all_options.signal; + +% if the samplerate is too high, sample it down per default +sr=22050; +if handles.all_options.signal.samplerate>sr +% ask user if he wants that hi sample rate + srneu=input('The samplerate of the specified signal \nis higher then 22050 Hz. \nPlease insert a smaller samperate \n(or return for keeping the old one): '); + if ~isempty(srneu) + sig=changesr(sig,srneu); + handles.all_options.signal.samplerate=srneu; + signalstruct.data=sig; + handles.data.sig=sig; + end +end + + +save(signalname,'signalstruct'); +savewave(sig,signalwavename,0); + +if fexist(pcpname) + [pcp,type,options]=aim_loadfile(pcpname); + handles.data.pcp=pcp; + handles.info.pcp_loaded=1; + handles.info.calculated_pcp_module=type; % this one is really calculated + select(handles.listbox0,type); + if ~isempty(type) + str=sprintf('handles.all_options.pcpoptions.%s=options;',type); + eval(str); + else % old style + type='ELC'; + handles.all_options.pcpoptions=options; + sai_savefile(pcp,pcpname,type,options,handles.all_options); + end +else + handles.info.pcp_loaded=0; +end + +if fexist(bmmname) + [bmm,type,options]=aim_loadfile(bmmname); + handles.data.bmm=bmm; + handles.info.bmm_loaded=1; + handles.info.calculated_bmm_module=type; % this one is really calculated + + select(handles.listbox1,type); +else + handles.info.bmm_loaded=0; +end +if fexist(napname) + [nap,type,options]=aim_loadfile(napname); + handles.data.nap=nap; + handles.info.nap_loaded=1; + select(handles.listbox2,type); +else + handles.info.nap_loaded=0; +end +if fexist(strobesname) + [strobes,type,options]=aim_loadfile(strobesname); + if fexist(thresholdsname) + thresholds=aim_loadfile(thresholdsname); + handles.data.thresholds=thresholds; + end + handles.data.strobes=strobes; + handles.info.strobes_loaded=1; + handles.info.calculated_strobes_module=type; % this one is really calculated + select(handles.listbox3,type); +else + handles.info.strobes_loaded=0; +end + +if fexist(sainame) + [sai,type,options]=aim_loadfile(sainame); + handles.data.sai=sai; + handles.info.sai_loaded=1; + handles.info.calculated_sai_module=type; % this one is really calculated + select(handles.listbox4,type); + + nr_frames=length(sai); + handles.slideredit_frames.minvalue=1; + handles.slideredit_frames.maxvalue=nr_frames; + % set the framecounter + handles.slideredit_frames=slidereditcontrol_set_value(handles.slideredit_frames,nr_frames); % set to the end + handles.slideredit_frames=slidereditcontrol_set_range(handles.slideredit_frames,nr_frames); % the duration + +else + handles.info.sai_loaded=0; +end + +if fexist(usermodulename) + [usermodule,type,options]=aim_loadfile(usermodulename); + handles.data.usermodule=usermodule; + handles.info.usermodule_loaded=1; + handles.info.calculated_usermodule_module=type; % this one is really calculated + + select(handles.listbox6,type); + handles.info.usermodule_loaded=1; +else + handles.info.usermodule_loaded=0; +end + +% TODO: only the first available movie is loaded. The others not +handles.info.movie_loaded=0; +if length(moviename)>1 + for i=1:length(moviename) + cname=moviename{i}; + if fexist(cname) + handles.info.movie_loaded=1; + handles.info.calculated_movie_module=cname; % this one is really calculated + break + end + end +end + +% change the sliders according to the new signal: +% combi_start=handles.slideredit_start; +% combi_duration=handles.slideredit_start; + +duration=0.04; +start_time=getminimumtime(sig); + +handles.slideredit_duration.maxvalue=getlength(sig); +handles.slideredit_duration.minvalue=0.005; +handles.slideredit_start.minvalue=start_time; +handles.slideredit_start.maxvalue=getlength(sig); + +handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,duration); % the duration +% handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration); % the duration +handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,start_time); % set to the beginning of the signal +handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,duration); % set to the beginning of the signal + + + + +set(handles.displayduration,'String',num2str(fround(getlength(sig)*1000,1))); + + + +% % start_time=offset; +% set(handles.edit2,'String',num2str(start_time*1000)); +% set(handles.edit3,'String',num2str(duration*1000)); +% +% +% set(handles.slider3,'Value',0); +% set(handles.slider3,'Value',duration/max_duration); +% +% handles.data.min_duration=min_duration; +% handles.data.max_duration=max_duration; +% handles.data.max_start_time=max_start_time; +% handles.data.min_start_time=min_start_time; +% +% set(handles.edit1,'String',num2str(1)); +% handles.data.min_scale=0.001; +% handles.data.max_scale=1000; +% set(handles.slider1,'Value',f2f(1,handles.data.min_scale,handles.data.max_scale,0,1,'loglin')); + +% set(handles.pushbutton8,'Enable','on'); +% set(handles.pushbutton9,'Enable','on'); +% set(handles.pushbutton10,'Enable','on'); +set(handles.edit1,'Enable','on'); +set(handles.slider1,'Enable','on'); +set(handles.edit2,'Enable','on'); +set(handles.slider2,'Enable','on'); +set(handles.edit3,'Enable','on'); +set(handles.slider3,'Enable','on'); + + +% aim_saveparameters(handles); + + +function select(hand,what) +str=get(hand,'String'); +for i=1:length(str) + if strcmp(str,what) + set(hand,'Value',i); + return + end +end +return + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/newsai_loadfile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/newsai_loadfile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,46 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function [frm,options]=newsai_loadfile(name) +% load the nap and its options + + +load(name); + +whodir=who; +for i=1:length(whodir) + if ~strcmp(whodir(i),'name') + eval(sprintf('classstruct=%s.data;',whodir{i})); + eval(sprintf('options=%s.options;',whodir{i})); + if strcmp(whodir(i),'strobestruct') + frm=classstruct; + else + % construct the frame from whatever (sometimes the object is not recognised + % as object due to the version ??) + if isobject(classstruct) + frm=classstruct; + else + nr=length(classstruct); + if nr==1 + frm=frame(classstruct); + else + for i=1:nr + frm{i}=frame(classstruct{i}); + end + end + end + end + end +end + + + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/quitprogram.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/quitprogram.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,42 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% my close function +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function quitprogram(obj,eventdata,handles) +% selection = questdlg('Close AIM?',... +% 'Close Request Function',... +% 'Yes','No','Yes'); +% switch selection, +% case 'Yes', + try + % first delete possible children + if isfield(handles.info,'children') + single_channel_gui('close'); + delete(handles.info.children.single_channel.windowhandle) + end + % then delete all graphic windows associated: + try + close(handles.info.current_figure); + end + + % the standart closing routine (first show window) + shh = get(0,'ShowHiddenHandles'); + set(0,'ShowHiddenHandles','on'); + currFig = get(0,'CurrentFigure'); + set(0,'ShowHiddenHandles',shh); + delete(currFig); + % delete(gcf); +% close(handles.info.current_figure); + end +% case 'No' +% return +% end \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/gui/release.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/release.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function ret=release(type) + +switch lower(type) + case 'ver' + ret='AIM-MAT v1.5'; + case 'date' + ret=date; + otherwise + ret=''; +end diff -r 000000000000 -r 74dedb26614d aim-mat/gui/setupnames.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/setupnames.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,99 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=setupnames(handles,signame_org) +% set up all relevant names according to the signal in signame + +[pathstr,signame,ext] = fileparts(signame_org); + +uniqueworkingname=signame; +directoryname=uniqueworkingname; + +handles.info.start_directory=pathstr; +signalname=fullfile(directoryname,sprintf('%s.signal.mat',uniqueworkingname)); +originalwavename=fullfile(directoryname,sprintf('%s.original_signal.wav',uniqueworkingname)); +% originalwavename=sprintf('%s/%s.original_signal.wav',directoryname,uniqueworkingname); + +signalwavename=fullfile(directoryname,sprintf('%s.wav',uniqueworkingname)); +% signalwavename=sprintf('%s/%s.wav',directoryname,uniqueworkingname); +oldsignalwavename=sprintf('%s.wav',uniqueworkingname); + +pcpname=fullfile(directoryname,sprintf('%s.pcp.mat',uniqueworkingname)); +% pcpname=sprintf('%s/%s.pcp.mat',directoryname,uniqueworkingname); +bmmname=fullfile(directoryname,sprintf('%s.bmm.mat',uniqueworkingname)); +% bmmname=sprintf('%s/%s.bmm.mat',directoryname,uniqueworkingname); +napname=fullfile(directoryname,sprintf('%s.nap.mat',uniqueworkingname)); +% napname=sprintf('%s/%s.nap.mat',directoryname,uniqueworkingname); +strobesname=fullfile(directoryname,sprintf('%s.strobes.mat',uniqueworkingname)); +% strobesname=sprintf('%s/%s.strobes.mat',directoryname,uniqueworkingname); +thresholdsname=fullfile(directoryname,sprintf('%s.thresholds.mat',uniqueworkingname)); +% thresholdsname=sprintf('%s/%s.thresholds.mat',directoryname,uniqueworkingname); +sainame=fullfile(directoryname,sprintf('%s.sai.mat',uniqueworkingname)); +% sainame=sprintf('%s/%s.sai.mat',directoryname,uniqueworkingname); + +% TCW AIM2006 Added for pitchresonance compatibility +pitch_imagename=fullfile(directoryname,sprintf('%s.pitch_image.mat',uniqueworkingname)); + +usermodulename=fullfile(directoryname,sprintf('%s.usermodule.mat',uniqueworkingname)); +% usermodulename=sprintf('%s/%s.usermodule.mat',directoryname,uniqueworkingname); + +% look which movies are there +% mnames = fieldnames(handles.all_options.movieoptions); +% moviename=[]; +% for i=1:length(mnames) +% cn=mnames(i); +% mname=sprintf('%s/%s.%s.mov',directoryname,uniqueworkingname,cn{1}); +% if fexist(mname) +% moviename{i}=mname; +% end +% end +% moviename{1}=sprintf('%s/%s.dp.mov',directoryname,uniqueworkingname); +% moviename{2}=sprintf('%s/%s.dpai.mov',directoryname,uniqueworkingname); + + +% these one has a underscore instead of a dot. Otherwise we cant run it +parameterfilename=fullfile(directoryname,sprintf('%s_parameters.m',uniqueworkingname)); +% parameterfilename=sprintf('%s/%s_parameters.m',directoryname,uniqueworkingname); +projectfilename=fullfile(directoryname,sprintf('%s_project.m',uniqueworkingname)); +% projectfilename=sprintf('%s/%s_project.m',directoryname,uniqueworkingname); + +% set the name of the figure +compname=[pwd '\' oldsignalwavename]; +if isfield(handles,'figure1') + set(handles.figure1,'Name',compname); +end + + +% we start here! +handles.info.original_soundfile_directory=pwd; + +handles.info.completesoundfilename=compname; +handles.info.uniqueworkingname=uniqueworkingname; +handles.info.directoryname=directoryname; +handles.info.signalname=signalname; +handles.info.signalwavename=signalwavename; +handles.info.originalwavename=originalwavename; +handles.info.oldsignalwavename=oldsignalwavename; +handles.info.pcpname=pcpname; +handles.info.bmmname=bmmname; +handles.info.napname=napname; +handles.info.strobesname=strobesname; +handles.info.thresholdsname=thresholdsname; +handles.info.sainame=sainame; + +% TCW AIM2006 Added for pitchresonance compatibility +handles.info.pitch_imagename=pitch_imagename; + +handles.info.usermodulename=usermodulename; +% handles.info.moviename=moviename; +handles.info.parameterfilename=parameterfilename; +handles.info.projectfilename=projectfilename; + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/single_channel_gui.fig Binary file aim-mat/gui/single_channel_gui.fig has changed diff -r 000000000000 -r 74dedb26614d aim-mat/gui/single_channel_gui.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/single_channel_gui.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,226 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function varargout = W(varargin) + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @single_channel_gui_OpeningFcn, ... + 'gui_OutputFcn', @single_channel_gui_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); +if nargin & isstr(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 single_channel_gui is made visible. +function single_channel_gui_OpeningFcn(hObject, eventdata, handles, varargin) + +% Choose default command line output for single_channel_gui +handles.output = hObject; + +set(handles.figure1,'Name','select channel'); + +import_options=varargin{1}; +handles.output=-1; +if isstruct(import_options) + handles.import_options=import_options; +else + if strcmp(import_options,'close'); + close(handles.figure1); + return + end + if strcmp(import_options,'getchannelnumber') + if ~isfield(handles,'slideredit') + handles.output=1; + else + handles.output=slidereditcontrol_get_value(handles.slideredit); + end + guidata(hObject, handles); + return + end +end + +% if ~isfield(import_options.info.children.single_channel,'windowhandle') +% fig=figure(import_options.info.children.single_channel.windowhandle); +% import_options.info.children.single_channel.windowhandle=fig; +% end +% +if ~isfield(handles,'figure_handle') || ~ishandle(handles.figure_handle) + handles.figure_handle=import_options.info.children.single_channel.windowhandle; + % set the window next to the graphic window + set(handles.figure1,'units','pixels'); + set(handles.figure_handle,'units','pixels'); + orgpos=get(handles.figure1,'position'); + winpos=get(handles.figure_handle,'position'); + newpos(1)=winpos(1)+winpos(3); + newpos(2)=winpos(2); + movegui(handles.figure1,newpos); +% newpos(3:4)=orgpos(3:4); +% set(handles.figure1,'position',orgpos); +end + +% this is an indicator for the main function, that it is called from a +% child +handles.import_options.info.iscallfromchild=1; + +data=import_options.data; +nrchan=getnrchannels(data.bmm); +if isfield(import_options.info.children.single_channel,'channelnumber') + curr_chan=import_options.info.children.single_channel.channelnumber; +else + curr_chan=round(nrchan/2); +end + +% handles.current_channel_nr=middle_chan; +handles.cfs=getcf(data.bmm); + +% set up the slider edit control +handles.slideredit=slidereditcontrol_setup(... + handles.slider1,... % handle of the slider + handles.edit1,...% handle of the edit control + 1, ... % min value + nrchan, ... % max value + curr_chan, ... % current value + 0, ... % islog + 1, ...% multiplier on the edit control + 0); % nr digits in the edit control after comma + +handles.slideredit=slidereditcontrol_set_range(handles.slideredit,10); % makes a stepsize of 1 + +set(handles.edit3,'String',1); + +% plot the result +handles=update(handles); + +% Update handles structure +guidata(hObject, handles); + +% UIWAIT makes single_channel_gui wait for user response (see UIRESUME) +% uiwait(handles.figure1); + + +% --- Outputs from this function are returned to the command line. +function varargout = single_channel_gui_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +if isstruct(handles) + varargout{1} = handles.output; +end + + +function edit1_Callback(hObject, eventdata, handles) +curval=get(hObject,'String'); +curval=str2num(curval); +handles.slideredit=... + slidereditcontrol_set_raweditvalue(handles.slideredit,curval); +handles=update(handles); +guidata(hObject, handles); +function edit2_Callback(hObject, eventdata, handles) +curval=get(hObject,'String'); +curval=str2num(curval); +nrchan=fre2chan(handles.import_options.data.bmm,curval); +nrchan=round(nrchan); +handles.slideredit=... + slidereditcontrol_set_value(handles.slideredit,nrchan); +handles=update(handles); +guidata(hObject, handles); +function edit3_Callback(hObject, eventdata, handles) +handles=update(handles); +guidata(hObject, handles); + +function slider1_Callback(hObject, eventdata, handles) +curval=get(hObject,'Value'); +% curval=round(curval); +handles.slideredit=... + slidereditcontrol_set_rawslidervalue(handles.slideredit,curval); +handles=update(handles); +guidata(hObject, handles); + +% dynamic feature for the calculation of the sai +function pushbutton1_Callback(hObject, eventdata, handles) + +stepsize=str2num(get(handles.edit3,'String')); + + +options=handles.import_options.all_options.sai; +% disp('generating and saving sai...'); +generating_module=handles.import_options.info.current_sai_module; +handles.import_options.info.calculated_sai_module=generating_module; % this one is really calculated +generating_functionline=['options.' generating_module '.generatingfunction']; +eval(sprintf('generating_function=%s;',generating_functionline')); +nap=handles.import_options.data.nap; +strobes=handles.import_options.data.strobes; +optline=sprintf('coptions=%s.%s;','handles.import_options.all_options.sai',generating_module); +eval(optline); +coptions.single_channel_do=1; +coptions.single_channel_channel_nr=slidereditcontrol_get_value(handles.slideredit); +coptions.single_channel_time_step=stepsize/1000; +coptions.thresholds=handles.import_options.data.thresholds; +callline=sprintf('res=%s(nap,strobes,coptions);',generating_function); +eval(callline); + + + + +function slider1_CreateFcn(hObject, eventdata, handles) +usewhitebg = 1;if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]);else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function edit1_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function edit2_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end +function edit3_CreateFcn(hObject, eventdata, handles) +if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end + + + +function handles=update(handles) + nr_chan=slidereditcontrol_get_value(handles.slideredit); + nr_chan=round(nr_chan); + handles.slideredit=slidereditcontrol_set_value(handles.slideredit,nr_chan); + cf=handles.cfs(nr_chan); + set(handles.edit2,'String',num2str(cf)); + + options.figure_handle=handles.figure_handle; + options.withtime=0; + options.withfre=0; + options.withsignal=0; + + options.display_single_channel=nr_chan; + switch handles.import_options.info.current_plot + case {3,4,5} % bmm + set(handles.edit3,'visible','off'); + set(handles.text3,'visible','off'); + set(handles.text5,'visible','off'); + set(handles.pushbutton1,'visible','off'); + case 6 %sai + set(handles.edit3,'visible','on'); + set(handles.text3,'visible','on'); + set(handles.text5,'visible','on'); + set(handles.pushbutton1,'visible','on'); + end + aim_replotgraphic(handles.import_options,options); + + set(handles.figure1,'Name','select channel'); % repair + + return + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/slider_duration.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/slider_duration.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,43 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +function handles=slider_duration(hObject, eventdata, handles) + + +curval=get(hObject,'Value'); +handles.slideredit_duration=... + slidereditcontrol_set_rawslidervalue(handles.slideredit_duration,curval); + + +% check range +start=slidereditcontrol_get_value(handles.currentslidereditcombi); +dur=slidereditcontrol_get_value(handles.slideredit_duration); +sig=handles.data.signal; +siglen=getmaximumtime(sig); +% siglen=getlength(sig); +if start+dur>siglen + dur=siglen-start; + handles.slideredit_duration=... + slidereditcontrol_set_value(handles.slideredit_duration,dur); +end + +% set the range of the start_slider accordingly +curstart=slidereditcontrol_get_value(handles.currentslidereditcombi); +dur=slidereditcontrol_get_value(handles.slideredit_duration); +handles.slideredit_start.maxvalue=siglen-dur; +handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,curstart); % the duration +handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,dur); % the duration + +if handles.info.current_plot<6 + handles.currentslidereditcombi=handles.slideredit_start; +end + +return diff -r 000000000000 -r 74dedb26614d aim-mat/gui/slider_scale.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/slider_scale.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,20 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=slider_scale(hObject, eventdata, handles) + +curval=get(hObject,'Value'); +handles.slideredit_scale=... + slidereditcontrol_set_rawslidervalue(handles.slideredit_scale,curval); + +return + diff -r 000000000000 -r 74dedb26614d aim-mat/gui/slider_start.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/gui/slider_start.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,45 @@ +% procedure for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function handles=slider_start(hObject, eventdata, handles) +% controls the bahaoviour of the top slider +% normaly its the start time of the displayed signal, but in case of sai, +% the current frame number is displayed + +curval=get(hObject,'Value'); +handles.currentslidereditcombi=... + slidereditcontrol_set_rawslidervalue(handles.currentslidereditcombi,curval); + +if handles.info.current_plot>=6 %sai has additionally the start time below: + sai=handles.data.sai; + cval=round(slidereditcontrol_get_value(handles.currentslidereditcombi)); + start_time=getcurrentframestarttime(sai{cval}); + set(handles.edit3,'String',num2str(fround(start_time*1000,1))); +else + % range check: + start=slidereditcontrol_get_value(handles.currentslidereditcombi); + dur=slidereditcontrol_get_value(handles.slideredit_duration); + sig=handles.data.signal; + siglen=getmaximumtime(sig); + if start+dur>siglen + start=siglen-dur; + handles.currentslidereditcombi=... + slidereditcontrol_set_value(handles.currentslidereditcombi,start); + end +% % and set a new range +% handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,dur); % the duration + +end + + + +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/ACFilterBank.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/ACFilterBank.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,101 @@ +% +% ACFilterBank : IIR ACF time-slice filtering for time-varing filter +% Toshio IRINO +% Created: 19 May 2004 +% Modifed: 11 Jun 2004 +% Modifed: 9 Sept 2004 (NO global variable for multiple filters) +% Modifed: 8 Jan 2005 (Controlling filtering order for inversion) +% +% function [SigOut,ACFstatus] = ACFilterBank(ACFcoef,ACFstatus,SigIn,SwOrdr); +% INPUT : ACFcoef: structured value +% ACFcoef.bz : MA coefficents (zero) NumCh*Lbz*NumFilt +% ACFcoef.ap : AR coefficents (pole) NumCh*Lap*NumFilt +% ACFstatus: structured value if length==0, then initialization +% ACFstatus.NumCh : Number of channels (Set by initialization) +% ACFstatus.Lbz : size of MA +% ACFstatus.Lap : size of AR +% ACFstatus.NumFilt: Length of Filters +% ACFstatus.SigInPrev : Previous status of SigIn +% ACFstatus.SigOutrev : Previous status of SigOut +% SigIn : Input signal (NumCh*1, vector) +% SwOrdr : Switch Filtering Order 0) default, 1) inverse +% +% OUTPUT: SigOut : Filtered signal (NumCh*1, vector) +% ACFstatus : Current status +% +% Basics (as shown by "help filter"): +% a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) +% - a(2)*y(n-1) - ... - a(na+1)*y(n-na) +% +% +function [SigOut,ACFstatus] = ACFilterBank(ACFcoef,ACFstatus,SigIn,SwOrdr); + +if nargin < 2, help ACFilterBank; end; +if nargin < 3 & length(ACFstatus) ~= 0, help ACFilterBank; end; +if nargin < 4, SwOrdr = 0; end; + +if length(ACFstatus) == 0, + [NumCh, Lbz, NumFilt] = size(ACFcoef.bz); + [NumCh, Lap, NumFilt] = size(ACFcoef.ap); + if Lbz ~= 3 | Lap ~= 3 + disp('No gaurantee for usual IIR filters except for AsymCmpFilter.'); + error('Please check MakeAsymCmpFiltersV2.m'); + end; + + ACFstatus.NumCh = NumCh; + ACFstatus.NumFilt = NumFilt; + ACFstatus.Lbz = Lbz; % size of MA + ACFstatus.Lap = Lap; % size of AR + ACFstatus.SigInPrev = zeros(NumCh,Lbz); + ACFstatus.SigOutPrev = zeros(NumCh,Lap,NumFilt); + ACFstatus.Count = 0; + disp('ACFilterBank: Initialization of ACFcoef'); + SigOut = []; + return; +end; + +[NumChSig, Lx] = size(SigIn); +if Lx ~= 1 | ACFstatus.NumCh ~= NumChSig + error('Input Signal should be NumCh*1 vector (1 sample time-slice)'); +end; + +%%%%%%%%%%% time stamp %%% +if 1 + +Tdisp = 50; % ms +Tcnt = ACFstatus.Count/(fix(ACFcoef.fs/1000)); % ms +if ACFstatus.Count == 0 + disp('ACFilterBank: Start processing'); + tic; +elseif rem(Tcnt, Tdisp) == 0, + disp(['ACFilterBank: Processed ' int2str(Tcnt) ... + ' (ms). elapsed Time = ' num2str(toc,3) ' (sec)']); +end; + +end; + +ACFstatus.Count = ACFstatus.Count+1; + +%%%%%%%%%%% processing %%% + +ACFstatus.SigInPrev = [ACFstatus.SigInPrev(:,2:ACFstatus.Lbz), SigIn]; + +x = ACFstatus.SigInPrev; +NfiltList = 1:ACFstatus.NumFilt; +if SwOrdr == 1, NfiltList = fliplr(NfiltList); end; +for Nfilt = NfiltList + + forward = ACFcoef.bz(:,1:ACFstatus.Lbz,Nfilt) .* fliplr(x); + feedback = ACFcoef.ap(:,2:ACFstatus.Lap,Nfilt) .* ... + fliplr(ACFstatus.SigOutPrev(:,2:ACFstatus.Lap,Nfilt)); + fwdSum = sum(forward')' ; + fbkSum = sum(feedback')'; + + y = (fwdSum - fbkSum)./ACFcoef.ap(:,1,Nfilt); + ACFstatus.SigOutPrev(:,:,Nfilt) = ... + [ACFstatus.SigOutPrev(:,2:ACFstatus.Lap,Nfilt), y]; + x = ACFstatus.SigOutPrev(:,:,Nfilt); +end; + +SigOut = y; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/AsymCmpCoef.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/AsymCmpCoef.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,42 @@ +% +% Asymmetric Compensation Coefficients of the IIR gammachirp +% Toshio Irino +% 14 Apr. 99 +% +% Edit this file for consistensy since these values would change. +% MakeAsymCmpFilters.m AsymCmpFrsp.m +% +% function [coef_r, coef_th, coef_fn, coef0] = AsymCmpCoef(c,coef0,NumFilt), +% INPUT c: array of c values +% coef0: vector of 6 coefficients. +% NumFilt: default 4 +% OUTPUT coef_r : coefficients for r +% coef_th: coefficients for th +% coef_fn: coefficients for fn +% +function [coef_r, coef_th, coef_fn, coef0] = AsymCmpCoef(c,coef0,NumFilt), + +if nargin < 2 | length(coef0) == 0, % default +% coef0 = [1.35, -0.19, 0.292, -0.004, 0.058, 0.0018]; +% coef0 = [1.35, -0.19, 0.292, -0.004, 0.058*4, 0.0018*4]; % n compensation + coef0 = [1.35, -0.19, 0.29, -0.0040, 0.23, 0.0072]; % n compensation +end; +if nargin < 3, NumFilt = 4; end; + +c = c(:); +NumCh = length(c); +coef_r = zeros(NumCh,NumFilt); +coef_th = zeros(NumCh,NumFilt); +coef_fn = zeros(NumCh,NumFilt); + +for Nfilt = 1:NumFilt, + coef_r(1:NumCh,Nfilt) = (coef0(1) + coef0(2)*abs(c)) * Nfilt; + coef_th(1:NumCh,Nfilt) = (coef0(3) + coef0(4)*abs(c)) * 2^(Nfilt-1); + coef_fn(1:NumCh,Nfilt) = (coef0(5) + coef0(6)*abs(c)) * Nfilt; +end; + + + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/AsymCmpFrspV2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/AsymCmpFrspV2.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,101 @@ +% +% AsymCmpFrsp Version 2 +% Amplitude Spectrum of Asymmetric Compensation IIR filter for the gammachirp +% corresponding to MakeAsymCmpFiltersV2.m +% +% Toshio Irino +% Original : 14 Apr. 99 (Version1) +% Modified : 11 Jun 2004 +% Modified : 7 Jul 2005 % NfrqRsl +% +% function [ACFFrsp, freq, AsymFunc] +% = AsymCmpFrspV2(Frs,fs,b,c,NfrqRsl,NumFilt) +% +% INPUT: fs: Sampling frequency +% Frs: array of the center frequencies +% b : array or scalar of a bandwidth coefficient +% c : array or scalar of asymmetric parameters +% NfrqRsl: freq. resolution +% NumFilt: Number of 2nd-order filters default 4 +% OUTPUT: ACFFrsp: abs(Frsp of ACF) (NumCh*NfrqRsl matrix) +% freq: freq. (1*NfrqRsl vector) +% AsymFunc: Original Asymmetric Function (NumCh*NfrqRsl matrix) +% +% +function [ACFFrsp,freq,AsymFunc] = AsymCmpFrspV2(Frs,fs,b,c,NfrqRsl,NumFilt) + +if nargin < 1, help AsymCmpFrspV2, end; +if nargin < 5, NfrqRsl = []; end; +if length(NfrqRsl) == 0, NfrqRsl = 1024; end; +if nargin < 6, NumFilt = []; end; +if length(NumFilt) == 0, NumFilt = 4; end; % default +if NumFilt ~= 4, error('NumFilter should be 4.'); end; + +Frs = Frs(:); +b = b(:); +c = c(:); +NumCh = length(Frs); + +SwCoef = 0; % self consitency +%SwCoef = 1; % referece to MakeAsymCmpFiltersV2 + +if SwCoef == 0 +% New Coefficients. NumFilter = 4; See [1] + p0 = 2; + p1 = 1.7818 .* (1 - 0.0791*b) .* (1 - 0.1655*abs(c)); + p2 = 0.5689 .* (1 - 0.1620*b) .* (1 - 0.0857*abs(c)); + p3 = 0.2523 .* (1 - 0.0244*b) .* (1 + 0.0574*abs(c)); + p4 = 1.0724; +else + + ACFcoef = MakeAsymCmpFiltersV2(fs,Frs,b,c); +end; + +[dummy ERBw] = Freq2ERB(Frs); +freq = (0:NfrqRsl-1)/NfrqRsl*fs/2; +ACFFrsp = ones(NumCh,NfrqRsl); +freq2 = [ones(NumCh,1)*freq, Frs]; + + +for Nfilt = 1:NumFilt + + if SwCoef == 0, + r = exp(-p1.*(p0./p4).^(Nfilt-1) .* 2 .* pi .*b .*ERBw /fs); + delfr = (p0*p4)^(Nfilt-1).*p2.*c.*b.*ERBw; + phi = 2*pi*max(Frs + delfr,0)/fs; + psy = 2*pi*max(Frs - delfr,0)/fs; + fn = Frs; + ap = [ones(NumCh,1), -2*r.*cos(phi), r.^2]; + bz = [ones(NumCh,1), -2*r.*cos(psy), r.^2]; + else + ap = ACFcoef.ap(:,:,Nfilt); + bz = ACFcoef.bz(:,:,Nfilt); + end; + + cs1 = cos(2*pi*freq2/fs); + cs2 = cos(4*pi*freq2/fs); + + bzz0 = (bz(:,1).^2 + bz(:,2).^2 + bz(:,3).^2 )*ones(1,NfrqRsl+1); + bzz1 = (2* bz(:,2).*( bz(:,1) + bz(:,3)))*ones(1,NfrqRsl+1); + bzz2 = (2* bz(:,1).*bz(:,3))*ones(1,NfrqRsl+1); + hb = bzz0 + bzz1.* cs1 + bzz2.* cs2; + + app0 = (ap(:,1).^2 + ap(:,2).^2 + ap(:,3).^2)*ones(1,NfrqRsl+1); + app1 = (2* ap(:,2).*( ap(:,1) + ap(:,3)))*ones(1,NfrqRsl+1); + app2 = (2* ap(:,1).*ap(:,3))*ones(1,NfrqRsl+1); + ha = app0 + app1.*cs1 + app2.*cs2; + + H = sqrt(hb./ha); + Hnorm = H(:,NfrqRsl+1)*ones(1,NfrqRsl); % Noimalization by fn value + + ACFFrsp = ACFFrsp .* H(:,1:NfrqRsl)./ Hnorm; + +end; + +%%% original Asymmetric Function without shift centering +fd = (ones(NumCh,1)*freq - Frs*ones(1,NfrqRsl)); +be = (b.*ERBw)*ones(1,NfrqRsl); +cc = (c.*ones(NumCh,1))*ones(1,NfrqRsl); % in case when c is scalar +AsymFunc = exp(cc.*atan2(fd,be)); + +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/CmprsGCFrsp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/CmprsGCFrsp.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,86 @@ +% +% Frequency Response of Compressive GammaChirp +% Toshio IRINO +% Created : 9 Sept. 2004 +% Modified: 9 Sept. 2004 +% Modified: 6 July 2005 % fixing bug in NfrqRsl +% +% function cGCresp = CmprsGCFrsp(Fr1,fs,n,b1,c1,frat,b2,c2,NfrqRsl); +% INPUT : Fr1 : Resonance Freq. (vector) +% fs : Sampling Freq. +% n : Order of Gamma function t^(n-1) (vector) +% b1 : b1 for exp(-2*pi*b1*ERB(f)) +% c1 : c1 for exp(j*2*pi*Fr + c1*ln(t)) +% frat : frequency ratio. Fr2 = frat*Fp1; +% b2 : b2 for HP-AF +% c2 : c2 for HP-AF +% NfrqRsl : freq. resolution +% OUTPUT: cGCresp : struct for cGC response +% pGCFrsp: passive gc frq. rsp. (NumCh*NfrqRsl matrix) +% cGCFrsp: compressive gc frq. rsp. (NumCh*NfrqRsl matrix) +% cGCNrmFrsp: Normalized cGCFrsp (NumCh*NfrqRsl matrix) +% ACFrsp : Asym Compnstation Filter frq. rsp. +% AsymFunc: Asym Func +% freq : frequency (1 * NfrqRsl vector) +% Fp2 : peak freq. +% ValFp2 : peak value +% +function cGCresp = CmprsGCFrsp(Fr1,fs,n,b1,c1,frat,b2,c2,NfrqRsl); + +if nargin < 1, help CmprsGCFrsp; return; end; +if nargin < 2, fs = 48000; end; +if length(fs) == 0, error('Specify Sampling Frequency'); end; +Fr1 = Fr1(:); +NumCh = length(Fr1); + +% Setting Default +% NOT using SetParam script for stand alone running +% Please check it with GCFBv2_SetParam.m +% +if nargin < 3, n = 4; end; +if length(n) == 1, n = n*ones(NumCh,1); end; +if nargin < 4, b1 = 1.81; end; +if length(b1) == 1, b1 = b1*ones(NumCh,1); end; +if nargin < 5, c1 = -2.96; end; +if length(c1) == 1, c1 = c1*ones(NumCh,1); end; +if nargin < 6, frat = 1; end; +if length(frat) == 1, frat = frat*ones(NumCh,1); end; +%if nargin < 7, b2 = 2.01; end; +if nargin < 7, b2 = 2.17; end; % debug 8 July 2005 +if length(b2) == 1, b2 = b2*ones(NumCh,1); end; +if nargin < 8, c2 = 2.20; end; +if length(c2) == 1, c2 = c2*ones(NumCh,1); end; +if nargin < 9, NfrqRsl = 1024; end; + +[pGCFrsp,freq] = GammaChirpFrsp(Fr1,fs,n,b1,c1,0,NfrqRsl); +Fp1 = Fr2Fpeak(n,b1,c1,Fr1); +Fr2 = frat.*Fp1; +[ACFFrsp,freq,AsymFunc] = AsymCmpFrspV2(Fr2,fs,b2,c2,NfrqRsl); +cGCFrsp = pGCFrsp.*AsymFunc; %% cGCFrsp = pGCFrsp.*ACFFrsp; +[ValFp2 nchFp2] = max(cGCFrsp'); +ValFp2 = ValFp2(:); +NormFactFp2 = 1./ValFp2; + +%%% function cGCresp = CmprsGCFrsp(Fr1,fs,n,b1,c1,frat,b2,c2,NfrqRsl); +cGCresp.Fr1 = Fr1; % including original parameter as well +cGCresp.n = n; +cGCresp.b1 = b1; +cGCresp.c1 = c1; +cGCresp.frat = frat; +cGCresp.b2 = b2; +cGCresp.c2 = c2; +cGCresp.NfrqRsl = NfrqRsl; +cGCresp.pGCFrsp = pGCFrsp; +cGCresp.cGCFrsp = cGCFrsp; +cGCresp.cGCNrmFrsp = cGCFrsp .* (NormFactFp2*ones(1,NfrqRsl)); +cGCresp.ACFFrsp = ACFFrsp; +cGCresp.AsymFunc = AsymFunc; +cGCresp.Fp1 = Fp1; +cGCresp.Fr2 = Fr2; +cGCresp.Fp2 = freq(nchFp2)'; +cGCresp.ValFp2 = ValFp2; +cGCresp.NormFctFp2 = NormFactFp2; +cGCresp.freq = freq; + +return + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/Eqlz2MeddisHCLevel.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/Eqlz2MeddisHCLevel.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,33 @@ +% Equalizing Signal RMS Level to the Level for MeddisHairCell +% Irino, T. +% Created: 9 Jun. 2004 +% Modified: 9 Jun. 2004 +% +% function [SndEqM, AmpdB] = Eqlz2MeddisHCLevel(Snd,fs,OutLeveldB); +% INPUT Snd: +% fs: sampling frequency +% OutLeveldB : Output level (default: 50 dB SPL) +% +% OUTPUT SndEq: Equalized Sound (rms value of 1 is 30 dB SPL) +% AmpdB: 3 values in dB +% [OutLevel, Compensation value, SourceLevel] +% +% Ref: Meddis (1986), JASA, 79(3),pp.702-711. +% +% rms(s(t)) == sqrt(mean(s.^2)) == 1 --> 30 dB SPL +% rms(s(t)) == sqrt(mean(s.^2)) == 10 --> 50 dB SPL +% rms(s(t)) == sqrt(mean(s.^2)) == 100 --> 70 dB SPL +% +function [SndEqM, AmpdB] = Eqlz2MeddisHCLevel(Snd,fs,OutLeveldB); + +if nargin < 2, help Eqlz2MeddisHCLevel; end; +if nargin < 3, OutLeveldB = []; end; +if length(OutLeveldB) == 0, OutLeveldB = 50; end; % for speech +if nargin < 4, Method = 'Peak'; end; + +SourceLevel = sqrt(mean(Snd.^2))*10^(30/20); % level in terms of Meddis Level + +Amp = (10^(OutLeveldB/20))/SourceLevel; +SndEqM = Amp * Snd; + +AmpdB = [OutLeveldB 20*log10([Amp, SourceLevel])]; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/EqualFreqScale.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/EqualFreqScale.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,53 @@ +% +% Calculation of Equal Frequency scale on ERB/Mel/Log/Linear scale +% Toshio IRINO +% 5 Oct 2001 +% +% function [Frs] = EqualFreqScale(NameScale,NumCh,RangeFreq), +% INPUT: NameScale: 'ERB', 'mel', 'log', 'linear' +% NumCh: Number of channels +% RangeFreq: Frequency Range +% OUTPUT: Frs: Fr vector +% WFval: Warped Freq. value +% +function [Frs, WFvals] = EqualFreqScale(NameScale,NumCh,RangeFreq), + +if nargin <3, help EqualFreqScale; end; +if diff(RangeFreq) < 0, + help EqualFreqScale; + error('RangeFreq(1) should be less than RangeFreq(2).'); +end; + +if strcmp(lower(NameScale),'linear') == 1, + RangeWF = RangeFreq; + dWF = diff(RangeWF)/(NumCh-1); + WFvals = RangeWF(1):dWF:RangeWF(2)+eps*1000; + Frs = WFvals; + +elseif strcmp(lower(NameScale),'mel') == 1, + RangeWF = Freq2Mel(RangeFreq); + dWF = diff(RangeWF)/(NumCh-1); + WFvals = RangeWF(1):dWF:RangeWF(2)+eps*1000; + Frs = Mel2Freq(WFvals); + +elseif strcmp(lower(NameScale),'erb') == 1, + RangeWF = Freq2ERB(RangeFreq); + dWF = diff(RangeWF)/(NumCh-1); + WFvals = RangeWF(1):dWF:RangeWF(2)+eps*1000; + Frs = ERB2Freq(WFvals); + +elseif strcmp(lower(NameScale),'log') == 1, + if min(RangeFreq) < 50, + disp([ 'min(RangeFreq) < 50. Replaced by 50.' ]); + RangeFreq(1) = 50; + end; + RangeWF = log10(RangeFreq); + dWF = diff(RangeWF)/(NumCh-1); + WFvals = RangeWF(1):dWF:RangeWF(2)+eps*1000; + Frs = 10.^WFvals; + +else + help EqualFreqScale; + error('Specify NameScale correctly'); +end; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/Fp2toFr1.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/Fp2toFr1.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,67 @@ +% Fp2toFr1 +% derives fr1 from the given fp2 +% +% function [fr1,fp1] = Fp2toFr1(n,b1,c1,b2,c2,frat,fp2) +% +% Author: Masashi Unoki +% Created: 3 July 2002 +% Updated: 15 July 2002 +% Revised: 9 Oct. 2003 (checked & renamed variables) +% Copyright (c) 2002, AIS-Lab. JAIST +% +function [fr1,fp1] = Fp2toFr1(n,b1,c1,b2,c2,frat,fp2) +if nargin < 1; help Fp2toFr1; end; + +SR=24000; +Nfft=1024*2; + +%%%%%%% Coefficients: ERB(fr1)=alp1*fr1+alp0 %%%%%%% +alp1=24.7*4.37/1000; +alp0=24.7; + +%%%%%%% Coefficients: fr2=bet1*fr2+bet0 %%%%%%% +bet1=frat*(1+c1*b1*alp1/n); +bet0=frat*c1*b1*alp0/n; + +%%%%%%% Coefficients: ERB(fr2)=zet1*fr1+zet0 %%%%%%% +zet1=alp1*bet1; +zet0=alp1*bet0+alp0; + +%%%%%%% D1*fr1^3 + D2*fr1^2 + D3*fr1 + D4 = 0 %%%%%%% + +D1=((b2^2*zet1^2+bet1^2)*(c1*b1*alp1+n) + (c2*b2*zet1)*(b1^2*alp1^2+1)); +D2=((b2^2*zet1^2+bet1^2)*(c1*b1*alp0-n*fp2) ... + + (2*b2^2*zet1*zet0-2*bet1*(fp2-bet0))*(c1*b1*alp1+n) ... + + (c2*b2*zet1)*(2*b1^2*alp1*alp0-2*fp2) + (c2*b2*zet0)*(b1^2*alp1^2+1)); +D3=((2*b2^2*zet1*zet0-2*bet1*(fp2-bet0))*(c1*b1*alp0-n*fp2) ... + + (b2^2*zet0^2+(fp2-bet0)^2)*(c1*b1*alp1+n)... + +(c2*b2*zet1)*(b1^2*alp0^2+fp2^2) + (c2*b2*zet0)*(2*b1^2*alp1*alp0-2*fp2) ); +D4=(b2^2*zet0^2+(fp2-bet0)^2)*(c1*b1*alp0-n*fp2) ... + + (c2*b2*zet0)*(b1^2*alp0^2+fp2^2); + +q=roots([D1 D2 D3 D4]); +candFr1=q(imag(q)==0); + +LenFr1=length(candFr1); +if (LenFr1 > 1) % finding the maximum peak of |Gcc(f)| + GccAtFp2=zeros(1,LenFr1); + for m=1:LenFr1 + fr1m=candFr1(m); + fr2m=bet1*fr1m+bet0; + [GcFrsp1, freq1]=GammaChirpFrsp(fr1m,SR,n,b1,c1,0,Nfft); + [dummy ERBw2] = Freq2ERB(fr2m); + AsymFuncFrsp = exp(c2*atan2((freq1 - fr2m),(b2*ERBw2))); + GcFrsp = GcFrsp1.*AsymFuncFrsp; + GcFrsp = GcFrsp/max(GcFrsp); + [dummy,pos]=min(abs(freq1-fp2)); + GccAtFp2(m)=GcFrsp(pos); + end + [dummy,pos]=max(GccAtFp2); + fr1=candFr1(pos); +else + fr1=candFr1; +end + +fp1=fr1+c1*b1*(alp1*fr1+alp0)/n; + +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/Fpeak2Fr.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/Fpeak2Fr.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,30 @@ +% +% Estimate fr from fpeak +% Toshio IRINO +% 10 June 98 +% +% function [fr, ERBw] = Fpeak2Fr(n,b,c,fpeak) +% INPUT: n,b,c : gammachirp param. +% fpeak : peak freq. +% OUTPUT: fr : fr +% ERBw : ERBw(fr) +% +function [fr, ERBw] = Fpeak2Fr(n,b,c,fpeak) + +if nargin < 4; help Fpeak2Fr; end; + +n = n(:); +b = b(:); +c = c(:); +fpeak = fpeak(:); + +% fpeak = fr + c*b*ERBw(fr)/n +% ERBw(fr) = 24.7*(4.37*fr/1000 + 1) = k1*fr + k2 % M&G 1990 + +k1 = 24.7*4.37/1000; +k2 = 24.7; + +fr = (fpeak - c.*b./n * k2)./(1 + c.*b./n * k1); +ERBw = k1*fr + k2; + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/Fr1toFp2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/Fr1toFp2.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,58 @@ +% Fr1toFp2 +% derives fp2 from the given fr1 +% +% function [fp2,fr2] = Fr1toFp2(n,b1,c1,b2,c2,frat,fr1,SR,Nfft) +% +% Author: Masashi Unoki +% Created: 11 July 2002 +% Updated: 12 July 2002 +% Updated: 15 July 2002 +% Revised: 9 Oct. 2003 (checked & renamed variables) +% Copyright (c) 2002, AIS-Lab. JAIST +% +function [fp2,fr2] = Fr1toFp2(n,b1,c1,b2,c2,frat,fr1,SR,Nfft) +if nargin < 1; help Fr1toFp2; end; +if nargin < 8; SR=24000; end; +if nargin < 9; Nfft=1024*2; end; + +%%%%%%% Coefficients: ERB(fr1)=alp1*fr1+alp0 %%%%%%% +alp1=24.7*4.37/1000; +alp0=24.7; + +ERBw1=alp1*fr1+alp0; +fp1=(1+c1*b1*alp1/n)*fr1+(c1*b1*alp0/n); +fr2=frat*fp1; +ERBw2=alp1*fr2+alp0; + +%%% B1=b1*ERBw1; % delete +%%% B2=b2*ERBw2; % delete + +%%%%%%% E1*fp2^3 + E2*fp2^2 + E3*fp2 + E4 = 0 %%%%%%% + +E1=-n; +E2=c1*b1*ERBw1+c2*b2*ERBw2+n*fr1+2*n*fr2; +E3=-2*fr2*(c1*b1*ERBw1+n*fr1)-n*((b2*ERBw2)^2+fr2^2)-2*c2*b2*ERBw2*fr1; +E4=c2*b2*ERBw2*((b1*ERBw1)^2+fr1^2)+(c1*b1*ERBw1+n*fr1)*((b2*ERBw2)^2+fr2^2); +p=roots([E1 E2 E3 E4]); +candFp2=p(imag(p)==0); + +LenFp2=length(candFp2); +if (LenFp2 > 1) % finding the maximum peak of |Gcc(f)| + GccAtFp2=zeros(1,LenFp2); + for m=1:LenFp2 + fp2m=candFp2(m); + [GcFrsp1, freq1]=GammaChirpFrsp(fr1,SR,n,b1,c1,0,Nfft); + [dummy ERBw2] = Freq2ERB(fr2); + AsymFuncFrsp = exp(c2*atan2((freq1 - fr2),(b2*ERBw2))); + GcFrsp = GcFrsp1.*AsymFuncFrsp; + [dummy,pos]=min(abs(freq1-fp2m)); + GccAtFp2(m)=GcFrsp(pos); + end + [dummy,pos]=max(GccAtFp2); + fp2=candFp2(pos); +else + fp2=candFp2; +end + + +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/Fr2Fpeak.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/Fr2Fpeak.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,22 @@ +% +% Estimate fr from fpeak +% Toshio IRINO +% 10 June 98 +% +% function [fpeak, ERBw] = Fr2Fpeak(n,b,c,fr) +% INPUT: n,b,c : gammachirp param. +% fr : fr +% OUTPUT: fpeak : peak freq. +% ERBw : ERBw(fr) +% +function [fpeak, ERBw] = Fr2Fpeak(n,b,c,fr) + +if nargin < 4, help Fr2Fpeak; end; + +n = n(:); +b = b(:); +c = c(:); +fr = fr(:); + +[dummy ERBw] = Freq2ERB(fr); +fpeak = fr + c.*ERBw.*b./n; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/Freq2ERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/Freq2ERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,35 @@ +% +% Frequency -> ERBrate and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [ERBrate, ERBwidth] = Freq2ERB(cf), +% INPUT cf: Center frequency +% OUTPUT ERBrate: ERB rate +% ERBwidth: ERB width +% +% Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see Freq2ERBYear.m +% +function [ERBrate, ERBwidth] = Freq2ERB(cf) + +if nargin < 1, help Freq2ERB; end; + +ERBrate = 21.4.*log10(4.37*cf/1000+1); +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + +%%% Warning for Freq. Range %%% +cfmin = 1; +cfmax = 20000; +if (min(cf) < cfmin || max(cf) > cfmax) + disp(['Warning : Min or max frequency exceeds the proper ERB range:']); + disp([' ' int2str(cfmin) '(Hz) <= Fc <= ' int2str(cfmax) '(Hz).']); +end; + +%if (min(cf) < 0) +% error(['Min frequency is less than 0.']); +%end; + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/GCFBv205.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/GCFBv205.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,263 @@ +% +% Dynamic Compressive Gammachirp Filterbank +% Version 2.05 +% Toshio IRINO +% Created: 6 Sep 2003 +% Modified: 7 Jun 2004 +% Modified: 12 Jul 2004 (PpgcEstShiftERB) +% Modified: 14 Jul 2004 (LinPpgc) +% Modified: 4 Aug 2004 (introducing GCresp) +% Modified: 16 Aug 2004 (ExpDecayVal) +% Modified: 31 Aug 2004 (introducing GCFBv2_SetParam) +% Modified: 8 Sep 2004 (TTS. tidy up the names. 2.00 -> 2.01) +% Modified: 10 Sep 2004 (Normalization at Level estimation path) +% Modified: 7 Oct 2004 (c2val is level dependent 2.02) +% Modified: 22 Oct 2004 (level estimation 2.03) +% Modified: 8 Nov 2004 (error detection of SndIn) +% Modified: 30 Nov 2004 (c2val control) +% Modified: 23 May 2005 (v205. Pc == average of two input, RMS2dBSPL, +% Fast filtering when 'fix' : under construction) +% Modified: 24 May 2005 (v205 Mod in LinLvl1 =..., LvldB= ...) +% Modified: 3 Jun 2005 (v205) +% Modified: 1 Jun 2005 (v205, GCparam.GainCmpnstdB) +% Modified: 14 Jul 2005 (v205, GCparam.LvlEst.RefdB, Pwr, Weight) +% Modified: 15 Sep 2005 (v205, rename GCparam.LvlRefdB --> GainRefdB) +% +% +% function [cGCout, pGCout, Ppgc, GCparam, GCresp] = GCFB2(Snd,GCparam) +% INPUT: Snd: Input Sound +% GCparam: Gammachirp parameters +% GCparam.fs: Sampling rate (48000) +% GCparam.NumCh: Number of Channels (75) +% GCparam.FRange: Frequency Range of GCFB [100 6000] +% specifying asymptotic freq. of passive GC (Fr1) +% +% OUTPUT: cGCout: Compressive GammaChirp Filter Output +% pGCout: Passive GammaChirp Filter Output +% Ppgc: power at the output of passive GC +% GCparam: GCparam values +% GCresp : GC response result +% +% Note +% 1) This version is completely different from GCFB v.1.04 (obsolete). +% We introduced the "compressive gammachirp" to accomodate both the +% psychoacoustical simultaneous masking and the compressive +% characteristics (Irino and Patterson, 2001). The parameters were +% determined from large dataset (See Patterson, Unoki, and Irino, 2003.) +% +% +% References: +% Irino, T. and Unoki, M.: IEEE ICASSP'98 paper, AE4.4 (12-15, May, 1998) +% Irino, T. and Patterson, R.D. : JASA, Vol.101, pp.412-419, 1997. +% Irino, T. and Patterson, R.D. : JASA, Vol.109, pp.2008-2022, 2001. +% Patterson, R.D., Unoki, M. and Irino, T. : JASA, Vol.114,pp.1529-1542,2003. +% +% +function [cGCout, pGCout, GCparam, GCresp] = GCFBv2(SndIn,GCparam) + +%%%% Handling Input Parameters %%%%% +if nargin < 2, help GCFBv205; end; + +[nc, LenSnd] = size(SndIn); +if nc ~= 1, error('Check SndIn. It should be 1 ch (Monaural).' ); end; + +GCparam = GCFBv205_SetParam(GCparam); + +%%%%%%%%%%%%% +fs = GCparam.fs; +NumCh = GCparam.NumCh; +if length(GCparam.b1) == 1 & length(GCparam.c1) == 1 + b1 = GCparam.b1(1); % Freq. independent + c1 = GCparam.c1(1); % Freq. independent +else + error('Not prepared yet: Freq. dependent b1, c1'); +end; + +[Fr1, ERBrate1] = EqualFreqScale('ERB',NumCh,GCparam.FRange); +Fr1 = Fr1(:); +ERBspace1 = mean(diff(ERBrate1)); + +GCresp.Fr1 = Fr1; +Fp1 = Fr2Fpeak(GCparam.n,b1,c1,Fr1); +GCresp.Fp1 = Fp1; + +[ERBrate ERBw] = Freq2ERB(Fr1); +[ERBrate1kHz ERBw1kHz] = Freq2ERB(1000); +Ef = ERBrate/ERBrate1kHz - 1; +GCresp.Ef = Ef; +%%%% +% fratVal = frat(1,1) + frat(1,2)*Ef + +% frat(2,1)*Ppgc + frat(2,2)*Ef*Ppgc; +%%% + +%%%%% Outer-Mid Ear Compensation %%%% +if length(GCparam.OutMidCrct) > 2 +% disp(['*** Outer/Middle Ear correction: ' GCparam.OutMidCrct ' ***']); + CmpnOutMid = OutMidCrctFilt(GCparam.OutMidCrct,fs,0); + % 1kHz: -4 dB, 2kHz: -1 dB, 4kHz: +4 dB + Snd = filter(CmpnOutMid,1,SndIn); +else +% disp('*** No Outer/Middle Ear correction ***'); + Snd = SndIn; +end; + +% for compensation filer, use OutMidCrctFilt('ELC',fs,0,1); + +%%%%% Gammachirp %%% +%disp('*** Gammmachirp Calculation ***'); +waithand=waitbar(0, 'Generating Basilar Membrane Motion - dcGC'); +if 0, disp(GCparam), end; +tic; + + + +%%%% Start calculation %%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% Passive Gammachirp filtering %%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + Tstart = clock; + cGCout = zeros(NumCh, LenSnd); + pGCout = zeros(NumCh, LenSnd); + Ppgc = zeros(NumCh, LenSnd); + + for nch=1:NumCh + + % passive gammachirp + pgc = GammaChirp(Fr1(nch),fs,GCparam.n,b1,c1,0,'','peak'); % pGC + pGCout(nch,1:LenSnd)=fftfilt(pgc,Snd); % fast fft based filtering + + end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% Compressive Gammachirp filtering %%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%% Initial settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +GCresp.Fr2 = zeros(NumCh,LenSnd); +GCresp.fratVal = zeros(NumCh,LenSnd); + +%%%% Level independent b2 & c2 for Signal path %%% +b2val = GCparam.b2(1,1)*ones(NumCh,1) + GCparam.b2(1,2)*Ef(:); +c2val = GCparam.c2(1,1)*ones(NumCh,1) + GCparam.c2(1,2)*Ef(:); +GCresp.b2val = b2val; +GCresp.c2val = c2val; + +nDisp = 20*fs/1000; % display every 20 ms +cGCout = zeros(NumCh,LenSnd); +GCresp.Fr2 = zeros(NumCh,LenSnd); +GCresp.fratVal = zeros(NumCh,LenSnd); +LvldB = zeros(NumCh,LenSnd); +LvlLinPrev = zeros(NumCh,2); +ExpDecayVal = exp(-1/(GCparam.LvlEst.DecayHL*fs/1000)*log(2)); % decay exp. + +NchShift = round(GCparam.LvlEst.LctERB/ERBspace1); +NchLvlEst = min(max(1, (1:NumCh)'+NchShift),NumCh); % shift in NumCh [1:NumCh] +Fp1LvlEst = Fp1(NchLvlEst(:)); +zrs = zeros(NumCh,1); +LvlLinMinLim = 10^(-GCparam.LvlEst.RMStoSPLdB/20); % minimum should be 0 dBSPL +LvlLinRef = 10.^(( GCparam.LvlEst.RefdB - GCparam.LvlEst.RMStoSPLdB)/20); + + +%%%%% Sample-by-sample processing %%%%%%%%%%%%%%%%%%%%%%%% + +Tstart = clock; + +%%%%% These lines moved from outside the inner loop +% TCW August 2006 +if strcmp(GCparam.Ctrl(1:3),'tim') == 1 + Fr2LvlEst = GCparam.LvlEst.frat * Fp1LvlEst; + [ACFcoefLvlEst] = ... + MakeAsymCmpFiltersV2(fs,Fr2LvlEst,GCparam.LvlEst.b2, GCparam.LvlEst.c2); +end +%%%% + + +for nsmpl=1:LenSnd + + if strcmp(GCparam.Ctrl,'fix') == 1 + LvldB(:,nsmpl) = GCparam.GainRefdB*ones(NumCh,1); % fixed value + + elseif strcmp(GCparam.Ctrl(1:3),'tim') == 1, % when time-varying + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%% Level estimation path %%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % Moved the following lines outside the main loop as they're not updated + % each time. Improves speed by about 25% + % TCW August 2006 + % Fr2LvlEst = GCparam.LvlEst.frat * Fp1LvlEst; + % [ACFcoefLvlEst] = ... + % MakeAsymCmpFiltersV2(fs,Fr2LvlEst,GCparam.LvlEst.b2, GCparam.LvlEst.c2); + + + if nsmpl == 1, %% initialization + [dummy,ACFstatusLvlEst] = ACFilterBank(ACFcoefLvlEst,[]); + end; + [cGCLvlEst,ACFstatusLvlEst] =... + ACFilterBank(ACFcoefLvlEst,ACFstatusLvlEst,pGCout(NchLvlEst,nsmpl)); + + %%%%% Modified: 24 May 05 + LvlLin(1:NumCh,1) = ... + max([max(pGCout(NchLvlEst,nsmpl),0), LvlLinPrev(:,1)*ExpDecayVal]')'; + LvlLin(1:NumCh,2) = ... + max([max(cGCLvlEst,0), LvlLinPrev(:,2)*ExpDecayVal]')'; + LvlLinPrev = LvlLin; + + %%%%% Modified: 14 July 05 + LvlLinTtl = GCparam.LvlEst.Weight * ... + LvlLinRef.*(LvlLin(:,1)/LvlLinRef).^GCparam.LvlEst.Pwr(1) ... + + ( 1 - GCparam.LvlEst.Weight ) * ... + LvlLinRef.*(LvlLin(:,2)/LvlLinRef).^GCparam.LvlEst.Pwr(2); + + LvldB(:,nsmpl) = 20*log10( max(LvlLinTtl,LvlLinMinLim) ) ... + + GCparam.LvlEst.RMStoSPLdB; + else + error([ 'GCparam.Ctrl should be "fix" or "tim[e-varying]" ']) + end; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%% Signal path %%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Filtering High-Pass Asym. Comp. Filter + fratVal = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*LvldB(:,nsmpl); + Fr2Val = Fp1(:).*fratVal; + + [ACFcoef] = MakeAsymCmpFiltersV2(fs,Fr2Val,b2val,c2val); + if nsmpl == 1, + [dummy,ACFstatus] = ACFilterBank(ACFcoef,[]); % initiallization + end; + + [SigOut,ACFstatus] = ACFilterBank(ACFcoef,ACFstatus,pGCout(:,nsmpl)); + cGCout(:,nsmpl) = SigOut; + + GCresp.Fr2(:,nsmpl) = Fr2Val; + GCresp.fratVal(:,nsmpl) = fratVal; + + if nsmpl==1 || rem(nsmpl,nDisp)==0, + waitbar(nsmpl./LenSnd, waithand); + end % waitbar + +end % loop over samples + + +%%%% Signal path Gain Normalization at Reference Level (GainRefdB) %%% + +fratRef = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*GCparam.GainRefdB; + +cGCRef = CmprsGCFrsp(Fr1,fs,GCparam.n,b1,c1,fratRef,b2val,c2val); +GCresp.cGCRef = cGCRef; +GCresp.LvldB = LvldB; + +GainFactor = 10^(GCparam.GainCmpnstdB/20)*(cGCRef.NormFctFp2 * ones(1,LenSnd)); +cGCout = GainFactor.*cGCout; + +%%%%%%%%%% +close(waithand); +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/GCFBv205ExtPtn.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/GCFBv205ExtPtn.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,162 @@ +% +% Excitation Pattern of Compressive Gammachirp +% Version 2.05 <-- GCFBv205 +% Toshio IRINO +% Created: 10 Jul 2005 +% Modified: 11 Jul 2005 +% Modified: 13 Jul 2005 +% +% +% function [cGCoutdB, pGCoutdB, GCparam] ... +% = GCFB205ExtPtn(SigFrqLvldBIn,GCparam,NfrqRsl) +% INPUT: SigFrqLvldB: Input Signal Freq. Level dB values +% [Frq1, LvlSPLdB1; Frq2, LvlSPLdB2;]; +% Probe Suppressor +% GCparam: Gammachirp parameters +% GCparam.fs: Sampling rate (48000) +% GCparam.NumCh: Number of Channels (75) +% GCparam.FRange: Frequency Range of GCFB [100 6000] +% specifying asymptotic freq. of passive GC (Fr1) +% NfrqRsl: Frequency resolution +% +% OUTPUT: LvlOutdB: OutputLevel at Probe freq. +% GCparam: GCparam values +% +% +function [cGCoutdB, pGCoutdB, GCparam, cGCresp ] ... + = GCFB205ExtPtn(SigFrqLvldBIn,GCparam,NfrqRsl) + +%%%% Handling Input Parameters %%%%% +if nargin < 2, help GCFBv205ExtPtn; end; +if nargin < 3, NfrqRsl = 1024; end; + +[nSig, nSpc] = size(SigFrqLvldBIn); +if nSpc ~= 2, error('Check SigFrqLvldBIn. [Frq,Lvl] pair' ); end; +SigFrqLvldB = SigFrqLvldBIn; + +GCparam = GCFBv205_SetParam(GCparam); + +%%%%%%%%%%%%% +fs = GCparam.fs; +NumCh = GCparam.NumCh; +if length(GCparam.b1) == 1 & length(GCparam.c1) == 1 + b1 = GCparam.b1(1); % Freq. independent + c1 = GCparam.c1(1); % Freq. independent +else + error('Not prepared yet: Freq. dependent b1, c1'); +end; + +[Fr1, ERBrate1] = EqualFreqScale('ERB',NumCh,GCparam.FRange); +Fr1 = Fr1(:); +ERBspace1 = mean(diff(ERBrate1)); + +Fp1 = Fr2Fpeak(GCparam.n,b1,c1,Fr1); +[ERBrate ERBw] = Freq2ERB(Fr1); +[ERBrate1kHz ERBw1kHz] = Freq2ERB(1000); +Ef = ERBrate/ERBrate1kHz - 1; +cGCresp.Ef = Ef; + +%%%%% Outer-Mid Ear Compensation %%%% +[CrctLinPwr, freq1] = OutMidCrct('ELC',NfrqRsl,fs,0); +for ns = 1:nSig +[dummy nf] = min(abs(freq1 - SigFrqLvldB(ns,1))); + SigFrqLvldB(ns,2) = SigFrqLvldB(ns,2) + 10*log10(CrctLinPwr(nf)); +end; + +%SigFrqLvldB(:,2) + +%%% Level Estimation path %%% +GCparam.LvlEst.LctERB = 1.5; + + NchShift = round(GCparam.LvlEst.LctERB/ERBspace1); + NchLvlEst = min(max(1, (1:NumCh)'+NchShift),NumCh); + Fp1LvlEst = Fp1(NchLvlEst(:)); + + Fr1L = Fpeak2Fr(GCparam.n,b1,c1,Fp1LvlEst); + + fratL= GCparam.LvlEst.frat; +%% fratL= 1; % not so diffrerent + + b2L= GCparam.LvlEst.b2; + c2L= GCparam.LvlEst.c2; + +SwTwoStageEst = 0; +if SwTwoStageEst == 1 + % when fratL is fixed + cGCLvlEst = CmprsGCFrsp(Fr1L,fs,GCparam.n,b1,c1,fratL,b2L,c2L,NfrqRsl); + + freq = cGCLvlEst.freq; + EstLvlTtl = zeros(NumCh,1); + for ns = 1:nSig + [dummy nf] = min(abs(freq - SigFrqLvldB(ns,1))); + EstLvldB0(1:NumCh,ns) = SigFrqLvldB(ns,2)+20*log10(cGCLvlEst.pGCFrsp(:,nf)); + end; + EstLvlTtl = sum( (10.^(EstLvldB0(:,:)/20))')'; + EstLvldB99 = 20*log10(EstLvlTtl(:)); + + fratL = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*EstLvldB99; +end; + +% fratLRef = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... +% (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*50; +% 1.0110 + + cGCLvlEst = CmprsGCFrsp(Fr1L,fs,GCparam.n,b1,c1,fratL,b2L,c2L,NfrqRsl); + + freq = cGCLvlEst.freq; + for ns = 1:nSig + [dummy nf] = min(abs(freq - SigFrqLvldB(ns,1))); + EstLvldB1(1:NumCh,ns) = SigFrqLvldB(ns,2)+20*log10(cGCLvlEst.pGCFrsp(:,nf)); + EstLvldB2(1:NumCh,ns) = SigFrqLvldB(ns,2)+20*log10(cGCLvlEst.cGCFrsp(:,nf)); +%% EstLvldB2(1:NumCh,ns) = SigFrqLvldB(ns,2)+20*log10(cGCLvlEst.cGCNrmFrsp(:,nf)); + end; + +%size(cGCLvlEst.pGCFrsp) +%20*log10(cGCLvlEst.NormFctFp2') +%20*log10( cGCLvlEst.ValFp2') + +%% alp = 0.5; beta = 0.5; % not good symmetric! +%% alp = 0.6; beta = 0.5; % little better +%%alp = 0.7; beta1 = 1; beta2 = 0.7; % for old version +%% alp = 0.7; beta1 = 1; beta2 = 0.5; % OK needs more asymmetry 13 July 05 +%% alp = 0.5; beta1 = 1; beta2 = 0.5; % more symmetric NG +%% alp = 0.5; beta1 = 1.5; beta2 = 0.5; % what happens? OK! +alp = GCparam.LvlEst.Weight; +beta1 = GCparam.LvlEst.Pwr(1); +beta2 = GCparam.LvlEst.Pwr(2); +a0 = 10.^(( GCparam.LvlEst.RefdB(1) - 0)/20); + +alp_beta12_a0 = [alp beta1 beta2 a0] + +%%% NG! 13 July +%% a1 = sum( (10.^( ((EstLvldB1(:,:) -50) * beta1 + 50) /20)) )' )'; +%% a2 = sum( (10.^( ((EstLvldB2(:,:) -50) * beta2 + 50) /20 ) )' )'; +%% + a1 = sum( 10.^(EstLvldB1(:,:)'/20) )'; + a2 = sum( 10.^(EstLvldB2(:,:)'/20) )'; +%[ [max(a1) a0] 20*log10([max(a1) a0])] + EstLvlTtl = alp * a0*(a1/a0).^beta1 + (1-alp) * a0*(a2/a0).^beta2; + EstLvldB = 20*log10(EstLvlTtl(:)); + +[ max(fratL) max(20*log10(a1)) max(20*log10(a2)) max(EstLvldB) ] + +%%%%% Signal path %%%%%%% + + fratVal = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*EstLvldB; + b2= GCparam.b2(1); + c2= GCparam.c2(1); + + cGCresp = CmprsGCFrsp(Fr1,fs,GCparam.n,b1,c1,fratVal,b2,c2,NfrqRsl); + + for ns = 1:nSig + [dummy nf] = min(abs(freq - SigFrqLvldB(ns,1))); + cGCoutdB1(1:NumCh,ns) = SigFrqLvldB(ns,2)+20*log10(cGCresp.cGCFrsp(:,nf)); + pGCoutdB1(1:NumCh,ns) = SigFrqLvldB(ns,2)+20*log10(cGCresp.pGCFrsp(:,nf)); + end; + + cGCoutdB = 20*log10( sum( ( 10.^(cGCoutdB1/20) )')'); + pGCoutdB = 20*log10( sum( ( 10.^(pGCoutdB1/20) )')'); + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/GCFBv205_SetParam.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/GCFBv205_SetParam.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,174 @@ +% +% Setting Default Parameter for GCFBv2 +% Version 2.05 +% Toshio IRINO +% Created: 31 Aug 2004 +% Modified: 9 Nov 2004 +% Modified: 31 May 2005 +% Modified: 1 July 2005 +% Modified: 8 July 2005 (bug fix in b2) +% Modified: 13 July 2005 ( GCparam.LvlEst.frat = 1.08) +% Modified: 14 July 2005 ( adding GCparam.LvlEst.RefdB, Pwr, Weight) +% Modified: 16 July 2005 ( GCparam.LvlEst.LctERB = 1.5) +% +% function GCparam = GCFBv2_SetParam(GCparam) +% INPUT: GCparam: Your preset gammachirp parameters +% GCparam.fs: Sampling rate (48000) +% GCparam.NumCh: Number of Channels (75) +% GCparam.FRange: Frequency Range of GCFB [100 6000] +% specifying asymptotic freq. of passive GC (Fr1) +% +% OUTPUT: GCparam: GCparam values +% +% Patterson, R.D., Unoki, M. and Irino, T. : JASA, Vol.114,pp.1529-1542,2003. +% +function GCparam = GCFBv2_SetParam(GCparam) + +%%%% Handling Input Parameters %%%%% +if isfield(GCparam,'fs') == 0, GCparam.fs = []; end; +if length(GCparam.fs) == 0, + GCparam.fs = 48000; +end; +% if isfield(GCparam,'OutMidCrct') == 0, GCparam.OutMidCrct = []; end; +% if length(GCparam.OutMidCrct) == 0, +% GCparam.OutMidCrct = 'ELC'; +% end; +GCparam.OutMidCrct = []; +%%% if no OutMidCrct is not necessary, specify GCparam.OutMidCrct = 'no'; +%% +if isfield(GCparam,'NumCh') == 0, GCparam.NumCh = []; end; +if length(GCparam.NumCh) == 0, + GCparam.NumCh = 75; +end; +if isfield(GCparam,'FRange') == 0, GCparam.FRange = []; end; +if length(GCparam.FRange) == 0, + GCparam.FRange = [100 6000]; +end; + +%%%%% Gammachirp parameters %%% +if isfield(GCparam,'n') == 0, GCparam.n = []; end; +if length(GCparam.n) == 0, + GCparam.n = 4; % default gammatone & gammachirp +end; + +%%% convention + +if isfield(GCparam,'b1') == 0, GCparam.b1 = []; end; +if length(GCparam.b1) == 0, + GCparam.b1 = [1.81]; % scalar: frequency independent +end; +if isfield(GCparam,'c1') == 0, GCparam.c1 = []; end; +if length(GCparam.c1) == 0, + GCparam.c1 = [-2.96]; % scalar: frequency independet +end; + +if isfield(GCparam,'frat') == 0, GCparam.frat = []; end; +if length(GCparam.frat) == 0, + GCparam.frat = [0.233, 0; 0.0050, 0]; +end; + +if isfield(GCparam,'b2') == 0, GCparam.b2 = []; end; +if length(GCparam.b2) == 0, + % GCparam.b2 = [2.01, 0; 0,0]; % no level-dependency bug + GCparam.b2 = [2.17, 0; 0,0]; % no level-dependency (8 Jul 05) +end; +if isfield(GCparam,'c2') == 0, GCparam.c2 = []; end; +if length(GCparam.c2) == 0, + % GCparam.c2 = [2.20, 0; 0,0]; %v203: no level-dependency; no freq-dependency + % GCparam.c2 = [1.98, 0; 0.0088, 0]; % == v203 + % GCparam.c2 = [2.0, 0; 0.010, 0]; % no freq-dependecy: level-dependent + % for simplicity v204 + % GCparam.c2 = [2.0, 0; 0.030, 0]; % 26 May 05 (NG! since Pc == mean value) + % GCparam.c2 = [2.1, 0; 0.010, 0]; % 27 May 05 (1 dB worse than 2.0 0.010 ) + % GCparam.c2 = [2.0, 0; 0.015, 0]; % 31 May 05 (much worse than 2.0 0.010 ) + % GCparam.c2 = [2.0, 0; 0.007, 0]; % 1 Jun 05 (OK! almost the same as 1st draft) + GCparam.c2 = [2.20, 0; 0, 0]; % 3 Jun 05 . It is good! +end; +if isfield(GCparam,'Ctrl') == 0, GCparam.Ctrl = []; end; +if length(GCparam.Ctrl) == 0, + GCparam.Ctrl = 'fix'; +end; + +if isfield(GCparam,'GainCmpnstdB') == 0, GCparam.GainCmpnstdB = []; end; +if length(GCparam.GainCmpnstdB) == 0, + GCparam.GainCmpnstdB = -1; % in dB. when LvlEst.c2==2.2, 1 July 2005 +end; + + +%%%%%%% Parameters for level estimation %%%%%%%%% + +if exist('GCparam.PpgcRef') == 1, + disp('The parameter "GCparam.PpgcRef" is obsolete.'); + error('Please change it to GCparam.LvlRefdB.'); +end; + +if isfield(GCparam,'LvlRefdB') == 0, GCparam.LvlRefdB = []; end; +if length(GCparam.LvlRefdB) == 0, + GCparam.LvlRefdB = 50; % reference Ppgc level for normalization +end; + +if isfield(GCparam,'LvlEst') == 0, GCparam.LvlEst = []; end; + +if isfield(GCparam.LvlEst,'LctERB') == 0, GCparam.LvlEst.LctERB = []; end; +if length(GCparam.LvlEst.LctERB) == 0, + GCparam.LvlEst.LctERB = 1.0; + % Location of Level Estimation pGC relative to the signal pGC in ERB + % see testGC_LctERB.m for fitting result. 10 Sept 2004 + GCparam.LvlEst.LctERB = 1.5; % 16 July 05 +end; + + +if isfield(GCparam.LvlEst,'DecayHL') == 0, GCparam.LvlEst.DecayHL=[]; end; +if length(GCparam.LvlEst.DecayHL) == 0, + %%% GCparam.LvlEst.DecayHL = 1; % half life in ms, Mar 2005 + GCparam.LvlEst.DecayHL = 0.5; % 18 July 2005 + %%% Original name was PpgcEstExpHL + %%% Interesting findings on 12 Jul 04 + %%% GCparam.PpgcEstExpHL = 2; % seems to produce distortion product + %%% GCparam.PpgcEstExpHL = 5; % original value without any info. + %%% Resonable value: + %%% GCparam.LvlEst.DecayHL = 1; % It is the best in the forward masking +end; + +if isfield(GCparam.LvlEst,'b2') == 0, GCparam.LvlEst.b2=[]; end; +if length(GCparam.LvlEst.b2) == 0, + % GCparam.LvlEst.b2 = 1.5; + % GCparam.LvlEst.b2 = 2.01; % = b2 bug! + GCparam.LvlEst.b2 = GCparam.b2(1,1); % = b2 8 July 2005 +end; + +if isfield(GCparam.LvlEst,'c2') == 0, GCparam.LvlEst.c2=[]; end; +if length(GCparam.LvlEst.c2) == 0, + % GCparam.LvlEst.c2 = 2.7; + % GCparam.LvlEst.c2 = 2.20; % = c2 + GCparam.LvlEst.c2 = GCparam.c2(1,1); % = c2 +end; + +if isfield(GCparam.LvlEst,'frat') == 0, GCparam.LvlEst.frat=[]; end; +if length(GCparam.LvlEst.frat) == 0, + % GCparam.LvlEst.frat = 1.1; % when b=2.01 & c=2.20 + GCparam.LvlEst.frat = 1.08; % peak of cGC ~= 0 dB (b2=2.17 & c2=2.20) +end; + +if isfield(GCparam.LvlEst,'RMStoSPLdB')==0, GCparam.LvlEst.RMStoSPLdB=[]; end; +if length(GCparam.LvlEst.RMStoSPLdB) == 0, + GCparam.LvlEst.RMStoSPLdB = 30; % 1 rms == 30 dB SPL for Meddis IHC +end; + +if isfield(GCparam.LvlEst,'Weight')==0, GCparam.LvlEst.Weight=[]; end; +if length(GCparam.LvlEst.Weight) ==0, + GCparam.LvlEst.Weight = 0.5; +end; + +if isfield(GCparam.LvlEst,'RefdB')==0, GCparam.LvlEst.RefdB=[]; end; +if length(GCparam.LvlEst.RefdB) < 2, + GCparam.LvlEst.RefdB = 50; % 50 dB SPL +end; + +if isfield(GCparam.LvlEst,'Pwr')==0, GCparam.LvlEst.Pwr=[]; end; +if length(GCparam.LvlEst.Pwr) < 2, + GCparam.LvlEst.Pwr = [ 1.5, 0.5 ]; % Weight for pGC & cGC +end; + +%%%%%%%%%%% + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/GCFBv205_old.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/GCFBv205_old.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,293 @@ +% +% Compressive Gammachirp Filterbank +% Version 2.05 +% Toshio IRINO +% Created: 6 Sept 2003 +% Modified: 7 June 2004 +% Modified: 12 July 2004 (PpgcEstShiftERB) +% Modified: 14 July 2004 (LinPpgc) +% Modified: 4 Aug 2004 (introducing GCresp) +% Modified: 16 Aug 2004 (ExpDecayVal) +% Modified: 31 Aug 2004 (introducing GCFBv2_SetParam) +% Modified: 8 Sept 2004 (TTS. tidy up the names. 2.00 -> 2.01) +% Modified: 10 Sept 2004 (Normalization at Level estimation path) +% Modified: 7 Oct 2004 (c2val is level dependent 2.02) +% Modified: 22 Oct 2004 (level estimation 2.03) +% Modified: 8 Nov 2004 (error detection of SndIn) +% Modified: 30 Nov 2004 (c2val control) +% Modified: 23 May 2005 (v205. Pc == average of two input, RMS2dBSPL, +% Fast filtering when 'fix' : under construction) +% Modified: 24 May 2005 (v205 Mod in LinLvl1 =..., LvldB= ...) +% Modified: 3 Jun 2005 (v205) +% Modified: 1 Jun 2005 (v205, GCparam.GainCmpnstdB) +% Modified: 14 July 2005 (v205, GCparam.LvlEst.RefdB, Pwr, Weight) +% +% +% function [cGCout, pGCout, Ppgc, GCparam, GCresp] = GCFB2(Snd,GCparam) +% INPUT: Snd: Input Sound +% GCparam: Gammachirp parameters +% GCparam.fs: Sampling rate (48000) +% GCparam.NumCh: Number of Channels (75) +% GCparam.FRange: Frequency Range of GCFB [100 6000] +% specifying asymptotic freq. of passive GC (Fr1) +% +% OUTPUT: cGCout: Compressive GammaChirp Filter Output +% pGCout: Passive GammaChirp Filter Output +% Ppgc: power at the output of passive GC +% GCparam: GCparam values +% GCresp : GC response result +% +% Note +% 1) This version is completely different from GCFB v.1.04 (obsolete). +% We introduced the "compressive gammachirp" to accomodate both the +% psychoacoustical simultaneous masking and the compressive +% characteristics (Irino and Patterson, 2001). The parameters were +% determined from large dataset (See Patterson, Unoki, and Irino, 2003.) +% +% +% References: +% Irino, T. and Unoki, M.: IEEE ICASSP'98 paper, AE4.4 (12-15, May, 1998) +% Irino, T. and Patterson, R.D. : JASA, Vol.101, pp.412-419, 1997. +% Irino, T. and Patterson, R.D. : JASA, Vol.109, pp.2008-2022, 2001. +% Patterson, R.D., Unoki, M. and Irino, T. : JASA, Vol.114,pp.1529-1542,2003. +% +% +function [cGCout, pGCout, GCparam, GCresp] = GCFBv2(SndIn,GCparam) + +%%%% Handling Input Parameters %%%%% +if nargin < 2, help GCFBv205; end; + +[nc, LenSnd] = size(SndIn); +if nc ~= 1, error('Check SndIn. It should be 1 ch (Monaural).' ); end; + +GCparam = GCFBv205_SetParam(GCparam); + +%%%%%%%%%%%%% +fs = GCparam.fs; +NumCh = GCparam.NumCh; +if length(GCparam.b1) == 1 & length(GCparam.c1) == 1 + b1 = GCparam.b1(1); % Freq. independent + c1 = GCparam.c1(1); % Freq. independent +else + error('Not prepared yet: Freq. dependent b1, c1'); +end; + +[Fr1, ERBrate1] = EqualFreqScale('ERB',NumCh,GCparam.FRange); +Fr1 = Fr1(:); +ERBspace1 = mean(diff(ERBrate1)); + +GCresp.Fr1 = Fr1; +Fp1 = Fr2Fpeak(GCparam.n,b1,c1,Fr1); +GCresp.Fp1 = Fp1; + +[ERBrate ERBw] = Freq2ERB(Fr1); +[ERBrate1kHz ERBw1kHz] = Freq2ERB(1000); +Ef = ERBrate/ERBrate1kHz - 1; +GCresp.Ef = Ef; +%%%% +% fratVal = frat(1,1) + frat(1,2)*Ef + +% frat(2,1)*Ppgc + frat(2,2)*Ef*Ppgc; +%%% + +%%%%% Outer-Mid Ear Compensation %%%% +if length(GCparam.OutMidCrct) > 2 + disp(['*** Outer/Middle Ear correction: ' GCparam.OutMidCrct ' ***']); + CmpnOutMid = OutMidCrctFilt(GCparam.OutMidCrct,fs,0); + % 1kHz: -4 dB, 2kHz: -1 dB, 4kHz: +4 dB + Snd = filter(CmpnOutMid,1,SndIn); +else + disp('*** No Outer/Middle Ear correction ***'); + Snd = SndIn; +end; + +% for compensation filer, use OutMidCrctFilt('ELC',fs,0,1); + +%%%%% Gammachirp %%% +disp('*** Gammmachirp Calculation ***'); +if 0, disp(GCparam), end; +tic; + +SwFastPrcs = 0; +if SwFastPrcs == 1, + error('Fast processing for linear cGC: Under construction.'); + %%%%%%%%%%% for HP-AF %%% + + b2val = GCparam.b2(1,1)*ones(NumCh,1) + GCparam.b2(1,2)*Ef(:); + %c2val = GCparam.c2(1,1)*ones(NumCh,1) + GCparam.c2(1,2)*Ef(:); + c2valRef = GCparam.c2(1,1)*ones(NumCh,1) + GCparam.c2(1,2)*Ef(:) ... + + (GCparam.c2(2,1)*ones(NumCh,1) + GCparam.c2(2,2)*Ef(:))*GCparam.LvlRefdB; + GCresp.b2val = b2val; + %GCresp.c2val = c2val; + GCresp.c2valRef = c2valRef; + + fratVal = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:))*GCparam.LvlRefdB; + fr2val = Fp1(:).*fratVal; + [ACFcoef] = MakeAsymCmpFiltersV2(fs,fr2val,b2val,c2valRef); +end; + +%%%% Start calculation %%%%% + +%%% Passive Gammachirp filtering %%% + Tstart = clock; + cGCout = zeros(NumCh, LenSnd); + pGCout = zeros(NumCh, LenSnd); + Ppgc = zeros(NumCh, LenSnd); + + for nch=1:NumCh + + % passive gammachirp + pgc = GammaChirp(Fr1(nch),fs,GCparam.n,b1,c1,0,'','peak'); % pGC + pGCout(nch,1:LenSnd)=fftfilt(pgc,Snd); % fast fft based filtering + + %%% Fast processing for fixed cGC: Under construction. %%% + if SwFastPrcs == 1 & strcmp(GCparam.Ctrl,'fix') == 1 + error('Fast processing for linear cGC: Under construction.'); + cGCout(nch,:) = pGCout(nch,:); + for Nfilt = 1:4; + cGCout(nch,:) = filter(ACFcoef.bz(nch,:,Nfilt), ... + ACFcoef.ap(nch,:,Nfilt), cGCout(nch,:)); + end; + end; + + if nch == 1 | rem(nch,20)==0 + disp(['Passive-Gammachirp ch #' num2str(nch) ... + ' / #' num2str(NumCh) '. elapsed time = ' ... + num2str(fix(etime(clock,Tstart)*10)/10) ' (sec)']); + end; + end; + + + +%%%% Frequency Response for determining normalization factor +%%%% normalization factor for level estimation path + +GCresp.Fr2 = zeros(NumCh,LenSnd); +GCresp.fratVal = zeros(NumCh,LenSnd); +% +% not necessary when LvlEst.frat = 1.08 ( max(pGCout) = max(cGCout) = 0 dB) +% cGCLvlEst = CmprsGCFrsp(Fr1,fs,GCparam.n,b1,c1, ... +% GCparam.LvlEst.frat,GCparam.LvlEst.b2,GCparam.LvlEst.c2); +% NormLvlEst = cGCLvlEst.NormFctFp2; +% GCresp.cGCLvlEst = cGCLvlEst; + +%%%% Level independent b2 & level-dependent c2 for signal pass at LvlRefdB %%% +b2val = GCparam.b2(1,1)*ones(NumCh,1) + GCparam.b2(1,2)*Ef(:); +% c2val = GCparam.c2(1,1)*ones(NumCh,1) + GCparam.c2(1,2)*Ef(:); +c2valRef = GCparam.c2(1,1)*ones(NumCh,1) + GCparam.c2(1,2)*Ef(:) ... + + (GCparam.c2(2,1)*ones(NumCh,1) + GCparam.c2(2,2)*Ef(:))*GCparam.LvlRefdB; +GCresp.b2val = b2val; +GCresp.c2valRef = c2valRef; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Now signal path filtering +%%% by calculating HP-AF for every time slice + +nDisp = 20*fs/1000; % display every 20 ms +cGCout = zeros(NumCh,LenSnd); +GCresp.Fr2 = zeros(NumCh,LenSnd); +GCresp.fratVal = zeros(NumCh,LenSnd); +LvldB = zeros(NumCh,LenSnd); +LvlLinPrev = zeros(NumCh,2); +ExpDecayVal = exp(-1/(GCparam.LvlEst.DecayHL*fs/1000)*log(2)); % decay exp. + +NchShift = round(GCparam.LvlEst.LctERB/ERBspace1); +NchLvlEst = min(max(1, (1:NumCh)'+NchShift),NumCh); % shift in NumCh +Fp1LvlEst = Fp1(NchLvlEst(:)); +zrs = zeros(NumCh,1); +LvlLinMinLim = 10^(-GCparam.LvlEst.RMStoSPLdB/20); % minimum should be 0 dBSPL +LvlLinRef = 10.^(( GCparam.LvlEst.RefdB - GCparam.LvlEst.RMStoSPLdB)/20); + +Tstart = clock; +for nsmpl=1:LenSnd + + if strcmp(GCparam.Ctrl,'fix') == 1 + LvldB(:,nsmpl) = GCparam.LvlRefdB*ones(NumCh,1); % fixed value + + elseif strcmp(GCparam.Ctrl(1:3),'tim') == 1, % when time-varying + +%%%% Level estimation path %%%% + Fr2LvlEst = GCparam.LvlEst.frat * Fp1LvlEst; + [ACFcoefLvlEst] = ... + MakeAsymCmpFiltersV2(fs,Fr2LvlEst,GCparam.LvlEst.b2, GCparam.LvlEst.c2); + if nsmpl == 1, %% initiallization + [dummy,ACFstatusLvlEst] = ACFilterBank(ACFcoefLvlEst,[]); + end; + [cGCLvlEst,ACFstatusLvlEst] =... + ACFilterBank(ACFcoefLvlEst,ACFstatusLvlEst,pGCout(NchLvlEst,nsmpl)); + + %% SigLvlEst = NormLvlEst .* SigLvlEst; %%%% Removed 14 July 05 + %% SumLvlLin = pGCout(:,nsmpl) + SigLvlEst; + %% SumLvlLin = abs(pGCout(:,nsmpl)) + abs(SigLvlEst); + %% LvlLin1 = max([pGCout(:,nsmpl), LvlLinPrev1*ExpDecayVal, zrs]')'; + %% <-- NchLvlEst <-- Bug! + %% LvlLin2 = max([cGCLvlEst, LvlLinPrev2*ExpDecayVal, zrs]')'; + %%%%% Modified: 24 May 05 + LvlLin(1:NumCh,1) = ... + max([max(pGCout(NchLvlEst,nsmpl),0), LvlLinPrev(:,1)*ExpDecayVal]')'; + LvlLin(1:NumCh,2) = ... + max([max(cGCLvlEst,0), LvlLinPrev(:,2)*ExpDecayVal]')'; + LvlLinPrev = LvlLin; + + %%%% + %% LvldB(:,nsmpl) = 20*log10(max((LvlLin1+LvlLin2)/2,0.1)) ... + %% + GCparam.LvlEst.RMStoSPLdB; % average <-- v205 + %%%%% Removed: 14 July 05 + %% LvldB(:,nsmpl) = 20*log10(max((LvlLin1+LvlLin2)/2,alim)) ... + %% + GCparam.LvlEst.RMStoSPLdB; % average <-- v205 + %%%%% Modified: 14 July 05 + LvlLinTtl = GCparam.LvlEst.Weight * ... + LvlLinRef.*(LvlLin(:,1)/LvlLinRef).^GCparam.LvlEst.Pwr(1) ... + + ( 1 - GCparam.LvlEst.Weight ) * ... + LvlLinRef.*(LvlLin(:,2)/LvlLinRef).^GCparam.LvlEst.Pwr(2); + + LvldB(:,nsmpl) = 20*log10( max(LvlLinTtl,LvlLinMinLim) ) ... + + GCparam.LvlEst.RMStoSPLdB; + else + error([ 'GCparam.Ctrl should be "fix" or "tim[e-varying]" ']) + end; + + %%%%% Signal path %%%%%%% + % Filtering High-Pass Asym. Comp. Filter + fratVal = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*LvldB(:,nsmpl); + Fr2Val = Fp1(:).*fratVal; + c2val = GCparam.c2(1,1)*ones(NumCh,1) + GCparam.c2(2,1)*LvldB(:,nsmpl); + + [ACFcoef] = MakeAsymCmpFiltersV2(fs,Fr2Val,b2val,c2val); + if nsmpl == 1, + [dummy,ACFstatus] = ACFilterBank(ACFcoef,[]); % initiallization + end; + + [SigOut,ACFstatus] = ACFilterBank(ACFcoef,ACFstatus,pGCout(:,nsmpl)); + cGCout(:,nsmpl) = SigOut; + + GCresp.Fr2(:,nsmpl) = Fr2Val; + GCresp.fratVal(:,nsmpl) = fratVal; + + if nsmpl==1 | rem(nsmpl,nDisp)==0, +%%% [ 20*log10([max(LvlLin(:,1)) max(LvlLin(:,2)) max(LvlLinTtl) ])... +%%% + GCparam.LvlEst.RMStoSPLdB max(LvldB(:,nsmpl))] + disp(['Compressive GC: Time ' num2str(nsmpl/fs*1000,3) ... + ' (ms) / ' num2str(LenSnd/fs*1000) ' (ms). elapsed time = ' ... + num2str(fix(etime(clock,Tstart)*10)/10) ' (sec)']); + end; +end; + + +%%%% Signal path Normalization factor at Reference Level +fratRef = GCparam.frat(1,1) + GCparam.frat(1,2)*Ef(:) + ... + (GCparam.frat(2,1) + GCparam.frat(2,2)*Ef(:)).*GCparam.LvlRefdB; + +cGCRef = CmprsGCFrsp(Fr1,fs,GCparam.n,b1,c1,fratRef,b2val,c2valRef); +GCresp.cGCRef = cGCRef; +GCresp.LvldB = LvldB; + +%%%% Result +GainFactor = 10^(GCparam.GainCmpnstdB/20)*(cGCRef.NormFctFp2 * ones(1,LenSnd)); +cGCout = GainFactor.*cGCout; + +return + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/GammaChirp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/GammaChirp.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,110 @@ +% +% Gammachirp : Theoretical auditory filter +% Toshio IRINO +% 7 Apr. 97 (additional comments) +% 20 Aug. 97 (Simplify & Carrier Selection) +% 10 Jun. 98 (SwNorm) +% 26 Nov. 98 (phase = phase + c ln fr/f0) +% 7 Jan. 2002 (adding 'envelope' option) +% 22 Nov. 2002 (debugging 'peak' option) +% +% gc(t) = t^(n-1) exp(-2 pi b ERB(Frs)) cos(2*pi*Frs*t + c ln t + phase) +% +% function [GC, LenGC, Fps, InstFreq ] ... +% = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm); +% INPUT : Frs : Asymptotic Frequency ( vector ) +% SR : Sampling Frequency +% OrderG : Order of Gamma function t^(OrderG-1) == n +% CoefERBw: Coeficient -> exp(-2*pi*CoefERBw*ERB(f)) == b +% CoefC : Coeficient -> exp(j*2*pi*Frs + CoefC*ln(t)) == c +% Phase : Start Phase(0 ~ 2*pi) +% SwCarr : Carrier ('cos','sin','complex','envelope': 3 letters) +% SwNorm : Normalization of peak spectrum level ('no', 'peak') +% OUTPUT: GC : GammaChirp ( matrix ) +% LenGC : Length of GC for each channel ( vector ) +% Fps : Peak Frequency ( vector ) +% InstFreq: Instanteneous Frequency ( matrix ) +% +% +function [GC, LenGC, Fps, InstFreq ] ... + = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm); + +if nargin < 2, help GammaChirp; return; end; +Frs = Frs(:); +NumCh = length(Frs); +if nargin < 3, OrderG = []; end; +if length(OrderG) == 0, OrderG = 4; end; % Default GammaTone +if length(OrderG) == 1, OrderG = OrderG*ones(NumCh,1); end; +if nargin < 4, CoefERBw = []; end; +if length(CoefERBw) == 0, CoefERBw = 1.019; end; % Default GammaTone +if length(CoefERBw) == 1, CoefERBw = CoefERBw*ones(NumCh,1); end; +if nargin < 5, CoefC = []; end; +if length(CoefC) == 0, CoefC = 0; end; % Default GammaTone +if length(CoefC) == 1, CoefC = CoefC*ones(NumCh,1); end; +if nargin < 6, Phase = []; end; +if length(Phase) == 0, Phase = 0; end; +if length(Phase) == 1, Phase = Phase*ones(NumCh,1); end; +if nargin < 7, SwCarr = []; end; +if length(SwCarr) == 0, SwCarr = 'cos'; end; +if nargin < 8, SwNorm = []; end; +if length(SwNorm) == 0, SwNorm = 'no'; end; + + +[ERBrate ERBw] = Freq2ERB(Frs); % G&M (1990) +LenGC1kHz = (40*max(OrderG)/max(CoefERBw) + 200)*SR/16000; % 2 Aug 96 +[dummy ERBw1kHz] = Freq2ERB(1000); + +if strcmp(SwCarr,'sin'), Phase = Phase - pi/2*ones(1,NumCh); end; +%%% Phase compensation +Phase = Phase + CoefC.*log(Frs/1000); % relative phase to 1kHz + +LenGC = fix(LenGC1kHz*ERBw1kHz./ERBw); + +%%%%% Production of GammaChirp %%%%% +GC = zeros(NumCh,max(LenGC)); +if nargout > 2, Fps = Fr2Fpeak(OrderG,CoefERBw,CoefC,Frs); end; % Peak Freq. +if nargout > 3, InstFreq = zeros(NumCh,max(LenGC)); end; + + +for nch = 1:NumCh, + t = (1:LenGC(nch)-1)/SR; + + GammaEnv = t.^(OrderG(nch)-1).*exp(-2*pi*CoefERBw(nch)*ERBw(nch)*t); + GammaEnv = [ 0 GammaEnv/max(GammaEnv)]; + + if strcmp(SwCarr(1:3),'env') % envelope + Carrier = ones(size(GammaEnv)); + elseif strcmp(SwCarr(1:3),'com') % complex + Carrier = [ 0 exp(i * (2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch)) )]; + else + Carrier = [ 0 cos(2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch))]; + end; + + GC(nch,1:LenGC(nch)) = GammaEnv.*Carrier; + + if nargout > 3, + InstFreq(nch,1:LenGC(nch)) = [0, [Frs(nch) + CoefC(nch)./(2*pi*t)]]; + end; + + if strcmp(SwNorm,'peak') == 1, % peak gain normalization + [frsp freq] = freqz(GC(nch,1:LenGC(nch)),1,LenGC(nch),SR); + fp = Fr2Fpeak(OrderG(nch),CoefERBw(nch),CoefC(nch),Frs(nch)); + [dummy np] = min(abs(freq-fp)); + GC(nch,:) = GC(nch,:)/abs(frsp(np)); + end; + +end; % nch = ... + +return + +%% ERBw = 0.128*Frs; % Complete Constant Q only for check. + +% old +% Amp = ones(NumCh,1); % No normalization +% if strcmp(SwNorm,'peak'), Amp = ERBw./ERBw1kHz; end; % Peak spectrum==const. +% when it is gammatone +% if strcmp(SwNorm,'peak'), ... +% Amp = 2.815*sqrt(4/OrderG).*CoefERBw.*ERBw/SR; end; +% Peak spectrum==const. The gain is 1.0 when filtering sinusoid at cf. +% GC(nch,:) = GC(nch,:)/max(abs(freqz(GC(nch,:),1,LenGC(nch)))); +% diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/GammaChirpFrsp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/GammaChirpFrsp.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,115 @@ +% +% Frequency Response of GammaChirp +% Toshio IRINO +% Original Version: 30 Sept 98 +% Modified: 7 June 2004 (removing transpose when NumCh==1) +% +% function [AmpFrsp, freq, Fpeak, GrpDly, PhsFrsp] ... +% = GammaChirpFrsp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,NfrqRsl); +% INPUT : Frs : Resonance Freq. (vector) +% SR : Sampling Freq. +% OrderG : Order of Gamma function t^(OrderG-1) (vector) +% CoefERBw: Coeficient -> exp(-2*pi*CoefERBw*ERB(f)) +% CoefC : Coeficient -> exp(j*2*pi*Fr + CoefC*ln(t)) +% Phase : Start Phase (0 ~ 2*pi) +% NfrqRsl : freq. resolution +% OUTPUT: AmpFrsp : abs(Response) (NumCh*NfrqRsl matrix) +% freq : frequency (1 * NfrqRsl vector) +% Fpeak : Peak frequency (NumCh * 1 vector) +% GrpDly : Group delay (NumCh*NfrqRsl matrix) +% PhsFrsp : angle(Response); (NumCh*NfrqRsl matrix) +% +function [AmpFrsp, freq, Fpeak, GrpDly, PhsFrsp ] ... + = GammaChirpFrsp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,NfrqRsl); + +if nargin < 1, help GammaChirpFrsp; return; end; +if nargin < 2, SR = 48000; end; +if length(SR) == 0, error('Specify Sampling Frequency'); end; +Frs = Frs(:); +NumCh = length(Frs); + +if nargin < 3, OrderG = 4; end; % Default GammaTone +if length(OrderG) == 1, OrderG = OrderG*ones(NumCh,1); end; +if nargin < 4, CoefERBw = 1.019; end; % Default GammaTone +if length(CoefERBw) == 1, CoefERBw = CoefERBw*ones(NumCh,1); end; +if nargin < 5, CoefC = 0; end; % Default GammaTone +if length(CoefC) == 1, CoefC = CoefC*ones(NumCh,1); end; +if nargin < 6, Phase = []; end; +if length(Phase)==0, Phase = zeros(NumCh,1); end; % Default GammaTone +if nargin < 7, NfrqRsl = 1024; end; +if NfrqRsl < 256, help GammaChirpFrsp; error('NfrqRsl < 256'); end; + +[ERBrate ERBw] = Freq2ERB(Frs(:)); +freq = [0:NfrqRsl-1]/NfrqRsl*SR/2; + +one1 = ones(1,NfrqRsl); +bh = ( CoefERBw(:).*ERBw(:) ) * one1; +fd = ones(NumCh,1)*freq(:)' - Frs(:)*one1; +cn = ( CoefC(:)./OrderG(:) ) * one1; +n = OrderG(:) *one1; +c = CoefC(:) *one1; +Phase = Phase(:) *one1; + +%%% Analytic form (normalized at Fpeak) %%% +AmpFrsp = ( (1 + cn.^2)./(1 + (fd./bh).^2) ).^(n/2) ... + .* exp( c .* (atan(fd./bh) - atan(cn))); + +if nargout > 2, + Fpeak = Frs + CoefERBw.*ERBw.*CoefC./OrderG; + if nargout > 3, + GrpDly = 1/(2*pi)*(n.*bh + c.*fd)./(bh.^2 + fd.^2); + if nargout > 4, + PhsFrsp= -n.*atan(fd./bh) -c./2.*log((2*pi*bh).^2 +(2*pi*fd).^2 )+Phase; + end; + end; +end; + +return + + + +%%% No use anymore since it is somewhat confusing 7 June 2004 %%%%%%%%%%%% + +if NumCh == 1, % to let the results in column vector (same as freqz) + AmpFrsp = AmpFrsp(:); + freq=freq(:); + if nargout > 3, + GrpDly = GrpDly(:); + if nargout > 4, + PhsFrsp = PhsFrsp(:); + end; + end; +end; + +return + + +% Fbw = sqrt( -1 + 2.^(1./OrderG)).*CoefERBw.*ERBw; % bandwidth when c=0 + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% OLD +% val = 2*pi*(bh + i*fd); +% arg = angle(val); +% FrspAna = 1./(abs(val)).^OrderG(nch) .* exp(CoefC(nch)* arg); +% FrspAna = FrspAna/max(FrspAna); + + +if 0 + +for nch = 1:NumCh + bh = CoefERBw(nch)*ERBw(nch); + fd = freq(:)' - Frs(nch); + cn = CoefC(nch)/OrderG(nch); + %%% Analytic form (normalized at Fpeak) %%% + FrspAna = (sqrt( (1+cn^2)./(1+(fd/bh).^2) ) ).^OrderG(nch) ... + .* exp( CoefC(nch) .* (atan(fd/bh) - atan(cn))); + % Frsp(nch, 1:NfrqRsl) = FrspAna; + sqrt(mean( ( Frsp(nch, 1:NfrqRsl) - FrspAna ).^2) ) + GrpDly(nch,1:NfrqRsl) = ... + 1/(2*pi)*(OrderG(nch)*bh + CoefC(nch)*fd)./(bh.^2 + fd.^2); +end; + +end; + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/InvFxGCFBv205.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/InvFxGCFBv205.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,122 @@ +% Inverse Filterbank with Fixed Passive/Compressive Gammachirp +% No dynamic resynthesis +% Version 2.05 +% Toshio IRINO +% Created: 9 Nov 2004 +% Modified: 11 Nov 2004 Renamed and based on InvPGCFBv2.m +% Modified: 18 July 2005 v205 +% +% function [SynSnd, SynGCout] = InvFxGCFB2(GCout,GCparam,GCresp,SwMethod) +% INPUT: GCout: pGCout or cGCout +% GCparam: Gammachirp parameters +% Fp: peak frequency vector for synthesis filter +% SwMethod: 1: pGCout - pGCsyn +% 2: cGCout - pGCsyn +% 3: cGCout - Fixed(Ref) cGCsyn +% +% OUTPUT: SynSnd: Synthetic Sound +% +% +% References: +% Irino, T. and Unoki, M.: IEEE ICASSP'98 paper, AE4.4 (12-15, May, 1998) +% Irino, T. and Patterson, R.D. : JASA, Vol.101, pp.412-419, 1997. +% Irino, T. and Patterson, R.D. : JASA, Vol.109, pp.2008-2022, 2001. +% Patterson, R.D., Unoki, M. and Irino, T. : JASA, Vol.114,pp.1529-1542,2003. +% +% +function [SynSnd,SynGCout] = InvFxGCFB2(GCout,GCparam,GCresp,SwMethod) + +%%%% Handling Input Parameters %%%%% +if nargin < 4, help InvFxGCFBv2; end; + + +GCparam = GCFBv205_SetParam(GCparam); + +%%%%%%%%%%%%% +fs = GCparam.fs; +NumCh0 = GCparam.NumCh; +if length(GCparam.b1) == 1 & length(GCparam.c1) == 1 + b1 = GCparam.b1(1); % Freq. independent + c1 = GCparam.c1(1); % Freq. independent +else + error('Not prepared yet: Freq. dependent b1, c1'); +end; + +[NumCh, LenSnd] = size(GCout); +if NumCh ~= NumCh0, error('Mismatch in NumCh'); end; + +if SwMethod == 1 + disp('*** Inverse Passive Gammmachirp Calculation ***'); + Fr1 = GCresp.Fr1; +elseif SwMethod == 2; + disp('*** Inverse Passive Gammmachirp Calculation ***'); + Fr1 = Fpeak2Fr(GCparam.n,b1,c1,GCresp.cGCRef.Fp2); % pGC peak == Fp2 +elseif SwMethod == 3 + disp('*** Inverse Fixed Compressive Gammmachirp Calculation ***'); + Fr1 = GCresp.Fr1; +end; + + +LenInv = 50/1000*fs; % 50 ms zero filling for processing +zz = zeros(NumCh,LenInv); +TrGCout = fliplr(GCout); %%% time-reversal %% +TrGCout = [zz TrGCout zz]; +[NumCh,LenTr] = size(TrGCout); +SynGCout = zeros(NumCh,LenTr); +TrGCout1 = zeros(NumCh,LenTr); + +%%%%% Time-Reversal ACfilter cGC %%% + +Tstart = clock; +nDisp = 20*fs/1000; % display every 20 ms +if SwMethod == 3, % The same function is applied like wavelet trans. + [ACFcoef] = MakeAsymCmpFiltersV2(fs,... + GCresp.cGCRef.Fr2,GCresp.cGCRef.b2,GCresp.cGCRef.c2); + [dummy,ACFstatus] = ACFilterBank(ACFcoef,[]); % initiallization + for nsmpl = 1:LenTr + [SigOut,ACFstatus] = ACFilterBank(ACFcoef,ACFstatus,TrGCout(:,nsmpl)); + TrGCout1(:,nsmpl) = GCresp.cGCRef.NormFctFp2.*SigOut; + if nsmpl==1 | rem(nsmpl,nDisp)==0, + disp(['Time-Reversal ACF-cGC : Time ' num2str(nsmpl/fs*1000,3) ... + ' (ms) / ' num2str(LenSnd/fs*1000) ' (ms). elapsed time = ' ... + num2str(fix(etime(clock,Tstart)*10)/10) ' (sec)']); + end; + end; + TrGCout = TrGCout1; +end; + +%%%%% Time-Reversal Passive Gammachirp %%% + +for nch=1:NumCh + pgc = GammaChirp(Fr1(nch),fs,GCparam.n,b1,c1,0,'','peak'); + SynGCout(nch,1:LenTr) = fftfilt(pgc,TrGCout(nch,:)); + if nch == 1 | rem(nch,20)==0 + disp(['Time-Reversal Passive-Gammachirp ch #' num2str(nch) ... + ' / #' num2str(NumCh) '. elapsed time = ' ... + num2str(fix(etime(clock,Tstart)*10)/10) ' (sec)']); + end; +end; + +SynGCout = fliplr(SynGCout); +SynSnd = mean(SynGCout)*sqrt(NumCh); % Approximately all right + % Maybe depend on filter shape + % 11 Nov 2004 + +%%%%% Inverse of Outer-Mid Ear Compensation %%%% +if length(GCparam.OutMidCrct) > 2 + disp(['*** Inverse Outer/Middle Ear correction: ' GCparam.OutMidCrct ' ***']); + InvOutMid = OutMidCrctFilt(GCparam.OutMidCrct,fs,0,1); % Inverse + %% OutMidCrct--> 1kHz: -4 dB, 2kHz: -1 dB, 4kHz: +4 dB + %% [dummy NpIOM] = max(abs(InvOutMid)); + SynSnd = filter(InvOutMid,1,SynSnd); + Nout = LenInv+length(InvOutMid)+(1:LenSnd); +else + disp('*** No Outer/Middle Ear correction ***'); + Nout = LenInv+(1:LenSnd); +end; + +SynSnd = SynSnd(Nout); +SynGCout = SynGCout(:,Nout); + +disp(' '); +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/MakeAsymCmpFiltersV2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/MakeAsymCmpFiltersV2.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,96 @@ +% +% MakeAsymCmpFilters Version 2 +% Computes the coefficients for a bank of Asymmetric Compensation Filters +% This is a modified version to fix the round off problem at low freqs. +% Use this with ACFilterBank.m +% See also AsymCmpFrspV2.m for frequency response +% See footnote in this m-file. +% +% Toshio Irino +% Created: 18 May 2004 +% Modifed: 11 Jun 2004 +% +% function ACFcoef=MakeAsymCmpFiltersV2(fs,fr,b,c) +% INPUT: fs: Sampling frequency +% Frs: array of the center frequencies +% b : array or scalar of a bandwidth coefficient +% c : array or scalar of asymmetric parameters +% +% OUTPUT: ACFcoef +% fs : Sampling frequnecy +% bz : MA coefficients (NumCh*3*NumFilt) +% ap : AR coefficients (NumCh*3*NumFilt) +% +function ACFcoef = MakeAsymCmpFiltersV2(fs,Frs,b,c) + +if nargin < 4, help MakeAsymCmpFiltersV2; end; + +Frs = Frs(:); +b = b(:); +c = c(:); +NumCh = length(Frs); +[dummy ERBw] = Freq2ERB(Frs); +ACFcoef.fs = fs; + +% New Coefficients. See [1] + NumFilt = 4; + p0 = 2; + p1 = 1.7818 .* (1 - 0.0791*b) .* (1 - 0.1655*abs(c)); + p2 = 0.5689 .* (1 - 0.1620*b) .* (1 - 0.0857*abs(c)); + p3 = 0.2523 .* (1 - 0.0244*b) .* (1 + 0.0574*abs(c)); + p4 = 1.0724; +% +if NumFilt > 4, error('NumFilt > 4'); end; +ACFcoef.ap = zeros(NumCh,3,NumFilt); +ACFcoef.bz = zeros(NumCh,3,NumFilt); + +for Nfilt = 1:NumFilt, + + r = exp(-p1.*(p0./p4).^(Nfilt-1) * 2*pi .*b .*ERBw /fs); + delFrs = (p0*p4)^(Nfilt-1).*p2.*c.*b.*ERBw; + phi = 2*pi*max(Frs + delFrs,0)/fs; + psy = 2*pi*max(Frs - delFrs,0)/fs; + fn = Frs; % see [2] + + %% Second order filter %% + ap = [ones(size(r)), -2*r.*cos(phi), r.^2]; + bz = [ones(size(r)), -2*r.*cos(psy), r.^2]; + + vwr = exp(i*2*pi*fn/fs); + vwrs = [ones(size(vwr)), vwr, vwr.^2]; + + nrm = abs( sum( (vwrs.*ap)')' ./ sum( (vwrs.*bz)')'); + + %TCW AIM-2006 + %nrm = abs( sum( (vwrs.*ap),2) ./ sum( (vwrs.*bz),2)); + % tried this optimisation, but it turns out to be slower! + + bz = bz .* (nrm*ones(1,3)); + + ACFcoef.ap(:,:,Nfilt) = ap; + ACFcoef.bz(:,:,Nfilt) = bz; +end; + +return + +%%%%%%%%%%%%%%%%%%%%%%%% + +% Note: +% +% [1] Ref for p1-p4: +% Unoki,M , Irino,T. , and Patterson, R.D. , "Improvement of an +% IIR asymmetric compensation gammachirp filter," Acost. Sci. & +% Tech. (ed. by the Acoustical Society of Japan ), 22 (6), pp. 426-430, +% Nov. 2001. +% +% [2] Conventional setting was removed. +% fn = Frs + Nfilt* p3 .*c .*b .*ERBw/n; +% +% This frequency fn is for normalizing GC(=GT*Hacf) filter to be unity +% at the peak, frequnecy. But now we use Hacf as a highpass filter as well. +% cGC = pGC *Hacf. In this case, this normalization is useless. +% So, it was set as the gain at Frs is unity. (4. Jun 2004 ) +% +% [3] Removed +% ACFcoef.fn(:,nff) = fn; +% n : scalar of order t^(n-1) % used only in normalization diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/gen_dcgc.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/gen_dcgc.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,82 @@ +% generating function for 'aim-mat' +% +% +% Toshio Irino and Roy Patterson (2005). "A dynamic, compressive gammachirp auditory filterbank" Revision submitted to IEEE SAP.. +% Implementation in aim-mat by Ralph van Dinther +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +function fr=gen_dcgc(sig,options) + +% Generating the dcgc + +NumCh = options.nr_channels; +fre1 = options.lowest_frequency; +fre2 = options.highest_frequency; +FRange = [fre1 fre2]; +Frs = FcNch2EqERB(min(FRange),max(FRange),NumCh); + +sr = getsr(sig); +GCparam.fs=sr;% Sampling rate (48000) +GCparam.NumCh=NumCh;% Number of Channels (75) +GCparam.FRange=FRange; +GCparam.Ctrl = 'tim'; + +% TCW AIM 2006 - Now defaults to 70 dB, not 40 as before +if isfield(options, 'gain_ref') + GCparam.GainRefdB=options.gain_ref; +else + GCparam.GainRefdB=70; +end + +%% Anticipating the noise pre-excitation stuff I'm going to write... +% if ~isfield(options, 'pre_excite_with_noise') +% do_pre_excite=0; +% else +% do_pre_excite=options.pre_excite_with_noise; +% end +% +% if ~isfield(options, 'pre_excite_time') +% pre_excite_time=0.2; % 200ms +% else +% pre_excite_time=options.pre_excite_time; +% end +% +% if ~isfield(options, 'pre_excite_level_dB') +% pre_excite_level_dB=-10; +% else +% pre_excite_level_dB=options.pre_excite_level_dB; +% end + +NAPparam.cf_afb = [fre1 fre2]; +cf_afb=NAPparam.cf_afb; +NAPparam.SubBase = 0.5; + + +sr = getsr(sig); +Snd = getvalues(sig); +LenSnd = length(Snd); + +if (fre2>(0.4.*sr)) + warning('Top filter centre frequency is > 0.4 times the signal samplerate - aliasing effects possible'); +end + +%%%%% BMM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +[cGCout, pGCout, GCparam, GCresp] = GCFBv205(Snd',GCparam); +BMM=cGCout; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +fr = frame(BMM); +fr = setsr(fr,sr); +fr = setstarttime(fr,getminimumtime(sig)); +fr = setcf(fr,Frs); + +if ~strcmp(options.do_phase_alignment,'off') + fr=phasealign(fr,options); +end + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/dcgc/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/dcgc/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,28 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +%%%%%%%%%%%%% +% bmm +% hidden parameters + +dcgc.generatingfunction = 'gen_dcgc'; +dcgc.displayname = 'dynamic compressive gammachirp'; +dcgc.revision='$Revision: 585 $'; + +dcgc.default_nextmodule='hl'; + +% parameters relevant for the calculation of this module + +dcgc.nr_channels = 50; +dcgc.lowest_frequency = 100; % in Hz +dcgc.highest_frequency = 6000; % in Hz +%dcgc.b=1.019; % Filterbandwidth standard: 1.019 +dcgc.do_phase_alignment='off'; %'off','maximum_envelope','nr_cycles' +dcgc.phase_alignment_nr_cycles=1.5; % only relevant when do_align is nr_cylcles + +dcgc.gain_ref=70; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/ERB2Freq.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/ERB2Freq.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,30 @@ +% support file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +% +% ERB -> Frequency and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [cf, ERBwidth] = ERB2Freq(ERBrate) +% INPUT ERBrate: ERB rate +% OUTPUT cf: Center frequency (Hz) +% ERBwidth: ERB bandwidth (Hz) +% +% Ref: Glasberg and Moore : Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see ERB2FreqYear.m +% +% +function [cf, ERBwidth] = ERB2Freq(ERBrate), + +if nargin < 1, help ERB2Freq; end; + +cf = (10.^(ERBrate./21.4) - 1)./4.37 * 1000; +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/FcNch2EqERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/FcNch2EqERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,27 @@ +% support file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +% +% Fc & Nch --> Frequencies which is equally spaced on ERB axis +% Toshio Irino +% 8 Jan. 2003 +% +% INPUT: FcMin : min. Fc +% FcMax : max. Fc +% NumCh : number of channels +% OUTPUT: Frs: Freuqencies +% +% +function Frs = FcNch2EqERB(FcMin, FcMax,NumCh) + +if nargin < 3, help FcNch2EqERB, end; + +dERB = (Freq2ERB(FcMax)-Freq2ERB(FcMin))/(NumCh-1); +Frs = ERB2Freq( Freq2ERB(FcMin):dERB:Freq2ERB(FcMax) ); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/Fr2Fpeak.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/Fr2Fpeak.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,29 @@ +% support file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +% +% Estimate fr from fpeak +% Toshio IRINO +% 10 June 98 +% +% function [fpeak, ERBw] = Fr2Fpeak(n,b,c,fr) +% INPUT: n,b,c : gammachirp param. +% fr : fr +% OUTPUT: fpeak : peak freq. +% ERBw : ERBw(fr) +% +function [fpeak, ERBw] = Fr2Fpeak(n,b,c,fr) + +if nargin < 4, help Fr2Fpeak; end; + +n = n(:); +b = b(:); +c = c(:); +fr = fr(:); + +[dummy ERBw] = Freq2ERB(fr); +fpeak = fr + c.*ERBw.*b./n; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/Freq2ERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/Freq2ERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,42 @@ +% support file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +% +% Frequency -> ERBrate and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [ERBrate, ERBwidth] = Freq2ERB(cf), +% INPUT cf: Center frequency +% OUTPUT ERBrate: ERB rate +% ERBwidth: ERB width +% +% Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see Freq2ERBYear.m +% +function [ERBrate, ERBwidth] = Freq2ERB(cf), + +if nargin < 1, help Freq2ERB; end; + +ERBrate = 21.4.*log10(4.37*cf/1000+1); +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + +%%% Warning for Freq. Range %%% +cfmin = 50; +cfmax = 12000; +if (min(cf) < cfmin | max(cf) > cfmax) + disp(['Warning : Min or max frequency exceeds the proper ERB range:']); + disp([' ' int2str(cfmin) '(Hz) <= Fc <= ' int2str(cfmax) '(Hz).']); +end; + +%if (min(cf) < 0) +% error(['Min frequency is less than 0.']); +%end; + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/GammaChirp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/GammaChirp.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,117 @@ +% support file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +% +% Gammachirp : Theoretical auditory filter +% Toshio IRINO +% 7 Apr. 97 (additional comments) +% 20 Aug. 97 (Simplify & Carrier Selection) +% 10 Jun. 98 (SwNorm) +% 26 Nov. 98 (phase = phase + c ln fr/f0) +% 7 Jan. 2002 (adding 'envelope' option) +% 22 Nov. 2002 (debugging 'peak' option) +% +% gc(t) = t^(n-1) exp(-2 pi b ERB(Frs)) cos(2*pi*Frs*t + c ln t + phase) +% +% function [GC, LenGC, Fps, InstFreq ] ... +% = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm); +% INPUT : Frs : Asymptotic Frequency ( vector ) +% SR : Sampling Frequency +% OrderG : Order of Gamma function t^(OrderG-1) == n +% CoefERBw: Coeficient -> exp(-2*pi*CoefERBw*ERB(f)) == b +% CoefC : Coeficient -> exp(j*2*pi*Frs + CoefC*ln(t)) == c +% Phase : Start Phase(0 ~ 2*pi) +% SwCarr : Carrier ('cos','sin','complex','envelope': 3 letters) +% SwNorm : Normalization of peak spectrum level ('no', 'peak') +% OUTPUT: GC : GammaChirp ( matrix ) +% LenGC : Length of GC for each channel ( vector ) +% Fps : Peak Frequency ( vector ) +% InstFreq: Instanteneous Frequency ( matrix ) +% +% +function [GC, LenGC, Fps, InstFreq ] ... + = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm); + +if nargin < 2, help GammaChirp; return; end; +Frs = Frs(:); +NumCh = length(Frs); +if nargin < 3, OrderG = []; end; +if length(OrderG) == 0, OrderG = 4; end; % Default GammaTone +if length(OrderG) == 1, OrderG = OrderG*ones(NumCh,1); end; +if nargin < 4, CoefERBw = []; end; +if length(CoefERBw) == 0, CoefERBw = 1.019; end; % Default GammaTone +if length(CoefERBw) == 1, CoefERBw = CoefERBw*ones(NumCh,1); end; +if nargin < 5, CoefC = []; end; +if length(CoefC) == 0, CoefC = 0; end; % Default GammaTone +if length(CoefC) == 1, CoefC = CoefC*ones(NumCh,1); end; +if nargin < 6, Phase = []; end; +if length(Phase) == 0, Phase = 0; end; +if length(Phase) == 1, Phase = Phase*ones(NumCh,1); end; +if nargin < 7, SwCarr = []; end; +if length(SwCarr) == 0, SwCarr = 'cos'; end; +if nargin < 8, SwNorm = []; end; +if length(SwNorm) == 0, SwNorm = 'no'; end; + + +[ERBrate ERBw] = Freq2ERB(Frs); % G&M (1990) +LenGC1kHz = (40*max(OrderG)/max(CoefERBw) + 200)*SR/16000; % 2 Aug 96 +[dummy ERBw1kHz] = Freq2ERB(1000); + +if strcmp(SwCarr,'sin'), Phase = Phase - pi/2*ones(1,NumCh); end; +%%% Phase compensation +Phase = Phase + CoefC.*log(Frs/1000); % relative phase to 1kHz + +LenGC = fix(LenGC1kHz*ERBw1kHz./ERBw); + +%%%%% Production of GammaChirp %%%%% +GC = zeros(NumCh,max(LenGC)); +if nargout > 2, Fps = Fr2Fpeak(OrderG,CoefERBw,CoefC,Frs); end; % Peak Freq. +if nargout > 3, InstFreq = zeros(NumCh,max(LenGC)); end; + + +for nch = 1:NumCh, + t = (1:LenGC(nch)-1)/SR; + + GammaEnv = t.^(OrderG(nch)-1).*exp(-2*pi*CoefERBw(nch)*ERBw(nch)*t); + GammaEnv = [ 0 GammaEnv/max(GammaEnv)]; + + if strcmp(SwCarr(1:3),'env') % envelope + Carrier = ones(size(GammaEnv)); + elseif strcmp(SwCarr(1:3),'com') % complex + Carrier = [ 0 exp(i * (2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch)) )]; + else + Carrier = [ 0 cos(2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch))]; + end; + + GC(nch,1:LenGC(nch)) = GammaEnv.*Carrier; + + if nargout > 3, + InstFreq(nch,1:LenGC(nch)) = [0, [Frs(nch) + CoefC(nch)./(2*pi*t)]]; + end; + + if strcmp(SwNorm,'peak') == 1, % peak gain normalization + [frsp freq] = freqz(GC(nch,1:LenGC(nch)),1,LenGC(nch),SR); + fp = Fr2Fpeak(OrderG(nch),CoefERBw(nch),CoefC(nch),Frs(nch)); + [dummy np] = min(abs(freq-fp)); + GC(nch,:) = GC(nch,:)/abs(frsp(np)); + end; + +end; % nch = ... + +return + +%% ERBw = 0.128*Frs; % Complete Constant Q only for check. + +% old +% Amp = ones(NumCh,1); % No normalization +% if strcmp(SwNorm,'peak'), Amp = ERBw./ERBw1kHz; end; % Peak spectrum==const. +% when it is gammatone +% if strcmp(SwNorm,'peak'), ... +% Amp = 2.815*sqrt(4/OrderG).*CoefERBw.*ERBw/SR; end; +% Peak spectrum==const. The gain is 1.0 when filtering sinusoid at cf. +% GC(nch,:) = GC(nch,:)/max(abs(freqz(GC(nch,:),1,LenGC(nch)))); +% diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/gen_gtfb.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/gen_gtfb.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,85 @@ +% generating function for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function fr=gen_gtfb(sig,options) + +NumCh=options.nr_channels; +fre1=options.lowest_frequency; +fre2=options.highest_frequency; +FRange = [fre1 fre2]; + + +samplerate=getsr(sig); +Snd=getvalues(sig); +Snd=Snd'; %- do we need this transpose? + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +fs = samplerate; +NAPparam.cf_afb = [fre1 fre2]; +cf_afb=NAPparam.cf_afb; +NAPparam.SubBase = 0.5; + +%%%%% Outer-Mid Ear Compensation %%%% +%CmpnOutMid = OutMidCrctFilt('ELC',fs,0); +%Snd_om = filter(CmpnOutMid,1,Snd); + +%we are already applying filter in PCP module +Snd_om = Snd; % if unnecessary + + +%%%%% BMM %%% +% disp('*** BMM & NAP Calculation ***'); +% disp(NAPparam) +% tic; +Frs = FcNch2EqERB(min(cf_afb),max(cf_afb),NumCh); +NAPparam.Frs = Frs; +NAPparam.b = options.b; % maah: 1.019; % default gammatone + +% IIR implementation +% disp('BMM : Start calculation, Wait a minute'); +% fcoefs = MakeERBFilters98B(fs,Frs,[],b); % new version +% BMM = ERBFilterBank(Snd_om, fcoefs); +% disp(['BMM : elapsed_time = ' num2str(toc,3) ' (sec)']); + +% %%%% Lowpass filter for representing Phase-lock property %%% +% flpcut = 1200; +% [bzLP apLP] = butter(1,flpcut/(fs/2)); +% bzLP2 = [bzLP(1)^2, 2*bzLP(1)*bzLP(2), bzLP(2)^2]; +% apLP2 = [apLP(1)^2, 2*apLP(1)*apLP(2), apLP(2)^2]; + + +LenSnd = length(Snd_om); +bias = 0.1; +waithand=waitbar(0,'generating basilar membrane motion'); + +for nch = 1:NumCh + if mod(nch,10)==0 + waitbar(nch/NumCh); + end + gt = GammaChirp(Frs(nch),fs,4,NAPparam.b,0,0,[],'peak'); + BMM(nch,:) = fftfilt(gt,Snd_om); +end; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%now we convert all the stuff into the form that aim mat wants it +fr=frame(BMM); +fr=setsr(fr,samplerate); +fr=setstarttime(fr,getminimumtime(sig)); + +fr=setcf(fr,Frs); + + +if ~strcmp(options.do_phase_alignment,'off') + fr=phasealign(fr,options); +end + + +close(waithand); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/gtfb/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/gtfb/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,23 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% bmm +% hidden parameters +gtfb.generatingfunction='gen_gtfb'; +gtfb.displayname='Gamma tone filter bank'; +gtfb.revision='$Revision: 585 $'; + +gtfb.default_nextmodule='hcl'; + +% parameters relevant for the calculation of this module +gtfb.nr_channels=75; +gtfb.lowest_frequency=100; % in Hz +gtfb.highest_frequency=6000; % in Hz +gtfb.do_phase_alignment='off'; %'off','maximum_envelope','nr_cycles' +gtfb.phase_alignment_nr_cycles=3; % only relevant when do_align is nr_cylcles +gtfb.b=1.019; % Filterbandwidth standard: 1.019 diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/none/gennobmm.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/none/gennobmm.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function fr=genobmm(sig,options) +% generating function for the outer/middle ear transfere function +fr=sig; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/none/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/none/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% basilar membrane +% hidden parameters +none.generatingfunction='gennobmm'; +none.displayname='no basilar membrane (only usefull if togehter with ams)'; +none.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/AGCdampStep.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/AGCdampStep.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,71 @@ +function [pdampsmod, agcstate] = AGCdampStep(detect, pdamps, ... + agcepsilons, agcgains, agcstate, agcfactor); + % + +% function [pdampsmod, agcstate] = AGCdampStep(detect, pdamps, +% agcepsilons, agcgains, agcstate); +% +% update the dampings and agcstates based on present outputs +% including 50% stereo coupling if two channels based on size of +% agcstate is twice the number of channels + +if nargin < 6 + agcfactor=12; +end + +Nch = length(pdamps); +Ntracks = size(detect,2); % two columns for stereo +Nstages = length(agcepsilons); + + +if length(detect)==0, + Ntracks = 1; % mono default + if size(agcstate,2)>Nstages + Ntracks = round(size(agcstate,2)/Nstages); % pass in agcstate big + % enough to do stereo + end + detect = DetectFun(0.0)*ones(Nch,1); + %agcstate = 1.2*detect*ones(1,Ntracks*Nstages); % a detect-dependent + %hack to initialize damping + rep = 1+rem((1:Ntracks*Nstages)-1,Nstages); + agcstate = 1.2*detect*agcgains(rep); % rep is like [1 2 3 4 1 2 3 4] + detect = DetectFun(0.0)*ones(Nch,Ntracks); +end + +agcepsleft = 0.3; % 0.15; +agcepsright = 0.3; % 0.15; +spacecoeffs = [agcepsleft, 1.0-agcepsleft-agcepsright, agcepsright]; + +for k = 1:Ntracks % track number (1 for mono, 2 for second channel) + for j = 1:Nstages % stage number + jj = j + (k-1)*Nstages; % index into state columns + %spatial smoothing: + agcavg = filter(spacecoeffs, 1, [agcstate(1,jj); agcstate(:,jj); ... + agcstate(Nch,jj)]); + agcavg = agcavg(3:(Nch+2)); + %time smoothing: + epsilon = agcepsilons(j); + agcstate(:,jj) = agcavg*(1-epsilon) + epsilon*detect(:,k)*agcgains(j); + end +end + +%agcstate can't exceed 0.25, usually , with max detect being 0.5 +% only INCREASE the damping over pdamp +%agcfactor = 12; % 6.0; % 12.0; +% now set above or as an argument + +offset = 1-agcfactor*DetectFun(0.0); % 0.7422 for DetectFun(0)=0.0215 +% this makes the minimum damping (with 0 signal into AGC and agcstate being +% equal to the DetectFun value at zero, which may be zero) equal the nominal + +for k = 1:Ntracks % track number (1 for mono, 2 for second channel) +% pdampsmod(:,k) = pdamps.*min(1.5,(offset+agcfactor*... +% (mean(agcstate')' + mean(agcstate(:,((k-1)*Nstages+1):k*Nstages)')')/2)); + pdampsmod(:,k) = pdamps.*(offset+agcfactor*... + (mean(agcstate')' + mean(agcstate(:,((k-1)*Nstages+1):k*Nstages)')')/2); + % the above hack weights the track AGC and the average equally + % for mono is same as just ...ofset+agcfactor*sum(agcstates')' +end + +%plot([detect, pdamps, pdampsmod, agcstate, sum(agcstate')']) +%drawnow diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/DetectFun.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/DetectFun.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,16 @@ +function detect = DetectFun(velocity) +% function detect = DetectFun(velocity) +% a somewhat-compressing HWR. + +negate = 0; % depending on filterbank parameters, one or other might "thump" +if negate + velocity = -velocity; +end + +velocity(velocity < 0) = 0; +a = 0.25; % limiting slope, relative to 1 where it starts +detect = min(1, velocity); +detect = a*velocity + (1-a)*(detect - (detect.^3)/3); + +% test it this way: +%plot(-1:.1:2, DetectFun(-1:.1:2)) \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/Freq2ERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/Freq2ERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,35 @@ +% +% Frequency -> ERBrate and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [ERBrate, ERBwidth] = Freq2ERB(cf), +% INPUT cf: Center frequency +% OUTPUT ERBrate: ERB rate +% ERBwidth: ERB width +% +% Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see Freq2ERBYear.m +% +function [ERBrate, ERBwidth] = Freq2ERB(cf), + +if nargin < 1, help Freq2ERB; end; + +ERBrate = 21.4.*log10(4.37*cf/1000+1); +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + +%%% Warning for Freq. Range %%% +cfmin = 1; % was 50 +cfmax = 20000; % was 12000 +if (min(cf) < cfmin || max(cf) > cfmax) + disp(['Warning : Min or max frequency exceeds the proper ERB range:']); + disp([' ' int2str(cfmin) '(Hz) <= Fc <= ' int2str(cfmax) '(Hz).']); +end; + +%if (min(cf) < 0) +% error(['Min frequency is less than 0.']); +%end; + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZBankCoeffsERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZBankCoeffsERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,67 @@ +function [Coeffs, Nch, freqs, bws] = PZBankCoeffsERB(fs, CFMax, CFMin, pdamp, zdamp, ... + zfactor, stepfactor) + +% Calculates coefficients for the pole-zero filter cascade filterbank, +% using the ERB scale for bandwidths. + + +% good defaults: +if nargin<1, fs = 44100; end +if nargin<2, CFMax = 18000; end % taken from 0.85*fs/2 from before +if nargin<3, CFMin = 40; end % as before +if nargin<4, pdamp = 0.12; end % can be as low as 0.1 if you start carefully +if nargin<5, zdamp = 0.2; end +if nargin<6, zfactor = 1.4; end % 1.4 seems to be the min for decent shape at low CF +if nargin<7, stepfactor = 0.3333; end + + +% initialize loop and storage: +freqs = [ ]; +zfreqs = [ ]; +zdamps = [ ]; +pfreqs = [ ]; +pdamps = [ ]; +za0 = [ ]; +za1 = [ ]; +za2 = [ ]; + + +pfreq= CFMax/fs*(2*pi); % normalised maximum pole frequency + +ch=0; + +% design channel coeffs: +while (pfreq/(2*pi))*fs > CFMin % keep above the lowest centre frequency + ch = ch+1; + freqs(ch) = pfreq/(2*pi)*fs; % next freq in Hz + % compute the coefficients for the zeros: + zfreq = min(pi, zfactor*pfreq); + % impulse-invariance mapping z=exp(sT): + ztheta = zfreq*sqrt(1-zdamp^2); + zrho = exp(-zdamp*zfreq); + % direct form coefficients from z-plane rho and theta: + a1 = -2*zrho*cos(ztheta); + a2 = zrho*zrho; + % normalize to unity gain at DC: + asum = 1 + a1 + a2; + za0(ch) = 1/asum; + za1(ch) = a1/asum; + za2(ch) = a2/asum; + pfreqs(ch) = pfreq; + pdamps(ch) = pdamp; + + %bw = bwOverCF*pfreq + 2*pi*bwMinHz/fs; % Greenwood formula? + [dummy, bw] = Freq2ERB(pfreq/(2*pi)*fs); + bw=bw*(2*pi)/fs; + bws(ch)=bw; + pfreq = pfreq - stepfactor*bw; +end + +Nch = ch; + +Coeffs = [ pfreqs', pdamps', za0', za1', za2' ]; + +freqs = freqs'; + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZBankCoeffsERBFitted.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZBankCoeffsERBFitted.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,127 @@ +function [Coeffs, Nch, freqs] = PZBankCoeffsERBFitted(fs, CFMax, CFMin, ValParam) + +% Calculates coefficients for the pole-zero filter cascade filterbank, +% using the ERB scale for bandwidths, taking its parameters from the fit +% data provided in ValParam + + +% good defaults: +if nargin<1, fs = 44100; end +if nargin<2, CFMax = 18000; end % taken from 0.85*fs/2 from before +if nargin<3, CFMin = 40; end % as before +if nargin<4, ValParam = [ ... % Fit 515 from Dick +% Final, Nfit = 515, 9-3 parameters, PZFC, cwt 0 + 1.72861 0.00000 0.00000 % SumSqrErr= 13622.24 + 0.56657 -0.93911 0.89163 % RMSErr = 3.26610 + 0.39469 0.00000 0.00000 % MeanErr = 0.00000 + Inf 0.00000 0.00000 % RMSCost = NaN + 0.00000 0.00000 0.00000 + 2.00000 0.00000 0.00000 + 1.27393 0.00000 0.00000 + 11.46247 5.46894 0.11800 +% -4.15525 1.54874 2.99858 % Kv + ]; +end + + +% initialize loop and storage: +freqs = [ ]; +zfreqs = [ ]; +zdamps = [ ]; +pfreqs = [ ]; +pdamps = [ ]; +za0 = [ ]; +za1 = [ ]; +za2 = [ ]; + +pfreq= CFMax/fs*(2*pi); % normalised maximum pole frequency + +ch=0; + + +% design channel coeffs: +while (pfreq/(2*pi))*fs > CFMin % keep above the lowest centre frequency + ch = ch+1; + freqs(ch) = pfreq/(2*pi)*fs; % next freq in Hz + + % Run the fit parameters through the necessary steps to get out s-plane + % filter parameters for a low-low level signal at the noise floor. + [b1, b2, c, n1, n2, frat] = PZFC_Small_Signal_Params(freqs(ch), ValParam); + + % Mapping of these outputs is as follows: + % b1 -> brat + % b2 -> coeferbw + % c -> coefc - should be at infinity, ignore + % n1 -> unused + % n2 -> orderg (gives channel step factor) + % frat -> frat + + % to define: zfactor + + % calculate pole bandwidth. This is a function of b2 (CoefERBw), and the current nominal + % ERB width. Use this to calculate pole damping. + [ERBrate ERBw] = Freq2ERB(freqs(ch)); + bw = b2.*ERBw.*(2*pi)/fs; % bandwidth (normalised) + % pole bandwidth is same as bandwidth when n2=4 (n2 is orderg), + % otherwise it needs recalculating: + pbw=(bw/2).*(n2.^0.5); + + pdamp=pbw./sqrt(pfreq.^2+pbw.^2); % f(b) + + zfactor= frat; % frat is the frequency ratio of the zero to the pole + bw=b1.*frat.*ERBw.*(2*pi)/fs; % check this + zbw=(bw/2).*(n2.^0.5); + + % From the previous version: + % % compute the coefficients for the zeros: + zfreq = zfactor*pfreq; + if zfreq > pi + warning('Zero frequency exceeds Nyquist frequency in PZBankCoeffsERBFitted'); + end + % We warn if this gets limited at pi, it implies that the zero is + % trying to drift up above the Nyquist frequency, which is bad. + + % zero damping: + zdamp=zbw./sqrt(zfreq.^2+zbw.^2); + + + + % impulse-invariance mapping z=exp(sT): + ztheta = zfreq*sqrt(1-zdamp^2); + zrho = exp(-zdamp*zfreq); + + % direct form coefficients from z-plane rho and theta: + a1 = -2*zrho*cos(ztheta); + a2 = zrho*zrho; + % normalize to unity gain at DC: + asum = 1 + a1 + a2; + za0(ch) = 1/asum; + za1(ch) = a1/asum; + za2(ch) = a2/asum; + pfreqs(ch) = pfreq; + pdamps(ch) = pdamp; + + + + + % This is calculated once per channel - but it should stay constant + % unless the fit parameters are really odd (it will change if there + % are nonzero entries in columns 2 and 3 in row 7 of ValParam). + stepfactor=1/n2; % this is what gives the final channel density + + + % Bandwidth calculation, as before + [dummy, bw] = Freq2ERB(pfreq/(2*pi)*fs); + bw=bw*(2*pi)/fs; + bws(ch)=bw; + pfreq = pfreq - stepfactor*bw; + +end + +Nch = ch; + +Coeffs = [ pfreqs', pdamps', za0', za1', za2' ]; + +freqs = freqs'; + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZBankCoeffsHiLow.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZBankCoeffsHiLow.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,64 @@ +function [Coeffs, Nch, freqs, bws] = PZBankCoeffsHiLow(fs, CFMax, CFMin, pdamp, zdamp, ... + zfactor, stepfactor, ... + bwOverCF, bwMinHz) +% function [Coeffs, Nch, freqs] = PZBankCoeffs(fs, pdamp, zdamp, zfactor, stepfactor, highpolefactor, minPoleHertz, bwOverCF, bwMinHz) +% design the pole-zero cascade filterbank: Coeffs = [ pfreqs', pdamps', za0', za1', za2']; + +% good defaults: +if nargin<1, fs = 44100; end +if nargin<2, CFMax = 18000; end % taken from 0.85*fs/2 from before +if nargin<3, CFMin = 40; end % as before +if nargin<4, pdamp = 0.12; end % can be as low as 0.1 if you start carefully +if nargin<5, zdamp = 0.2; end +if nargin<6, zfactor = 1.4; end % 1.4 seems to be the min for decent shape at low CF +if nargin<7, stepfactor = 0.3333; end +if nargin<8, bwOverCF = 0.11; end +if nargin<9, bwMinHz = 27; end + +% initialize loop and storage: +freqs = [ ]; +zfreqs = [ ]; +zdamps = [ ]; +pfreqs = [ ]; +pdamps = [ ]; +za0 = [ ]; +za1 = [ ]; +za2 = [ ]; +%deps = [ ]; +%pfreq = pi * highpolefactor; % highest nominal pole frequency - eg 85% of half the samplerate ( check this with Dick) +% in this version we can set the max centre freuency independently +pfreq= CFMax/fs*(2*pi); % normalised maximum pole frequency + +ch=0; + +% design channel coeffs: +while (pfreq/(2*pi))*fs > CFMin % keep above the lowest centre frequency + ch = ch+1; + freqs(ch) = pfreq/(2*pi)*fs; % next freq in Hz + % compute the coefficients for the zeros: + zfreq = max(pi, zfactor*pfreq); + + % impulse-invariance mapping z=exp(sT): + ztheta = zfreq*sqrt(1-zdamp^2); + zrho = exp(-zdamp*zfreq); + % direct form coefficients from z-plane rho and theta: + a1 = -2*zrho*cos(ztheta); + a2 = zrho*zrho; + % normalize to unity gain at DC: + asum = 1 + a1 + a2; + za0(ch) = 1/asum; + za1(ch) = a1/asum; + za2(ch) = a2/asum; + pfreqs(ch) = pfreq; + pdamps(ch) = pdamp; + bw = bwOverCF*pfreq + 2*pi*bwMinHz/fs; % Greenwood formula? + bws(ch)=bw; + pfreq = pfreq - stepfactor*bw; +end + +Nch = ch; + +Coeffs = [ pfreqs', pdamps', za0', za1', za2' ]; + +freqs = freqs'; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZBankStep2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZBankStep2.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,114 @@ +function [outputs, state1, state2] = PZBankStep2(inputs, pfreqs, pdamps, ... + mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, state1, state2, ... + showconstellation, showtransfuns) +% function [outputs, state1, state2] = PZBankStep2(inputs, pfreqs, pdamps, ... +% mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, state1, state2, ... +% showconstellation, showtransfuns) +% one time step of Pole-Zero-FilterBank, using row vectors of parameters +% inputs should contain shifted outputs from last time with new scalar +% waveform input on the front: inputs = [newin, outputs(1:N-1)]; +% version 2 uses pole x and radius interpolation to adjust dampling +% the min and max are interpolation reference points, not limits to enforce +% and it should all work for multiple channels in parallel if the +% parameter vectors are all appropriately duplicated as well + +if nargin < 15 + showconstellation = 0; % don't by default; value is used as fig num. +end + +if nargin < 16 + showtransfuns = 0; % don't by default; value is used as fig num. +end + +[nstages, nchans] = size(pfreqs); % number of filter channels and stereo channels + +damprate = 1/(maxdamp - mindamp); % to save a bunch of divides + +% limit to keep the poles reasonably stable: +interpfactor = (pdamps - mindamp)*damprate; +% interpfactor = min(1.5, interpfactor); % seems to keep it stable + +x = xmin + (xmax - xmin).*interpfactor; +r = rmin + (rmax - rmin).*interpfactor; + +%optional improvement to constellation adds a bit to r: +fd = pfreqs.*pdamps; +r = r + 0.25*fd.*min(0.05, fd); % quadratic for small values, then linear + +zb1 = -2*x; +zb2 = r.*r; + +bExtraDelay = 1; % boolean to control whether to do allow extra sample of filter delay + +if bExtraDelay + % canonic poles but with input provided where unity DC gain is assured + % (mean value of state is always equal to mean value of input) + newstate = inputs - (state1 - inputs).*zb1 - (state2 - inputs).*zb2; + + % canonic zeros part as before: + + outputs = za0 .* newstate + za1 .* state1 + za2 .* state2 ; + outputs = outputs - 0.0001*outputs.^3; % cubic compression nonlinearity + + state2 = state1; + state1 = newstate; +else + input = inputs(1,:); % first stage input is top input; ignore the rest + for stage = 1:nstages + newstate = input - (state1(stage,:) - input).*zb1(stage) - (state2(stage,:) - input).*zb2(stage); + % output of stage immediately becomes input for next stage, if needed: + input = za0(stage) .* newstate + za1(stage) .* state1(stage,:) + za2(stage) .* state2(stage,:) ; + input = input - 0.0001*input.^3; % cubic compression nonlinearity + outputs(stage,:) = input; + state2(stage,:) = state1(stage,:); + state1(stage,:) = newstate; + end +end + + +if showconstellation + figure(showconstellation); + % keyboard + hold off + % I have exact x and r, just need y + py = (r.*r - x.*x).^0.5; + % let it error out if we get a complex y. + plot(x,py,'x'); + hold on + zr = (za2./za0).^0.5; + zx = -0.5*(za1./za0); + zy = (zr.*zr - zx.*zx).^0.5; + % zy(zy<0) = 0; + % zy = zy.^0.5; + plot(zx, zy, 'o'); + + drawnow +end + +if showtransfuns % 1D indexing does only 1 channel for now + fbasis = pi*2.^((-129:0)' /12); %% 120 semitones, 10 octaves, leading up to pi rad/samp + z = exp(i*fbasis); + z2 = z.*z; + nch = size(pfreqs,1); + nf = length(fbasis); + chanxfns = zeros(nf, nch); + cascxfns = ones(nf, nch); + for ch = 1:length(pfreqs) + chanxfns(:,ch) = abs((1+zb1(ch)+zb2(ch)).*(za0(ch)+za1(ch).*z+za2(ch).*z2)./(1+zb1(ch).*z+zb2(ch).*z2)); + cascxfns(:,ch) = cascxfns(:,max(1,ch-1)) .* chanxfns(:,ch); + end + + figure(showtransfuns) + hold off + loglog(fbasis, chanxfns); + axis([min(fbasis), max(fbasis), 0.1, 10]); + + figure(showtransfuns+1) + hold off + loglog(fbasis, cascxfns); + axis([min(fbasis), max(fbasis), 0.02, 20000]); +end + + +return; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZFC_Params.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZFC_Params.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,31 @@ +function [b1, B2, B21, c, n1, n2, frat, P0] = PZFC_Params(Fc, ValParam) +% function [b1, B2, B21, c, n1, n2, frat, Pref, P0] = OZGF_Params(Fc, ValParam) +% +% Make filter parameters from the ValParam +% inputs: +% Fc is filter nominal center frequency +% ValParam: Nx3 array of fitting parameters +% row 1 are constant, f and f^2 coeffs for first return value, etc. +% outputs: +% the parameter scalars as listed; B21 is power coeff for B2 to make b2 + +if nargout < 7 + error('wrong number of args out, OZGF_Params') +end + +% adjust any frequency-dependent parameters, on normalized ERBRate scale: +DpndF = Freq2ERB(Fc)/Freq2ERB(1000) - 1; % corresponding to Ef + +% compute all of: [b1; B2; B21; c; n1; n2; frat; Pref] +params = ValParam * [1; DpndF; DpndF.^2]; + +b1 = params(1); +B2 = params(2); +B21 = params(3); +c = params(4); +n1 = params(5); +n2 = params(6); +frat = params(7); +P0 = params(8); + +% b1 = b1*B2; % make b1 vary like B2 (w/o level dependent part) diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZFC_Small_Signal_Params.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZFC_Small_Signal_Params.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,11 @@ +function [b1, b2, c, n1, n2, frat] = PZFC_Small_Signal_Params(Fc, ValParam) +% function [b1, b2, c, n1, n2, frat] = PZFC_Small_Signal_Params(Fc, ValParam) +% +% get all the PZFC parameters, including b2 in the small-signal limit + +[b1, B2, B21, c, n1, n2, frat, P0] = PZFC_Params(Fc, ValParam); + +% The P0 is the noise floor that sets the small-signal limit of b2 + +b2 = PZFC_b2(B2, B21, P0, n2); + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/PZFC_b2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/PZFC_b2.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,11 @@ +function b2 = PZFC_b2(B2, B21, Pp, n2); +% compute the power-dependent pole position coeff b2 for the PZFC filter +% (same as OZGF_b2 until/unless we change it) + +% try for 1.0 input-output slope approx when B21 is about like B2: +b2 = B2 * 10^((B21/(B2*n2)) * (Pp - 60)/20); % arbitrary 60 dB ref point + +% limit to a ridiculously small value: +if b2 <= 0.2 + b2 = 0.2; +end diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/RunPZBankSegment.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/RunPZBankSegment.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,52 @@ +function [outarray, prevout, agcstate, state1, state2, pdampsmod] = ... + RunPZBankSegment(inputSegment, prevout, agcstate, state1, state2, pfreqs, pdamps, pdampsmod, ... + mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, agcepsilons, agcgains, agcfactor, doagcstep, doplot) +% function [outarray, prevout, agcstate, state1, state2, pdampsmod] = ... +% RunPZBankSegment(inputSegment, prevout, agcstate, state1, state2, pfreqs, pdamps, pdampsmod, ... +% mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, agcepsilons, agcgains) + +if nargin < 21 + doagcstep = 1; +end + +[Nt, Ntracks] = size(inputSegment); + +Nch = length(pfreqs); + +if nargin < 22 + doplot = 0; +end + +if doplot ~= 0 + figa = 13; + figb = 14; +else + figa = 0; %don't plot + figb = 0; % don't plot +end + +for t = 1:Nt + + inputs = [inputSegment(t,:); prevout(1:Nch-1,:)]; + + [outputs state1 state2] = PZBankStep2(inputs, pfreqs, pdampsmod, ... + mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, state1, state2, figa, figb); + + % differential velocity detection: + %detect = DetectFun(outputs-prevout); + detect = DetectFun(outputs); + + if doagcstep ==1 + [pdampsmod agcstate] = AGCdampStep(detect, pdamps, agcepsilons, agcgains, agcstate, agcfactor); + end + + %outarray(:,t) = detect(:); % flatten Ntracks columns into one + outarray(:,t)=outputs(:); % no rectification. + prevout = outputs; + + figa = 0; + figb = 0; + +end + +return; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/fit515.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/fit515.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,27 @@ +% Dick's PZFC Fit params + +%case 515 % order 2, 6 params + %FeedbackType = 1; % enable feedback iteration + %ModelName = 'PZFC'; % pole-zero filter cascade + ValParam = [ ... +% Final, Nfit = 515, 9-3 parameters, PZFC, cwt 0 + 1.72861 0.00000 0.00000 % SumSqrErr= 13622.24 + 0.56657 -0.93911 0.89163 % RMSErr = 3.26610 + 0.39469 0.00000 0.00000 % MeanErr = 0.00000 + Inf 0.00000 0.00000 % RMSCost = NaN + 0.00000 0.00000 0.00000 + 2.00000 0.00000 0.00000 + 1.27393 0.00000 0.00000 + 11.46247 5.46894 0.11800 +% -4.15525 1.54874 2.99858 % Kv + ]; +% CtrlParam = [ ... % a 6-parameter fit +% 1 0 0 % b1 zero BW relative to ERB +% 1 1 1 % B2 +% 1 0 0 % B21 +% 0 0 0 % c one extra zero maybe +% 0 0 0 % n1 unused +% 0 0 0 % n2 order, stages per nominal ERB +% 1 0 0 % frat Fzero:Fpole +% 1 1 1 % P0 +% ]; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/fit516.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/fit516.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,12 @@ + ValParam = [ ... +% Final, Nfit = 516, 11-3 parameters, PZFC, cwt 0 + 1.73848 0.00000 0.00000 % SumSqrErr= 10226.95 + 0.62250 -1.02349 0.94190 % RMSErr = 2.82994 (compare to 3.266 before) + 0.37208 0.00000 0.00000 % MeanErr = 0.00000 + Inf 0.00000 0.00000 % RMSCost = NaN + 0.00000 0.00000 0.00000 + 2.00000 0.00000 0.00000 + 1.27403 -0.26291 0.21906 + 11.30471 5.33017 0.33995 +% -3.63143 -1.59230 4.68184 % Kv +]; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/fit524.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/fit524.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,14 @@ +% High channel density version of the PZFC + +ValParam = [... +% Filed, Nfit = 524, 11-3 parameters, PZFC, cwt 0, fit time 9915 sec + 1.14827 0.00000 0.00000 % SumSqrErr= 10125.41 + 0.53571 -0.70128 0.63246 % RMSErr = 2.81586 + 0.76779 0.00000 0.00000 % MeanErr = 0.00000 + Inf 0.00000 0.00000 % RMSCost = NaN + 0.00000 0.00000 0.00000 + 6.00000 0.00000 0.00000 + 1.08869 -0.09470 0.07844 + 10.56432 2.52732 1.86895 +% -3.45865 -1.31457 3.91779 % Kv +]; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/gen_pzfc.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/gen_pzfc.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,226 @@ +% Generating function for AIM-MAT +% Based on Dick Lyon's code for the Pole-Zero filter cascade +function fr=gen_pzfc(sig,options) + +% Unpack the options and get the raw signal from the signal class +CFMin=options.lowest_frequency; +CFMax=options.highest_frequency; + + +% Default parameters (these defaults should be the same as in the parameter +% file) +if ~isfield(options,'segment_length') + segLength=200; +else + segLength=options.segment_length; +end + +if ~isfield(options,'stepfactor') + stepfactor=1/3; +else + stepfactor=options.stepfactor; +end + +if ~isfield(options,'pdamp') + pdamp=0.12; +else + pdamp=options.pdamp; +end + +if ~isfield(options,'zdamp') + zdamp=0.2; +else + zdamp=options.zdamp; +end + +if ~isfield(options,'zfactor') + zfactor=1.4; +else + zfactor=options.zfactor; +end + +if ~isfield(options, 'bw_over_cf') + bwOverCF = 0.11; +else + bwOverCF = options.bw_over_cf; +end + +if ~isfield(options, 'bw_min_hz'); + bwMinHz = 27; +else + bwMinHz=options.bw_min_hz; +end + +if ~isfield(options, 'use_fitted_params') + useFit=0; +else + useFit=options.use_fitted_params; +end + +if ~isfield(options, 'agcfactor') + agcfactor=12; +else + agcfactor=options.agcfactor; +end + +if ~isfield(options, 'do_agc') + doagcstep=1; +else + doagcstep=options.do_agc; +end + +if ~isfield(options, 'pre_excite_with_noise') + do_pre_excite=0; +else + do_pre_excite=options.pre_excite_with_noise; +end + +if ~isfield(options, 'pre_excite_time') + pre_excite_time=0.2; % 200ms +else + pre_excite_time=options.pre_excite_time; +end + +if ~isfield(options, 'pre_excite_level_dB') + pre_excite_level_dB=-10; +else + pre_excite_level_dB=options.pre_excite_level_dB; +end + +if ~isfield(options, 'doplot') + doplot=0; +else + doplot=options.doplot; +end + +if useFit~=0 + if isfield(options, 'fitted_params') + eval(options.fitted_params); % sets the varaible ValParam + if ~isvector('ValParam') + error('PZFC param file specified is not in the right format. Should set variable ValParam.'); + end + else + error('If use_fitted_params is nonzero (i.e. true) then fitted_params must be a real filename'); + end +end + + + +fs=getsr(sig); +inputColumn=getvalues(sig); +Nt = length(inputColumn); + +if useFit==0 + if options.erb_scale == 0 + [Coeffs Nch, freqs] = PZBankCoeffsHiLow(fs, CFMax, CFMin, pdamp, zdamp, zfactor, stepfactor, bwOverCF, bwMinHz); + else + [Coeffs Nch, freqs] = PZBankCoeffsERB(fs, CFMax, CFMin, pdamp, zdamp, zfactor, stepfactor); + end +else + % Use the parameters from the fit to set up the filterbank (using ERB scale) + [Coeffs, Nch, freqs] = PZBankCoeffsERBFitted(fs, CFMax, CFMin, ValParam); +end + +deskewDelay = 0; +doStereo = 0; % no stereo option for AIM-MAT version +Ntracks=1; % ditto - don't try and make this any more than 1! + +pfreqs = Coeffs(:,1); +pdamps = Coeffs(:,2); +za0 = Coeffs(:,3); +za1 = Coeffs(:,4); +za2 = Coeffs(:,5); +Nch = length(pfreqs); + +mindamp = .18; % (Q = 3 max end of interp) +maxdamp = .4; % (Q = 1.25 min end of interp) +% min and max refer to the damping, not the x and r coordinates +rmin = exp(-mindamp*pfreqs); +rmax = exp(-maxdamp*pfreqs); +xmin = rmin.*cos(pfreqs.*(1-mindamp^2).^0.5); +xmax = rmax.*cos(pfreqs.*(1-maxdamp^2).^0.5); + + +agcepsilons = [0.0064, 0.0016, 0.0004, 0.0001]; % roughly 3 ms, 12 ms, 48 ms, 200 ms +agcgains = [1, 1.4, 2, 2.8]; +agcgains = agcgains/mean(agcgains); +Nstages = length(agcepsilons); + +outarray = []; %zeros(Nch*Ntracks,Nt); +for j = 1:Ntracks + inputColumn(:,j) = filter([0.5 0.5], 1, inputColumn(:,j)); % puts a zero in the TF +end + +state1 = zeros(Nch,Ntracks); +state2 = zeros(Nch,Ntracks); +prevout = zeros(Nch,Ntracks); +agcstate = zeros(Nch, Nstages*Ntracks); +% initialize with double dampling: +[pdampsmod agcstate] = AGCdampStep([ ], pdamps, agcepsilons, agcgains, agcstate); % initialize pdampsmod, agcstate +% make safer place to start than full gain, in case input is abruptly loud: +pdampsmod = pdampsmod + 0.05; +agcstate = agcstate + 0.05; + +% Noise pre-excitation +if do_pre_excite == 1 + wbh=waitbar(0, 'Pre-calculating noise excitaiton for Pole-Zero filter cascade'); + Nt_noise=pre_excite_time.*fs; + doagcstep_noise=1; % we want to run the AGC in this section, even if not in the main section. + + nsegs = floor(Nt_noise/segLength); + %wbh=waitbar(0, 'Calculating Pole-Zero filter cascade'); + for segno = 1:nsegs + inputSegment = rand(segLength,1); + inputSegment = inputSegment.*10.^(pre_excite_level_dB./20); + + [outsegment, prevout, agcstate, state1, state2, pdampsmod] = ... + RunPZBankSegment(inputSegment, prevout, agcstate, state1, state2, pfreqs, pdamps, pdampsmod, ... + mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, agcepsilons, agcgains, agcfactor, doagcstep_noise, doplot); + + waitbar(segno/nsegs, wbh); + + + end + close(wbh); +end + +% Reset the previous output of the filterbank +state1 = zeros(Nch,Ntracks); +state2 = zeros(Nch,Ntracks); +prevout = zeros(Nch,Ntracks); + +nsegs = floor(Nt/segLength); +wbh=waitbar(0, 'Calculating Pole-Zero filter cascade'); +for segno = 1:nsegs + inputSegment = inputColumn((segno-1)*segLength + (1:segLength), :); + + + [outsegment, prevout, agcstate, state1, state2, pdampsmod] = ... + RunPZBankSegment(inputSegment, prevout, agcstate, state1, state2, pfreqs, pdamps, pdampsmod, ... + mindamp, maxdamp, xmin, xmax, rmin, rmax, za0, za1, za2, agcepsilons, agcgains, agcfactor, doagcstep, doplot); + + if isempty(outarray) + outarray=outsegment; + else + outarray = [outarray, outsegment]; % gather up the segments + end + + waitbar(segno/nsegs, wbh); + + +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Convert all the stuff into the form that AIM-MAT wants it +outarray=flipdim(outarray, 1); +freqs=flipdim(freqs, 1); + +fr=frame(outarray); +fr=setsr(fr,fs); +fr=setstarttime(fr,getminimumtime(sig)); +fr=setcf(fr,freqs); +close(wbh); + +return; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/bmm/pzfc/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/bmm/pzfc/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,46 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% bmm +% hidden parameters +pzfc.generatingfunction='gen_pzfc'; +pzfc.displayname='Pole-Zero Filter Cascade'; +pzfc.revision='$Revision: $'; + +pzfc.default_nextmodule='hl'; + +% parameters relevant for the calculation of this module +pzfc.lowest_frequency=100; % in Hz +pzfc.highest_frequency=6000; % in Hz + +pzfc.segment_length=200; + +pzfc.erb_scale=1; % 1 to use ERB scale, 0 to use Lyon's original scale + +pzfc.stepfactor=1/3; % step factor between channels + +pzfc.pdamp=0.12; +pzfc.zdamp=0.2; +pzfc.zfactor=1.4; +pzfc.bw_over_cf=0.11; % only used when erb_scale==0 +pzfc.bw_min_hz=27; %only used when erb_scale==0 + +pzfc.use_fitted_params=1; + +% use fit parameters from specified file +% pzfc.fitted_params='fit524'; % 6 channels per ERB +pzfc.fitted_params='fit516'; % 2 channels per ERB + +pzfc.agcfactor=12; + +% Parameters for tinkering with the AGC for the filterbank +pzfc.do_agc=1; % Set to 1 to run the AGC as usual. 0 to disable the AGC after the noise excitation stage. +pzfc.pre_excite_with_noise=0; % Set to 1 to run noise through the filterbank before the stimulus +pzfc.pre_excite_time=0.2; % 200ms by default, time in seconds. +pzfc.pre_excite_level_dB=-10; % dB re. max level for the sound file + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/dcgc/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/dcgc/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,18 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +dcgc.is_log=0; +dcgc.time_reversed=0; +dcgc.plotstyle='waterfall'; +dcgc.colormap='cool'; +dcgc.colorbar='off'; +dcgc.camlight='left'; +dcgc.lighting='phong'; % can be one of 'phong', 'gouraud', 'flat' diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/gtfb/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/gtfb/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,17 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +% the parameters for the graphics. +% They are independent from the module parameters + +gtfb.is_log=0; +gtfb.time_reversed=0; +gtfb.plotstyle='surf'; +gtfb.colormap='cool'; +gtfb.colorbar='off'; +gtfb.camlight='left'; +gtfb.lighting='phong'; % can be one of 'phong', 'gouraud', 'flat' diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/hcl/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/hcl/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,16 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +hcl.is_log=0; +hcl.time_reversed=0; +hcl.plotstyle='surf'; +hcl.colormap='gray'; +hcl.colorbar='off'; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/hl/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/hl/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,18 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +hl.is_log=0; +hl.time_reversed=0; +hl.plotstyle='surf'; +hl.colormap='cool'; +hl.colorbar='off'; +hl.camlight='left'; +hl.lighting='phong'; % can be one of 'phong', 'gouraud', 'flat' diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/mellin/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/mellin/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,13 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +mellin.is_log=0; +mellin.time_profile_scale=100; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/sst/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/sst/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,12 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +sst.time_reversed=0; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/ti1992/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/ti1992/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,20 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +ti1992.minimum_time=0.001; +ti1992.maximum_time=0.035; +ti1992.is_log=1; +ti1992.time_reversed=1; +ti1992.display_time=0; +ti1992.time_profile_scale=1; +ti1992.plotstyle='surf'; +ti1992.colormap='pink'; +ti1992.colorbar='off'; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/graphics/ti2003/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/graphics/ti2003/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,24 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% the parameters for the graphics. +% They are independent from the module parameters + +ti2003.minimum_time=0.001; +ti2003.maximum_time=0.035; +ti2003.is_log=1; +ti2003.time_reversed=0; +ti2003.display_time=0; +ti2003.time_profile_scale=1; +ti2003.plotstyle='surf'; +ti2003.colormap='gray'; +ti2003.colorbar='off'; +ti2003.viewpoint=[0 90]; +ti2003.camlight=[50,30;0,90]; % several different possible +ti2003.lighting='phong'; +ti2003.shiftcolormap=0.0; % a linear shift of the colormap towards higher numbers (if >0.5) or towards lower numbers \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/help.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/help.html Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,20 @@ + + + +Redirect... + + + +

http://www.soton.ac.uk/aim.htm +

+ + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/logo-aim2006.gif Binary file aim-mat/modules/logo-aim2006.gif has changed diff -r 000000000000 -r 74dedb26614d aim-mat/modules/logo.gif Binary file aim-mat/modules/logo.gif has changed diff -r 000000000000 -r 74dedb26614d aim-mat/modules/movie/bmm_movie/gen_bmm_movie.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/movie/bmm_movie/gen_bmm_movie.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,98 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function gen_screen_movie(data,options) +% just produce the movie from the basilar membrane + +handles=options.handles; +handles.info.domovie=1; + +si=get(0,'ScreenSize'); +waithand=waitbar(0,'generating movie'); +set(waithand,'Units','Pixel'); +si2=get(waithand,'Position'); +si2(1)=110; +si2(2)=si(4)-si2(4)-25; +set(waithand,'Position',si2); + +moviefilename=options.moviename; +soundfilename=options.soundfilename; +[sounddata,samplerate,bits] = wavread(soundfilename); + +oldfig=gcf; +% if there has never been a figure, create a new one +options.figure_handle=figure; +newfig=options.figure_handle; + + +MakeQTMovie('start',moviefilename); +MakeQTMovie('size', [options.movie_width options.movie_height]); +MakeQTMovie('quality', options.quality); % reduces the size + +% bmm movie +% first get bmm-data +currentdata=data.bmm; +handles=options.handles; +len=getlength(data.signal); +% pic_wide=handles.slideredit_duration.current_value; +pic_wide=options.show_bmm_duration; +handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,pic_wide); +mov_len=len-pic_wide; + +nr_frames=mov_len*options.physical_frames_per_second; +frame_duration=1/options.physical_frames_per_second; +for ii=1:nr_frames + waitbar(ii/nr_frames,waithand); + + figure(newfig); + set(gca,'Position',[0 0.1 0.93 0.9]); + + start_time=(ii-1)*frame_duration; + + if options.use_nap_instead==0 + handles.info.current_plot=3; % the bmm + elseif options.use_nap_instead==1 + handles.info.current_plot=4; % the nap + end + if handles.with_graphic==1 + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,start_time); +% handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,start_time); + else + handles.current_frame_nr=ii; + end + + % plot the graphic with the standard method in the new window: + handles=aim_replotgraphic(handles,options); + + drawnow; + + MakeQTMovie('addframe'); % and add it to the movie +end + +% put the same picture at the end, so often, till the movie is finished +nr_additional=pic_wide/frame_duration; +for ii=1:nr_additional + MakeQTMovie('addframe'); % and add it to the movie +end + +% add one, to fill the last picture (the sound is longer than n*nr_frames) +MakeQTMovie('addframe'); + +% Optional slowmotion of the movie for MIs without sound +MakeQTMovie('framerate',options.shown_frames_per_second); + +MakeQTMovie('finish'); +MakeQTMovie('cleanup'); +figure(oldfig); +close(newfig); + +close(waithand); diff -r 000000000000 -r 74dedb26614d aim-mat/modules/movie/bmm_movie/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/movie/bmm_movie/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,37 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% user defined module +% hidden parameters +bmm_movie.generatingfunction='gen_bmm_movie'; +bmm_movie.displayname='produces a movie from the basilar membrane motion'; +bmm_movie.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +% how fast the movement of the bmm should be recorded +bmm_movie.physical_frames_per_second=1000; + +% how many frames per second shell the movie have. +bmm_movie.shown_frames_per_second=20; + +% how many seconds of the BMM should be shown +bmm_movie.show_bmm_duration=0.01; + +% instead of the bmm we can also generate movies of the nap: +bmm_movie.use_nap_instead=0; + +bmm_movie.withfre=1; +bmm_movie.withtime=1; +bmm_movie.withsignal=1; +bmm_movie.data_scale=1; +bmm_movie.movie_width=640; +bmm_movie.movie_height=400; +bmm_movie.quality=0.9; + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/movie/screen/gen_screen_movie.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/movie/screen/gen_screen_movie.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,112 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function gen_screen_movie(data,options) + +% movie generation works as follows: Copy all the handles (with all +% information to a local variable and pass that one to the plotting +% routine. +handles=options.handles; +% marker, that we are in a movie generation function +handles.info.domovie=1; + +% if ~isfield(options,'frames_per_second') +% frames_per_second=20; +% else +% frames_per_second=options.frames_per_second; +% end + +si=get(0,'ScreenSize'); +waithand=waitbar(0,'generating movie'); +set(waithand,'Units','Pixel'); +si2=get(waithand,'Position'); +si2(1)=110; +si2(2)=si(4)-si2(4)-25; +set(waithand,'Position',si2); + +moviefilename=options.moviename; +soundfilename=options.soundfilename; +[sounddata,samplerate,bits] = wavread(soundfilename); + +oldfig=gcf; +% if there has never been a figure, create a new one +options.figure_handle=figure; +newfig=options.figure_handle; + + +MakeQTMovie('clear'); +MakeQTMovie('start',moviefilename); +MakeQTMovie('size', [options.movie_width options.movie_height]); +MakeQTMovie('quality', options.quality); % reduces the size + + + +handles=options.handles; +if handles.info.current_plot==6 + data=data.sai; +elseif handles.info.current_plot==7 + data=handles.data.usermodule; +end + +nr_frames=length(data); +for ii=1:nr_frames + waitbar(ii/nr_frames,waithand); + + figure(newfig); + clf + set(gca,'Position',[0 0.1 0.93 0.9]); + + if handles.with_graphic==1 + handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,ii); + else + handles.current_frame_nr=ii; + handles.info.current_plot=6; % the usermodule + end + + % plot the graphic with the standard method in the new window: + handles=aim_replotgraphic(handles,options); + + drawnow; + + MakeQTMovie('addframe'); % and add it to the movie +end + +% add one, to fill the last picture (the sound is longer than n*nr_frames) +MakeQTMovie('addframe'); + +% get the frame rate +frames_per_second=1/(getcurrentframestarttime(data{2})-getcurrentframestarttime(data{1})); +frames_per_second=round(frames_per_second); +if (frames_per_second == Inf) + frames_per_second=nr_frames./(length(sounddata)./samplerate); + frames_per_second=round(frames_per_second); +end + + +% Optional slowmotion of the movie for MIs without sound +if ~isfield(options,'slowmotion') + options.slowmotion=1; +end + +if (options.slowmotion == 1) + MakeQTMovie('framerate',frames_per_second); + MakeQTMovie('addsound',sounddata,samplerate); +else + MakeQTMovie('framerate',round(frames_per_second / options.slowmotion)); +end; + +MakeQTMovie('finish'); +MakeQTMovie('cleanup'); +figure(oldfig); +close(newfig); + +close(waithand); diff -r 000000000000 -r 74dedb26614d aim-mat/modules/movie/screen/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/movie/screen/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,36 @@ +% parameter file for 'aim-mat' +% +% % (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% user defined module +% hidden parameters +screen.generatingfunction='gen_screen_movie'; +screen.displayname='produces a movie from the auditory image or whatever is on the screen'; +screen.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +% how fast the movement of the bmm should be recorded +screen.physical_frames_per_second=1000; + +% how many frames per second shell the movie have. +screen.shown_frames_per_second=20; + +% how many seconds of the BMM should be shown +screen.show_bmm_duration=0.01; + +% instead of the bmm we can also generate movies of the nap: +screen.use_nap_instead=0; + +screen.withfre=1; +screen.withtime=1; +screen.withsignal=1; +screen.data_scale=1; +screen.movie_width=640; +screen.movie_height=400; +screen.quality=0.9; + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/hcl/gen_hcl.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/hcl/gen_hcl.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,71 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +function nap=gen_hcl(bmm,options) + +waithand=waitbar(0,'generating NAP'); + +compression=options.compression; +switch compression + case 'sqrt' + nap=halfwayrectify(bmm); + nap=sqrt(nap); + case 'log' + nap=logcompress(bmm,options); +end +%save bmm.mat bmm; +%save nap.mat nap; + +% lowpassfiltering in the end +if isfield(options,'do_lowpassfiltering') % this is multiplied to the threshold_time_const + do_lowpassfiltering=options.do_lowpassfiltering; +else + do_lowpassfiltering=1; +end + +% cut off frequency lowpassfiltering in the end +if isfield(options,'lowpass_cutoff_frequency') % this is multiplied to the threshold_time_const + lowpass_cutoff_frequency=options.lowpass_cutoff_frequency; +else + lowpass_cutoff_frequency=1200; +end + + + +% order of the lowpassfiltering in the end +if isfield(options,'lowpass_order') % this is multiplied to the threshold_time_const + lowpass_order=options.lowpass_order; +else + lowpass_order=2; +end + + +nr_chan=getnrchannels(nap); +if options.do_lowpassfiltering==1 + for ii=1:nr_chan % through all channels: prepare working variable + if mod(ii,10)==0 + waitbar(ii/nr_chan); + end + sig=getsinglechannel(nap,ii); + newsig=leakyintegrator(sig,lowpass_cutoff_frequency,lowpass_order); + nap=setsinglechannel(nap,ii,newsig); + end +end + + + +timesum=getsum(nap); +maxt=max(timesum); +nap=setscalesumme(nap,maxt); +%save nap1.mat nap; +close(waithand); + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/hcl/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/hcl/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,18 @@ +% parameter file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% hcl +% hidden parameters +hcl.generatingfunction='gen_hcl'; +hcl.displayname='halfwave rectification, compression and lowpass filtering'; +hcl.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +hcl.compression='log'; +hcl.do_lowpassfiltering=1; +hcl.lowpass_cutoff_frequency=1200; +hcl.lowpass_order=2; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/hl/gen_hl.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/hl/gen_hl.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,78 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function nap=gen_hl(bmm,options) + +waithand=waitbar(0,'generating NAP'); + +nap=halfwayrectify(bmm); + +vals=getvalues(nap); + +%gtfb output values are: 0< gt_vals <1 +%therefore we will scale for 16bit values +%operationally only 15 bits are used as we +%half wave rectify + +% TCW AIM 2006 - 07/03/06 autoscaling now fixed +%vals=vals.*2.^15; +% Note: tcw Nov '05 - only re-added this part (from the log code) since otherwise it really +% screws up the display code later on. See do_aim_autoscale, cases {4,5} +% for why - the scaling seems a bit arbitrary to me! + +nap=setvalues(nap,vals); + +% lowpassfiltering in the end +if isfield(options,'do_lowpassfiltering') % this is multiplied to the threshold_time_const + do_lowpassfiltering=options.do_lowpassfiltering; +else + do_lowpassfiltering=1; +end + +% cut off frequency lowpassfiltering in the end +if isfield(options,'lowpass_cutoff_frequency') % this is multiplied to the threshold_time_const + lowpass_cutoff_frequency=options.lowpass_cutoff_frequency; +else + lowpass_cutoff_frequency=1200; +end + + + +% order of the lowpassfiltering in the end +if isfield(options,'lowpass_order') % this is multiplied to the threshold_time_const + lowpass_order=options.lowpass_order; +else + lowpass_order=2; +end + + +nr_chan=getnrchannels(nap); +if options.do_lowpassfiltering==1 + for ii=1:nr_chan % through all channels: prepare working variable + if mod(ii,10)==0 + waitbar(ii/nr_chan); + end + sig=getsinglechannel(nap,ii); + newsig=leakyintegrator(sig,lowpass_cutoff_frequency,lowpass_order); + nap=setsinglechannel(nap,ii,newsig); + end +end + + + +timesum=getsum(nap); +maxt=max(timesum); +nap=setscalesumme(nap,maxt); +%save nap1.mat nap; +close(waithand); + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/hl/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/hl/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,18 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% hl +% hidden parameters +hl.generatingfunction='gen_hl'; +hl.displayname='halfwave rectification and lowpass filtering'; +hl.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +hl.do_lowpassfiltering=1; +hl.lowpass_cutoff_frequency=1200; +hl.lowpass_order=2; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/none/gennonap.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/none/gennonap.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function fr=genobmm(sig,options) +% generating function for the outer/middle ear transfere function +fr=sig; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/none/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/none/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,14 @@ +% parameter file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% no nap +% hidden parameters +none.generatingfunction='gennonap'; +none.displayname='no neural activity pattern'; +none.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/twodat2003/calcfreqslope.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/twodat2003/calcfreqslope.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,33 @@ +% +% function adjacent_band_level=calcfreqslope(cf,af); +% +% INPUT VALUES: +% +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function adjacent_band_level=calcfreqslope(cf,af,b); +% function used to calculate the relative amplitudes in adjacent GTFBs +%e.g to calculate the level in 2000Hz critical band due to excitation +%in 1000Hz critical band calcfreqslope(2000,1000); + + +n=4; +%ERB = 24.7+0.108.*cf; +[dummy ERB]=Freq2ERB(cf); +B=b.*ERB; + + +h_cf=abs(3.*(B./(2.*pi.*i.*(cf-cf)+2.*pi.*B)).^n); +h_af=abs(3.*(B./(2.*pi.*i.*(af-cf)+2.*pi.*B)).^n); + +adjacent_band_level=h_af./h_cf; +adjacent_band_level=20.*log10(adjacent_band_level); + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/twodat2003/gen_twoDat2003.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/twodat2003/gen_twoDat2003.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,298 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + + +function ret=gen_twoDat2003(bmm,options) +% two D adaptive thresholding + +% first do the normal nap: +nap=gen_hcl(bmm,options.nap); + +if nargin < 2 + options=[]; +end + + +vals=getvalues(nap); + + + +%%%normalise to 0-60dB range +%max_nap=max(max(vals)); +%nap_norm=60./max_nap; +%vals=vals*nap_norm; +%save vals.mat vals; + +new_vals=zeros(size(vals)); +nr_chan=size(vals,1); +nr_dots=size(vals,2); +sr=getsr(nap); +cfs=getcf(nap); +%load bmm.mat; + + +% the delays can be set by an option +if isfield(options,'time_constant_factor') % this is multiplied to the threshold_time_const + time_constant_factor=options.time_constant_factor; +else + time_constant_factor=0.8; +end + +if isfield(options,'frequency_constant_factor') % the influence of the left and the right channel + frequency_constant_factor=options.frequency_constant_factor; +else + frequency_constant_factor=0.9; +end + + +if isfield(options,'threshold_rise_constant') % the rate at which the threshold may rise + threshold_rise_constant=options.threshold_rise_constant; +else + threshold_rise_constant=1; +end + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%the following calculates the envelope of nap response +%out_li=zeros(nr_chan,nr_dots); +%for chan=1:nr_chan +%out_li(chan,:)=standard_leaky_integrator(vals(chan,:),0.003,1,16000); +%out_li_scale=max(vals(chan,:))./max(out_li(chan,:)); +%out_li(chan,:)=out_li(chan,:).*out_li_scale; +%end +%[ERB_no, dummy] = Freq2ERB(cfs); +%for chan=1:nr_chan +%out_li(chan,:)=standard_leaky_integrator(vals(chan,:),0.003,1,16000); +%out_li_scale=max(vals(chan,:))./max(out_li(chan,:)); +%out_li(chan,:)=out_li(chan,:).*out_li_scale; +%end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%save cfs.mat cfs; +order = 4; +[rate ERB] = Freq2ERB(cfs); +B=options.b *ERB; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%note: decay of gammatone is described by: exp(-2*pi*B*t) +% time to drop to 1/2 (6dB) --in seconds +%i.e. exp(-2*pi*B*t)=0.5 +drop6dbtime=-log(0.5)./(2*pi.*B); + +% this means so many per samplepoint +threshold_decay_constant=-log10(2)*20./(drop6dbtime*sr); +threshold_decay_constant=threshold_decay_constant./time_constant_factor; + + +%threshold_rise_constant=.5; + +threshold_rise=(100.*B.^0.9)./sr; +threshold_rise=threshold_rise.*threshold_rise_constant; +%threshold_rise=zeros(nr_chan); + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%calc frequency slope values +if nr_chan>1 + %frequency_slope_c=calcfreqslope(cfs(2),cfs(1)); + %frequency_slope_a=calcfreqslope(cfs(1),cfs(2)); + + %c is effect from channel above but we must input + %the higher frequency (2) as the adjacent band and + %the channel in which we want the level (1)as + %the centre freq + frequency_slope_c=calcfreqslope(cfs(1),cfs(2),options.b); + + %a is effect from channel below but we must input + %the lower frequency (1) as the adjacent band and + %the channel in which we want the level (2) as + %the centre freq + frequency_slope_a=calcfreqslope(cfs(2),cfs(1),options.b); + +else + frequency_slope_c=0; + frequency_slope_a=0; +end + +%we divide by the frequency_constant_factor because we want a +%frequency_constant_factor of 1 to mean we use the actual +%frequency slope and a frequency_constant_factor of 0.5 +%to mean that the frequency slope falls away at twice the rate +%i.e. less effect +frequency_slope_c=frequency_slope_c./frequency_constant_factor; +frequency_slope_a=frequency_slope_a./frequency_constant_factor; + + + + +oldfigure=gcf; +if nr_chan==1 + onechannelfigure=figure(3); % assuming, the other one is 1 +end + +% channel_select=1:nr_chan; +times_per_ms=round(sr*0.01); +if nr_chan>1 + waithand=waitbar(0,'generating 2dat'); +end + + + +%val_e=zeros(nr_chan,nr_dots); +%val_inp=zeros(nr_chan,nr_dots); +%val_thres=zeros(nr_chan,nr_dots); + + + + +% a is the decayed working variable from the channel above +% b is the range limit +% c is the decayed working variable from the channel below +% d is the delayed and decayed nap signal from on-channel +% e is the maximum of [a b c d] +% threshold is the working variable +% thresholdlast is the working variable in the last round +% inp is the current input + + +thresholdlast=zeros(nr_chan,1); +threshold=zeros(nr_chan,1); +a=0;b=1;c=0;d=0;e=0; + + + +for ii=1:nr_dots % through the time + if nr_chan>1 + if mod(ii,times_per_ms)==0 + waitbar(ii/nr_dots); + end + end + + for jj=1:nr_chan % through all channels: prepare working variable + inp=vals(jj,ii);% current input + + if jj< nr_chan + chan_above=thresholdlast(jj+1); + a=chan_above+frequency_slope_a; + else + a=0; + end + if jj>1 + chan_below=thresholdlast(jj-1); + c=chan_below+frequency_slope_c; + else + c=0; + end + + %a=0; + %c=0; + + + + + d=max(thresholdlast(jj)+threshold_decay_constant(jj),0); + + + e1=max(a,b); + e2=max(c,d); + e=max(e1,e2); + + + + + if inp>e %threshold is exceeded + + threshold(jj)=min(thresholdlast(jj)+threshold_rise(jj),inp); + %threshold(jj)=inp; + + %new_vals(jj,ii)=threshold(jj)-e; + new_vals(jj,ii)=inp-threshold(jj); + % % else threshold decays + else + + threshold(jj)=e; + new_vals(jj,ii)=0; + end + + + + %val_e(jj,ii)=e; + %val_inp(jj,ii)=inp; + %val_thres(jj,ii)=threshold(jj); + + + end + + + + + + % prepare next round + if ii< nr_dots + thresholdlast=threshold; + end + + if nr_chan==1 + tvals(ii)=thresholdlast; + end + + +end + + + + + +if nr_chan==1 + figure(onechannelfigure); + plot(nap); + hold on + a=plot(tvals,'r'); + set(a,'LineWidth',1.5); +end + + +nap=setvalues(nap,new_vals); +%save nap.mat nap; + +vals=getvalues(nap); +nap=setallmaxvalue(nap,max(max(vals))*2); +nap=setallminvalue(nap,min(min(vals))); + + + +%save val_e.mat val_e; +%save new_vals.mat new_vals; +%save val_inp.mat val_inp; +%save val_thres.mat val_thres; + + + + + + + +ret=nap; +if nr_chan>1 + close(waithand); +end + +figure(oldfigure); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/twodat2003/gen_twoDat2003b.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/twodat2003/gen_twoDat2003b.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,297 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + + + +function ret=gen_twoDat2003(bmm,options) +% two D adaptive thresholding + +% first do the normal nap: +nap=gen_hcl(bmm,options.nap); + +if nargin < 2 + options=[]; +end + + +vals=getvalues(nap); + + + +%%%normalise to 0-60dB range +%max_nap=max(max(vals)); +%nap_norm=60./max_nap; +%vals=vals*nap_norm; +%save vals.mat vals; + +new_vals=zeros(size(vals)); +nr_chan=size(vals,1); +nr_dots=size(vals,2); +sr=getsr(nap); +cfs=getcf(nap); +load bmm.mat; + + +% the delays can be set by an option +if isfield(options,'time_constant_factor') % this is multiplied to the threshold_time_const + time_constant_factor=options.time_constant_factor; +else + time_constant_factor=0.8; +end + +if isfield(options,'frequency_constant_factor') % the influence of the left and the right channel + frequency_constant_factor=options.frequency_constant_factor; +else + frequency_constant_factor=0.9; +end + + +if isfield(options,'threshold_rise_constant') % the rate at which the threshold may rise + threshold_rise_constant=options.threshold_rise_constant; +else + threshold_rise_constant=1; +end + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%the following calculates the envelope of nap response +%out_li=zeros(nr_chan,nr_dots); +%for chan=1:nr_chan +%out_li(chan,:)=standard_leaky_integrator(vals(chan,:),0.003,1,16000); +%out_li_scale=max(vals(chan,:))./max(out_li(chan,:)); +%out_li(chan,:)=out_li(chan,:).*out_li_scale; +%end +%[ERB_no, dummy] = Freq2ERB(cfs); +%for chan=1:nr_chan +%out_li(chan,:)=standard_leaky_integrator(vals(chan,:),0.003,1,16000); +%out_li_scale=max(vals(chan,:))./max(out_li(chan,:)); +%out_li(chan,:)=out_li(chan,:).*out_li_scale; +%end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +save cfs.mat cfs; +order = 4; +[rate ERB] = Freq2ERB(cfs); +B=1.019.*ERB; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%note: decay of gammatone is described by: exp(-2*pi*B*t) +% time to drop to 1/2 (6dB) --in seconds +%i.e. exp(-2*pi*B*t)=0.5 +drop6dbtime=-log(0.5)./(2*pi.*B); + +% this means so many per samplepoint +threshold_decay_constant=-log10(2)*20./(drop6dbtime*sr); +threshold_decay_constant=threshold_decay_constant./time_constant_factor; + + + + +threshold_rise=(100.*B.^0.9)./sr; +threshold_rise=threshold_rise.*threshold_rise_constant; +%threshold_rise=zeros(nr_chan); + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%calc frequency slope values +if nr_chan>1 + %frequency_slope_c=calcfreqslope(cfs(2),cfs(1)); + %frequency_slope_a=calcfreqslope(cfs(1),cfs(2)); + + %c is effect from channel above but we must input + %the higher frequency (2) as the adjacent band and + %the channel in which we want the level (1)as + %the centre freq + frequency_slope_c=calcfreqslope(cfs(1),cfs(2)); + + %a is effect from channel below but we must input + %the lower frequency (1) as the adjacent band and + %the channel in which we want the level (2) as + %the centre freq + frequency_slope_a=calcfreqslope(cfs(2),cfs(1)); + +else + frequency_slope_c=0; + frequency_slope_a=0; +end + +%we divide by the frequency_constant_factor because we want a +%frequency_constant_factor of 1 to mean we use the actual +%frequency slope and a frequency_constant_factor of 0.5 +%to mean that the frequency slope falls away at twice the rate +%i.e. less effect +frequency_slope_c=frequency_slope_c./frequency_constant_factor; +frequency_slope_a=frequency_slope_a./frequency_constant_factor; + + + + +oldfigure=gcf; +if nr_chan==1 + onechannelfigure=figure(3); % assuming, the other one is 1 +end + +% channel_select=1:nr_chan; +times_per_ms=round(sr*0.01); +if nr_chan>1 + waithand=waitbar(0,'generating 2dat'); +end + + + +val_e=zeros(nr_chan,nr_dots); +val_inp=zeros(nr_chan,nr_dots); +val_thres=zeros(nr_chan,nr_dots); + + + + +% a is the decayed working variable from the channel above +% b is the range limit +% c is the decayed working variable from the channel below +% d is the delayed and decayed nap signal from on-channel +% e is the maximum of [a b c d] +% threshold is the working variable +% thresholdlast is the working variable in the last round +% inp is the current input + + +thresholdlast=zeros(nr_chan,1); +threshold=zeros(nr_chan,1); +a=0;b=1;c=0;d=0;e=0; + + + +for ii=1:nr_dots % through the time + if nr_chan>1 + if mod(ii,times_per_ms)==0 + waitbar(ii/nr_dots); + end + end + + for jj=1:nr_chan % through all channels: prepare working variable + inp=vals(jj,ii);% current input + + if jj< nr_chan + chan_above=thresholdlast(jj+1); + a=chan_above+frequency_slope_a; + else + a=0; + end + if jj>1 + chan_below=thresholdlast(jj-1); + c=chan_below+frequency_slope_c; + else + c=0; + end + + %a=0; + %c=0; + + + + + d=max(thresholdlast(jj)+threshold_decay_constant(jj),0); + + + e1=max(a,b); + e2=max(c,d); + e=max(e1,e2); + + + + + if inp>e %threshold is exceeded + + threshold(jj)=min(thresholdlast(jj)+threshold_rise(jj),inp); + %threshold(jj)=inp; + + %new_vals(jj,ii)=threshold(jj)-e; + new_vals(jj,ii)=inp-threshold(jj); + % % else threshold decays + else + threshold(jj)=e; + new_vals(jj,ii)=0; + end + + + + val_e(jj,ii)=e; + val_inp(jj,ii)=inp; + val_thres(jj,ii)=threshold(jj); + + + end + + + + + + % prepare next round + if ii< nr_dots + thresholdlast=threshold; + end + + if nr_chan==1 + tvals(ii)=thresholdlast; + end + + +end + + + + + +if nr_chan==1 + figure(onechannelfigure); + plot(nap); + hold on + a=plot(tvals,'r'); + set(a,'LineWidth',1.5); +end + + +nap=setvalues(nap,new_vals); +%save nap.mat nap; + +vals=getvalues(nap); +nap=setallmaxvalue(nap,max(max(vals))*2); +nap=setallminvalue(nap,min(min(vals))); + + + +%save val_e.mat val_e; +%save new_vals.mat new_vals; +%save val_inp.mat val_inp; +%save val_thres.mat val_thres; + + + + + + + +ret=nap; +if nr_chan>1 + close(waithand); +end + +figure(oldfigure); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/nap/twodat2003/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/nap/twodat2003/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,26 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +% +% hidden parameters +twodat2003.generatingfunction='gen_twoDat2003'; +twodat2003.displayname='two dimensional adaptive threshold'; +twodat2003.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +% napoptions +twodat2003.nap.compression='log'; +twodat2003.nap.do_lowpassfiltering=1; +twodat2003.nap.lowpass_cutoff_frequency=1200; +twodat2003.nap.time_constant=0.000133; +twodat2003.nap.lowpass_order=2; + +% sharpening options +twodat2003.time_constant_factor=0.9; +twodat2003.frequency_constant_factor=0.9; +twodat2003.threshold_rise_constant=1; +twodat2003.b=1.019; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/elc/OutMidCrct.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/elc/OutMidCrct.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,90 @@ +% +% Correction of ELC, MAF, MAP +% IRINO Toshio +% 18 Mar 96 +% 29 Aug 96 renamed AFShapeCrct -> OutMidCrct +% 14 May 97 option of Direct Output +% +% It produces interpolated points for the ELC/MAF/MAP correction. +% +% Reference: +% Glassberg and Moore (1990) +% "Derivation of auditory filter shapes from notched noise data" +% Hearing Research, 47 , pp.103-138. +% +% function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% Npnts: Number of data points, if zero, then direct out. +% SR: Sampling Rate +% SwPlot: Switch for plot +% OUTPUT CrctLinPwr : Correction value in LINEAR POWER +% frqNpnts: Corresponding Frequency at the data point +% CrctdB: Correction value in dB +% +function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR,SwPlot); + +if nargin < 1, help OutMidCrct; end; +if nargin < 2, Npnts = 0; end; +if nargin < 3, SR = 32000; end; +if nargin < 4, SwPlot = 1; end; + +f1 = [ 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, ... + 125, 150, 177, 200, 250, 300, 350, 400, 450, 500, 550, ... + 600, 700, 800, 900, 1000, 1500, 2000, 2500, 2828, 3000, ... + 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, ... + 12748, 15000]; + +ELC = [ 31.8, 26.0, 21.7, 18.8, 17.2, 15.4, 14.0, 12.6, 11.6, 10.6, ... + 9.2, 8.2, 7.7, 6.7, 5.3, 4.6, 3.9, 2.9, 2.7, 2.3, ... + 2.2, 2.3, 2.5, 2.7, 2.9, 3.4, 3.9, 3.9, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +MAF = [ 73.4, 65.2, 57.9, 52.7, 48.0, 45.0, 41.9, 39.3, 36.8, 33.0, ... + 29.7, 27.1, 25.0, 22.0, 18.2, 16.0, 14.0, 11.4, 9.2, 8.0, ... + 6.9, 6.2, 5.7, 5.1, 5.0, 5.0, 4.4, 4.3, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +f2 = [ 125, 250, 500, 1000, 1500, 2000, 3000, ... + 4000, 6000, 8000,10000,12000,14000,16000]; +MAP = [ 30.0, 19.0, 12.0, 9.0, 11.0, 16.0, 16.0, ... + 14.0, 14.0, 9.9, 24.7, 32.7, 44.1, 63.7]; + +frqTbl = []; +CrctTbl = []; +if length(StrCrct)==3 + if strcmp(upper(StrCrct(1:3)),'ELC'), frqTbl = f1'; CrctTbl = ELC'; + elseif strcmp(upper(StrCrct(1:3)),'MAF'), frqTbl = f1'; CrctTbl = MAF'; + elseif strcmp(upper(StrCrct(1:3)),'MAP'), frqTbl = f2'; CrctTbl = MAP'; + else error('Specifiy correction: ELC / MAF / MAP or NO correction.'); + end; +elseif length(StrCrct)~=2, + error('Specifiy correction: ELC / MAF / MAP or NO correction.'); +end; + +str1 = ''; +if Npnts <= 0, + str1 = 'No interpolation. Output original table.'; + frqNpnts = frqTbl; + CrctdB = CrctTbl; +else + frqNpnts = (0:Npnts-1)'/Npnts * SR/2; + if strcmp(upper(StrCrct(1:2)), 'NO'), + CrctdB = zeros(size(frqNpnts)); + else + str1 = 'Spline interpolated value in equal frequency spacing.'; + CrctdB = spline(frqTbl,CrctTbl,frqNpnts); + end; +end; + +if SwPlot == 1, + disp(['*** Outer/Middle Ear Transfer Function ( ' ... + upper(StrCrct) ' Correction ) ***']); + disp(str1); + plot(frqTbl,CrctTbl,frqNpnts,CrctdB,'o'); +end; + +CrctLinPwr = 10.^(-CrctdB/10); % in Linear Power + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/elc/OutMidCrctFilt.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/elc/OutMidCrctFilt.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,62 @@ +% +% Produce compensation filter to simulate outer/middle ear +% IRINO Toshio +% 29 Aug. 1996 (check on 14 May 1997 ) +% 8 Jan. 2002 (Multiply Win for avoid sprious) +% 19 Nov. 2002 (remez : even integer) +% +% It is a linear phase filter for the ELC/MAF/MAP correction. +% see OutMidCrct.m +% +% function [FIRCoef] = OutMidCrctFilt(StrCrct,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% SR: Sampling Rate +% SwPlot: SwPlot +% OUTPUT FIRCoef: FIR filter coefficients +% +function [FIRCoef] = OutMidCrctFilt(StrCrct,SR,SwPlot); + +if nargin < 2, help OutMidCrctFilt; end; +if nargin < 3, SwPlot = 1; end; + +if length(StrCrct)~=3, + error('Specifiy correction in 3 characters: ELC / MAF / MAP.'); +end; +if ~(strcmp(upper(StrCrct(1:3)), 'ELC') | ... + strcmp(upper(StrCrct(1:3)),'MAF') ... + | strcmp(upper(StrCrct(1:3)),'MAP')), + error('Specifiy correction: ELC / MAF / MAP.'); +end; + +Nint = 1024; +% Nint = 0; % No spline interpolation: NG no convergence at remez +[crctPwr freq] = OutMidCrct(StrCrct,Nint,SR,0); +crct = sqrt(crctPwr); + +%% FIRCoef = remez(50/16000*SR,freq/SR*2,crct); % NG +%% FIRCoef = remez(300/16000*SR,freq/SR*2,crct); % Original +% FIRCoef = remez(LenCoef/16000*SR,freq/SR*2,crct); % when odd num : warning +%% modified on 8 Jan 2002, 19 Nov 2002 +LenCoef = 200; % ( -45 dB) <- 300 (-55 dB) +FIRCoef = remez(fix(LenCoef/16000*SR/2)*2,freq/SR*2,crct); % even number only +Win = TaperWindow(length(FIRCoef),'han',LenCoef/10); + % Necessary to avoid sprious +FIRCoef = Win.*FIRCoef; + +if SwPlot==1 + [frsp freq2] = freqz(FIRCoef,1,Nint,SR); + subplot(2,1,1) + plot(FIRCoef); + subplot(2,1,2) + plot(freq2,abs(frsp),freq,crct,'--') + % plot(freq2,20*log10(abs(frsp)),freq,20*log10(crct)) + + ELCError = mean((abs(frsp) - crct).^2)/mean(crct.^2); + ELCErrordB = 10*log10(ELCError) % corrected + if ELCErrordB > -30, + disp(['Warning: Error in ELC correction = ' ... + num2str(ELCErrordB) ' dB > -30 dB']) + end; +end; + +return; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/elc/TaperWindow.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/elc/TaperWindow.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,76 @@ +% +% Taper Window Generator for signal onset/offset +% 7 Apr. 1993 +% 29 Aug. 96 +% IRINO Toshio +% +% function [TaperWin, TypeTaper] = ... +% TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) +% INPUT LenWin : Length of Window (Number of points) +% TypeTaper : Type of Taper (KeyWords of 3 letters) +% (Hamming, Hanning (=cosine^2), Blackman, Gauss, Line) +% LenTaper : Length of Taper (Number of points) +% RangeSigma: Range in Sigma (default: 3) for Gauss +% SwPlot : 0) Omit plotting, 1) Plot Taper +% OUTPUT TaperWin : Taper Window Points (max==1); +% TypeTaper : Type of Taper (Full Name) +% +function [TaperWin, TypeTaper] = ... + TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) + +if nargin < 2, +help TaperWindow +error([ 'Specify Type of Taper : ' ... + ' Hamming, Hanning (=cosine^2), Blackman, Gauss, Line ']); +%TaperWin = ones(1,LenWin); +%return; +end; + +if nargin < 3, LenTaper = fix(LenWin/2); end; +if nargin < 4, RangeSigma = 3; end; + +if LenTaper*2 >= LenWin, + disp('Caution (TaperWindow.m) : No flat part. '); + if LenTaper ~= fix(LenWin/2), + disp('Caution (TaperWindow.m) : LenTaper <-- fix(LenWin/2)'); + end; + LenTaper = fix(LenWin/2); +end; + +if nargin < 5, SwPlot = 0; end; % changing default Swplot 29 Aug. 96 + +%TypeTaper = lower(TypeTaper(1:3)); + +if upper(TypeTaper(1:3)) == 'HAM', + Taper = hamming(LenTaper*2)'; + TypeTaper = 'Hamming'; +elseif upper(TypeTaper(1:3)) == 'HAN' | upper(TypeTaper(1:3)) == 'COS', + Taper = hanning(LenTaper*2)'; + TypeTaper = 'Hanning/Cosine'; +elseif upper(TypeTaper(1:3)) == 'BLA', + Taper = blackman(LenTaper*2)'; + TypeTaper = 'Blackman'; +elseif upper(TypeTaper(1:3)) == 'GAU', + if length(RangeSigma) == 0, RangeSigma = 3; end; + nn = -LenTaper+0.5:1:LenTaper-0.5; + Taper = exp(-(RangeSigma*nn/LenTaper).^2 /2); + TypeTaper = 'Gauss'; +else Taper = [1:LenTaper LenTaper:-1:1]/LenTaper; % 'line', + TypeTaper = 'Line'; +end; + +%plot(Taper) +%size(Taper); +LenTaper = fix(LenTaper); +TaperWin = [ Taper(1:LenTaper) ones(1,LenWin-LenTaper*2) ... + Taper(LenTaper+1:LenTaper*2)]; + +if SwPlot == 1, + +plot(TaperWin) +xlabel('Points'); +ylabel('Amplitude'); +title(['TypeTaper = ' TypeTaper] ); + +end; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/elc/genelc.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/elc/genelc.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,40 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function sig=genome(sig,options) +% generating function for the outer/middle ear transfere function + +waithand=waitbar(0,'generating pre cochlea processing'); + +samplerate=getsr(sig); +start_time=getminimumtime(sig); + +firfiltercoef = OutMidCrctFilt('ELC',samplerate,0); + +% to compensate the huge delay from the filter, a pause is added to the +% signal, that is taken away in the end: +pause=signal(abs(options.delay_correction),samplerate); +sig=setstarttime(sig,0); +sig=append(sig,pause); + +Snd=getvalues(sig); +Snd=Snd'; +Snd = filter(firfiltercoef,1,Snd); + +sig=setvalues(sig,Snd); + +%take the delay back: +siglen=getlength(sig); +sig=getpart(sig,abs(options.delay_correction),siglen); +sig=setstarttime(sig,start_time); + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/elc/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/elc/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% parameter file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% outer/middle ear filter function +% hidden parameters +elc.generatingfunction='genelc'; +elc.displayname='outer/middle ear transfere function: Equal-Loudness Contours'; +elc.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +elc.delay_correction=-0.0063; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/gm2002/all_corrns.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/gm2002/all_corrns.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,57 @@ +%%%%%%%% Table data file, from BRG May 2001 + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% This is the current file as of at least September 3rd 2001 %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% Killion JASA 63 1501-1509 (1978) + +Hz = [ 0.,... + 20., 25., 31.5, 40., 50., 63., 80., 100., 125., 160., 200., 250., 315., 400., 500., 630.,... + 750., 800., 1000., 1250., 1500., 1600., 2000., 2500., 3000., 3150., 4000., 5000., 6000., 6300., 8000., 9000.,... + 10000., 11200.,12500., 14000., 15000., 16000.,20000.]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%% This is the AES paper midear correction with slight increases in the corrections of 80 Hz & below +%% USED TO CALC FILES ff.32k and df.32k + +Midear=[ 55.0,... + 43.6, 34.9, 27.9, 22.4, 19.0, 16.6, 14.5, 12.5, 11.13, 9.71, 8.42, 7.2, 6.1, 4.7, 3.7, 3.0,... + 2.7, 2.6, 2.6, 2.7, 3.7, 4.6, 8.5, 10.8, 7.3, 6.7, 5.7, 5.7, 7.6, 8.4, 11.3, 10.6,... + 9.9, 11.9, 13.9, 16.0, 17.3, 17.8, 20.0]; + +%% This is the truer AES paper midear correction, no low-freq +MidearAES=[ 42,... %% apart from 0 Hz which was 50 + 39.15, 31.4, 25.4, 20.9, 18.0, 16.1, 14.2, 12.5, 11.13, 9.71, 8.42, 7.2, 6.1, 4.7, 3.7, 3.0,... + 2.7, 2.6, 2.6, 2.7, 3.7, 4.6, 8.5, 10.8, 7.3, 6.7, 5.7, 5.7, 7.6, 8.4, 11.3, 10.6,... + 9.9, 11.9, 13.9, 16.0, 17.3, 17.8, 20.0]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% FF_ED correction for threshold (was ISO std Table 1 - 4.2 dB) +% i.e. relative to 0.0 dB at 1000 Hz, Shaw 1974 + +Ff_ed= [0.0,... + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.3, 0.5, 0.9, 1.4, 1.6, 1.7, 2.5,... + 2.7, 2.6, 2.6, 3.2, 5.2, 6.6, 12.0, 16.8, 15.3, 15.2, 14.2, 10.7, 7.1, 6.4, 1.8, -0.9,... + -1.6, 1.9, 4.9, 2.0, -2.0, 2.5, 2.5]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% diffuse field correction +%% DIFFUSE correction ( relative to 0.0 dB at 1000Hz) +Diffuse= [0.0,... + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.3, 0.4, 0.5, 1.0, 1.6, 1.7, 2.2,... + 2.7, 2.9, 3.8, 5.3, 6.8, 7.2, 10.2, 14.9, 14.5, 14.4, 12.7, 10.8, 8.9, 8.7, 8.5, 6.2,... + 5.0, 4.5, 4.0, 3.3, 2.6, 2.0, 2.0]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% ITU Rec P 58 08/96 Head and Torso Simulator transfer fns. +%% from Peter Hugher BTRL , 4-June-2001 + +ITU_Hz = [0 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000]; + +%% ERP-DRP transfer fn, Table 14A/P.58, sect 6.2. NB negative of table since defined other way round. +%% Ear Reference Point to Drum Reference Point + +ITU_erp_drp = [0. 0. 0. 0. 0. .3 .2 .5 .6 .7 1.1 1.7 2.6 4.2 6.5 9.4 10.3 6.6 3.2 3.3 16 14.4]; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/gm2002/ff_design.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/gm2002/ff_design.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,176 @@ +function fir_eq=genstonefir(fs,type) +% adapted version von S.Bleeck +% +%%% May 2001 M.A.Stone. To design FIR filters for fir_corr.c +%%% produces output on screen, and to file dummy.??k where ?? is clock freq in kHz +%%% select variables below, such as ntaps (output is ntaps +1) fs, +%%% and inverse =1 sets for inverse filter, 0 for normal filter. +%%% and eq characteristic is set by choosing appropriate variables: +%%%% function_str and dB corrn. Ff_ed , Df_ed, Midear, and Hz come +%%%% from a separate file [all_corrns.m]. Insert new characteristics +%%%% in there, eg ITU_erp_drp/ITU_Hz + +%%% FORMAT for output file +%%% first line is comment +%%%% second line is number of taps (preferably odd) +%%%% third and subsequent lines are filter taps, one per line, floating point + +all_corrns; %%%%%% external file for reference corrections, hz, midear, ff_ed, diffuse +%%%%%% NB, midear response has limit/flatten-off at lowest freqs to prevent enormous changes < 25 Hz +%%%%%%%% design parameters here +%%% NB sometomes for inverse, cannot have ntaps too high: claims index error in fir2. +% fs = 50000; %%%% sampling rate +ntaps = 1+2*(round(fs/24)); %% always odd +nFFT = 2.^(nextpow2(ntaps) + 1); %% FIR size is ntaps + 1, otherwise delay has extra half-sample +%% more taps require kaiser beta to be higher +inverse = 0; %% options 0/1 : whether to do forward or inverse filter + +posh_print = 0; %%% just if we want publication figure, so no output file + +beta = 6; %%% used to window INVERSE filter shape, and reduce ripple +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%% Uncomment which of the three sections below you require +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +switch type + case 1 + %%%%%%% Section 1 + function_str= sprintf(' Frontal free-field to cochlea correction,fs=%d',fs); + if fs <= 32000 + dBcorrn = Ff_ed - Midear; %%%%% result in dB + else %% for high fs use truer version, without low freq fiddle + dBcorrn = Ff_ed - MidearAES; %%%%% result in dB + end + case 2 + %%%%%%% Section 2 + function_str= sprintf(' Diffuse-field to cochlea correction,fs=%d',fs); + if fs <= 32000 + dBcorrn = Diffuse - Midear; %%%%% result in dB NB midear is inverted !! + else %% for high fs use truer version, without low freq fiddle + dBcorrn = Diffuse - MidearAES; %%%%% result in dB + end + + case 3 + %%%%%% Section 3 + %%%%% ITU corrections for telephony. + function_str= sprintf(' ITU Ear Ref Pnt via Drum Ref Pnt to cochlea,fs=%d',fs); + ITU_on_Hz = interp1(ITU_Hz,ITU_erp_drp,Hz,'spline'); %%%% corrn on linear frequency spacing + dBcorrn = ITU_on_Hz - Midear; %%%%% result in dB. NB midear is inverted !! +end +%%%% END OF VARIABLE USER ENTRY/SET-UP +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% rest is just calculations +if ~inverse + filename = sprintf('ff.%dk',floor(fs/1000)); +else + filename = sprintf('iff.%dk',floor(fs/1000)); +end +% if ~posh_print +% txt_file = fopen(filename,'wt'); +% end +%%%% spacing for linear frequency design grid +deltaf = (fs)/nFFT; + +linf = 0:deltaf:fs/2; %%%% frequencies of FFT bins (DC-nyq-1) + +if inverse == 1 + dBcorrn = -dBcorrn; + title_str = strcat('INVERSE',function_str); +else + title_str= function_str; + title_str=' '; +end + +if Hz(end) < fs/2 %% handle interpolation of high fs data + dBcorrn_linf = interp1([Hz fs/2],[dBcorrn dBcorrn(end)],linf,'linear'); %%%% corrn on linear frequency spacing +else + dBcorrn_linf = interp1(Hz,dBcorrn,linf,'linear'); %%%% corrn on linear frequency spacing +end +%%%%%% limit/flatten-off at lowest freqs +dBcorrn_linf_orig = dBcorrn_linf; +%%%dBcorrn_linf(2) = dBcorrn_linf(3) - (dBcorrn_linf(3)-dBcorrn_linf(2))/2; +%%%dBcorrn_linf(1) = dBcorrn_linf(2); + +[smth_b smth_a] = butter(4,.5); %% smooth to control roughness +eq_linf = filtfilt(smth_b,smth_a,dBcorrn_linf); + +% if posh_print, figure(1); plot(linf,eq_linf,'r','linewidth',1.8); hold on; end + +%%%%% design fir filter: NB taming of response by (gentle) Kaiser window +if inverse + halfwid = 10.^(eq_linf/20.); + npi = pi*mod((0:nFFT/2),2); %% include phase shift to put response in middle of aperture + phase_shift = exp(i*npi); + halfwid = halfwid .* phase_shift; + fullwid = [halfwid conj(halfwid(nFFT/2:-1:2))]; + t_filt = real(ifft(fullwid)); + %%%%%%%%figure(2); plot(real(t_filt)); figure(1); + ntaps2 = floor(ntaps/2); %% extract relevant portion + fir_eq = t_filt((nFFT/2+1)-ntaps2 : (nFFT/2+1)+ntaps2); + fir_eq = fir_eq.*kaiser(ntaps,beta)'; +else + %TCW AIM 2006 naps -> ntaps+1 to remove error from fir2 which makes + %the filter order even anyway. (Ntaps is always odd, see line 23). + fir_eq = fir2(ntaps+1,linf./(fs/2),10.^(eq_linf/20.)); % f= 1 is Nyquist +end + + +%%%%% and plot response +if posh_print ~=0 + [hz,fz] = freqz(fir_eq,1,16384,fs); + +% GET AN OUTPUT FILE +% outfile=fopen('frq_res.ff','w'); +% fprintf(outfile,'%.4f,%.4f\n',[fz,20*log10(abs(hz))]'); +% fclose(outfile); + plot(fz,20*log10(abs(hz)),'b','linewidth',1.8); + set(gca,'box','on'); %%%% default with R12 is off + title(title_str,'fontsize',13); xlabel('Frequency (Hz)','fontsize',11); ylabel('Relative transmission (dB)','fontsize',11); + set(gca,'TickDirMode','manual','TickLength',[0 0]); %% turn off ticking + + xfl = 20-.1; xfh = fs/2; + xticking = [20 50 100 200 500 1000 2000 5000 10000]; + if fs/2 > 20e3, xticking = [xticking 20e3]; end + if fs/2 > 50e3, xticking = [xticking 50e3]; end % no point in any higher + + set(gca,'xlim',[xfl xfh],'xscale','log'); + set(gca,'xtickmode','manual','xtick',xticking,'xticklabel',xticking); + + if inverse, dBl = -10; dBh = 40; else dBl = -40; dBh = 10; end + yticking = [dBl:5:dBh]; + set(gca,'linewidth',1.3,'ylim',[dBl dBh],'fontsize',11); + set(gca,'ytickmode','manual','ytick',yticking,'yticklabel',yticking); + +%% grid on ; set(gca,'GridLineStyle','-'); +%%%%%% to overcome bugs in MATLAB with xscale producing extra ticks 20-06-2001 + for ix = 1:length(xticking) %% draw ylines + line([xticking(ix) xticking(ix)],[min(yticking), max(yticking)],'linewidth',0.6,'linestyle','--'); + end + for ix = 1:length(yticking) %% draw xlines + line([xfl xfh],[yticking(ix), yticking(ix)],'linewidth',0.6,'linestyle','--'); + end + +else +% freqz(fir_eq,1,8192,fs); +% subplot(2,1,1); set(gca,'xlim',[10 fs/2],'xscale','log'); +% hold on ; grid on; +% semilogx(linf,dBcorrn_linf_orig,'r'); +% title(title_str); xlabel('frequency (Hz)'); ylabel('dB (red=target, blue=actual)'); +% subplot(2,1,1); hold off +% subplot(2,1,2); hold off +end + +% hold off % for figure(1) + +% %%%% print out design values to file (and was screen) +% if posh_print ~=0 +% fprintf(1,'\nThis version has also created the file %s\n',filename); +% fprintf(1,'%s\n',function_str); +% fprintf(1,'%d\n',length(fir_eq)); +% %% fprintf(1,'%11.8f\n',fir_eq); +% fprintf(txt_file,'%s\n',function_str); +% fprintf(txt_file,'%d\n',length(fir_eq)); +% fprintf(txt_file,'%f\n',fir_eq); +% fclose(txt_file); +% end +% +% WriteDSAMFIRParFile(fir_eq, fs, inverse); diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/gm2002/ff_design50k.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/gm2002/ff_design50k.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,169 @@ +%%% May 2001 M.A.Stone. To design FIR filters for fir_corr.c +%%% produces output on screen, and to file dummy.??k where ?? is clock freq in kHz +%%% select variables below, such as ntaps (output is ntaps +1) fs, +%%% and inverse =1 sets for inverse filter, 0 for normal filter. +%%% and eq characteristic is set by choosing appropriate variables: +%%%% function_str and dB corrn. Ff_ed , Df_ed, Midear, and Hz come +%%%% from a separate file [all_corrns.m]. Insert new characteristics +%%%% in there, eg ITU_erp_drp/ITU_Hz + +%%% FORMAT for output file +%%% first line is comment +%%%% second line is number of taps (preferably odd) +%%%% third and subsequent lines are filter taps, one per line, floating point + +all_corrns; %%%%%% external file for reference corrections, hz, midear, ff_ed, diffuse +%%%%%% NB, midear response has limit/flatten-off at lowest freqs to prevent enormous changes < 25 Hz +%%%%%%%% design parameters here +%%% NB sometomes for inverse, cannot have ntaps too high: claims index error in fir2. +fs = 50000; %%%% sampling rate +ntaps = 1+2*(round(fs/24)); %% always odd +nFFT = 2.^(nextpow2(ntaps) + 1); %% FIR size is ntaps + 1, otherwise delay has extra half-sample +%% more taps require kaiser beta to be higher +inverse = 0; %% options 0/1 : whether to do forward or inverse filter + +posh_print = 0; %%% just if we want publication figure, so no output file + +beta = 6; %%% used to window INVERSE filter shape, and reduce ripple +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%% Uncomment which of the three sections below you require +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%% Section 1 +% function_str= sprintf(' Frontal free-field to cochlea correction,fs=%d',fs); +% +% if fs <= 32000 +% dBcorrn = Ff_ed - Midear; %%%%% result in dB +% else %% for high fs use truer version, without low freq fiddle +% dBcorrn = Ff_ed - MidearAES; %%%%% result in dB +% end +%%%%%%% Section 2 +function_str= sprintf(' Diffuse-field to cochlea correction,fs=%d',fs); + +if fs <= 32000 + dBcorrn = Diffuse - Midear; %%%%% result in dB NB midear is inverted !! +else %% for high fs use truer version, without low freq fiddle + dBcorrn = Diffuse - MidearAES; %%%%% result in dB +end + +%%%%%%% Section 3 +%%%%%% ITU corrections for telephony. +%%function_str= sprintf(' ITU Ear Ref Pnt via Drum Ref Pnt to cochlea,fs=%d',fs); +%%ITU_on_Hz = interp1(ITU_Hz,ITU_erp_drp,Hz,'spline'); %%%% corrn on linear frequency spacing +%%dBcorrn = ITU_on_Hz - Midear; %%%%% result in dB. NB midear is inverted !! + +%%%% END OF VARIABLE USER ENTRY/SET-UP +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% rest is just calculations +if ~inverse + filename = sprintf('ff.%dk',floor(fs/1000)); +else + filename = sprintf('iff.%dk',floor(fs/1000)); +end +if ~posh_print + txt_file = fopen(filename,'wt'); +end +%%%% spacing for linear frequency design grid +deltaf = (fs)/nFFT; + +linf = 0:deltaf:fs/2; %%%% frequencies of FFT bins (DC-nyq-1) + +if inverse == 1 + dBcorrn = -dBcorrn; + title_str = strcat('INVERSE',function_str); +else + title_str= function_str; + title_str=' '; +end + +if Hz(end) < fs/2 %% handle interpolation of high fs data + dBcorrn_linf = interp1([Hz fs/2],[dBcorrn dBcorrn(end)],linf,'linear'); %%%% corrn on linear frequency spacing +else + dBcorrn_linf = interp1(Hz,dBcorrn,linf,'linear'); %%%% corrn on linear frequency spacing +end +%%%%%% limit/flatten-off at lowest freqs +dBcorrn_linf_orig = dBcorrn_linf; +%%%dBcorrn_linf(2) = dBcorrn_linf(3) - (dBcorrn_linf(3)-dBcorrn_linf(2))/2; +%%%dBcorrn_linf(1) = dBcorrn_linf(2); + +[smth_b smth_a] = butter(4,.5); %% smooth to control roughness +eq_linf = filtfilt(smth_b,smth_a,dBcorrn_linf); + +if posh_print, figure(1); plot(linf,eq_linf,'r','linewidth',1.8); hold on; end + +%%%%% design fir filter: NB taming of response by (gentle) Kaiser window +if inverse + halfwid = 10.^(eq_linf/20.); + npi = pi*mod((0:nFFT/2),2); %% include phase shift to put response in middle of aperture + phase_shift = exp(i*npi); + halfwid = halfwid .* phase_shift; + fullwid = [halfwid conj(halfwid(nFFT/2:-1:2))]; + t_filt = real(ifft(fullwid)); + %%%%%%%%figure(2); plot(real(t_filt)); figure(1); + ntaps2 = floor(ntaps/2); %% extract relevant portion + fir_eq = t_filt((nFFT/2+1)-ntaps2 : (nFFT/2+1)+ntaps2); + fir_eq = fir_eq.*kaiser(ntaps,beta)'; +else + fir_eq = fir2(ntaps,linf./(fs/2),10.^(eq_linf/20.)); % f= 1 is Nyquist +end + + +%%%%% and plot response +if posh_print + [hz,fz] = freqz(fir_eq,1,16384,fs); + +% GET AN OUTPUT FILE +% outfile=fopen('frq_res.ff','w'); +% fprintf(outfile,'%.4f,%.4f\n',[fz,20*log10(abs(hz))]'); +% fclose(outfile); + plot(fz,20*log10(abs(hz)),'b','linewidth',1.8); + set(gca,'box','on'); %%%% default with R12 is off + title(title_str,'fontsize',13); xlabel('Frequency (Hz)','fontsize',11); ylabel('Relative transmission (dB)','fontsize',11); + set(gca,'TickDirMode','manual','TickLength',[0 0]); %% turn off ticking + + xfl = 20-.1; xfh = fs/2; + xticking = [20 50 100 200 500 1000 2000 5000 10000]; + if fs/2 > 20e3, xticking = [xticking 20e3]; end + if fs/2 > 50e3, xticking = [xticking 50e3]; end % no point in any higher + + set(gca,'xlim',[xfl xfh],'xscale','log'); + set(gca,'xtickmode','manual','xtick',xticking,'xticklabel',xticking); + + if inverse, dBl = -10; dBh = 40; else dBl = -40; dBh = 10; end + yticking = [dBl:5:dBh]; + set(gca,'linewidth',1.3,'ylim',[dBl dBh],'fontsize',11); + set(gca,'ytickmode','manual','ytick',yticking,'yticklabel',yticking); + +%% grid on ; set(gca,'GridLineStyle','-'); +%%%%%% to overcome bugs in MATLAB with xscale producing extra ticks 20-06-2001 + for ix = 1:length(xticking) %% draw ylines + line([xticking(ix) xticking(ix)],[min(yticking), max(yticking)],'linewidth',0.6,'linestyle','--'); + end + for ix = 1:length(yticking) %% draw xlines + line([xfl xfh],[yticking(ix), yticking(ix)],'linewidth',0.6,'linestyle','--'); + end + +else + freqz(fir_eq,1,8192,fs); + subplot(2,1,1); set(gca,'xlim',[10 fs/2],'xscale','log'); + hold on ; grid on; + semilogx(linf,dBcorrn_linf_orig,'r'); + title(title_str); xlabel('frequency (Hz)'); ylabel('dB (red=target, blue=actual)'); + subplot(2,1,1); hold off + subplot(2,1,2); hold off +end + +hold off % for figure(1) + +%%%% print out design values to file (and was screen) +if ~posh_print + fprintf(1,'\nThis version has also created the file %s\n',filename); + fprintf(1,'%s\n',function_str); + fprintf(1,'%d\n',length(fir_eq)); +%% fprintf(1,'%11.8f\n',fir_eq); + fprintf(txt_file,'%s\n',function_str); + fprintf(txt_file,'%d\n',length(fir_eq)); + fprintf(txt_file,'%f\n',fir_eq); + fclose(txt_file); +end + +WriteDSAMFIRParFile(fir_eq, fs, inverse); diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/gm2002/gen_gm2002.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/gm2002/gen_gm2002.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,45 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function sig=gensgm(sig,options) +% generating function for the outer/middle ear transfere function + +%waithand=waitbar(0,'generating pre cochlea processing'); + +samplerate=getsr(sig); +start_time=getminimumtime(sig); + + +firfiltercoef = ff_design(samplerate,1); % Frontal free-field to cochlea correction +% firfiltercoef = ff_design(samplerate,2); % Diffuse-field to cochlea correction +% firfiltercoef = ff_design(samplerate,3); % ITU corrections for telephony. + + + +% to compensate the huge delay from the filter, a pause is added to the +% signal, that is taken away in the end: +pause=signal(abs(options.delay_correction),samplerate); +sig=setstarttime(sig,0); +sig=append(sig,pause); + +Snd=getvalues(sig); +Snd=Snd'; +Snd = filter(firfiltercoef,1,Snd); + +sig=setvalues(sig,Snd); + +%take the delay back: +siglen=getlength(sig); +sig=getpart(sig,abs(options.delay_correction),siglen); +sig=setstarttime(sig,start_time); + +%close(waithand); diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/gm2002/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/gm2002/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,17 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% outer/middle ear filter function +% hidden parameters +gm2002.generatingfunction='gen_gm2002'; +gm2002.displayname='outer/middle ear transfere function from Glasberg and Moore (2002)'; +gm2002.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +gm2002.select_correction=1; +gm2002.delay_correction=-0.04205; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/maf/OutMidCrct.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/maf/OutMidCrct.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,90 @@ +% +% Correction of ELC, MAF, MAP +% IRINO Toshio +% 18 Mar 96 +% 29 Aug 96 renamed AFShapeCrct -> OutMidCrct +% 14 May 97 option of Direct Output +% +% It produces interpolated points for the ELC/MAF/MAP correction. +% +% Reference: +% Glassberg and Moore (1990) +% "Derivation of auditory filter shapes from notched noise data" +% Hearing Research, 47 , pp.103-138. +% +% function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% Npnts: Number of data points, if zero, then direct out. +% SR: Sampling Rate +% SwPlot: Switch for plot +% OUTPUT CrctLinPwr : Correction value in LINEAR POWER +% frqNpnts: Corresponding Frequency at the data point +% CrctdB: Correction value in dB +% +function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR,SwPlot); + +if nargin < 1, help OutMidCrct; end; +if nargin < 2, Npnts = 0; end; +if nargin < 3, SR = 32000; end; +if nargin < 4, SwPlot = 1; end; + +f1 = [ 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, ... + 125, 150, 177, 200, 250, 300, 350, 400, 450, 500, 550, ... + 600, 700, 800, 900, 1000, 1500, 2000, 2500, 2828, 3000, ... + 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, ... + 12748, 15000]; + +ELC = [ 31.8, 26.0, 21.7, 18.8, 17.2, 15.4, 14.0, 12.6, 11.6, 10.6, ... + 9.2, 8.2, 7.7, 6.7, 5.3, 4.6, 3.9, 2.9, 2.7, 2.3, ... + 2.2, 2.3, 2.5, 2.7, 2.9, 3.4, 3.9, 3.9, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +MAF = [ 73.4, 65.2, 57.9, 52.7, 48.0, 45.0, 41.9, 39.3, 36.8, 33.0, ... + 29.7, 27.1, 25.0, 22.0, 18.2, 16.0, 14.0, 11.4, 9.2, 8.0, ... + 6.9, 6.2, 5.7, 5.1, 5.0, 5.0, 4.4, 4.3, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +f2 = [ 125, 250, 500, 1000, 1500, 2000, 3000, ... + 4000, 6000, 8000,10000,12000,14000,16000]; +MAP = [ 30.0, 19.0, 12.0, 9.0, 11.0, 16.0, 16.0, ... + 14.0, 14.0, 9.9, 24.7, 32.7, 44.1, 63.7]; + +frqTbl = []; +CrctTbl = []; +if length(StrCrct)==3 + if strcmp(upper(StrCrct(1:3)),'ELC'), frqTbl = f1'; CrctTbl = ELC'; + elseif strcmp(upper(StrCrct(1:3)),'MAF'), frqTbl = f1'; CrctTbl = MAF'; + elseif strcmp(upper(StrCrct(1:3)),'MAP'), frqTbl = f2'; CrctTbl = MAP'; + else error('Specifiy correction: ELC / MAF / MAP or NO correction.'); + end; +elseif length(StrCrct)~=2, + error('Specifiy correction: ELC / MAF / MAP or NO correction.'); +end; + +str1 = ''; +if Npnts <= 0, + str1 = 'No interpolation. Output original table.'; + frqNpnts = frqTbl; + CrctdB = CrctTbl; +else + frqNpnts = (0:Npnts-1)'/Npnts * SR/2; + if strcmp(upper(StrCrct(1:2)), 'NO'), + CrctdB = zeros(size(frqNpnts)); + else + str1 = 'Spline interpolated value in equal frequency spacing.'; + CrctdB = spline(frqTbl,CrctTbl,frqNpnts); + end; +end; + +if SwPlot == 1, + disp(['*** Outer/Middle Ear Transfer Function ( ' ... + upper(StrCrct) ' Correction ) ***']); + disp(str1); + plot(frqTbl,CrctTbl,frqNpnts,CrctdB,'o'); +end; + +CrctLinPwr = 10.^(-CrctdB/10); % in Linear Power + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/maf/OutMidCrctFilt.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/maf/OutMidCrctFilt.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,62 @@ +% +% Produce compensation filter to simulate outer/middle ear +% IRINO Toshio +% 29 Aug. 1996 (check on 14 May 1997 ) +% 8 Jan. 2002 (Multiply Win for avoid sprious) +% 19 Nov. 2002 (remez : even integer) +% +% It is a linear phase filter for the ELC/MAF/MAP correction. +% see OutMidCrct.m +% +% function [FIRCoef] = OutMidCrctFilt(StrCrct,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% SR: Sampling Rate +% SwPlot: SwPlot +% OUTPUT FIRCoef: FIR filter coefficients +% +function [FIRCoef] = OutMidCrctFilt(StrCrct,SR,SwPlot); + +if nargin < 2, help OutMidCrctFilt; end; +if nargin < 3, SwPlot = 1; end; + +if length(StrCrct)~=3, + error('Specifiy correction in 3 characters: ELC / MAF / MAP.'); +end; +if ~(strcmp(upper(StrCrct(1:3)), 'ELC') | ... + strcmp(upper(StrCrct(1:3)),'MAF') ... + | strcmp(upper(StrCrct(1:3)),'MAP')), + error('Specifiy correction: ELC / MAF / MAP.'); +end; + +Nint = 1024; +% Nint = 0; % No spline interpolation: NG no convergence at remez +[crctPwr freq] = OutMidCrct(StrCrct,Nint,SR,0); +crct = sqrt(crctPwr); + +%% FIRCoef = remez(50/16000*SR,freq/SR*2,crct); % NG +%% FIRCoef = remez(300/16000*SR,freq/SR*2,crct); % Original +% FIRCoef = remez(LenCoef/16000*SR,freq/SR*2,crct); % when odd num : warning +%% modified on 8 Jan 2002, 19 Nov 2002 +LenCoef = 200; % ( -45 dB) <- 300 (-55 dB) +FIRCoef = remez(fix(LenCoef/16000*SR/2)*2,freq/SR*2,crct); % even number only +Win = TaperWindow(length(FIRCoef),'han',LenCoef/10); + % Necessary to avoid sprious +FIRCoef = Win.*FIRCoef; + +if SwPlot==1 + [frsp freq2] = freqz(FIRCoef,1,Nint,SR); + subplot(2,1,1) + plot(FIRCoef); + subplot(2,1,2) + plot(freq2,abs(frsp),freq,crct,'--') + % plot(freq2,20*log10(abs(frsp)),freq,20*log10(crct)) + + ELCError = mean((abs(frsp) - crct).^2)/mean(crct.^2); + ELCErrordB = 10*log10(ELCError) % corrected + if ELCErrordB > -30, + disp(['Warning: Error in ELC correction = ' ... + num2str(ELCErrordB) ' dB > -30 dB']) + end; +end; + +return; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/maf/TaperWindow.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/maf/TaperWindow.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,76 @@ +% +% Taper Window Generator for signal onset/offset +% 7 Apr. 1993 +% 29 Aug. 96 +% IRINO Toshio +% +% function [TaperWin, TypeTaper] = ... +% TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) +% INPUT LenWin : Length of Window (Number of points) +% TypeTaper : Type of Taper (KeyWords of 3 letters) +% (Hamming, Hanning (=cosine^2), Blackman, Gauss, Line) +% LenTaper : Length of Taper (Number of points) +% RangeSigma: Range in Sigma (default: 3) for Gauss +% SwPlot : 0) Omit plotting, 1) Plot Taper +% OUTPUT TaperWin : Taper Window Points (max==1); +% TypeTaper : Type of Taper (Full Name) +% +function [TaperWin, TypeTaper] = ... + TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) + +if nargin < 2, +help TaperWindow +error([ 'Specify Type of Taper : ' ... + ' Hamming, Hanning (=cosine^2), Blackman, Gauss, Line ']); +%TaperWin = ones(1,LenWin); +%return; +end; + +if nargin < 3, LenTaper = fix(LenWin/2); end; +if nargin < 4, RangeSigma = 3; end; + +if LenTaper*2 >= LenWin, + disp('Caution (TaperWindow.m) : No flat part. '); + if LenTaper ~= fix(LenWin/2), + disp('Caution (TaperWindow.m) : LenTaper <-- fix(LenWin/2)'); + end; + LenTaper = fix(LenWin/2); +end; + +if nargin < 5, SwPlot = 0; end; % changing default Swplot 29 Aug. 96 + +%TypeTaper = lower(TypeTaper(1:3)); + +if upper(TypeTaper(1:3)) == 'HAM', + Taper = hamming(LenTaper*2)'; + TypeTaper = 'Hamming'; +elseif upper(TypeTaper(1:3)) == 'HAN' | upper(TypeTaper(1:3)) == 'COS', + Taper = hanning(LenTaper*2)'; + TypeTaper = 'Hanning/Cosine'; +elseif upper(TypeTaper(1:3)) == 'BLA', + Taper = blackman(LenTaper*2)'; + TypeTaper = 'Blackman'; +elseif upper(TypeTaper(1:3)) == 'GAU', + if length(RangeSigma) == 0, RangeSigma = 3; end; + nn = -LenTaper+0.5:1:LenTaper-0.5; + Taper = exp(-(RangeSigma*nn/LenTaper).^2 /2); + TypeTaper = 'Gauss'; +else Taper = [1:LenTaper LenTaper:-1:1]/LenTaper; % 'line', + TypeTaper = 'Line'; +end; + +%plot(Taper) +%size(Taper); +LenTaper = fix(LenTaper); +TaperWin = [ Taper(1:LenTaper) ones(1,LenWin-LenTaper*2) ... + Taper(LenTaper+1:LenTaper*2)]; + +if SwPlot == 1, + +plot(TaperWin) +xlabel('Points'); +ylabel('Amplitude'); +title(['TypeTaper = ' TypeTaper] ); + +end; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/maf/genmaf.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/maf/genmaf.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,43 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function sig=genome(sig,options) +% generating function for the outer/middle ear transfere function + +waithand=waitbar(0,'generating pre cochlea processing'); + +samplerate=getsr(sig); +start_time=getminimumtime(sig); + + + firfiltercoef = OutMidCrctFilt('MAF',samplerate,0); + + +% to compensate the huge delay from the filter, a pause is added to the +% signal, that is taken away in the end: +pause=signal(abs(options.delay_correction),samplerate); +sig=setstarttime(sig,0); +sig=append(sig,pause); + +Snd=getvalues(sig); +Snd=Snd'; +Snd = filter(firfiltercoef,1,Snd); + +sig=setvalues(sig,Snd); + +%take the delay back: +siglen=getlength(sig); +sig=getpart(sig,abs(options.delay_correction),siglen); +sig=setstarttime(sig,start_time); + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/maf/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/maf/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,17 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ +%%%%%%%%%%%%% +% outer/middle ear filter function +% hidden parameters +maf.generatingfunction='genmaf'; +maf.displayname='outer/middle ear transfere function: Minimum Audible Field'; +maf.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +maf.delay_correction=-0.0063; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/map/OutMidCrct.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/map/OutMidCrct.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,90 @@ +% +% Correction of ELC, MAF, MAP +% IRINO Toshio +% 18 Mar 96 +% 29 Aug 96 renamed AFShapeCrct -> OutMidCrct +% 14 May 97 option of Direct Output +% +% It produces interpolated points for the ELC/MAF/MAP correction. +% +% Reference: +% Glassberg and Moore (1990) +% "Derivation of auditory filter shapes from notched noise data" +% Hearing Research, 47 , pp.103-138. +% +% function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% Npnts: Number of data points, if zero, then direct out. +% SR: Sampling Rate +% SwPlot: Switch for plot +% OUTPUT CrctLinPwr : Correction value in LINEAR POWER +% frqNpnts: Corresponding Frequency at the data point +% CrctdB: Correction value in dB +% +function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR,SwPlot); + +if nargin < 1, help OutMidCrct; end; +if nargin < 2, Npnts = 0; end; +if nargin < 3, SR = 32000; end; +if nargin < 4, SwPlot = 1; end; + +f1 = [ 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, ... + 125, 150, 177, 200, 250, 300, 350, 400, 450, 500, 550, ... + 600, 700, 800, 900, 1000, 1500, 2000, 2500, 2828, 3000, ... + 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, ... + 12748, 15000]; + +ELC = [ 31.8, 26.0, 21.7, 18.8, 17.2, 15.4, 14.0, 12.6, 11.6, 10.6, ... + 9.2, 8.2, 7.7, 6.7, 5.3, 4.6, 3.9, 2.9, 2.7, 2.3, ... + 2.2, 2.3, 2.5, 2.7, 2.9, 3.4, 3.9, 3.9, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +MAF = [ 73.4, 65.2, 57.9, 52.7, 48.0, 45.0, 41.9, 39.3, 36.8, 33.0, ... + 29.7, 27.1, 25.0, 22.0, 18.2, 16.0, 14.0, 11.4, 9.2, 8.0, ... + 6.9, 6.2, 5.7, 5.1, 5.0, 5.0, 4.4, 4.3, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +f2 = [ 125, 250, 500, 1000, 1500, 2000, 3000, ... + 4000, 6000, 8000,10000,12000,14000,16000]; +MAP = [ 30.0, 19.0, 12.0, 9.0, 11.0, 16.0, 16.0, ... + 14.0, 14.0, 9.9, 24.7, 32.7, 44.1, 63.7]; + +frqTbl = []; +CrctTbl = []; +if length(StrCrct)==3 + if strcmp(upper(StrCrct(1:3)),'ELC'), frqTbl = f1'; CrctTbl = ELC'; + elseif strcmp(upper(StrCrct(1:3)),'MAF'), frqTbl = f1'; CrctTbl = MAF'; + elseif strcmp(upper(StrCrct(1:3)),'MAP'), frqTbl = f2'; CrctTbl = MAP'; + else error('Specifiy correction: ELC / MAF / MAP or NO correction.'); + end; +elseif length(StrCrct)~=2, + error('Specifiy correction: ELC / MAF / MAP or NO correction.'); +end; + +str1 = ''; +if Npnts <= 0, + str1 = 'No interpolation. Output original table.'; + frqNpnts = frqTbl; + CrctdB = CrctTbl; +else + frqNpnts = (0:Npnts-1)'/Npnts * SR/2; + if strcmp(upper(StrCrct(1:2)), 'NO'), + CrctdB = zeros(size(frqNpnts)); + else + str1 = 'Spline interpolated value in equal frequency spacing.'; + CrctdB = spline(frqTbl,CrctTbl,frqNpnts); + end; +end; + +if SwPlot == 1, + disp(['*** Outer/Middle Ear Transfer Function ( ' ... + upper(StrCrct) ' Correction ) ***']); + disp(str1); + plot(frqTbl,CrctTbl,frqNpnts,CrctdB,'o'); +end; + +CrctLinPwr = 10.^(-CrctdB/10); % in Linear Power + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/map/OutMidCrctFilt.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/map/OutMidCrctFilt.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,62 @@ +% +% Produce compensation filter to simulate outer/middle ear +% IRINO Toshio +% 29 Aug. 1996 (check on 14 May 1997 ) +% 8 Jan. 2002 (Multiply Win for avoid sprious) +% 19 Nov. 2002 (remez : even integer) +% +% It is a linear phase filter for the ELC/MAF/MAP correction. +% see OutMidCrct.m +% +% function [FIRCoef] = OutMidCrctFilt(StrCrct,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% SR: Sampling Rate +% SwPlot: SwPlot +% OUTPUT FIRCoef: FIR filter coefficients +% +function [FIRCoef] = OutMidCrctFilt(StrCrct,SR,SwPlot); + +if nargin < 2, help OutMidCrctFilt; end; +if nargin < 3, SwPlot = 1; end; + +if length(StrCrct)~=3, + error('Specifiy correction in 3 characters: ELC / MAF / MAP.'); +end; +if ~(strcmp(upper(StrCrct(1:3)), 'ELC') | ... + strcmp(upper(StrCrct(1:3)),'MAF') ... + | strcmp(upper(StrCrct(1:3)),'MAP')), + error('Specifiy correction: ELC / MAF / MAP.'); +end; + +Nint = 1024; +% Nint = 0; % No spline interpolation: NG no convergence at remez +[crctPwr freq] = OutMidCrct(StrCrct,Nint,SR,0); +crct = sqrt(crctPwr); + +%% FIRCoef = remez(50/16000*SR,freq/SR*2,crct); % NG +%% FIRCoef = remez(300/16000*SR,freq/SR*2,crct); % Original +% FIRCoef = remez(LenCoef/16000*SR,freq/SR*2,crct); % when odd num : warning +%% modified on 8 Jan 2002, 19 Nov 2002 +LenCoef = 200; % ( -45 dB) <- 300 (-55 dB) +FIRCoef = remez(fix(LenCoef/16000*SR/2)*2,freq/SR*2,crct); % even number only +Win = TaperWindow(length(FIRCoef),'han',LenCoef/10); + % Necessary to avoid sprious +FIRCoef = Win.*FIRCoef; + +if SwPlot==1 + [frsp freq2] = freqz(FIRCoef,1,Nint,SR); + subplot(2,1,1) + plot(FIRCoef); + subplot(2,1,2) + plot(freq2,abs(frsp),freq,crct,'--') + % plot(freq2,20*log10(abs(frsp)),freq,20*log10(crct)) + + ELCError = mean((abs(frsp) - crct).^2)/mean(crct.^2); + ELCErrordB = 10*log10(ELCError) % corrected + if ELCErrordB > -30, + disp(['Warning: Error in ELC correction = ' ... + num2str(ELCErrordB) ' dB > -30 dB']) + end; +end; + +return; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/map/TaperWindow.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/map/TaperWindow.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,76 @@ +% +% Taper Window Generator for signal onset/offset +% 7 Apr. 1993 +% 29 Aug. 96 +% IRINO Toshio +% +% function [TaperWin, TypeTaper] = ... +% TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) +% INPUT LenWin : Length of Window (Number of points) +% TypeTaper : Type of Taper (KeyWords of 3 letters) +% (Hamming, Hanning (=cosine^2), Blackman, Gauss, Line) +% LenTaper : Length of Taper (Number of points) +% RangeSigma: Range in Sigma (default: 3) for Gauss +% SwPlot : 0) Omit plotting, 1) Plot Taper +% OUTPUT TaperWin : Taper Window Points (max==1); +% TypeTaper : Type of Taper (Full Name) +% +function [TaperWin, TypeTaper] = ... + TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) + +if nargin < 2, +help TaperWindow +error([ 'Specify Type of Taper : ' ... + ' Hamming, Hanning (=cosine^2), Blackman, Gauss, Line ']); +%TaperWin = ones(1,LenWin); +%return; +end; + +if nargin < 3, LenTaper = fix(LenWin/2); end; +if nargin < 4, RangeSigma = 3; end; + +if LenTaper*2 >= LenWin, + disp('Caution (TaperWindow.m) : No flat part. '); + if LenTaper ~= fix(LenWin/2), + disp('Caution (TaperWindow.m) : LenTaper <-- fix(LenWin/2)'); + end; + LenTaper = fix(LenWin/2); +end; + +if nargin < 5, SwPlot = 0; end; % changing default Swplot 29 Aug. 96 + +%TypeTaper = lower(TypeTaper(1:3)); + +if upper(TypeTaper(1:3)) == 'HAM', + Taper = hamming(LenTaper*2)'; + TypeTaper = 'Hamming'; +elseif upper(TypeTaper(1:3)) == 'HAN' | upper(TypeTaper(1:3)) == 'COS', + Taper = hanning(LenTaper*2)'; + TypeTaper = 'Hanning/Cosine'; +elseif upper(TypeTaper(1:3)) == 'BLA', + Taper = blackman(LenTaper*2)'; + TypeTaper = 'Blackman'; +elseif upper(TypeTaper(1:3)) == 'GAU', + if length(RangeSigma) == 0, RangeSigma = 3; end; + nn = -LenTaper+0.5:1:LenTaper-0.5; + Taper = exp(-(RangeSigma*nn/LenTaper).^2 /2); + TypeTaper = 'Gauss'; +else Taper = [1:LenTaper LenTaper:-1:1]/LenTaper; % 'line', + TypeTaper = 'Line'; +end; + +%plot(Taper) +%size(Taper); +LenTaper = fix(LenTaper); +TaperWin = [ Taper(1:LenTaper) ones(1,LenWin-LenTaper*2) ... + Taper(LenTaper+1:LenTaper*2)]; + +if SwPlot == 1, + +plot(TaperWin) +xlabel('Points'); +ylabel('Amplitude'); +title(['TypeTaper = ' TypeTaper] ); + +end; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/map/genmap.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/map/genmap.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,42 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function sig=genome(sig,options) +% generating function for the outer/middle ear transfere function + +waithand=waitbar(0,'generating pre cochlea processing'); + +samplerate=getsr(sig); +start_time=getminimumtime(sig); + + + firfiltercoef = OutMidCrctFilt('MAP',samplerate,0); + + +% to compensate the huge delay from the filter, a pause is added to the +% signal, that is taken away in the end: +pause=signal(abs(options.delay_correction),samplerate); +sig=setstarttime(sig,0); +sig=append(sig,pause); + +Snd=getvalues(sig); +Snd=Snd'; +Snd = filter(firfiltercoef,1,Snd); + +sig=setvalues(sig,Snd); + +%take the delay back: +siglen=getlength(sig); +sig=getpart(sig,abs(options.delay_correction),siglen); +sig=setstarttime(sig,start_time); + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/map/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/map/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,16 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% outer/middle ear filter function +% hidden parameters +map.generatingfunction='genmap'; +map.displayname='outer/middle ear transfere function Minimum Audible Pressures'; +map.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +map.delay_correction=-0.0063; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/none/gennopcp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/none/gennopcp.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function sig=genopcp(sig,options) +% generating function for the outer/middle ear transfere function + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/pcp/none/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/pcp/none/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,15 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% outer/middle ear filter function +% hidden parameters +none.generatingfunction='gennopcp'; +none.displayname='no correction by outer/middle ear'; +none.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti1992/gen_ti1992.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti1992/gen_ti1992.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,225 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% the old temporal integration module. Puts add every strobe point a copy +% of the past signal in the buffer +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function returnframes=gen_ti1992(nap,strobes,options) +% calculates the stablized image from the data given in options + + +returnframes=[]; + +% option, how long the whole auditory image is: +if isfield(options,'maxdelay') + maxdelay=options.maxdelay; +else + maxdelay=0.035; +end + +% how fast the values decay by themself +if isfield(options,'buffer_memory_decay') + buffer_memory_decay=options.buffer_memory_decay; +else + buffer_memory_decay=0.03; +end + +% how the values are weighted by their time before they are added in the +% buffer. +if isfield(options,'buffer_tilt_time') + buffer_tilt_time=options.buffer_tilt_time; +else + buffer_tilt_time=0.04; % 40 ms standart +end + +% how often a current frame buffer is saved +if isfield(options,'frames_per_second') + frames_per_second=options.frames_per_second; +else + frames_per_second=100; +end + +len=getlength(nap); +output_times=0:1/frames_per_second:len; +nr_output_times=length(output_times); % so many pictures in the end + + +% construct the starting SAI with zeros +sr=getsr(nap); +sampletime=1/sr; +nrdots_insai=round(options.maxdelay*sr); + +const_memory_decay=power(0.5,1/(options.buffer_memory_decay*sr)); % the amount per sampletime +signal_start_time=getminimumtime(nap); + + + +% helping variables to speed things up +nr_channels=getnrchannels(nap); +for ii=1:nr_channels + if length(strobes{ii}.strobes) > 0 + next_strobe(ii)=strobes{ii}.strobes(1); % the next strobe in line + else + next_strobe(ii)=inf; % no strobe + end + last_strobe(ii)=-inf; % the last strobe in this channel + current_strobe_nr(ii)=1; % the current number of the strobe which is processed + nr_active_strobes(ii)=0; % the number of active strobes in memory + strobe_adjust_phase(ii)=inf; % the next update of weights + was_adjusted(ii)=0; +end +nr_maximal_strobes=20; +stropo_time=zeros(nr_channels,nr_maximal_strobes); % no active strobes in queue +copy_stropo_time=stropo_time; +stropo_weight=zeros(nr_channels,nr_maximal_strobes); % no active strobes in queue + +maxst=0; +for ii=1:nr_channels % make strobes faster + maxstg=length(strobes{ii}.strobes); + maxst=max(maxst,maxstg); +end +allstrobes=zeros(nr_channels,maxst); +for ii=1:nr_channels % make strobes faster + nr_str_total=length(strobes{ii}.strobes); + allstrobes(ii,1:nr_str_total)=strobes{ii}.strobes; + allstrobesval(ii,1:nr_str_total)=strobes{ii}.strobe_vals; + nrstrobes(ii)=nr_str_total; + % allchannelallstrobes(ii)=allstrobes(ii,1:nr_str_total); % all the strobes in this channel +end + +output_counter=1; +nr_dots=getnrpoints(nap); +current_time=signal_start_time; +times_per_ms=round(sr*0.002); +cfs=getcf(nap); +napvalues=getvalues(nap); +count=0; +tic; + +saibuffer=zeros(nr_channels,nrdots_insai); +waithand=waitbar(0,'generating SAI'); + +% and go! +for bintime=1:nr_dots + if mod(bintime,times_per_ms)==0 + waitbar(bintime/nr_dots); + end + current_time=current_time+sampletime; + + for channel_nr=1:nr_channels +% for channel_nr=25 + current_cf=cfs(channel_nr); + nr_str_total=nrstrobes(channel_nr); + % find out, if a new strobe arrived + this_strobe_time=next_strobe(channel_nr); % here is the next strobe + nr_current_str=current_strobe_nr(channel_nr); + channelallstrobes=allstrobes(channel_nr,1:nr_str_total); % all the strobes in this channel + + if current_time > this_strobe_time % if we are beyond the next strpbe + + % calculate the time of the next strobe + if nr_current_str < nrstrobes(channel_nr) % define the next strobe + next_strobe(channel_nr) =channelallstrobes(nr_current_str + 1); + else + next_strobe(channel_nr)=inf; % if no more strobes we will never get here any more + end + nr_current_str=nr_current_str+1; + current_strobe_nr(channel_nr)=nr_current_str; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % copy the whole signal from the past in the buffer + current_time_int=floor((current_time-signal_start_time)/sampletime); + start_time_int=current_time_int-nrdots_insai+1; + if start_time_int > 0 % if bejond 35 ms + % the signal, that we want to add to the buffer + addsig=napvalues(channel_nr,start_time_int:current_time_int); + else % not enough signal yet! Pat with zeros + zerosig=zeros(1,-start_time_int+1); + len=current_time_int; % copy this number + start_time_int=1; + addsigval=napvalues(channel_nr,start_time_int:len); + addsig=[zerosig addsigval]; % append them + end + % now in addsig is the complete signal before the strobe + % that is tilted with time: + + dt=buffer_tilt_time*sr-nrdots_insai; % übrige Zeit, die links aus dem Bild rausgeht + dnull=dt/nrdots_insai; + ti=linspace(dnull,1,nrdots_insai); + addsig=addsig.*ti; + addsig=addsig(end:-1:1); + + % build in + saibuffer(channel_nr,:)=saibuffer(channel_nr,:)+addsig; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + end + end + + saibuffer=saibuffer*const_memory_decay; + + % output finished frames at the appropriate times + if current_time >= output_times(output_counter) + resframes{output_counter}=saibuffer; + output_counter=output_counter+1; + if output_counter >nr_output_times + break; % no need to go on! + end + end +end + +% translate the arrays from data to frames +nrfrms=length(resframes); +start_time=getminimumtime(nap); % start time of first frame +if nrfrms>1 + interval=output_times(2)-output_times(1); +else + interval=0; % doesnt matter... +end +maxval=-inf; +maxsumval=-inf; +maxfreval=-inf; +cfs=getcf(nap); + +if nr_channels>1 + for ii=1:nrfrms + cfr=frame(resframes{ii}); + maxv=getmaximumvalue(cfr); + maxval=max([maxv maxval]); + maxs=max(getsum(cfr)); + maxsumval=max([maxs maxsumval]); + maxf=max(getfrequencysum(cfr)); + maxfreval=max([maxf maxfreval]); + end +else + maxfreval=1; + maxsumval=1; + maxval=max(resframes{nrfrms}); + minval=0; +end + +for ii=1:nrfrms + cfr=frame(resframes{ii}); + cfr=setsr(cfr,sr); + cfr=setcurrentframenumber(cfr,ii); + cfr=setcurrentframestarttime(cfr,start_time); + cfr=setcf(cfr,cfs); + start_time=start_time+interval; + cfr=setscalesumme(cfr,maxsumval); + cfr=setallmaxvalue(cfr,maxval); + cfr=setallminvalue(cfr,0); + cfr=setscalefrequency(cfr,maxfreval); + returnframes{ii}=cfr; +end + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti1992/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti1992/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,21 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ +%%%%%%%%%%%%% +% sai +% hidden parameters +ti1992.generatingfunction='gen_ti1992'; +ti1992.displayname='time integration stabilized auditory image old model'; +ti1992.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +ti1992.buffer_memory_decay=0.03; +ti1992.buffer_tilt=0.04; % memory decay in the buffer +ti1992.maxdelay=0.035; +ti1992.mindelay=0.001; +ti1992.frames_per_second=100; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti2003/gen_grouped.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti2003/gen_grouped.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,52 @@ +% generating function for 'aim-mat' +%function returnframes=gen_ti2003(nap,strobes,options) +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% time integration +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function returnframes=gen_grouped(nap,strobes,options) +% calculates the stablized image from the data given in options + + +if ~isfield(strobes,'grouped') + error('does only work with strobes ''grouping'''); +end +nr_sources=size(strobes.cross_strobes{1}.source_cross_channel_value,2); + +% Aufteilen auf Quellen (nur über und unter Hälfte) +nr_chan=getnrchannels(nap); + +% for ii=1:nr_sources +for ii=2:2 + for jj=1:nr_chan + newstrobes{jj}.strobes=strobes.cross_strobes{jj}.strobe_times; + newstrobes{jj}.strobe_vals=strobes.cross_strobes{jj}.strobe_vals; + newstrobes{jj}.strobe_weights=strobes.cross_strobes{jj}.source_cross_channel_value(:,ii); + end + + options.criterion='fixed_weights'; + options.start_time=0; + options.maxdelay=0.035; + options.buffer_memory_decay=0.03; + options.frames_per_second=200; + options.weight_threshold=0; + options.do_normalize=1; + options.do_adjust_weights=1; + options.strobe_weight_alpha=0.5; + options.delay_weight_change=0.5; + options.mindelay=0.001; + retfr=gen_ti2003(nap,newstrobes,options); + +end +returnframes=retfr; +return + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti2003/gen_ti2003.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti2003/gen_ti2003.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,605 @@ +% generating function for 'aim-mat' +%function returnframes=gen_ti2003(nap,strobes,options) +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% time integration +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function returnframes=gen_ti2003(nap,strobes,options) +% calculates the stablized image from the data given in options + + +if isfield(options,'do_click_reduction'); + do_click_reduction=options.do_click_reduction; + if do_click_reduction + try + load(options.click_reduction_sai); + catch + error('cant load file for click reduction. Generate it with ''generate_clicktrain_normal'''); + end + % load click_frame; + end +else + do_click_reduction=0; +end + +if isfield(options,'single_channel_do') + single_channel_do=logical(options.single_channel_do); +else + single_channel_do=logical(false); +end + +if isfield(options,'do_times_nap_height') + donapheight=options.do_times_nap_height; % if the strobe height has an influence +else + donapheight=0; % not per default +end + + +if isfield(options,'single_channel_channel_nr') + single_channel_channel_nr=options.single_channel_channel_nr; +else + single_channel_channel_nr=0; +end +if isfield(options,'single_channel_time_step') + single_channel_time_step=options.single_channel_time_step; + graphic_times=single_channel_time_step:single_channel_time_step:getlength(nap); % each ms + next_graphic=graphic_times(1); + current_graphic=1; +else + next_graphic=[]; + current_graphic=0; + graphic_times=[]; +end + + +if isfield(options,'select_channel_center_frequency') + % center frequency for the selection (off, if 0) + select_channel_center_frequency=options.select_channel_center_frequency; + if select_channel_center_frequency > 0 + select_certain_channels=1; + % upper and lower bound of selection in octaves + select_channel_frequency_above=options.select_channel_frequency_range_above; + select_channel_frequency_below=options.select_channel_frequency_range_below; + + % calculate, which channels are wanted, and wich are not + min_selected_frequency=select_channel_center_frequency/power(2,select_channel_frequency_below); + max_selected_frequency=select_channel_center_frequency*power(2,select_channel_frequency_above); + + %if 1, then all are calculated, and selected are plotted in other color + if options.select_channel_calculate_all==1; + select_certain_channels=0; + end + else + select_certain_channels=0; + end +else + select_certain_channels=0; +end + +returnframes=[]; +maxdelay=options.maxdelay; +mindelay=options.mindelay; +% the weight of a strobe is determined by the time since the last strobe +% adjusted by the following constant: (decay from 100% to 0%) +% delay_time_strobe_weight_decay=options.delay_time_strobe_weight_decay; +len=getlength(nap); +fps=options.frames_per_second; +output_times=0:1/fps:len; +output_times=output_times+getminimumtime(nap); +nr_output_times=length(output_times); % so many pictures in the end +output_counter=1; +% construct the starting SAI with zeros +sr=getsr(nap); +sampletime=1/sr; +nrdots_insai=round(options.maxdelay*sr); +const_memory_decay=power(0.5,1/(options.buffer_memory_decay*sr)); % the amount per sampletime +signal_start_time=getminimumtime(nap); +nr_channels=getnrchannels(nap); +% calculate the initial strobe times in the past +for ii=1:nr_channels + if length(strobes{ii}.strobes) > 0 + next_strobe(ii)=strobes{ii}.strobes(1); % the next strobe in line + else + next_strobe(ii)=inf; % no strobe + end + last_strobe(ii)=-inf; % the last strobe in this channel + current_strobe_nr(ii)=1; % the current number of the strobe which is processed + nr_active_strobes(ii)=0; % the number of active strobes in memory + last_strobe(ii)=-inf; % the last strobe was long ago + strobe_adjust_phase(ii)=inf; % the next update of weights + was_adjusted(ii)=0; +end +nr_maximal_strobes=100; +stropo_time=zeros(nr_channels,nr_maximal_strobes); % no active strobes in queue +copy_stropo_time=stropo_time; +stropo_weight=zeros(nr_channels,nr_maximal_strobes); % no active strobes in queue +stropo_org_weight=zeros(nr_channels,nr_maximal_strobes); % the weight of each strobe at generation point + +% calculate the inital strobe settings in one variable (accelleration) +maxst=0; +for ii=1:nr_channels % make strobes faster + maxstg=length(strobes{ii}.strobes); + maxst=max(maxst,maxstg); +end +allstrobes=zeros(nr_channels,maxst); +for ii=1:nr_channels % make strobes faster + nr_str_total=length(strobes{ii}.strobes); + allstrobes(ii,1:nr_str_total)=strobes{ii}.strobes; + allstrobesval(ii,1:nr_str_total)=strobes{ii}.strobe_vals; + nrstrobes(ii)=nr_str_total; +end + +do_fixed_weights=0; +if strcmp(options.criterion,'fixed_weights') + do_fixed_weights=1; + fixed_weights=zeros(nr_channels,100); + for ii=1:nr_channels + a=strobes{ii}.strobe_weights; + fixed_weights(ii,1:length(a))=a'; + end +end + +nr_dots=getnrpoints(nap); +current_time=signal_start_time; +times_per_ms=round(sr*0.005); % how often the bar should be updated +cfs=getcf(nap); +napvalues=getvalues(nap); +count=0; +tic; + +% copy some vairables +weight_threshold=options.weight_threshold; +strobe_weight_alpha=options.strobe_weight_alpha; +delay_weight_change=options.delay_weight_change; +% criterion=options.criterion; +do_adjust_weights=options.do_adjust_weights; +do_normalize=options.do_normalize; % if weights are do_normalized + +% each strobe induces strobes in neighboring channels in this +% vicinity: +if isfield(options,'erb_frequency_integration') + erb_strobe_width=options.erb_frequency_integration; + erbdensity=erbdensity(nap); + nrintegrate=round(erbdensity*erb_strobe_width); + do_interchannel_interaction=1; +else + do_interchannel_interaction=0; + nrintegrate=0; +end +% if strcmp(criterion,'integrate_erbs') +% % define the integration area for each channel in frequency and time +% erbsearchwidth=options.erb_frequency_integration; +% erbdensity=erbdensity(nap); +% nrintegrate=round(erbdensity*erbsearchwidth); +% +% for ii=1:nr_channels +% % the frequency window +% a=ii+(-nrintegrate:nrintegrate); +% a(find(a<0))=0; +% a(find(a>nr_channels))=0; +% a(find(a==ii))=0; % dont search in the identical channel +% +% neighboring_channels(ii,:)=a; +% +% % the time window +% current_cf=cfs(ii); +% timewindow_start(ii)=-1/current_cf; +% timewindow_stop(ii)=1/current_cf; +% end +% end +% + +% Beschleunigung der Berechnung durch vorziehen der Schleife: +% der Einfluß der Zeit: je mehr Strobes da sind, +% umso unwichtiger werden die älteren: +% adapt the weights of all the old strobes +weighfactor=ones(nr_maximal_strobes); +if do_adjust_weights %only if wanted + for ii=1:nr_maximal_strobes + for jj=1:ii + wfactor=power(1/(ii-jj+1),strobe_weight_alpha); + weighfactor(ii,jj)=wfactor; + end + end +end + + +if single_channel_do==1 + oldfigure=gcf; + onechannelfigure=figure(1954211404); % some strange number that should not be an existing figure + set(onechannelfigure,'name','Dynamic single channel'); + set(onechannelfigure,'numbertitle','off'); +end + +saibuffer=zeros(nr_channels,nrdots_insai); +if nr_channels>1 + waithand=waitbar(0,'generating SAI'); +end + +for bintime=1:nr_dots + if nr_channels>1 + if mod(bintime,times_per_ms)==0 + waitbar(bintime/nr_dots); + end + end + + + current_time=current_time+sampletime; + for channel_nr=1:nr_channels + % for channel_nr=25 + current_cf=cfs(channel_nr); + + if select_certain_channels + if current_cf < min_selected_frequency || current_cf > max_selected_frequency + continue; % outside wanted range, no need to calculate! + end + end + + nr_str_total=nrstrobes(channel_nr); + channelallstrobes=allstrobes(channel_nr,1:nr_str_total); % all the strobes in this channel + nr_active_str=nr_active_strobes(channel_nr); + nr_current_str=current_strobe_nr(channel_nr); + + % find out, if a new strobe arrived + this_strobe_time=next_strobe(channel_nr); % here is the next strobe + if current_time > this_strobe_time % if we are beyond the next strpbe + + if nr_current_str < nrstrobes(channel_nr) % define the next strobe + next_strobe(channel_nr) =channelallstrobes(nr_current_str + 1); + else + next_strobe(channel_nr)=inf; % if no more strobes we will never get here any more + end + nr_current_str=nr_current_str+1; + + % if strcmp(criterion,'integrate_erbs') + % % find out, which weight this strobe has by integration over + % % time and frequency of the neighbouring strobes + % t1=timewindow_start(channel_nr)+current_time; + % t2=timewindow_stop(channel_nr)+current_time; + % strobeweight=zeros(nr_channels,1); + % normalizer=0; + % for chn=neighboring_channels(channel_nr,:); + % if chn>0 + % nrstr=nrstrobes(chn); + % chstr=allstrobes(chn,1:nrstr); % all strobes in this channel + % neistrobes=find(chstr>t1 & chstr= strobe_adjust_phase(channel_nr)); + logi2=~logical(was_adjusted(channel_nr)); % ugly, but accelerated + logi3= nr_active_str>0; + if logi1 && logi2 && logi3 + + % jetzt ist Zeit zum Adjusten, erst mal alle auf das + % Orginalgewicht (Zahl der Zyclen) + + % % jetzt der Einfluß der Zeit: je mehr Strobes da sind, + % % umso unwichtiger werden die älteren: + % % adapt the weights of all the old strobes + % weighfactor=ones(length(nr_active_str),1); + % if do_adjust_weights %only if wanted + % for ii=1:nr_active_str + % wfactor=power(1/(nr_active_str-ii+1),strobe_weight_alpha); + % weighfactor(ii)=wfactor; + % end + % else + % stropo_weight=stropo_org_weight; + % end + + if do_adjust_weights %only if wanted + wfactor=weighfactor(nr_active_str,:); + + + % und dann alle Strobes in diesem Kanal auf eins + % normieren, damit die Summe über alle Aktivität in jedem + % Channel immer gleich der Summe im Nap ist. + % normalise them to 1 + if do_normalize==1 + if nr_active_str>1 + sumweight=0; + for ii=1:nr_active_str + sumweight=sumweight+stropo_org_weight(channel_nr,ii)*wfactor(ii); + end + for ii=1:nr_active_str + tmp=stropo_org_weight(channel_nr,ii)*wfactor(ii); + tmp=tmp/sumweight; + stropo_weight(channel_nr,ii)=tmp; + end + end + end + else + stropo_weight=stropo_org_weight; + end % do_normalize + was_adjusted(channel_nr)=1; + end % strobe has arrived + + % delete old strobe processes + nr_deleted=0; + for ii=1:nr_active_str-nr_deleted + time_strobe=stropo_time(channel_nr,ii-nr_deleted); + delay=current_time-time_strobe; + weight=stropo_weight(channel_nr,ii-nr_deleted); + if delay > maxdelay || weight < weight_threshold % forget this strobe + stropo_time(channel_nr,ii-nr_deleted:end-1)=stropo_time(channel_nr,ii-nr_deleted+1:end); + stropo_weight(channel_nr,ii-nr_deleted:end-1)=stropo_weight(channel_nr,ii-nr_deleted+1:end); + stropo_org_weight(channel_nr,ii-nr_deleted:end-1)=stropo_org_weight(channel_nr,ii-nr_deleted+1:end); + nr_deleted=nr_deleted+1; + end + end + nr_active_str=nr_active_str-nr_deleted; + + % bug found by Federico Flego + % if nr_active_str-count~=0, allstrobesval(channel_nr,:)=shift(allstrobesval(channel_nr,:),-(nr_active_str-count)); + % end; + + % process all strobes + for ii=1:nr_active_str + time_strobe=stropo_time(channel_nr,ii); + delay=current_time-time_strobe; + if delay >= mindelay + current_time_int=floor((current_time-signal_start_time)/sampletime); + delayint=round(delay/sampletime); + weight=stropo_weight(channel_nr,ii); + +% if donapheight==0 % if the strobe heigt has influence +% weight=weight*allstrobesval(channel_nr,ii); +% end + + oldval=saibuffer(channel_nr,delayint); + newval=oldval+weight*napvalues(channel_nr,current_time_int); + saibuffer(channel_nr,delayint)=newval; % put the new value in the buffer at the correct position + + % interchannel interaction + if do_interchannel_interaction + for jj=channel_nr-nrintegrate:channel_nr+nrintegrate + if jj==ii || jj<1 || jj>nr_channels + continue + end + oldval=saibuffer(jj,delayint); + adjacent_weight=weight*(1-abs(jj-channel_nr)/(nrintegrate+1)); + newval=oldval+adjacent_weight*napvalues(jj,current_time_int); + saibuffer(jj,delayint)=newval; % put the new value in the buffer at the correct position + end + end + + end + end + + % save for the next run + current_strobe_nr(channel_nr)=nr_current_str; % strobe counter + nr_active_strobes(channel_nr)=nr_active_str; % active strobe counter + + % special graphics, when only one channel: display signal, + % threshold and strobe weights + if single_channel_do && channel_nr==single_channel_channel_nr + if current_time>=next_graphic + if current_graphic= output_times(output_counter) + if do_click_reduction + reduced_saibuffer=saibuffer; + for channel_nr=1:nr_channels + org_channel=saibuffer(channel_nr,:); + org_sig=signal(org_channel); + org_sig=setsr(org_sig,sr); + + clickvals_sig=getsinglechannel(click_frame,channel_nr); + + relevant_click_time=0.035; + clicksig=getpart(clickvals_sig,0,relevant_click_time); + % clicksig=changesr(clicksig,sr); + org_sig_part=getpart(org_sig,0,relevant_click_time); + maxval=max(org_sig); + clicksig=scaletomaxvalue(clicksig,maxval); + new_sig=org_sig-clicksig; + new_sig=halfwayrectify(new_sig); + + grafix=0; + if grafix==1 + figure(324234) + clf + hold on + plot(clicksig,'m'); + plot(org_sig,'b'); + plot(new_sig,'r'); + end + newvals=getvalues(new_sig); + reduced_saibuffer(channel_nr,:)=newvals'; + end + resframes{output_counter}=reduced_saibuffer; + else + resframes{output_counter}=saibuffer; + end + output_counter=output_counter+1; + if output_counter >nr_output_times + break; % no need to go on! + end + + end +end + + +if single_channel_do==1 + figure(oldfigure); +end + +% translate the arrays from data to frames +nrfrms=length(resframes); +start_time=getminimumtime(nap); % start time of first frame +if nrfrms>1 + interval=output_times(2)-output_times(1); +else + interval=0; % doesnt matter... +end +maxval=-inf; +maxsumval=-inf; +maxfreval=-inf; +cfs=getcf(nap); + +if nr_channels>1 + for ii=1:nrfrms + cfr=frame(resframes{ii}); + maxv=getmaximumvalue(cfr); + maxval=max([maxv maxval]); + maxs=max(getsum(cfr)); + maxsumval=max([maxs maxsumval]); + maxf=max(getfrequencysum(cfr)); + maxfreval=max([maxf maxfreval]); + end + +else + maxfreval=1; + maxsumval=1; + maxval=1; +end + + +for ii=1:nrfrms + cfr=frame(resframes{ii}); + cfr=setsr(cfr,sr); + cfr=setcurrentframenumber(cfr,ii); + cfr=setcurrentframestarttime(cfr,start_time); + cfr=setcf(cfr,cfs); + start_time=start_time+interval; + cfr=setscalesumme(cfr,maxsumval); + cfr=setallmaxvalue(cfr,maxval); + cfr=setallminvalue(cfr,0); + cfr=setscalefrequency(cfr,maxfreval); + returnframes{ii}=cfr; +end + +if nr_channels>1 + close(waithand); +end + + + +% function for one channel: Plot some nice graphic +function extraplot(onechannelfigure,napvalues,sr,current_time,maxdelay,options,bintime,nr_active_str,saibuffer,stropo_time,stropo_weight,channel_nr) + +persistent maxamp; % how big the biggest amplitude was so far +if isempty(maxamp) + maxamp=0; +end +figure(onechannelfigure); +subplot(2,1,1); % the signal, threshold and strobes: +cla +single_channel= signal(napvalues(channel_nr,:),sr); +maxval=max(single_channel); +siglen=getlength(single_channel); +threshold=getsinglechannel(options.thresholds,channel_nr); +if current_time < maxdelay + single_channel=getpart(single_channel,0,maxdelay); + threshold=getpart(threshold,0,maxdelay); +else + % try + single_channel=getpart(single_channel,current_time-maxdelay,current_time); + % catch + % a=0; + % end + threshold=getpart(threshold,current_time-maxdelay,current_time); +end +plot(single_channel,'-');hold on +ax=axis; +ax(4)=maxval*1.3; +axis(ax); +line([time2bin(single_channel,current_time) time2bin(single_channel,current_time)],[0 1],'Color','red'); +title('nap, threshold and strobes'); +thresholdvals=getvalues(threshold); +if current_timemaxamp + maxamp=max(buffer); +end +set(gca,'Ylim',[-0.00001 maxamp*1.1]); + +nr_labels=8; +tix=1:(nrx-1)/nr_labels:nrx; +xstep=(maximum_time_interval-minimum_time_interval)*1000/(nr_labels); %works from -35 to 5 +ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000+1]); +ti=ti(end:-1:1); +ti=round(ti*10)/10; +set(gca,'XScale','linear') +set(gca,'XTick',tix); +set(gca,'XTickLabel',ti); +xlabel('delay (ms)'); +title('buffer'); + +drawnow; +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti2003/gen_ti2003_mit autocor.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti2003/gen_ti2003_mit autocor.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,652 @@ +% generating function for 'aim-mat' +%function returnframes=gen_ti2003(nap,strobes,options) +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% time integration +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function returnframes=gen_ti2003(nap,strobes,options) +% calculates the stablized image from the data given in options + + +if isfield(options,'do_click_reduction'); + do_click_reduction=options.do_click_reduction; + if do_click_reduction + try + load(options.click_reduction_sai); + catch + error('cant load file for click reduction. Generate it with ''generate_clicktrain_normal'''); + end + % load click_frame; + end +else + do_click_reduction=0; +end + +if isfield(options,'single_channel_do') + single_channel_do=logical(options.single_channel_do); +else + single_channel_do=logical(false); +end +if isfield(options,'single_channel_channel_nr') + single_channel_channel_nr=options.single_channel_channel_nr; +else + single_channel_channel_nr=0; +end +if isfield(options,'single_channel_time_step') + single_channel_time_step=options.single_channel_time_step; + graphic_times=single_channel_time_step:single_channel_time_step:getlength(nap); % each ms + next_graphic=graphic_times(1); + current_graphic=1; +else + next_graphic=[]; + current_graphic=0; + graphic_times=[]; +end + + +if isfield(options,'select_channel_center_frequency') + % center frequency for the selection (off, if 0) + select_channel_center_frequency=options.select_channel_center_frequency; + if select_channel_center_frequency > 0 + select_certain_channels=1; + % upper and lower bound of selection in octaves + select_channel_frequency_above=options.select_channel_frequency_range_above; + select_channel_frequency_below=options.select_channel_frequency_range_below; + + % calculate, which channels are wanted, and wich are not + min_selected_frequency=select_channel_center_frequency/power(2,select_channel_frequency_below); + max_selected_frequency=select_channel_center_frequency*power(2,select_channel_frequency_above); + + %if 1, then all are calculated, and selected are plotted in other color + if options.select_channel_calculate_all==1; + select_certain_channels=0; + end + else + select_certain_channels=0; + end +else + select_certain_channels=0; +end + + + +%%%%%%%%%%%%%%%%%%%%%%%% +%%% init some local variables: + +returnframes=[]; % the return frames +maxdelay=options.maxdelay; +% the weight of a strobe is determined by the time since the last strobe +% adjusted by the following constant: (decay from 100% to 0%) +% delay_time_strobe_weight_decay=options.delay_time_strobe_weight_decay; +len=getlength(nap); % the length in seconds +fps=options.frames_per_second; +output_times=0:1/fps:len; +output_times=output_times+getminimumtime(nap); +nr_output_times=length(output_times); % so many pictures in the end +output_counter=1; +% construct the starting SAI with zeros +sr=getsr(nap); +sampletime=1/sr; +nrdots_insai=round(options.maxdelay*sr); +const_memory_decay=power(0.5,1/(options.buffer_memory_decay*sr)); % the amount per sampletime +signal_start_time=getminimumtime(nap); +nr_channels=getnrchannels(nap); + +% calculate the initial strobe times in the past +for ii=1:nr_channels + if length(strobes{ii}.strobes) > 0 + next_strobe(ii)=strobes{ii}.strobes(1); % the next strobe in line + else + next_strobe(ii)=inf; % no strobe + end + last_strobe(ii)=-inf; % the last strobe in this channel + current_strobe_nr(ii)=1; % the current number of the strobe which is processed + nr_active_strobes(ii)=0; % the number of active strobes in memory + last_strobe(ii)=-inf; % the last strobe was long ago + strobe_adjust_phase(ii)=inf; % the next update of weights + was_adjusted(ii)=0; +end + +nr_maximal_strobes=100; % there should never be more then 100 strobe processes active at the same time +% remember all strobe process times +stropo_time=zeros(nr_channels,nr_maximal_strobes); % no active strobes in queue +% remember the current weights of all strobes: +stropo_weight=zeros(nr_channels,nr_maximal_strobes); % no active strobes in queue +% remember the original weights of all strobes: +stropo_org_weight=zeros(nr_channels,nr_maximal_strobes); % the weight of each strobe at generation point + +% calculate the inital strobe settings in one variable (acceleration) +maxst=0; +for ii=1:nr_channels % make strobes faster + maxstg=length(strobes{ii}.strobes); + maxst=max(maxst,maxstg); +end +allstrobes=zeros(nr_channels,maxst); +for ii=1:nr_channels % make strobes faster + nr_str_total=length(strobes{ii}.strobes); + allstrobes(ii,1:nr_str_total)=strobes{ii}.strobes; + allstrobesval(ii,1:nr_str_total)=strobes{ii}.strobe_vals; + nrstrobes(ii)=nr_str_total; +end + +nr_dots=getnrpoints(nap); % so many points in time must be calculated +times_per_ms=round(sr*0.005); % how often the bar should be updated +cfs=getcf(nap); % the center frequencies +napvalues=getvalues(nap); % the values of the neural activity pattern + +% copy some variables from the struct to real variables (speed!!) +weight_threshold=options.weight_threshold; +strobe_weight_alpha=options.strobe_weight_alpha; +delay_weight_change=options.delay_weight_change; +% criterion=options.criterion; +do_adjust_weights=options.do_adjust_weights; +do_normalize=options.do_normalize; % if weights are do_normalized +% donapheight=options.do_times_nap_height; % if the strobe height has an influence + +% each strobe induces strobes in neighboring channels in this +% vicinity: +if isfield(options,'erb_frequency_integration') + erb_strobe_width=options.erb_frequency_integration; + erbdensity=erbdensity(nap); + nrintegrate=round(erbdensity*erb_strobe_width); + do_interchannel_interaction=1; +else + do_interchannel_interaction=0; + nrintegrate=0; +end +% if strcmp(criterion,'integrate_erbs') +% % define the integration area for each channel in frequency and time +% erbsearchwidth=options.erb_frequency_integration; +% erbdensity=erbdensity(nap); +% nrintegrate=round(erbdensity*erbsearchwidth); +% +% for ii=1:nr_channels +% % the frequency window +% a=ii+(-nrintegrate:nrintegrate); +% a(find(a<0))=0; +% a(find(a>nr_channels))=0; +% a(find(a==ii))=0; % dont search in the identical channel +% +% neighboring_channels(ii,:)=a; +% +% % the time window +% current_cf=cfs(ii); +% timewindow_start(ii)=-1/current_cf; +% timewindow_stop(ii)=1/current_cf; +% end +% end +% + +% Beschleunigung der Berechnung durch vorziehen der Schleife: +% der Einfluß der Zeit: je mehr Strobes da sind, +% umso unwichtiger werden die älteren: +% adapt the weights of all the old strobes +weighfactor=ones(nr_maximal_strobes); +if do_adjust_weights %only if wanted + for ii=1:nr_maximal_strobes + for jj=1:ii + wfactor=power(1/(ii-jj+1),strobe_weight_alpha); + weighfactor(ii,jj)=wfactor; + end + end +end + + +if single_channel_do==1 + oldfigure=gcf; + onechannelfigure=figure(1954211404); % some strange number that should not be an existing figure + set(onechannelfigure,'name','Dynamic single channel'); + set(onechannelfigure,'numbertitle','off'); +end + +saibuffer=zeros(nr_channels,nrdots_insai); +if nr_channels>1 + waithand=waitbar(0,'generating SAI'); +end + + + + +% calculate the repetition rate of the signal by the strobes alone +strobe_window=0.025; +current_time=0; +real_strobes=zeros(nr_channels,100); +acs=zeros(nr_channels,round(sr*strobe_window)); +stepss=round(0.001*sr); % one result per ms +nr_do=round(nr_dots/stepss); +saveacs=zeros(nr_do,round(sr*strobe_window)); +current_estimated_pitch=zeros(1,nr_do); +count=1; +for ii=1:stepss:nr_dots + for jj=1:nr_channels + current_time=ii/sr; + strobes=allstrobes(jj,:); % all strobes here + % find the strobes in the last 50 ms: + selected_strobes=find(strobes > current_time-strobe_window & strobes <= current_time & strobes > 0); + nr_str=length(selected_strobes); + if nr_str>2 + rs=strobes(selected_strobes); +% real_strobes(jj,1:nr_str)=strobes(selected_strobes); +% real_strobes(jj,nr_str+1:end)=0; + autoc=myautocorr(rs,sr,strobe_window); % my own autorcor w/o fft + acs(jj,:)=autoc; + end + end + % now sum all autocorrelations togehter + sumautoc=sum(acs); + saveacs(count,:)=sumautoc; + % find the maximum in this summarized correlation + [val,max_peak]=max(sumautoc); + current_estimated_pitch(count)=max_peak; + count=count+1; +end + +% figure(11); +% plot(current_estimated_pitch); + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% start of big loop +current_time=signal_start_time; % start time for calculation +for bintime=1:nr_dots + if nr_channels>1 + if mod(bintime,times_per_ms)==0 + waitbar(bintime/nr_dots); + end + end + + current_time=current_time+sampletime; + + for channel_nr=1:nr_channels + % for channel_nr=25 + current_cf=cfs(channel_nr); + + if select_certain_channels + if current_cf < min_selected_frequency || current_cf > max_selected_frequency + continue; % outside wanted range, no need to calculate! + end + end + + nr_str_total=nrstrobes(channel_nr); + channelallstrobes=allstrobes(channel_nr,1:nr_str_total); % all the strobes in this channel + nr_active_str=nr_active_strobes(channel_nr); + nr_current_str=current_strobe_nr(channel_nr); + + % find out, if a new strobe arrived + this_strobe_time=next_strobe(channel_nr); % here is the next strobe + if current_time > this_strobe_time % if we are beyond the next strpbe + + if nr_current_str < nrstrobes(channel_nr) % define the next strobe + next_strobe(channel_nr) =channelallstrobes(nr_current_str + 1); + else + next_strobe(channel_nr)=inf; % if no more strobes we will never get here any more + end + nr_current_str=nr_current_str+1; + + % if strcmp(criterion,'integrate_erbs') + % % find out, which weight this strobe has by integration over + % % time and frequency of the neighbouring strobes + % t1=timewindow_start(channel_nr)+current_time; + % t2=timewindow_stop(channel_nr)+current_time; + % strobeweight=zeros(nr_channels,1); + % normalizer=0; + % for chn=neighboring_channels(channel_nr,:); + % if chn>0 + % nrstr=nrstrobes(chn); + % chstr=allstrobes(chn,1:nrstr); % all strobes in this channel + % neistrobes=find(chstr>t1 & chstr= strobe_adjust_phase(channel_nr)); + logi2=~logical(was_adjusted(channel_nr)); % ugly, but accelerated + if logi1 && logi2 + + % jetzt ist Zeit zum Adjusten, erst mal alle auf das + % Orginalgewicht (Zahl der Zyclen) + + % % jetzt der Einfluß der Zeit: je mehr Strobes da sind, + % % umso unwichtiger werden die älteren: + % % adapt the weights of all the old strobes + % weighfactor=ones(length(nr_active_str),1); + % if do_adjust_weights %only if wanted + % for ii=1:nr_active_str + % wfactor=power(1/(nr_active_str-ii+1),strobe_weight_alpha); + % weighfactor(ii)=wfactor; + % end + % else + % stropo_weight=stropo_org_weight; + % end + + if do_adjust_weights %only if wanted + if nr_active_str>0 + wfactor=weighfactor(nr_active_str,:); + end + else + wfactor=ones(1,nr_active_str); + end + + + % und dann alle Strobes in diesem Kanal auf eins + % normieren, damit die Summe über alle Aktivität in jedem + % Channel immer gleich der Summe im Nap ist. + % normalise them to 1 + if do_normalize==1 + if nr_active_str>1 + sumweight=0; + for ii=1:nr_active_str + sumweight=sumweight+stropo_org_weight(channel_nr,ii)*wfactor(ii); + end + for ii=1:nr_active_str + tmp=stropo_org_weight(channel_nr,ii)*wfactor(ii); + tmp=tmp/sumweight; + stropo_weight(channel_nr,ii)=tmp; + end + end + else + stropo_weight=stropo_org_weight; + end % do_normalize + was_adjusted(channel_nr)=1; + end % strobe has arrived + + % delete old strobe processes + nr_deleted=0; + for ii=1:nr_active_str-nr_deleted + time_strobe=stropo_time(channel_nr,ii-nr_deleted); + delay=current_time-time_strobe; + weight=stropo_weight(channel_nr,ii-nr_deleted); + + cur_time_ms=round(current_time*1000); + if cur_time_ms>0 + maxdelay=current_estimated_pitch(cur_time_ms)/sr; + else + maxdelay=0.034; + end + maxdelay=maxdelay-0.001; + if delay > maxdelay || weight < weight_threshold % forget this strobe + + +% if delay > maxdelay || weight < weight_threshold % forget this strobe + stropo_time(channel_nr,ii-nr_deleted:end-1)=stropo_time(channel_nr,ii-nr_deleted+1:end); + stropo_weight(channel_nr,ii-nr_deleted:end-1)=stropo_weight(channel_nr,ii-nr_deleted+1:end); + stropo_org_weight(channel_nr,ii-nr_deleted:end-1)=stropo_org_weight(channel_nr,ii-nr_deleted+1:end); + nr_deleted=nr_deleted+1; + end + end + nr_active_str=nr_active_str-nr_deleted; + + + % process all strobes + for ii=1:nr_active_str + time_strobe=stropo_time(channel_nr,ii); + delay=current_time-time_strobe; + % if delay >= sampletime + if delay >= 0.0001 + % if delay > 0.0 + current_time_int=floor((current_time-signal_start_time)/sampletime); + delayint=round(delay/sampletime); + weight=stropo_weight(channel_nr,ii); + % if donapheight==1 % if the strobe heigt has influence + % weight=weight*allstrobesval(channel_nr,ii); + % end + oldval=saibuffer(channel_nr,delayint); + newval=oldval+weight*napvalues(channel_nr,current_time_int); + saibuffer(channel_nr,delayint)=newval; % put the new value in the buffer at the correct position + + % interchannel interaction + if do_interchannel_interaction + for jj=channel_nr-nrintegrate:channel_nr+nrintegrate + if jj==ii || jj<1 || jj>nr_channels + continue + end + oldval=saibuffer(jj,delayint); + adjacent_weight=weight*(1-abs(jj-channel_nr)/(nrintegrate+1)); + newval=oldval+adjacent_weight*napvalues(jj,current_time_int); + saibuffer(jj,delayint)=newval; % put the new value in the buffer at the correct position + end + end + + end + end + + % save for the next run + current_strobe_nr(channel_nr)=nr_current_str; % strobe counter + nr_active_strobes(channel_nr)=nr_active_str; % active strobe counter + + % special graphics, when only one channel: display signal, + % threshold and strobe weights + if single_channel_do && channel_nr==single_channel_channel_nr + if current_time>=next_graphic + if current_graphic= output_times(output_counter) + if do_click_reduction + reduced_saibuffer=saibuffer; + for channel_nr=1:nr_channels + org_channel=saibuffer(channel_nr,:); + org_sig=signal(org_channel); + org_sig=setsr(org_sig,sr); + + clickvals_sig=getsinglechannel(click_frame,channel_nr); + + relevant_click_time=0.035; + clicksig=getpart(clickvals_sig,0,relevant_click_time); + % clicksig=changesr(clicksig,sr); + org_sig_part=getpart(org_sig,0,relevant_click_time); + maxval=max(org_sig); + clicksig=scaletomaxvalue(clicksig,maxval); + new_sig=org_sig-clicksig; + new_sig=halfwayrectify(new_sig); + + grafix=0; + if grafix==1 + figure(324234) + clf + hold on + plot(clicksig,'m'); + plot(org_sig,'b'); + plot(new_sig,'r'); + end + newvals=getvalues(new_sig); + reduced_saibuffer(channel_nr,:)=newvals'; + end + resframes{output_counter}=reduced_saibuffer; + else + resframes{output_counter}=saibuffer; + end + output_counter=output_counter+1; + if output_counter >nr_output_times + break; % no need to go on! + end + + end +end % time loop + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +if single_channel_do==1 + figure(oldfigure); +end + +% translate the arrays from data to frames +nrfrms=length(resframes); +start_time=getminimumtime(nap); % start time of first frame +if nrfrms>1 + interval=output_times(2)-output_times(1); +else + interval=0; % doesnt matter... +end +maxval=-inf; +maxsumval=-inf; +maxfreval=-inf; +cfs=getcf(nap); + +if nr_channels>1 + for ii=1:nrfrms + cfr=frame(resframes{ii}); + maxv=getmaximumvalue(cfr); + maxval=max([maxv maxval]); + maxs=max(getsum(cfr)); + maxsumval=max([maxs maxsumval]); + maxf=max(getfrequencysum(cfr)); + maxfreval=max([maxf maxfreval]); + end + +else + maxfreval=1; + maxsumval=1; + maxval=1; +end + + +for ii=1:nrfrms + cfr=frame(resframes{ii}); + cfr=setsr(cfr,sr); + cfr=setcurrentframenumber(cfr,ii); + cfr=setcurrentframestarttime(cfr,start_time); + cfr=setcf(cfr,cfs); + start_time=start_time+interval; + cfr=setscalesumme(cfr,maxsumval); + cfr=setallmaxvalue(cfr,maxval); + cfr=setallminvalue(cfr,0); + cfr=setscalefrequency(cfr,maxfreval); + returnframes{ii}=cfr; +end + +if nr_channels>1 + close(waithand); +end + + + +% function for one channel: Plot some nice graphic +function extraplot(onechannelfigure,napvalues,sr,current_time,maxdelay,options,bintime,nr_active_str,saibuffer,stropo_time,stropo_weight,channel_nr) + +persistent maxamp; % how big the biggest amplitude was so far +if isempty(maxamp) + maxamp=0; +end +figure(onechannelfigure); +subplot(2,1,1); % the signal, threshold and strobes: +cla +single_channel= signal(napvalues(channel_nr,:),sr); +maxval=max(single_channel); +siglen=getlength(single_channel); +threshold=getsinglechannel(options.thresholds,channel_nr); +if current_time < maxdelay + single_channel=getpart(single_channel,0,maxdelay); + threshold=getpart(threshold,0,maxdelay); +else + % try + single_channel=getpart(single_channel,current_time-maxdelay,current_time); + % catch + % a=0; + % end + threshold=getpart(threshold,current_time-maxdelay,current_time); +end +plot(single_channel,'-');hold on +ax=axis; +ax(4)=maxval*1.3; +axis(ax); +line([time2bin(single_channel,current_time) time2bin(single_channel,current_time)],[0 1],'Color','red'); +title('nap, threshold and strobes'); +thresholdvals=getvalues(threshold); +if current_timemaxamp + maxamp=max(buffer); +end +set(gca,'Ylim',[-0.00001 maxamp*1.1]); + +nr_labels=8; +tix=1:(nrx-1)/nr_labels:nrx; +xstep=(maximum_time_interval-minimum_time_interval)*1000/(nr_labels); %works from -35 to 5 +ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000+1]); +ti=ti(end:-1:1); +ti=round(ti*10)/10; +set(gca,'XScale','linear') +set(gca,'XTick',tix); +set(gca,'XTickLabel',ti); +xlabel('delay (ms)'); +title('buffer'); + +drawnow; +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti2003/myautocorr.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti2003/myautocorr.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,29 @@ +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +function cor=myautocorr(data,sr,window) +% calculate the autocorrelation (all interval histogram) +% for the data in data with the samplerate in sr, but only the time +% window given my window + +nr_dat=length(data); + +if nr_dat<2 + cor=[]; + return +end + +cor=zeros(1,round(window*sr)); + +for ii=1:nr_dat-1 + dat1=data(ii); + for jj=ii+1:nr_dat + dat2=data(jj); + len=(dat2-dat1)*sr; + indx=round(len); + if indx < window*sr && indx >= 1 + cor(indx)=cor(indx)+1; + end + end +end diff -r 000000000000 -r 74dedb26614d aim-mat/modules/sai/ti2003/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/sai/ti2003/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,36 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% sai +% hidden parameters +ti2003.generatingfunction='gen_ti2003'; +ti2003.displayname='time integration stabilized auditory image on several sources'; +ti2003.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +ti2003.criterion='change_weights'; % can be 'integrate_erbs','change_weights' +% relevant for all criterions: +ti2003.mindelay=0.0005; +ti2003.maxdelay=0.035; +ti2003.buffer_memory_decay=0.03; +ti2003.frames_per_second=200; + +ti2003.weight_threshold=0.0; % when strobe weight drops under this threshold, forget it! +ti2003.do_normalize=1; % yes, strobes are normalized to a weight of 1 +ti2003.do_times_nap_height=0; % no, nap height is not multiplied per default +ti2003.do_adjust_weights=1; % yep, the weights are changed by the following parameter +ti2003.strobe_weight_alpha=0.5; % the factor by which the strobe weight decreases +ti2003.delay_weight_change=0.5; % change the weights after this time + + +ti2003.do_click_reduction=0; +ti2003.click_reduction_sai='click_frame.mat'; + +ti2003.dual_output=0; + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/signal/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/signal/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,17 @@ +% parameter file for 'aim-mat' +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% signal options +% hidden parameters +signal.generatingfunction=''; % there is no generating fungction for signal +signal.revision='$Revision: 585 $'; +signal.displayname='the signal'; + +% parameters relevant for the calculation of this module +signal.start_time=0; +signal.duration=inf; +signal.sampleratemax=16000; % the only important parameter \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/strobes/none/gennostrobes.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/strobes/none/gennostrobes.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,16 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function [strobes,thres]=gennostrobes(nap,options) +strobes=[]; +thres=[]; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/strobes/none/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/strobes/none/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,16 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ +%%%%%%%%%%%%% +% no nap +% hidden parameters +none.generatingfunction='gennostrobes'; +none.displayname='no strobes'; +none.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module diff -r 000000000000 -r 74dedb26614d aim-mat/modules/strobes/sf1992/gen_sf1992.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/strobes/sf1992/gen_sf1992.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,67 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function [allstrobeprocesses,allthresholds]=gen_sf1992(nap,strobeoptions) + +% this is the same function as sf2003, only the strobe criterium is changed +[allstrobeprocesses,allthresholds]=gen_sf2003(nap,strobeoptions); + + + + +% % find in each channel each strobe and gives it back as an list of +% % structures of strobes +% +% waithand=waitbar(0,'generating strobes'); +% % % if not all channels are wanted to be seen +% % +% allthresholds=nap; +% cfs=getcf(nap); +% +% +% % switch strobeoptions.strobe_criterion +% % case 'threshold' +% % case 'peak' +% % case 'temporal_shadow' +% % case 'temporal_shadow_plus' +% % case 'delta_gamma' +% % case 'parabola' +% % case 'bunt' +% % case 'adaptive' +% % end +% +% % strobeoptions.strobe_criterion='peak'; +% % strobeoptions.strobe_criterion='temporal_shadow'; +% % strobeoptions.strobe_criterion='temporal_shadow_plus'; +% +% +% nr_channels=getnrchannels(nap); +% for ii=1:nr_channels +% waitbar(ii/nr_channels); +% single_channel=getsinglechannel(nap,ii); +% current_cf=cfs(ii); +% +% [strobe_points,threshold]=findstrobes(single_channel,strobeoptions); +% strobe_vals=gettimevalue(single_channel,strobe_points); +% +% thresvals=getvalues(threshold); +% +% if size(strobe_points,1) > size(strobe_points,2) +% strobe_points=strobe_points'; +% strobe_vals=strobe_vals'; +% end +% allstrobeprocesses{ii}.strobes=strobe_points; +% allstrobeprocesses{ii}.strobe_vals=strobe_vals; +% allthresholds=setsinglechannel(allthresholds,ii,thresvals); +% end +% close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/strobes/sf1992/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/strobes/sf1992/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,29 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ +%%%%%%%%%%%%% +% old strobe finding +% hidden parameters +sf1992.generatingfunction='gen_sf1992'; +sf1992.displayname='strobe finding old ams version'; +sf1992.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module + +% can be 'peak','temporal_shadow','local_maximum','delta_gamma' +sf1992.strobe_criterion='local_maximum'; +% parameter for temporal_shadow +sf1992.strobe_decay_time=0.02; + + +% which unit is applied to the time measurements below +% can be sec,ms,cycles: +sf1992.unit='sec'; +% parameter for local_maximum +sf1992.strobe_lag=0.005; +sf1992.timeout=0.01; \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/strobes/sf2003/gen_sf2003.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/strobes/sf2003/gen_sf2003.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,182 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + + +function [allstrobeprocesses,allthresholds]=gen_sf2003(nap,strobeoptions) + +% find in each channel each strobe and gives it back as an list of +% structures of strobes + +% possible values of strobe_criterion: +% switch strobeoptions.strobe_criterion +% case 'threshold' +% case 'peak' +% case 'temporal_shadow' +% case 'local_maximum' +% case 'delta_gamma' +% case 'parabola' +% case 'bunt' +% case 'adaptive' +% end + +if strcmp(strobeoptions.strobe_criterion,'interparabola') + [allstrobeprocesses,allthresholds]=do_interparabola(nap,strobeoptions); + return +end + +% non interchannel methods: +% buffer for all thrsholds afterwards. Exact copy of the signal: +allthresholds=nap; +cfs=getcf(nap); + +waithand=waitbar(0,'generating strobes'); +nr_channels=getnrchannels(nap); +for ii=1:nr_channels + waitbar(ii/nr_channels); + single_channel=getsinglechannel(nap,ii); + current_cf=cfs(ii); + strobeoptions.current_cf=current_cf; + + % here they are calculated: + [strobe_points,threshold]=findstrobes(single_channel,strobeoptions); + + % return values: strobes in sec + % threshold= signal indicating the adaptive threshold + + strobe_points=strobe_points(find(strobe_points>0)); + strobe_vals=gettimevalue(single_channel,strobe_points); + + thresvals=getvalues(threshold); + + % make shure, they are in one column + if size(strobe_points,1) > size(strobe_points,2) + strobe_points=strobe_points'; + strobe_vals=strobe_vals'; + end + allstrobeprocesses{ii}.strobes=strobe_points; + allstrobeprocesses{ii}.strobe_vals=strobe_vals; + allthresholds=setsinglechannel(allthresholds,ii,thresvals); +end +close(waithand); +return + + +% interchannel methods: +function [all_processes,thresholds]=do_interparabola(nap,options) +% the threshold is calculated relativ to the hight of the last strobe +% the sample rate is needed for the calculation of the next thresholds +% for time_constant_alpha this is a linear decreasing function that goes +% from the maximum value to 0 in the time_constant +% +% with interchannel interaction: A strobe in one channel reduces the +% threshold in the neighbouring channels + +nr_channels=getnrchannels(nap); + +current_threshold=zeros(nr_channels,1); +sr=getsr(nap); +last_strobe=ones(nr_channels,1)* -inf; + +napvals=getvalues(nap); +tresval=zeros(size(napvals)); +nr_dots=length(napvals); + +strobe_points=zeros(nr_channels,1000); % makes things faster +strobe_times=zeros(size(strobe_points)); % makes things faster + +%when the last strobe occured +last_strobe_time=ones(nr_channels,1)* -inf; +last_threshold_value=zeros(nr_channels,1); +last_val=napvals(:,1); + +cfs=getcf(nap); +% copy options to save time +h=options.parabel_heigth; +wnull=options.parabel_width_in_cycles*1./cfs; +w_variabel=wnull; + +strobe_decay_time=options.strobe_decay_time; +times_per_ms=round(sr*0.005); % how often the bar should be updated +counter=ones(nr_channels,1); + +waithand=waitbar(0,'generating Interchannel Strobes'); + +for ii=2:nr_dots-1 + current_time=ii/sr; + if mod(ii,times_per_ms)==0 + waitbar(ii/nr_dots); + end + + for jj=1:nr_channels + current_val=napvals(jj,ii); + next_val=napvals(jj,ii+1); + + if current_val>=current_threshold(jj) % above threshold -> criterium for strobe + current_threshold(jj)=current_val; + if current_val > last_val(jj) && current_val > next_val % only strobe on local maxima + % take this one as a new one + strobe_points(jj,counter(jj))=ii; + strobe_time(jj,counter(jj))=ii/sr; + counter(jj)=counter(jj)+1; % strobecounter + + last_strobe_time(jj)=ii/sr; % anyhow, its a candidate + last_threshold_value(jj)=current_threshold(jj); + a=4*(1-h)/(wnull(jj)*wnull(jj)); + b=-wnull(jj)/2; + w_variabel(jj)=wnull(jj)-(current_threshold(jj)-2*a*b)/(2*a); + + % the interchannel action: reduce the threshold in adjacent channel + if jj>1 + current_threshold(jj-1)=current_threshold(jj-1)/1.2; + last_threshold_value(jj-1)=last_threshold_value(jj-1)/1.2; + end + + end + end + tresval(jj,ii)=current_threshold(jj); + + time_since_last_strobe(jj)=current_time-last_strobe_time(jj); + if time_since_last_strobe(jj) > w_variabel(jj) % linear falling threshold + const_decay=last_threshold_value(jj)/sr/strobe_decay_time; + current_threshold(jj)=current_threshold(jj)-const_decay; + current_threshold(jj)=max(0,current_threshold(jj)); + else % parabel for the first time y=a(x+b)^2+c + a=4*(1-h)/(wnull(jj)*wnull(jj)); + b=-wnull(jj)/2; + c=h; + factor=a*(time_since_last_strobe(jj) + b) ^2+c; + current_threshold(jj)=last_threshold_value(jj)*factor; + end + + current_threshold(jj)=max(0,current_threshold(jj)); % cant be smaller then 0 + last_val(jj)=current_val; + end +end + + % give back only the strobes, that really occured: +for jj=1:nr_channels + if counter(jj)>1 + real_strobe_points=strobe_points(jj,1:counter(jj)-1); + strobe_vals=napvals(jj,real_strobe_points); + all_processes{jj}.strobe_vals=strobe_vals; + real_strobe_points=bin2time(nap,real_strobe_points); + all_processes{jj}.strobes=real_strobe_points; + else + all_processes{jj}.strobe_vals=[]; + all_processes{jj}.strobes=[]; + end +end + +thresholds=nap; +thresholds=setvalues(thresholds,tresval); + +close(waithand); +return \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/strobes/sf2003/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/strobes/sf2003/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,30 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2011, University of Southampton +% Maintained and written by Stefan Bleeck (bleec@gmail.com) +% http://www.soton.ac.uk/aim + +%%%%%%%%%%%%% +% strobes +% hidden parameters +sf2003.generatingfunction='gen_sf2003'; +sf2003.displayname='strobe finding'; +sf2003.revision='$Revision: 585 $'; + +% parameters relevant for the calculation of this module +sf2003.strobe_criterion='interparabola'; % can be 'parabola', 'bunt','adaptive' +% sf2003.unit='sec'; % which unit all the other parameters have + +sf2003.strobe_decay_time=0.02; +% parameters for parabola: +sf2003.parabel_heigth=1.2; +sf2003.parabel_width_in_cycles=1.5; +% parameters for bunt: +sf2003.bunt=1.02; +sf2003.wait_cycles=1.5; % the time, that no new strobe is accepted +sf2003.wait_timeout_ms=20; + +% parameters for 'adaptive': +sf2003.slope_coefficient=1; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/dualprofile/displaydualprofile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/dualprofile/displaydualprofile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,72 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003, University of Cambridge, Medical Research Council +% Stefan Bleeck (stefan@bleeck.de) +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual +% $Date: 2003/06/27 16:03:30 $ +% $Revision: 1.6 $ + +function displaydualprofile(sai,options,frame_number,ax) +if nargin<4 + ax=gca; +end + + +% Test if the frame_number is available +if length(sai)=(minimum_time_interval/1000)) & tip_x<=(maximum_time_interval/1000)); +tip = tip(time2bin(sai{frame_number}.interval_sum,tip_x(1)):time2bin(sai{frame_number}.interval_sum,tip_x(end))); +% tip_x is in ms. Change to Hz +tip_x = 1./tip_x; +plot(tip_x, tip, 'b'); +set(ax,'XScale','log'); + +% Now lable it ! +xlabel('Frequency [Hz]'); +set(ax, 'YAxisLocation','right'); +ti=50*power(2,[0:nr_labels]); +set(ax,'XTick', ti); +set(ax, 'XLim',[1000/maximum_time_interval sai{frame_number}.channel_center_fq(end)]) +set(options.handles.checkbox6, 'Value',0); +set(options.handles.checkbox7, 'Value',0); +hold off + + +return diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/dualprofile/gendualprofile.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/dualprofile/gendualprofile.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,42 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003, University of Cambridge, Medical Research Council +% Stefan Bleeck (stefan@bleeck.de) +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual +% $Date: 2003/03/04 18:51:26 $ +% $Revision: 1.4 $ + +function usermodule=gendualprofile(sai,options) + +% find out about scaling: +maxval=-inf; +maxfreval=-inf; +maxsumval=-inf; + +nr_frames=length(sai); +for ii=1:nr_frames + maxval=max([maxval getmaximumvalue(sai{ii})]); + maxsumval=max([maxsumval getscalesumme(sai{ii})]); + maxfreval=max([maxfreval getscalefrequency(sai{ii})]); +end + +waithand = waitbar(0,'Generating dualprofile with peak detection'); +for frame_number=1:nr_frames + + waitbar(frame_number/nr_frames, waithand); + + current_frame = sai{frame_number}; + current_frame = setallmaxvalue(current_frame, maxval); + current_frame = setscalesumme(current_frame, maxsumval); + current_frame = setscalefrequency(current_frame, maxfreval); + + usermodule{frame_number}.interval_sum = getsum(current_frame); + usermodule{frame_number}.frequency_sum = getfrequencysum(current_frame); + usermodule{frame_number}.channel_center_fq = getcf(sai{frame_number}); +end +close(waithand); diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/dualprofile/parameters.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/dualprofile/parameters.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,21 @@ +% parameter file for 'aim-mat' +% +% +% (c) 2003, University of Cambridge, Medical Research Council +% Stefan Bleeck (stefan@bleeck.de) +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual +% $Date: 2003/03/10 13:39:14 $ +% $Revision: 1.4 $ +%%%%%%%%%%%%% +% usermodule dual profile +% hidden parameters +dualprofile.generatingfunction='gendualprofile'; +dualprofile.displayname='dual profile'; +dualprofile.displayfunction='displaydualprofile'; +dualprofile.revision='$Revision: 1.4 $'; + +% parameters relevant for the calculation of this module +dualprofile.minimum_time_interval=0; +dualprofile.maximum_time_interval=32; +dualprofile.scalefactor = 2.335; +dualprofile.nr_labels=8; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/CalMI.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/CalMI.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,169 @@ +% tester generating function for Calculation of the Mellin Image in 'aim-mat' +% +% INPUT VALUES: SAI3d : 3D SAI +% NAPparam: Parameter for NAP +% SAIparam: Parameter for SAI +% MIparam: Parameter for MI +% RETURN VALUE: +% MI3d: 3D Mellin Image +% +% (c) 2003, University of Cambridge, Medical Research Council +% Original Code IRINO T +% 10 Jan. 2002 +% Modified by R. Turner (ret26@cam.ac.uk) +% Feb. 2003 +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual + +function [MI3d] = CalMI(SAI3d,options,sample_rate) + +%here we setup all the variables that the function requires +%%% CHANGE THE NAMES SO IT'S CLEAR WHAT'S GOING ON!!! + +%what do these do? +MIparam.NSAIPhsCmp = 0; %was 2 but aim uses a window starting at 0ms +MIparam.F0mode = 300; + +%these values set the resolution and scale of the axes in the final MT +%they are now defined in the parameter file +MIparam.TFval = options.TFval; +MIparam.c_2pi = options.c_2pi; +Lenc2pi = length(MIparam.c_2pi); +LenTF = length(MIparam.TFval); + +%not sure what these do +MIparam.Mu = -0.5; % flat if Mu <0.5: high pass, Mu>0.5 low pass +SAIparam.Nwidth = 0; %sets the negative width of the window +MIparam.SSI = options.ssi; + +%we find the maximum temporal interval size, the no of channels and the no +%of frames +[NumCh, LenSAI, LenFrame] = size(SAI3d); + +%going to remove any information in the first N channels +% N=5; +% for no_ch = 1:N, +% SAI3d(no_ch,:,:)=zeros(LenSAI,LenFrame); +% end; + +%saving the SAI3d for comparison with irino's +% savefile = 'SAI3d_AIM.mat'; +% SAI3d_AIM=SAI3d/max(max(max(SAI3d))); +% save(savefile,'SAI3d_AIM'); + +%for using irino's SAI in AIM +% load SAI3d_Irino.mat; +% SAI3d=SAI3d_Irino; + +%here we set up the Frs values for each channel +% TCW AIM2006 - the upper and lower cfs were hard-coded. +%cf_afb = [100 6000]; %4500]; altered for 2dAT +% +if isfield(options, 'lowest_frequency') + fre1=options.lowest_frequency; +else + fre1=100; +end +if isfield(options, 'highest_frequency') + fre2=options.highest_frequency; +else + fre2=6000; +end + + +cf_afb=[fre1 fre2]; +NAPparam.Frs = FcNch2EqERB(min(cf_afb),max(cf_afb),NumCh); +NAPparam.fs = sample_rate; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%cwd = pwd; +%cd(tempdir); +%pack +%cd(cwd) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%We initialise the mellin image matrix (why is it best to do this - is it +%so we can spot errors more easily? +MI3d = zeros(Lenc2pi,LenTF,LenFrame); + +%user information (commented out) + new wait bar +%disp('*** MI Calculation ***'); + +%MIparam.RangeAudFig = []; +%disp(MIparam); +waithand=waitbar(0,'generating the Mellin Transform'); + +% set the frame range, the mellin image is calculated for +if (options.do_all_frames == 1) + start_frame = 1; + end_frame = LenFrame; +else + start_frame = options.framerange(1); + end_frame = options.framerange(2); +end; + + +%this section does the filter response alignment +for nfr = start_frame:end_frame + %set up the waitbar + fraction_complete=nfr/LenFrame; + waitbar(fraction_complete,waithand); + + %generate the new matricies of the frames + SAIval = SAI3d(:,:,nfr); + SAIPhsCmp = zeros(size(SAIval)); + + %we shift each channel along the time interval axis by adding zeros + for nch = 1:NumCh, + NPeriod = NAPparam.fs/NAPparam.Frs(nch) * MIparam.NSAIPhsCmp; + shift_matrix = [zeros(1,fix(NPeriod)), SAIval(nch,:)]; + SAIPhsCmp(nch,1:LenSAI) = shift_matrix(1:LenSAI); + %MI3d(:,:,nfr) = SAIPhsCmp'; %added line + %SAIPhsCmp = SAI3d(:,:,nfr); %tester line + end; + if MIparam.F0mode == 0 + % No estimation of F0 + else + F0est(nfr) = MIparam.F0mode; + end; + + %Here we extract the information required to ensure that we have + %only one presentation of the 'timbre' information + ZeroLoc = abs(SAIparam.Nwidth)*NAPparam.fs/1000+1; + MarginAF = 0; % No margin by introducing WinAF + + % maah: set the range for the auditory image + if (options.do_all_image == 1) + MIparam.RangeAudFig = [1 LenSAI]; + else + MIparam.RangeAudFig = options.audiorange; + end; + % maah: was MIparam.RangeAudFig = [ZeroLoc+[0 , (fix(NAPparam.fs/F0est(nfr))-MarginAF)]]; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%% this section is my optimized code (JRH) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % Calculation of the Mellin Coefficients + %[MImtrx] = CalMellinCoef_Rich(SAIPhsCmp,NAPparam,MIparam); + + % instead of the above command, execute that and the bottom commands + % all at once, thereby cutting the computation time by approx 75% + MI3d(1:Lenc2pi,1:LenTF,nfr) = abs(CalMellinCoef(SAIPhsCmp,NAPparam,MIparam)); + + %Output into the 3d matrix + %MI3d(1:Lenc2pi,1:LenTF,nfr) = MImtrx; + + % maah: Magnitude + %MI3d(1:Lenc2pi,1:LenTF,nfr) = abs(MI3d(1:Lenc2pi,1:LenTF,nfr)); + %MI3d(:,:,nfr) = MImtrx; %added line + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +end; + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/CalMI_Rich.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/CalMI_Rich.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,135 @@ + + + +% tester generating function for Calculation of the Mellin Image in 'aim-mat' +% +% INPUT VALUES: SAI3d : 3D SAI +% NAPparam: Parameter for NAP +% SAIparam: Parameter for SAI +% MIparam: Parameter for MI +% RETURN VALUE: +% MI3d: 3D Mellin Image +% +% (c) 2003, University of Cambridge, Medical Research Council +% Original Code IRINO T +% 10 Jan. 2002 +% Modified by R. Turner (ret26@cam.ac.uk) +% Feb. 2003 +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual + +function [MI3d] = CalMI_Rich(SAI3d,options,sample_rate) + +%here we setup all the variables that the function requires +%%% CHANGE THE NAMES SO IT'S CLEAR WHAT'S GOING ON!!! + +%what do these do? +MIparam.NSAIPhsCmp = 0; %was 2 but aim uses a window starting at 0ms +MIparam.F0mode = 300; + +%these values set the resolution and scale of the axes in the final MT +%they are now defined in the parameter file +MIparam.TFval = options.TFval; +MIparam.c_2pi = options.c_2pi; +Lenc2pi = length(MIparam.c_2pi); +LenTF = length(MIparam.TFval); + +%not sure what these do +MIparam.Mu = -0.5; % flat if Mu <0.5: high pass, Mu>0.5 low pass +SAIparam.Nwidth = 0; %sets the negative width of the window +MIparam.SSI = options.ssi; + +%we find the maximum temporal interval size, the no of channels and the no +%of frames +[NumCh, LenSAI, LenFrame] = size(SAI3d); + +%going to remove any information in the first N channels +% N=5; +% for no_ch = 1:N, +% SAI3d(no_ch,:,:)=zeros(LenSAI,LenFrame); +% end; + +%saving the SAI3d for comparison with irino's +% savefile = 'SAI3d_AIM.mat'; +% SAI3d_AIM=SAI3d/max(max(max(SAI3d))); +% save(savefile,'SAI3d_AIM'); + +%for using irino's SAI in AIM +% load SAI3d_Irino.mat; +% SAI3d=SAI3d_Irino; + +%here we set up the Frs values for each channel +cf_afb = [100 6000]; %4500]; altered for 2dAT +NAPparam.Frs = FcNch2EqERB(min(cf_afb),max(cf_afb),NumCh); +NAPparam.fs = sample_rate; + +%We initialise the mellin image matrix (why is it best to do this - is it +%so we can spot errors more easily? +MI3d = zeros(Lenc2pi,LenTF,LenFrame); + +%user information (commented out) + new wait bar +%disp('*** MI Calculation ***'); + +%MIparam.RangeAudFig = []; +%disp(MIparam); +waithand=waitbar(0,'generating the MT'); + +% set the frame range, the mellin image is calculated for +if (options.do_all_frames == 1) + start_frame = 1; + end_frame = LenFrame; +else + start_frame = options.framerange(1); + end_frame = options.framerange(2); +end; + + +%this section does the filter response alignment +for nfr = start_frame:end_frame + %set up the waitbar + fraction_complete=nfr/LenFrame; + waitbar(fraction_complete); + + %generate the new matricies of the frames + SAIval = SAI3d(:,:,nfr); + SAIPhsCmp = zeros(size(SAIval)); + + %we shift each channel along the time interval axis by adding zeros + for nch = 1:NumCh, + NPeriod = NAPparam.fs/NAPparam.Frs(nch) * MIparam.NSAIPhsCmp; + shift_matrix = [zeros(1,fix(NPeriod)), SAIval(nch,:)]; + SAIPhsCmp(nch,1:LenSAI) = shift_matrix(1:LenSAI); + %MI3d(:,:,nfr) = SAIPhsCmp'; %added line + %SAIPhsCmp = SAI3d(:,:,nfr); %tester line + end; + if MIparam.F0mode == 0 + % No estimation of F0 + else + F0est(nfr) = MIparam.F0mode; + end; + + %Here we extract the information required to ensure that we have + %only one presentation of the 'timbre' information + ZeroLoc = abs(SAIparam.Nwidth)*NAPparam.fs/1000+1; + MarginAF = 0; % No margin by introducing WinAF + + % maah: set the range for the auditory image + if (options.do_all_image == 1) + MIparam.RangeAudFig = [1 LenSAI]; + else + MIparam.RangeAudFig = options.audiorange; + end; + % maah: was MIparam.RangeAudFig = [ZeroLoc+[0 , (fix(NAPparam.fs/F0est(nfr))-MarginAF)]]; + + % Calculation of the Mellin Coefficients + [MImtrx] = CalMellinCoef_Rich(SAIPhsCmp,NAPparam,MIparam); + + %Output into the 3d matrix + MI3d(1:Lenc2pi,1:LenTF,nfr) = MImtrx; + + % maah: Magnitude + MI3d(1:Lenc2pi,1:LenTF,nfr) = abs(MI3d(1:Lenc2pi,1:LenTF,nfr)); + %MI3d(:,:,nfr) = MImtrx; %added line + +end; + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/CalMI_Rich.old.and.slow.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/CalMI_Rich.old.and.slow.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,132 @@ +% tester generating function for Calculation of the Mellin Image in 'aim-mat' +% +% INPUT VALUES: SAI3d : 3D SAI +% NAPparam: Parameter for NAP +% SAIparam: Parameter for SAI +% MIparam: Parameter for MI +% RETURN VALUE: +% MI3d: 3D Mellin Image +% +% (c) 2003, University of Cambridge, Medical Research Council +% Original Code IRINO T +% 10 Jan. 2002 +% Modified by R. Turner (ret26@cam.ac.uk) +% Feb. 2003 +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual + +function [MI3d] = CalMI_Rich(SAI3d,options,sample_rate) + +%here we setup all the variables that the function requires +%%% CHANGE THE NAMES SO IT'S CLEAR WHAT'S GOING ON!!! + +%what do these do? +MIparam.NSAIPhsCmp = 0; %was 2 but aim uses a window starting at 0ms +MIparam.F0mode = 300; + +%these values set the resolution and scale of the axes in the final MT +%they are now defined in the parameter file +MIparam.TFval = options.TFval; +MIparam.c_2pi = options.c_2pi; +Lenc2pi = length(MIparam.c_2pi); +LenTF = length(MIparam.TFval); + +%not sure what these do +MIparam.Mu = -0.5; % flat if Mu <0.5: high pass, Mu>0.5 low pass +SAIparam.Nwidth = 0; %sets the negative width of the window +MIparam.SSI = options.ssi; + +%we find the maximum temporal interval size, the no of channels and the no +%of frames +[NumCh, LenSAI, LenFrame] = size(SAI3d); + +%going to remove any information in the first N channels +% N=5; +% for no_ch = 1:N, +% SAI3d(no_ch,:,:)=zeros(LenSAI,LenFrame); +% end; + +%saving the SAI3d for comparison with irino's +% savefile = 'SAI3d_AIM.mat'; +% SAI3d_AIM=SAI3d/max(max(max(SAI3d))); +% save(savefile,'SAI3d_AIM'); + +%for using irino's SAI in AIM +% load SAI3d_Irino.mat; +% SAI3d=SAI3d_Irino; + +%here we set up the Frs values for each channel +cf_afb = [100 6000]; %4500]; altered for 2dAT +NAPparam.Frs = FcNch2EqERB(min(cf_afb),max(cf_afb),NumCh); +NAPparam.fs = sample_rate; + +%We initialise the mellin image matrix (why is it best to do this - is it +%so we can spot errors more easily? +MI3d = zeros(Lenc2pi,LenTF,LenFrame); + +%user information (commented out) + new wait bar +%disp('*** MI Calculation ***'); + +%MIparam.RangeAudFig = []; +%disp(MIparam); +waithand=waitbar(0,'generating the MT'); + +% set the frame range, the mellin image is calculated for +if (options.do_all_frames == 1) + start_frame = 1; + end_frame = LenFrame; +else + start_frame = options.framerange(1); + end_frame = options.framerange(2); +end; + + +%this section does the filter response alignment +for nfr = start_frame:end_frame + %set up the waitbar + fraction_complete=nfr/LenFrame; + waitbar(fraction_complete); + + %generate the new matricies of the frames + SAIval = SAI3d(:,:,nfr); + SAIPhsCmp = zeros(size(SAIval)); + + %we shift each channel along the time interval axis by adding zeros + for nch = 1:NumCh, + NPeriod = NAPparam.fs/NAPparam.Frs(nch) * MIparam.NSAIPhsCmp; + shift_matrix = [zeros(1,fix(NPeriod)), SAIval(nch,:)]; + SAIPhsCmp(nch,1:LenSAI) = shift_matrix(1:LenSAI); + %MI3d(:,:,nfr) = SAIPhsCmp'; %added line + %SAIPhsCmp = SAI3d(:,:,nfr); %tester line + end; + if MIparam.F0mode == 0 + % No estimation of F0 + else + F0est(nfr) = MIparam.F0mode; + end; + + %Here we extract the information required to ensure that we have + %only one presentation of the 'timbre' information + ZeroLoc = abs(SAIparam.Nwidth)*NAPparam.fs/1000+1; + MarginAF = 0; % No margin by introducing WinAF + + % maah: set the range for the auditory image + if (options.do_all_image == 1) + MIparam.RangeAudFig = [1 LenSAI]; + else + MIparam.RangeAudFig = options.audiorange; + end; + % maah: was MIparam.RangeAudFig = [ZeroLoc+[0 , (fix(NAPparam.fs/F0est(nfr))-MarginAF)]]; + + % Calculation of the Mellin Coefficients + [MImtrx] = CalMellinCoef_Rich(SAIPhsCmp,NAPparam,MIparam); + + %Output into the 3d matrix + MI3d(1:Lenc2pi,1:LenTF,nfr) = MImtrx; + + % maah: Magnitude + MI3d(1:Lenc2pi,1:LenTF,nfr) = abs(MI3d(1:Lenc2pi,1:LenTF,nfr)); + %MI3d(:,:,nfr) = MImtrx; %added line + +end; + +close(waithand); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/CalMellinCoef.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/CalMellinCoef.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,123 @@ +% +% +% CalMICoef +% SAI -> Mellin Image Coefficient Direct +% IRINO T. +% 18 Jan 01 +% 27 Jun 01 (modified to MFCC type, Not on LogFrq) +% 11 Jan 02 (NAPparam, MIparam) +% +% TCW +% 27 Jan 06 - an attempt to increase speed somewhat +% +% function [ MICoef ] = CalMellinCoef(SAIPhsCmp,NAPparam,MIparam) +% INPUT: SAIPhsCmp : SAI val with Phase Compensation +% NAPparam: +% fs : Sampling Frequency +% Frs : Channel frequencies +% MIparam: +% RangeAudFig: Range of Auditory Figure +% [ZERO, Boundary] in sampling-point +% TFval : TFval == Hval (--> abscissa of MI) +% c_2pi : Kernel spatial frequeny (--> ordinate of MI) +% Mu : Kernel spatial weighting +% OUTPUT: MICoef : MI value +% +% +function [ MICoef ] = CalMellinCoef(SAIPhsCmp,NAPparam,MIparam) + + +fs = NAPparam.fs; +Frs = NAPparam.Frs; +RangeAudFig = MIparam.RangeAudFig; +TFval = MIparam.TFval; +c_2pi = MIparam.c_2pi; +Mu = MIparam.Mu; + +[NumCh LenSAI] = size(SAIPhsCmp); +LenAF = diff(RangeAudFig)+1; +LenTaper = round(0.5*NAPparam.fs/1000); % 0.5 ms taper +WinAF = TaperWindow(LenAF+LenTaper,'han',LenTaper); +WinAF = ones(NumCh,1)*WinAF(LenTaper+(1:LenAF)); + + + +AFval = WinAF .* SAIPhsCmp(:,RangeAudFig(1):RangeAudFig(2)); +[NumCh,LenAF] = size(AFval); +%MICoef=AFval; %added line +%%%%%%%%%% +%% LogFrs = log10(Frs(:)/min(Frs))/log10(6000/100); % normalized in [100 6000] +%% NormFrq = LogFrs; +%% Change to MFCC type, DCT on ERB domain on 27 Jun 2001 +NormFreq = ( (0:NumCh-1) + 0.5 )/NumCh; +c_pi = 2*c_2pi; + +amp = exp((Mu-0.5)*0.5)*sqrt(2/NumCh); % mag. norm. when NormFreq == 0.5 + % when using ERB --> Frs~=760 Hz +Kernel = amp*exp( ( i*pi*c_pi(:) - (Mu-0.5)) * NormFreq(:)'); +Kernel(1,1:NumCh) = Kernel(1,1:NumCh)/sqrt(2); +% +% for confirmation (15 Jan 2002) +% Kernel1 = Kernel; +% Kernel2 = DCTWarpFreq(0,length(NormFreq),length(c_pi),0); +% plot(real(Kernel1(7,:))) +% hold on +% plot(1:NumCh,real(Kernel(4,:)),'r--', 1:NumCh,abs(Kernel(4,:))) +% sum(Kernel1(3,:)-Kernel2(2,:)) +% hold off +% pause +% +% Kernel Mag at 100Hz Mag at 6000Hz +% Mu = 2: 2.1170 0.4724 % lowpass +% Mu = 1: 1.2840 0.7788 % lowpass +% Mu = 0.5: 1.0 1.0 % flat +% Mu = 0: 0.7788 1.2840 % high pass +% +% clf +% plot(LogFrs,Kernel); +% amp*exp((-Mu+0.5)*[0 1]) + +%%%%%%%%%% + +TFmargin = 0.1; +AFave = zeros(NumCh,length(TFval)); +MICoef = zeros(length(c_2pi),length(TFval)); + +ValNorm = 1; + +for cntTF = 1:length(TFval); + cntCh = 0; + for nch = 1:NumCh + nSAImin = max(1,fix((TFval(cntTF)-TFmargin)/Frs(nch)*fs)); + nSAImax = min(ceil((TFval(cntTF)+TFmargin)/Frs(nch)*fs), LenAF); + % aaa(nch,1:5) = [cntTF, nch, Frs(nch), nSAImin nSAImax]; + if nSAImin <= nSAImax, + AFave(nch,cntTF) = mean(AFval(nch,nSAImin:nSAImax))/ValNorm; + cntCh = cntCh +1; + end; + end; + NumValidCh(cntTF) = cntCh; +% ChNorm = NumCh/cntCh; % 10 Oct 01 --> Too much normalization + ChNorm = 1; % it seems the best at 15 Jan 02 + MICoef(1:length(c_2pi),cntTF) = ( Kernel*AFave(:,cntTF) )*ChNorm; +end; + +if MIparam.SSI == 1 + figure; + PrintFave = flipud(AFave); + image(PrintFave*10); +end; + +% Normalization by Number of channels within one AF, +% which depends on h values. + +ValRatio = sum(NumValidCh)/(length(TFval)*NumCh); +MICoef = MICoef*ValRatio; + +return + +% Do not apply this. (12 Mar. 2001) +% if length(SAIval) > 1, +% ValNorm = max(mean(SAIval)); % Mag. of strobing point +% if ValNorm < 0.01, ValNorm = 1; end; +% end; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/CalMellinCoef_Rich.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/CalMellinCoef_Rich.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,129 @@ +% +% +% CalMICoef +% SAI -> Mellin Image Coefficient Direct +% IRINO T. +% 18 Jan 01 +% 27 Jun 01 (modified to MFCC type, Not on LogFrq) +% 11 Jan 02 (NAPparam, MIparam) +% +% Tom Walters +% 11 Nov 04 Tweaks to double speed of processing +% +% function [ MICoef ] = CalMellinCoef(SAIPhsCmp,NAPparam,MIparam) +% INPUT: SAIPhsCmp : SAI val with Phase Compensation +% NAPparam: +% fs : Sampling Frequency +% Frs : Channel frequencies +% MIparam: +% RangeAudFig: Range of Auditory Figure +% [ZERO, Boundary] in sampling-point +% TFval : TFval == Hval (--> abscissa of MI) +% c_2pi : Kernel spatial frequeny (--> ordinate of MI) +% Mu : Kernel spatial weighting +% OUTPUT: MICoef : MI value +% +% +function [ MICoef ] = CalMellinCoef_Rich(SAIPhsCmp,NAPparam,MIparam) + +fs = NAPparam.fs; +Frs = NAPparam.Frs; +RangeAudFig = MIparam.RangeAudFig; +TFval = MIparam.TFval; +c_2pi = MIparam.c_2pi; +Mu = MIparam.Mu; + +[NumCh LenSAI] = size(SAIPhsCmp); +LenAF = diff(RangeAudFig)+1; +LenTaper = 0.5*NAPparam.fs/1000; % 0.5 ms taper +WinAF = TaperWindow(LenAF+LenTaper,'han',LenTaper); +WinAF = ones(NumCh,1)*WinAF(LenTaper+(1:LenAF)); + + + +AFval = WinAF .* SAIPhsCmp(:,RangeAudFig(1):RangeAudFig(2)); +[NumCh,LenAF] = size(AFval); +%MICoef=AFval; %added line +%%%%%%%%%% +%% LogFrs = log10(Frs(:)/min(Frs))/log10(6000/100); % normalized in [100 6000] +%% NormFrq = LogFrs; +%% Change to MFCC type, DCT on ERB domain on 27 Jun 2001 +NormFreq = ( (0:NumCh-1) + 0.5 )/NumCh; +c_pi = 2*c_2pi; + +amp = exp((Mu-0.5)*0.5)*sqrt(2/NumCh); % mag. norm. when NormFreq == 0.5 + % when using ERB --> Frs~=760 Hz +Kernel = amp*exp( ( i*pi*c_pi(:) - (Mu-0.5)) * NormFreq(:)'); +Kernel(1,1:NumCh) = Kernel(1,1:NumCh)/sqrt(2); +% +% for confirmation (15 Jan 2002) +% Kernel1 = Kernel; +% Kernel2 = DCTWarpFreq(0,length(NormFreq),length(c_pi),0); +% plot(real(Kernel1(7,:))) +% hold on +% plot(1:NumCh,real(Kernel(4,:)),'r--', 1:NumCh,abs(Kernel(4,:))) +% sum(Kernel1(3,:)-Kernel2(2,:)) +% hold off +% pause +% +% Kernel Mag at 100Hz Mag at 6000Hz +% Mu = 2: 2.1170 0.4724 % lowpass +% Mu = 1: 1.2840 0.7788 % lowpass +% Mu = 0.5: 1.0 1.0 % flat +% Mu = 0: 0.7788 1.2840 % high pass +% +% clf +% plot(LogFrs,Kernel); +% amp*exp((-Mu+0.5)*[0 1]) + +%%%%%%%%%% + +TFmargin = 0.1; +AFave = zeros(NumCh,length(TFval)); +MICoef = zeros(length(c_2pi),length(TFval)); + +ValNorm = 1; + +for cntTF = 1:length(TFval); + cntCh = 0; + for nch = 1:NumCh + nSAImin = max(1,fix((TFval(cntTF)-TFmargin)/Frs(nch)*fs)); + nSAImax = min(ceil((TFval(cntTF)+TFmargin)/Frs(nch)*fs), LenAF); + % aaa(nch,1:5) = [cntTF, nch, Frs(nch), nSAImin nSAImax]; + if nSAImin <= nSAImax, + %AFave(nch,cntTF) = mean(AFval(nch,nSAImin:nSAImax),2)/ValNorm; %Added dimension to take mean along TCW 11/2004 + + % Don't call mean directly to save on overheads. TCW 11/2004 + % Profiling shows this over *doubles* the speed of MI generation! + val_tcw=AFval(nch,nSAImin:nSAImax); + AFave(nch,cntTF)=(sum(val_tcw,2)/size(val_tcw,2))/ValNorm; + % TCW + + cntCh = cntCh +1; + end; + end; + NumValidCh(cntTF) = cntCh; +% ChNorm = NumCh/cntCh; % 10 Oct 01 --> Too much normalization + ChNorm = 1; % it seems the best at 15 Jan 02 + MICoef(1:length(c_2pi),cntTF) = ( Kernel*AFave(:,cntTF) )*ChNorm; +end; + +if MIparam.SSI == 1 + figure; + PrintFave = flipud(AFave); + image(PrintFave*10); +end; + +% Normalization by Number of channels within one AF, +% which depends on h values. + +ValRatio = sum(NumValidCh)/(length(TFval)*NumCh); +MICoef = MICoef*ValRatio; + +return + +% Do not apply this. (12 Mar. 2001) +% if length(SAIval) > 1, +% ValNorm = max(mean(SAIval)); % Mag. of strobing point +% if ValNorm < 0.01, ValNorm = 1; end; +% end; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalAIMIall.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalAIMIall.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,82 @@ + +% +% Calculation of all of AIMI: NAP-SAI-MI +% IRINO T +% 9 Oct 2002 +% +% function [MI3d, StrobeInfo, NAPparam, STBparam, SAIparam, MIparam] = ... +% CalAIMIall(Snd,fs,NAPparam,STBparam,SAIparam,MIparam,SwSave); +% +% INPUT: Snd : sound for MI +% fs: sampling rate +% NAPparam,STBparam,SAIparam,MIparam : parameters +% NameMI: Name of save file. if empty : No save +% +function [MI3d, StrobeInfo, NAPparam, STBparam, SAIparam, MIparam] = ... + CalAIMIall(Snd,fs,NAPparam,STBparam,SAIparam,MIparam,NameMI); + +if nargin < 3, NAPparam = []; end; +if nargin < 4, STBparam = []; end; +if nargin < 5, SAIparam = []; end; +if nargin < 6, MIparam = []; end; +if nargin < 7, NameMI = []; end; + +if isfield(NAPparam,'fs') == 0, NAPparam.fs = []; end; +if length(NAPparam.fs) == 0, NAPparam.fs = fs; end; +if NAPparam.fs ~= fs, error('Sampling rate is inconsistent.'); end; + +% NAPparam = []; +% NAPparam.fs = fs; + +%%%%%%%%%%%%% CHANGED FROM COMMENTED OUT %%%%%%%%%%%%%% +NAPparam.NumCh = 75; % default was 75 + +% NAPparam.cf_afb = [100 6000]; % default +NAPparam.SubBase = 0.5; + +if isfield(STBparam,'StInfo_EventLoc') == 0, + STBparam.StInfo_EventLoc = []; +end; + +% SAIparam.Nwidth = -5; % default +% SAIparam.Pwidth = 15; % default +SAIparam.FrstepAID = 0; % Event Synchronous +% SAIparam.ImageDecay = 10; % SAI image decay / Switch of window function +SAIparam.ImageDecay = 0; % using Window function +SAIparam.SwSmthWin = 1; % Window shape #1 + +% MIparam.F0mode = 300; % default +% MIparam.TFval = [0:0.25:5]; % default +% MIparam.c_2pi = [0:0.25:20]; % default +MIparam.Mu = -0.5; % pre-emphasis of high freq. + +LenSnd = length(Snd); +% disp([NameFile ' : T= ' num2str(LenSnd/NAPparam.fs, 4) ' (sec)']); + +[NAP, NAPparam] = CalNAPghll(Snd,NAPparam); +% PlaySound(Snd,NAPparam.fs); + +load C:\MATLAB6p5\work\napat.mat; +NAP=napat; + +[NAPPhsCmp, StrobeInfo, STBparam] = CalStrobePoint(NAP,NAPparam,STBparam); + +if length(STBparam.StInfo_EventLoc) > 0 + disp('StrobeInfo.EventLoc is replaced by STBparam.StInfo_EventLoc' ) + disp([ length(StrobeInfo.EventLoc), length(STBparam.StInfo_EventLoc) ]) + StrobeInfo.NAPpoint = []; + StrobeInfo.EventLoc = STBparam.StInfo_EventLoc; +end; +[SAI3d, RAI3d, SAIparam, StrobeInfo] = ... + CalSAIstinfo(NAPPhsCmp,NAPparam,StrobeInfo,STBparam,SAIparam); + + savefile = 'Irino_SAI.mat'; + save(savefile,'SAI3d'); + +[MI3d, MIparam] = CalMI(SAI3d,NAPparam,SAIparam,MIparam); + +if length(NameMI) > 0, + str = ['save ' NameMI ' MI3d StrobeInfo ' ... + ' NAPparam STBparam SAIparam MIparam ; ']; + disp(str); eval(str); +end; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalF0Strobe.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalF0Strobe.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,90 @@ +% +% Calculation of Strobe point from F0 information +% 5 Jun 2002 +% Irino, T. +% +% +% +function [ NAPPhsCmp, StrobeInfo, STBparam ] ... + = CalF0Strobe(NAP,NAPparam,STBparam) + +fs = NAPparam.fs; +Frs = NAPparam.Frs; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin < 3, STBparam = []; end; +if isfield(STBparam,'ExtDur') == 0, STBparam.ExtDur = []; end; +if length(STBparam.ExtDur) == 0, + STBparam.ExtDur = [0.5 1.5]; % Strobe Timing Range Extension + % better than [0.5 2] or [0.5 1] +end; + +if isfield(STBparam,'F0per1ms') == 0, + error('Specify STBparam.F0per1ms'); % F0 value for every 1ms +end; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +tic +disp('*** Calculation of Strobe Point ***'); + +[NumCh LenNAP] = size(NAP); +DelayNAPPhsCmp = 2.0; % strict & better +NAPPhsCmp = CmpnstERBFilt(NAP,Frs,fs,DelayNAPPhsCmp); + +% disp('******* F0 per 1ms to rough Event Timing *********'); +TPper1ms = 1000./STBparam.F0per1ms; +tmsCur = 0; +cnt = 0; +RoughEventTms = []; +while (tmsCur < length(TPper1ms)); + tmsCur = tmsCur + round(TPper1ms(tmsCur+1)); + cnt = cnt+1; + RoughEventTms(cnt) = tmsCur; +end; +RoughEventTms = min(RoughEventTms, length(TPper1ms)); +F0ev = STBparam.F0per1ms(RoughEventTms); + +nGW = 3*fs/1000+1; +GaussWin = Gauss(nGW,0.3*fs/1000); + +nRangeNAP = 30*fs/1000; +nRN = -nRangeNAP:nRangeNAP; +NAPweight = [ ( 1 - 1./(1:nRangeNAP)), 1 , fliplr( 1 - 1./(1:nRangeNAP))]; +nRangePeak = 1*fs/1000; +nEx = -nRangePeak:nRangePeak; +StrobePoint = zeros(NumCh,length(RoughEventTms)); + +for nev = 10:( length(RoughEventTms)-2) + nt1 = [1:nGW]; + nt2 = round(fs/F0ev(nev))+[1:nGW]; + nCntrMF = nt2(ceil(nGW/2)); + nt3 = round(2*fs/F0ev(nev))+[1:nGW]; + MatchFilt = zeros(1,max(nt3)); + MatchFilt(nt1) = GaussWin; + MatchFilt(nt2) = GaussWin; + MatchFilt(nt3) = GaussWin; + subplot(3,1,1); plot(MatchFilt) + nRET = RoughEventTms(nev)*fs/1000; + + for nch = NumCh/2:NumCh + nappc = NAPweight.*NAPPhsCmp(nch, nRET+ nRN); + val = conv(MatchFilt,nappc); + subplot(3,1,2); plot(nappc) + subplot(3,1,3); plot(val) + [dummy nPeakCan] = max(val); + CntrLoc = RoughEventTms(nev) + nPeakCan - nRangeNAP - nCntrMF + [dummy nEv] = max( NAPPhsCmp(CntrLoc + nEx)); + StrobePoint(nch,nev-2) = nEv + CntrLoc; + % pause + end; +end; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +StrobeInfo.NAPpoint = StrobePoint; +StrobeInfo.F0ev = F0ev; % F0 at event + +disp(['Strobe Point : elapsed_time = ' num2str(toc,3) ' (sec)']); + +return + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalF0estSAI.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalF0estSAI.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,71 @@ +% +% Calculation of F0 from Summary SAI +% Irino, T. +% 31 Jan 00 +% modified from CalPeakSumSAI(SAIval, fs, NumPeak); +% +% function [F0estSAI, MeanSAI, ModMeanSAI] ... +% = CalF0estSAI(SAIval, fs, Frs, StrobeLoc, MaxF0, PreF0); +% INPUT: SAIval : SAI value +% fs : Sampling frequency +% StrobeLoc: Number of Strobe Location (TimeInterval == 0) +% MaxF0: Maximum value of F0 +% PreF0: Pre-Estimated value of F0 +% OUTPUT: F0estSAI: Estimated F0 from SAI +% MeanSAI: Summary of SAI +% ModMeanSAI: Modified version of MeanSAI for period detection +% +function [F0estSAI, MeanSAI, ModMeanSAI, F0estSAIprof, ProfSAI ] ... + = CalF0estSAI(SAIval, fs, Frs, StrobeLoc, MaxF0, PreF0); + +if nargin < 4, StrobeLoc = 5*fs/1000+1; end; % at 5 ms +if nargin < 5, MaxF0 = 400; end; +if nargin < 6, PreF0 = 150; end; + +MinF0 = 80; +MeanSAI = mean(SAIval); +[NCh LenSAI] = size(SAIval); + +[dummy nc1] = min(abs(Frs-500)); +% wgtChSAI = [ (1:nc1)'/nc1; ones(NCh-nc1,1)]; useless +wgtChSAI = ones(NCh,1); + +nTilt = StrobeLoc + fix(fs/max(PreF0,MinF0)); % F0 > 80 Hz +nnt = [0:(LenSAI-nTilt)]; +wgtTISAI = [zeros(1,StrobeLoc-1), ones(1,nTilt-StrobeLoc), ... + (1 - nnt/max(nnt)) ]; +ModMeanSAI = mean((wgtChSAI*wgtTISAI).*SAIval); + +%[dummy nc0] = min(abs(Frs-70)); % Frs > 100 +nc0 = 1; +wgtProSAI = [zeros(1,nc0), (1 - ((nc0+1):nc1)/nc1) zeros(1,NCh-nc1)]'; + +ProfSAI = wgtProSAI.*mean(SAIval')'; +[dummy mp] = max(ProfSAI); +F0estSAIprof = Frs(mp); + +ThreshUV = 0.95; + + F0estSAI = 0; + if max(MeanSAI) == 0, F0estSAI = 0; return; end; + + [PeakVal1 PeakLoc1 ] = max(MeanSAI); + if PeakLoc1 ~= StrobeLoc; + disp([ 'StrobeLoc is strangely detected at ' int2str(PeakLoc1)]); + F0estSAI = 0; + return; + end; + + ModMeanSAI2 = ModMeanSAI; + nz = StrobeLoc+(0: fix(fs/MaxF0)-1); + ModMeanSAI2(nz) = zeros(size(nz)); % suppress 1st peak + [PeakVal2 PeakLoc2] = max(ModMeanSAI2); + F0estSAI = fs/(PeakLoc2-StrobeLoc); + + [TroughVal dummy] = min(ModMeanSAI(StrobeLoc:PeakLoc2)); + if TroughVal/PeakVal2 >= ThreshUV; + F0estSAI = 0; + end; + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalMI.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalMI.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,105 @@ +% +% Calculation of Mellin Image from SAI3d +% IRINO T +% 10 Jan. 2002 +% +% function [MI3d, MIparam] = CalMI(SAI3d,NAPparam,SAIparam,MIparam) +% +% INPUT: SAI3d : 3D SAI +% NAPparam: Parameter for NAP +% SAIparam: Parameter for SAI +% MIparam: Parameter for MI +% OUTPUT: MI3d: 3D Mellin Image +% +function [MI3d, MIparam] = CalMI(SAI3d,NAPparam,SAIparam,MIparam) + +%%%%%%%%% +if nargin < 4, MIparam = []; end; +if isfield(MIparam,'NSAIPhsCmp') == 0, MIparam.NSAIPhsCmp = []; end; +if length(MIparam.NSAIPhsCmp) == 0, + MIparam.NSAIPhsCmp = 0; %was 2 but now window is causal - Rich +end; +if isfield(MIparam,'F0mode') == 0, MIparam.F0mode = []; end; +if length(MIparam.F0mode) == 0, + MIparam.F0mode = 300; +end; +if isfield(MIparam,'TFval') == 0, MIparam.TFval = []; end; +if length(MIparam.TFval) == 0, + MIparam.TFval = [0:0.05:15]; %was 15 +end; +if isfield(MIparam,'c_2pi') == 0, MIparam.c_2pi = []; end; +if length(MIparam.c_2pi) == 0, + MIparam.c_2pi = [0:0.05:30]; +end; +if isfield(MIparam,'Mu') == 0, MIparam.Mu = []; end; +if length(MIparam.Mu) == 0, + MIparam.Mu = 0.5; % flat if Mu <0.5: high pass, Mu>0.5 low pass +end; + +[NumCh, LenSAI, LenFrame] = size(SAI3d); + +Lenc2pi = length(MIparam.c_2pi); +LenTF = length(MIparam.TFval); +%MI3d = zeros(Lenc2pi,LenTF,LenFrame); + +disp('*** MI Calculation ***'); +MIparam.RangeAudFig = []; +disp(MIparam) + +%saving the SAI3d for comparison with AIM's + savefile = 'SAI3d_Irino.mat'; + SAI3d_Irino=SAI3d/max(max(max(SAI3d))); + save(savefile,'SAI3d_Irino'); + +tic +%%%%%%%% For each frame %%%%%%%%% +for nfr = 1:LenFrame, + + SAIval = SAI3d(:,:,nfr); + + SAIPhsCmp = zeros(size(SAIval)); + for nch = 1:NumCh, + NPeriod = NAPparam.fs/NAPparam.Frs(nch) * MIparam.NSAIPhsCmp; + vv = [zeros(1,fix(NPeriod)), SAIval(nch,:)]; + SAIPhsCmp(nch,1:LenSAI) = vv(1:LenSAI); + % MI3d(:,:,nfr) = SAIPhsCmp; + end; + + if MIparam.F0mode == 0 + %%% F0 estimation if necessary + else + F0est(nfr) = MIparam.F0mode; % No estimation of F0 + end; + ZeroLoc = abs(SAIparam.Nwidth)*NAPparam.fs/1000+1; + % MarginAF = fix(0.3 * NAPparam.fs/1000); % 0.3 ms margin + MarginAF = 0; % No margin by introducing WinAF + MIparam.RangeAudFig = ... + [ZeroLoc+[0 , (fix(NAPparam.fs/F0est(nfr))-MarginAF)]]; + %RangeAudFigKeep(1:2,nfr) = MIparam.RangeAudFig(:); +%MIparam.RangeAudFig=[1 300] %added as an experiment + %%%%%%%% Mellin Coefficients %%%%%%%%% + + [MImtrx] = CalMellinCoef(SAIPhsCmp,NAPparam,MIparam); + %% 80 times faster than showSSI + showMI + + %MI3d(1:Lenc2pi,1:LenTF,nfr) = MImtrx; + MI3d(:,:,nfr) = MImtrx; %added line - should behave no different + if rem(nfr, 20) == 0 | nfr == LenFrame + disp(['Mellin Image Frame #' int2str(nfr) '/#' int2str(LenFrame) ... + ': elapsed_time = ' num2str(toc,3) ' (sec)']); + % if SwPlot > 0, CalMI_plotImage; end; drawnow; + end; + + + if 0 + subplot(3,1,1) + image(flipud(SAI3d(:,:,nfr))*5) + subplot(3,1,2) + image(flipud(SAIPhsCmp)*5) + subplot(3,1,3) + image(flipud(abs(MI3d(:,:,nfr)))*20) + drawnow + end; + + +end; % for nfr = 1:LenFrame diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalMellinCoef.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalMellinCoef.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,119 @@ +% +% +% CalMICoef +% SAI -> Mellin Image Coefficient Direct +% IRINO T. +% 18 Jan 01 +% 27 Jun 01 (modified to MFCC type, Not on LogFrq) +% 11 Jan 02 (NAPparam, MIparam) +% +% function [ MICoef ] = CalMellinCoef(SAIPhsCmp,NAPparam,MIparam) +% INPUT: SAIPhsCmp : SAI val with Phase Compensation +% NAPparam: +% fs : Sampling Frequency +% Frs : Channel frequencies +% MIparam: +% RangeAudFig: Range of Auditory Figure +% [ZERO, Boundary] in sampling-point +% TFval : TFval == Hval (--> abscissa of MI) +% c_2pi : Kernel spatial frequeny (--> ordinate of MI) +% Mu : Kernel spatial weighting +% OUTPUT: MICoef : MI value +% +% +function [ MICoef ] = CalMellinCoef_Rich(SAIPhsCmp,NAPparam,MIparam) + +fs = NAPparam.fs; +Frs = NAPparam.Frs; +RangeAudFig = MIparam.RangeAudFig; +TFval = MIparam.TFval; +c_2pi = MIparam.c_2pi; +Mu = MIparam.Mu; + +[NumCh LenSAI] = size(SAIPhsCmp); +LenAF = diff(RangeAudFig)+1; +LenTaper = 0.5*NAPparam.fs/1000; % 0.5 ms taper +WinAF = TaperWindow(LenAF+LenTaper,'han',LenTaper); +WinAF = ones(NumCh,1)*WinAF(LenTaper+(1:LenAF)); + +AFval = WinAF .* SAIPhsCmp(:,RangeAudFig(1):RangeAudFig(2)); +[NumCh,LenAF] = size(AFval); +%MICoef=AFval; %added line +%%%%%%%%%% +%% LogFrs = log10(Frs(:)/min(Frs))/log10(6000/100); % normalized in [100 6000] +%% NormFrq = LogFrs; +%% Change to MFCC type, DCT on ERB domain on 27 Jun 2001 +NormFreq = ( (0:NumCh-1) + 0.5 )/NumCh; +c_pi = 2*c_2pi; + +amp = exp((Mu-0.5)*0.5)*sqrt(2/NumCh); % mag. norm. when NormFreq == 0.5 + % when using ERB --> Frs~=760 Hz +Kernel = amp*exp( ( i*pi*c_pi(:) - (Mu-0.5)) * NormFreq(:)'); +Kernel(1,1:NumCh) = Kernel(1,1:NumCh)/sqrt(2); +% +% for confirmation (15 Jan 2002) +% Kernel1 = Kernel; +% Kernel2 = DCTWarpFreq(0,length(NormFreq),length(c_pi),0); +% plot(real(Kernel1(7,:))) +% hold on +% plot(1:NumCh,real(Kernel(4,:)),'r--', 1:NumCh,abs(Kernel(4,:))) +% sum(Kernel1(3,:)-Kernel2(2,:)) +% hold off +% pause +% +% Kernel Mag at 100Hz Mag at 6000Hz +% Mu = 2: 2.1170 0.4724 % lowpass +% Mu = 1: 1.2840 0.7788 % lowpass +% Mu = 0.5: 1.0 1.0 % flat +% Mu = 0: 0.7788 1.2840 % high pass +% +% clf +% plot(LogFrs,Kernel); +% amp*exp((-Mu+0.5)*[0 1]) + +%%%%%%%%%% + +TFmargin = 0.1; +AFave = zeros(NumCh,length(TFval)); +MICoef = zeros(length(c_2pi),length(TFval)); + +ValNorm = 1; + +for cntTF = 1:length(TFval); + cntCh = 0; + for nch = 1:NumCh + nSAImin = max(1,fix((TFval(cntTF)-TFmargin)/Frs(nch)*fs)); + nSAImax = min(ceil((TFval(cntTF)+TFmargin)/Frs(nch)*fs), LenAF); + % aaa(nch,1:5) = [cntTF, nch, Frs(nch), nSAImin nSAImax]; + if nSAImin <= nSAImax, + AFave(nch,cntTF) = mean(AFval(nch,nSAImin:nSAImax))/ValNorm; + cntCh = cntCh +1; + end; + end; + + NumValidCh(cntTF) = cntCh; + %ChNorm = NumCh/cntCh; % 10 Oct 01 --> Too much normalization - RICH + %TOOK THIS OUT + ChNorm = 1; % it seems the best at 15 Jan 02 + MICoef(1:length(c_2pi),cntTF) = ( Kernel*AFave(:,cntTF) )*ChNorm; +end; + +% Normalization by Number of channels within one AF, +% which depends on h values. + +ValRatio = sum(NumValidCh)/(length(TFval)*NumCh); +MICoef = MICoef*ValRatio; + +return + +% Do not apply this. (12 Mar. 2001) +% if length(SAIval) > 1, +% ValNorm = max(mean(SAIval)); % Mag. of strobing point +% if ValNorm < 0.01, ValNorm = 1; end; +% end; + + + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalNAPghll.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalNAPghll.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,125 @@ +% +% Calculation of NAP +% (gammatone, halfwave rectification, lowpass, log compression) +% 7 Jan 2002 +% Toshio Irino +% +function [NAP, NAPparam, BMM] = CalNAPghll(Snd, NAPparam) + +fs = NAPparam.fs; +if isfield(NAPparam,'NumCh') == 0, NAPparam.NumCh = []; end; +if length(NAPparam.NumCh) == 0, + NAPparam.NumCh = 75; +end; +if isfield(NAPparam,'cf_afb') == 0, NAPparam.cf_afb = []; end; +if length(NAPparam.cf_afb) == 0, + NAPparam.cf_afb = [100 6000]; %4500 in aim-mat 6000 used by irino +end; +if isfield(NAPparam,'SubBase') == 0, NAPparam.SubBase = []; end; +if length(NAPparam.SubBase) == 0, + NAPparam.SubBase = 0; +end; + +fs = NAPparam.fs; +NumCh = NAPparam.NumCh; +cf_afb = NAPparam.cf_afb; + +%%%%% Outer-Mid Ear Compensation %%%% +%CmpnOutMid = OutMidCrctFilt('ELC',fs,0); +%Snd_om = filter(CmpnOutMid,1,Snd); TAKEN OUT THE PCP %%%%%%%%%%%%% +Snd_om = Snd; % if unnecessary + + save Snd.mat Snd; + +%%%%% BMM %%% +disp('*** BMM & NAP Calculation ***'); +disp(NAPparam) +tic; +%% dERB = (Freq2ERB(max(cf_afb))-Freq2ERB(min(cf_afb)))/(NumCh-1); +%% Frs = ERB2Freq( Freq2ERB(min(cf_afb)):dERB:Freq2ERB(max(cf_afb)) ); +Frs = FcNch2EqERB(min(cf_afb),max(cf_afb),NumCh); +NAPparam.Frs = Frs; +NAPparam.b = 1.019; % default gammatone + +% IIR implementation +% disp('BMM : Start calculation, Wait a minute'); +% fcoefs = MakeERBFilters98B(fs,Frs,[],b); % new version +% BMM = ERBFilterBank(Snd_om, fcoefs); +% disp(['BMM : elapsed_time = ' num2str(toc,3) ' (sec)']); + +%%%%% Lowpass filter for representing Phase-lock property %%% - do we want +%%%%% to remove this? +flpcut = 1200; +% [bzLP apLP] = butter(1,flpcut/(fs/2)); +% bzLP2 = [bzLP(1)^2, 2*bzLP(1)*bzLP(2), bzLP(2)^2]; +% apLP2 = [apLP(1)^2, 2*apLP(1)*apLP(2), apLP(2)^2]; + +%%%%% NAP %%%% +tic; +LenSnd = length(Snd_om); +bias = 0.1; +for nch = 1:NumCh + if rem(nch, 20) == 0 | nch == 1 | nch == NumCh + disp(['BMM-NAP #' int2str(nch) '/#' int2str(NumCh) ': ' ... + 'elapsed_time = ' num2str(toc,3) ' (sec)']); + end; + + gt = GammaChirp(Frs(nch),fs,4,NAPparam.b,0,0,[],'peak'); + % BMM(nch,:) = filter(gt,1,Snd_om); + BMM(nch,:) = fftfilt(gt,Snd_om); + + % save BMM.mat BMM; + + NAPraw = log10(max(BMM(nch,:),bias)) - log10(bias); + %NAP(nch,1:LenSnd) = filter(bzLP2,apLP2,NAPraw); % LP filtered - + %REMOVED BY RICH + NAP(nch,1:LenSnd) = NAPraw; + + % [Frs(nch) max(max(NAPraw)) max(max(NAP(nch,:)))] +end; + + savefile = 'bmm_irino.mat'; + save(savefile,'BMM'); + + +if NAPparam.SubBase ~= 0, +disp([ '=== Baseline subtraction : Max NAP = ' num2str( max(max(NAP))) ... + ', NAPparam.SubBase = ' num2str(NAPparam.SubBase) ' ===']); +end; + +NAP0 = NAP; +NAP = max((NAP0 - NAPparam.SubBase),0); + +NAPparam.height = max(max(NAP)); +NAPparam.tms = (0:LenSnd-1)/fs*1000; + +return + +%%%%%%%%%%%% + +if 1 + ProfNAP0 = mean(NAP0')'; + ProfNAP = mean(NAP')'; + plot(NAPparam.Frs,ProfNAP0,NAPparam.Frs,ProfNAP0) + subplot(2,1,1) + image(flipud(NAP0(:,1:100:LenSnd))*15) + subplot(2,1,2) + image(flipud(NAP(:,1:100:LenSnd))*20) +end; + + +return + +%%%%%%%%%%%%%%%%%%%% + +% [bzGT, apGT, Frs, ERBw] = MakeERBFiltersB(fs,NumCh,Frs,b); % NG for low freq + +%%Simple pre-emphasis +%%CoefPreEmph = [1, -0.97]; +%%Snd = filter(CoefPreEmph,1,Snd); + +% [frsp, freq] = freqz(bzLP,apLP,1024,fs); +% [frsp2, freq] = freqz(bzLP2,apLP2,1024,fs); +% plot(freq,20*log10(abs(frsp)),freq,20*log10(abs(frsp2))) +% axis([0 2000 -10 2]); +% grid; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalPeakSumSAI.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalPeakSumSAI.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,51 @@ +% +% Calculation of Peaks in Summary SAI +% (Candidates of Auditory Figure Boundary) +% Irino, T. +% 5 Jan. 98 +% +% function [PeakLoc, PeakVal, PitchVal] ... +% = CalPeakSumSAI(SAIval, fs, NumPeak); +% INPUT: SAIval : SAI value +% fs : Sampling frequency +% NumPeak: Number of peaks to detect +% ExpPeak1: Expected Peak1 +% OUTPUT: PeakLoc: Peak location in sampling points +% PeakVal: Peak value +% PitchVal: Pitch Value in ms +% +function [PeakLoc, PeakVal, PitchVal] ... + = CalPeakSumSAI(SAIval,fs,NumPeak); + +if nargin < 3, NumPeak = 3; end; +if nargin < 4, verbose = 0; end; + +SumSAI = sum(SAIval); + +if max(SumSAI) > 0, + for np = 1:NumPeak, + [vv mm ] = max(SumSAI); + PeakVal(np) = vv; + PeakLoc(np) = mm; + % zp = -1*fs/1000:1.5*fs/1000; % remove for search next peak + zp = -1*fs/1000:2.5*fs/1000; % max 400 Hz + zzp = mm+zp; + SumSAI(zzp(zzp>0)) = zeros(size(zzp(zzp>0))); + if np == 1, SumSAI(1:mm-1) = zeros(1,mm-1); end; + % remove negative peak + end; + PitchVal = (PeakLoc(2)-PeakLoc(1))/fs*1000; +else + PeakLoc = 0; + PitchVal = 0; +end; + +if 0, + disp('Peak Positions in Sammry SAI (Zero point candidates):'); + disp([PeakVal; PeakVal/fs*1000]); + disp(['Estimated Pitch Value = ' num2str(PitchVal) ' ms']); +end; + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalSAIstinfo.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalSAIstinfo.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,191 @@ +% +% Calculation of SAI using Strobe point information +% 30 May 2002 +% 18 Feb 2002 +% 9 Oct 2002 +% Toshio Irino +% +% Frame Base (ex. SAIparam.FrstepAID == 10) +% Event Base (SAIparam.FrstepAID == 0) +% +function [SAI3d, RAI3d, SAIparam, StrobeInfo] ... + = CalSAIstinfo(NAPPhsCmp,NAPparam,StrobeInfo,STBparam,SAIparam); + +%%%%% Parameter setting %%%% +if nargin < 5, SAIparam = []; end; + +if isfield(SAIparam,'Nwidth') == 0, SAIparam.Nwidth = []; end; +if length(SAIparam.Nwidth) == 0, + SAIparam.Nwidth = 0; % Negative width of auditory image (ms). +end; +if isfield(SAIparam,'Pwidth') == 0, SAIparam.Pwidth = []; end; +if length(SAIparam.Pwidth) == 0, + SAIparam.Pwidth = 35; % Positive width of auditory image (ms). +end; +if isfield(SAIparam,'NAPdecay') == 0, SAIparam.NAPdecay = []; end; +if length(SAIparam.NAPdecay) == 0, + SAIparam.NAPdecay = -2.5; % NAP (input) decay rate (%/ms) +end; +if isfield(SAIparam,'ImageDecay') == 0, SAIparam.ImageDecay = []; end; +if length(SAIparam.ImageDecay) == 0, + SAIparam.ImageDecay = 30; % Auditory image decay half-life (ms). + % NG for 10 ? +end; +if isfield(SAIparam,'FrstepAID') == 0, SAIparam.FrstepAID = []; end; +if length(SAIparam.FrstepAID) == 0, + SAIparam.FrstepAID = 0; % default : Event base + % SAIparam.FrstepAID = 10; % frame shift 10 ms +end; + +if isfield(SAIparam,'SwSmthWin') == 0, SAIparam.SwSmthWin = []; end; +if length(SAIparam.SwSmthWin) == 0, + SAIparam.SwSmthWin = 1; % Switch of Smoothing Window +end; + +if SAIparam.SwSmthWin == 0, SAIparam.CoefSmthWin = 1; end; % no smoothing +if SAIparam.SwSmthWin == 1, SAIparam.CoefSmthWin = hanning(5); end; %hanning window +if SAIparam.SwSmthWin == 2, SAIparam.CoefSmthWin = [1 2 3 4 0 0 0]; end; +SAIparam.CoefSmthWin = SAIparam.CoefSmthWin/sum(SAIparam.CoefSmthWin); + +fs = NAPparam.fs; +nExtDur = []; +if length(StrobeInfo.NAPpoint) == 0, + nExtDur = fix(STBparam.ExtDur(1)*fs/1000):fix(STBparam.ExtDur(2)*fs/1000); +end; +% if StrobeInfo.NAPpoint is missing, then Reproduce NAPpoint. +% Max Loc Error is about 100 sample point. Error in MI3d is about 1.5% +% check on 16 Oct 2002 +% + +disp('*** SAI Calculation ***'); +disp(SAIparam) + +%%%%% Initialize %%%% +[NumCh, LenNAP] = size(NAPPhsCmp); +LenNwid = abs(SAIparam.Nwidth)*fs/1000; +LenPwid = abs(SAIparam.Pwidth)*fs/1000; +LenSAI = LenPwid +LenNwid +1; +NAPdecayWin = 1 + (SAIparam.NAPdecay/100/fs*1000)*(-LenNwid:LenPwid); +NAPdecayWin = ones(NumCh,1)*NAPdecayWin; +if SAIparam.ImageDecay > 0, + SAIdecayConst = 1 - log(2)/(SAIparam.ImageDecay*fs/1000); % ^ (sample point) +end; +RawAI = zeros(NumCh,LenSAI); +SAI = zeros(NumCh,LenSAI); + +LenStrb = length(StrobeInfo.EventLoc); +if SAIparam.FrstepAID > 0, LenFrame = fix(LenNAP/(SAIparam.FrstepAID*fs/1000)); +else LenFrame = LenStrb; % event base +end; +FrameTiming = (1:LenFrame)*SAIparam.FrstepAID*fs/1000; +SAI3d = zeros(NumCh,LenSAI,LenFrame); +RAI3d = zeros(NumCh,LenSAI,LenFrame); +IntgrPoint = zeros(1,LenStrb); +dIntgrPoint = zeros(1,LenStrb); +MeandIP0 = 8*fs/1000; % setting to 8 ms period + +if SAIparam.FrstepAID == 0, %%%%% Event Base %%%% + + for nst = 1:LenStrb + for nch = 1:NumCh + if length(nExtDur) > 0 + nrng = StrobeInfo.EventLoc(nst) + nExtDur; + nrng = min( LenNAP, max(1,nrng)); + [val Npeak] = max(NAPPhsCmp(nch,nrng)); + nstp = min(nrng)+Npeak-1; + StrobeInfo.NAPpoint(nch,nst) = nstp; + end; + npt = StrobeInfo.NAPpoint(nch,nst) +(-LenNwid:LenPwid); + npt = min(LenNAP,max(1,npt)); + RawAI(nch,:) = NAPPhsCmp(nch,npt); % Raw SAI + end; + + IntgrPoint(nst) = max(StrobeInfo.NAPpoint(:,nst))+1; % in sample point + dIntgrPoint(nst) = IntgrPoint(nst) - IntgrPoint(max(1,nst-1)); + MeandIP = mean(dIntgrPoint(max(1,nst-10):nst)); % last 10 strobe + % MeandIP = MeandIP0; % fixed --> NG level difference. 13 Jun 2002 + + RAI3d(:,:,nst) = RawAI; + + if SAIparam.ImageDecay > 0 + AmpDecay = SAIdecayConst^dIntgrPoint(nst); + AmpIntgr = min(MeandIP/MeandIP0,3)*NAPdecayWin; + SAI = AmpDecay * SAI + AmpIntgr .* RawAI; % 12 June 2002 + SAI3d(:,:,nst) = SAI; + end; + + if rem(nst, 50) == 0 | nst == LenFrame + disp(['SAI-STI Event-Base Frame #' ... + int2str(nst) '/#' int2str(LenFrame) ': ' ... + 'elapsed_time = ' num2str(toc,3) ' (sec)']); + end; + end; + + % size(StrobeInfo.NAPpoint) + + if SAIparam.ImageDecay == 0 & SAIparam.SwSmthWin == 0 + disp('Set SAI3d == RAI3d'); + SAI3d = RAI3d; + return; + end; + + %%% Smoothing with window %%% + if SAIparam.ImageDecay == 0 + for nst = 1:LenStrb + SAI = zeros(NumCh,LenSAI); + LenCSW = length(SAIparam.CoefSmthWin); + for nwin = -fix(LenCSW/2):fix(LenCSW/2) + ncf = nwin+fix(LenCSW/2)+1; + SAI = SAI + SAIparam.CoefSmthWin(ncf) ... + * RAI3d(:,:,min(max(nst+nwin,1), LenStrb)); + end; + SAI3d(:,:,nst) = SAI; + end; + end; + +else %%%%%%%%%%% if SAIparam.FrstepAID > 0, %%%%% Constant Frame Base %%%% + +%appears to be no point in the following code +error('Constant Frame Base. I am not sure it is maintained. 12 Jun 2002'); + IntgrPoint(1) = 1; + nfr = 0; + + for nst = 2:LenStrb + for nch = 1:NumCh + npt = StrobeInfo.NAPpoint(nch,nst) +(-LenNwid:LenPwid); + npt = min(LenNAP,max(1,npt)); + RawAI(nch,:) = NAPPhsCmp(nch,npt); + end; + + IntgrPoint(nst) = max(StrobeInfo.NAPpoint(:,nst))+1; + + nkk = find( FrameTiming >= IntgrPoint(nst-1) & ... + FrameTiming < IntgrPoint(nst)); + if nst == LenStrb, nkk2 = find(FrameTiming >= IntgrPoint(LenStrb)); + else nkk2 = []; + end; + + for nn = [nkk nkk2], + nfr = nfr+1; + dTim = FrameTiming(nn) - IntgrPoint(nst-1); + SAI3d(:,:,nfr) = SAI * ( SAIdecayConst^dTim); + RAI3d(:,:,nfr) = RawAI; + SwOn(nfr) = nfr; + + if rem(nfr, 50) == 0 | nfr == LenFrame + disp(['SAI-STI ' int2str(SAIparam.FrstepAID) ... + '-ms Uniform Frame #' int2str(nfr) '/#' int2str(LenFrame) ': ' ... + 'elapsed_time = ' num2str(toc,3) ' (sec)']); + end; + end; + + %%% Add in here %%% + dIntgrPoint = IntgrPoint(nst)-IntgrPoint(nst-1); + SAI = SAI*( SAIdecayConst^dIntgrPoint) + RawAI.*NAPdecayWin; + end; + +end; %%%%%%%%%%% if SAIparam.FrstepAID > 0, %%%%% + + +return; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CalStrobePoint.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CalStrobePoint.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,221 @@ +% +% Calculation of Strobe point using NAP compensation +% 17 Oct 2002 +% Irino, T. +% +% +% +function [NAPPhsCmp,StrobeInfo,STBparam]=CalStrobePoint(NAP,NAPparam,STBparam); + +fs = NAPparam.fs; +Frs = NAPparam.Frs; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin < 3, STBparam = []; end; +if isfield(STBparam,'ExtDur') == 0, STBparam.ExtDur = []; end; +if length(STBparam.ExtDur) == 0, + STBparam.ExtDur = [-0.5 1.5]; % Strobe Timing Range Extension + % better than [-0.5 2] or [-0.5 1] + % changed polarity 0.5 --> -0.5 on 17 Oct 2002 +end; + +if isfield(STBparam,'ThreshDecay') == 0, STBparam.ThreshDecay = []; end; +if length(STBparam.ThreshDecay) == 0, + %%% STBparam.ThreshDecay = 50; % helf life ms . better than 30 + STBparam.ThreshDecay = 40; +end; + +if isfield(STBparam,'TimeSpont') == 0, STBparam.TimeSpont = []; end; +if length(STBparam.TimeSpont ) == 0, + STBparam.TimeSpont = 20; % for every 20 ms Spotaneous firing occur if no peak info. +end; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +tic +disp('*** Calculation of Strobe Point ***'); + +[NumCh LenNAP] = size(NAP); +DelayNAPPhsCmp = 2.0; % strict & better + +%%%%REMOVED BY RICH AS TEST +NAPPhsCmp = CmpnstERBFilt(NAP,Frs,fs,DelayNAPPhsCmp); + +%%%%REPLACED WITH +%NAPPhsCmp = NAP; + +NchAve = 1:NumCh; % +NchAve = find(Frs<1500); +PwrVal = 3; + +% MeanNAPPhsCmp = mean(NAPPhsCmp(NchAve,:)); +% MeanNAPPhsCmp = mean(NAPPhsCmp(NchAve,:).^2); % with STBparam.ThreshDecay==50 +MeanNAPPhsCmp = mean(NAPPhsCmp(NchAve,:).^PwrVal);% 3 seems better + % STBparam.ThreshDecay == 40 + +% LinPwrNAPpc = 10.^(NAPPhsCmp(NchAve,:).^2/10); +% MeanNAPPhsCmp = mean(LinPwrNAPpc); % Lin Power + + +% disp('******* Producing NAPmask *********'); +DecayConst = 1 - log(2)/(STBparam.ThreshDecay*fs/1000); +Threshold = zeros(1,LenNAP); +SwVal = zeros(1,LenNAP); + +%% Every sample point +PeakLoc = []; +cnt1 = 0; +PrePeakDiff = 200; +NpeakPre = 5; +MeanNAPPhsCmp1 = MeanNAPPhsCmp; +for nsmp = 2:LenNAP + [Threshold(nsmp) SwVal(nsmp) ] = ... + max([ MeanNAPPhsCmp1(nsmp), Threshold(nsmp-1)*DecayConst]); + if rem(nsmp/fs*1000, 200) == 0, + disp(['Strobe Point Time : #' int2str((nsmp-1)/fs*1000) ... + ' (ms) / ' int2str((LenNAP-1)/fs*1000) ' (ms)']); + end; + if SwVal(nsmp) == 2, % when it is not in Pulse + if sum(SwVal(nsmp-1)) == 1, + cnt1 = cnt1 + 1; + PeakLoc(cnt1) = nsmp-1; + CanPeakDiff = diff(PeakLoc(max(cnt1+(-NpeakPre:0),1))); + %%%% Linear regression here for next expected peak %%% + %% [areg breg] = LinRegress(1:NpeakPre,CanPeakDiff); + % PrePeakDiff = areg*(NpeakPre+1)+breg; + % PrePeakDiff1 = areg*(NpeakPre)+breg; % all right + % PrePeakDiff2 = mean(CanPeakDiff); % 3rd + PrePeakDiff = median(CanPeakDiff); % better + PrePeakDiff = max(PrePeakDiff,fs/300); % min boundary + + % n*F0 channel selection : NG % see below + end; + if nsmp - PeakLoc(cnt1) > STBparam.TimeSpont*fs/1000; + Threshold(nsmp) = 0; % reset Threshold + end; + if nsmp - (PeakLoc(cnt1)+fix(PrePeakDiff - 0.2*fs/1000) ) == 0, + Threshold(nsmp) = Threshold(nsmp)*0.8; + % decrease Threshold at expected time + end; + if nsmp - (PeakLoc(cnt1)+fix(PrePeakDiff + 0.2*fs/1000 ) ) == 0, + Threshold(nsmp) = Threshold(nsmp)/0.82; + % increase Threshold after expected time + end; + + end; +end; + +% disp('******* NAPMask *********'); +NAPmask = zeros(1,LenNAP); +nExtDur = fix(STBparam.ExtDur(1)*fs/1000):fix(STBparam.ExtDur(2)*fs/1000); +nEx = PeakLoc'*ones(size(nExtDur)) + ones(size(PeakLoc'))*nExtDur; +nEx = min(max(nEx,1),LenNAP); +NAPmask(nEx(:)) = ones(size(nEx(:))); +NAPstrb = NAPPhsCmp.*(ones(NumCh,1)*NAPmask); + +nONmask = find(diff([0 NAPmask]) > 0); +nOFFmask = find(diff([NAPmask 0]) < 0); +StrobePoint = zeros(NumCh,length(nONmask)); + +NchAve1 = find(Frs<1000); +MeanPwrNPC = mean(NAPPhsCmp(NchAve1,:).^2); +EventLoc(1) = 0; +cnt = 0; + +% disp('******* Strobe Point & Event Location *********'); +for nsw = 1:length(nONmask) + nrng = nONmask(nsw):nOFFmask(nsw); + for nch = 1:NumCh + [val Npeak] = max(NAPPhsCmp(nch,nrng)); + nstp = nONmask(nsw)+Npeak-1; + StrobePoint(nch,nsw) = nstp; + end; + [val nmax] = max(MeanNAPPhsCmp(nrng)); + newEventLoc = nONmask(nsw)+nmax-1; + + if newEventLoc ~= EventLoc(max(cnt,1)), cnt = cnt+1; end; + EventLoc(cnt) = newEventLoc; + PeakVal(cnt) = MeanPwrNPC(EventLoc(cnt)); + TroughVal(cnt) = min(MeanPwrNPC(EventLoc(max(cnt-1,1)):EventLoc(cnt))); +end; + +% disp('******* UV decision *********'); +EventUV = PeakVal-TroughVal; +EventUV = EventUV/mean(EventUV); +MeanUV = 0.7; +SlopeUV = 10; +EventUV = 1./(1 + exp(-SlopeUV*(EventUV-MeanUV))); + +NAPuv = zeros(1,LenNAP); +for cnt = 2:length(EventLoc), + nv = EventLoc(cnt-1):EventLoc(cnt); + val = ( EventUV(cnt-1) * EventUV(cnt) > 0.5); + NAPuv(nv) = val*ones(size(nv)); +end; + +% disp('******* Event Location to F0 info *******'); +tms = (0:LenNAP-1)/fs*1000; +TmsNe = (EventLoc-1)/fs*1000; +F0ev = [0, 1./diff(EventLoc)*fs]; +F0med = GetF0median(F0ev); +%%% F0spl = max(50,spline(TmsNe,F0med,tms)); Not so good +F0spl = max(50,interp1(TmsNe,F0med,tms,'linear')); % better +F0raw = F0spl.*NAPuv; +F0var = (NAPuv == 0); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +StrobeInfo.NAPpoint = StrobePoint; +StrobeInfo.EventLoc = EventLoc; + +%StrobeInfo.EventLoc=StrobeInfo.NAPpoint(1,:); +%StrobeInfo.EventLoc(1)=0; +%difference=EventLoc-StrobeInfo.EventLoc; +%disp(difference); + + +StrobeInfo.EventUV = EventUV; +StrobeInfo.NAPuv = NAPuv; % UV for all sample +StrobeInfo.TmsNe = TmsNe; % Event location in ms +StrobeInfo.F0ev = F0ev; % F0 at event +StrobeInfo.F0med = F0med; % F0 median at event +StrobeInfo.F0spl = F0spl; % F0 for all sample +StrobeInfo.F0raw = F0raw; % F0 for all sample +StrobeInfo.F0var = F0var; % F0 for all sample + +StrobeInfo.Threshold = Threshold; +StrobeInfo.NchAve = NchAve; +StrobeInfo.PwrVal = PwrVal; + +disp(['Strobe Point : elapsed_time = ' num2str(toc,3) ' (sec)']); + +return + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +nn = 1 + (1:2000); +nn = 1:length(NAP); +nn = 11000:13000; +% nn = 6000:8000; + +ave = mean(NAP(NchAve,:)); +plot(nn,MeanNAPPhsCmp(nn)+3,nn,ave(nn), nn,Threshold(nn)+3, ... + nn,3*NAPmask(nn), ... + nONmask, 1.5*ones(size(nONmask)),'o', ... + nOFFmask, 1.5*ones(size(nOFFmask)),'x') +ax = axis; +axis([min(nn) max(nn) ax(3) ax(4)]) + + + +%%%%%%%%%%%% + +if 0 + ave = mean(NAP(NchAve,:)); + sgm = sqrt(mean( (MeanNAPPhsCmp-ave).^2)); + StrbWght = 1./( 1 + exp(-3*(MeanNAPPhsCmp-ave)/sgm)); + %StrbWght = 1./( 1 + exp(-5*(MeanNAPPhsCmp-ave)/sgm)); + NAPstrb = NAPPhsCmp.*(ones(NumCh,1)*StrbWght); + +end; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/CmpnstERBFilt.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/CmpnstERBFilt.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,45 @@ +% +% Compensation Env+Phase of ERB Filter +% IRINO Toshio +% 14 Oct 93 +% 16 Dec 93 : ChERB->ChFreq +% +% function CmpnstVal = CmpnstERBFilt(ValIn,ChFreq,SR,TCmpnst), +% INPUT ValIn : Value for Each Ch (NumCh * LenSnd) +% ChFreq : Frequency at each Ch (NumCh) +% SR : Sampling Rate +% TCmpnst : Compensation Time (ms) at 1kHz (default 2 ms); +% ( Amount = Tcmpnst(1kHz)*1000/ChFreq.) +% +function CmpnstVal = CmpnstERBFilt(ValIn,ChFreq,SR,TCmpnst), + +if nargin < 4, TCmpnst =2.00; end; + +disp('*** Compensation of Lag of GammaTone Filter ***'); +if max(ChFreq) < 40, + error('It might be ERB. Convert ERB -> Freq !'); +end; +ChERB = Freq2ERB(ChFreq); + +[NumCh LenVal] = size(ValIn); + +NCmpnst = TCmpnst*SR/1000; + +CmpnstVal = zeros(size(ValIn)); % To take working memory for speed up. +for nch =1:NumCh, +if rem(nch,20) == 0 | nch == NumCh +disp(['Compensate ERB : Ch #' int2str(nch) '/' int2str(NumCh) ]); +end; +np = fix(NCmpnst*1000/ChFreq(nch))+1; + +if np > LenVal, +error('Sampling point for Compensation is greater than the signal length.'); +end; + +CmpnstVal(nch,1:LenVal) = [ValIn(nch,np:LenVal) zeros(1,np-1)]; +end; + +% Do not dispplay here. Time consuming. 5 Aug. 94 +% PlotTimeERB('Compensated NAP',CmpnstVal,ChERB,SR) +% + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/DemoAIMI.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/DemoAIMI.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,122 @@ +% +% Demo Auditory Image/Mellin Image +% IRINO T +% 21 Jan. 2003 +% +clear +NameFile.Snd = 'ct8ms'; +%NameFile.Snd = 'damped_sinus2'; + +%NameFile.Snd = 'roy_a_canon'; +%NameFile.Snd = 'dampedsinus'; +%NameFile.Snd = 'MOak'; +% NameFile.Snd = 'MJAra'; + +[Snd, fs] = wavread([NameFile.Snd '.wav']); + +Snd = (2^15-1)*Snd(:)'; +% PlaySound(Snd,fs); +plot(Snd); +drawnow +NameFile.MI = [NameFile.Snd '_Rslt.mat']; + +%want to make the thing recalculate each time to see what's going on +%if exist(NameFile.MI) ~= 2 +[MI3d, StrobeInfo, NAPparam, STBparam, SAIparam, MIparam] ... + = CalAIMIall(Snd,fs,[],[],[],[],NameFile.MI); + %else + %str = ['load ' NameFile.MI]; + %disp(str); eval(str); + %end +MI3d=abs(MI3d); +max_value=max(max(max(MI3d))); +disp('the max value is:'); +disp(max_value); +MI3d=MI3d/max_value; + +[xx, yy, tt] = size(MI3d); +disp(tt); +for nn = 5 + matrix_of_current_frame = abs(MI3d(:,:,nn)); + +%set the range of values for the axes +coef_range=[0,max(MIparam.c_2pi)]; +h_range=[0,max(MIparam.TFval)]; + +%set the resolution of the axes +coef_step=(coef_range(1,2)-coef_range(1,1))/10; +%h_step=(h_range(1,2)-h_range(1,1))/10; +h_step=1; + +%sets the axis divisions +coef_axis = [coef_range(1,1):coef_step:coef_range(1,2)]; +h_axis = [h_range(1,1):h_step:h_range(1,2)]; + +%this section sets up the colormap to be the correct gray scale version that we want +colormap_name=gray(128); +size_colormap=size(colormap_name); +% disp(size_colormap); +for ii=1:size_colormap(1); + rich_map(ii,:)=colormap_name((129-ii),:); +end; +colormap(rich_map); + +%now we generate the image matlab automatically scales the colours +%note that we take the magnitude of the components +%we reset the the colourmap, scaling it's maximum to 1 +mellin_image = image(h_axis, coef_axis, matrix_of_current_frame,'CDataMapping','scaled'); + +set(gca,'CLimMode','manual'); +set(gca,'CLim',[0 0.15]); %second of these values is the threshold + +%now we scale the image so that it fills the display area +limitx=ceil(max(h_axis)); +limity=ceil(max(coef_axis)); +set(gca,'XLim',[0 limitx]); +set(gca,'YLim',[0 limity]); + +%here we setup the scale and location of the axes +set(gca,'XTick', h_axis); +set(gca,'XTickLabel', h_axis,'FontSize',8); + +set(gca,'YTick', coef_axis); +set(gca,'YTickLabel', coef_axis,'FontSize',8,'YAxisLocation','right'); + +%flip the y axis +set(gca,'YDir','normal') + +%and put on the labels +mellin_image = xlabel('Time-Interval, Peak-Frequency product, \ith','FontSize',8); +mellin_image = ylabel('Mellin variable, \it{c/2\pi}','FontSize',8); + + + +% %this section sets up the colormap to be the correct gray scale version that we want +% colormap_name=gray(128); +% size_colormap=size(colormap_name); +% disp(size_colormap); +% for ii=1:size_colormap(1); +% rich_map(ii,:)=colormap_name((129-ii),:); +% end; +% colormap(rich_map); +% +% h = image(MIparam.TFval,MIparam.c_2pi,Mval,'CDataMapping','scaled'); +% +% set(gca,'CLimMode','manual'); +% set(gca,'CLim',[0 0.7]); +% +% set(gca,'YDir','normal'); +% ntick = [ 0:1:max(ceil(MIparam.TFval))]; +% set(gca,'XLim',[0 ceil(max(MIparam.TFval))]); +% set(gca,'XTick',ntick); +% set(gca,'XTickLabel', ntick); +% ytv = 0:5:max(MIparam.c_2pi); +% set(gca,'YTick',ytv); +% set(gca,'YTickLabel', num2str(flipud(ytv(:)))); +% h = xlabel('Time-Interval frequency product'); +% h = ylabel('Mellin Coefficient'); +% +drawnow +end; + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/ERB2Freq.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/ERB2Freq.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,23 @@ +% +% ERB -> Frequency and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [cf, ERBwidth] = ERB2Freq(ERBrate) +% INPUT ERBrate: ERB rate +% OUTPUT cf: Center frequency (Hz) +% ERBwidth: ERB bandwidth (Hz) +% +% Ref: Glasberg and Moore : Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see ERB2FreqYear.m +% +% +function [cf, ERBwidth] = ERB2Freq(ERBrate), + +if nargin < 1, help ERB2Freq; end; + +cf = (10.^(ERBrate./21.4) - 1)./4.37 * 1000; +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/FcNch2EqERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/FcNch2EqERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,20 @@ +% +% Fc & Nch --> Frequencies which is equally spaced on ERB axis +% Toshio Irino +% 8 Jan. 2003 +% +% INPUT: FcMin : min. Fc +% FcMax : max. Fc +% NumCh : number of channels +% OUTPUT: Frs: Freuqencies +% +% +function Frs = FcNch2EqERB(FcMin, FcMax,NumCh) + +if nargin < 3, help FcNch2EqERB, end; + +dERB = (Freq2ERB(FcMax)-Freq2ERB(FcMin))/(NumCh-1); +Frs = ERB2Freq( Freq2ERB(FcMin):dERB:Freq2ERB(FcMax) ); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/For Tim/CalAIMIall.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/For Tim/CalAIMIall.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,72 @@ +% +% Calculation of all of AIMI: NAP-SAI-MI +% IRINO T +% 9 Oct 2002 +% +% function [MI3d, StrobeInfo, NAPparam, STBparam, SAIparam, MIparam] = ... +% CalAIMIall(Snd,fs,NAPparam,STBparam,SAIparam,MIparam,SwSave); +% +% INPUT: Snd : sound for MI +% fs: sampling rate +% NAPparam,STBparam,SAIparam,MIparam : parameters +% NameMI: Name of save file. if empty : No save +% +function [MI3d, StrobeInfo, NAPparam, STBparam, SAIparam, MIparam] = ... + CalAIMIall(Snd,fs,NAPparam,STBparam,SAIparam,MIparam,NameMI); + +if nargin < 3, NAPparam = []; end; +if nargin < 4, STBparam = []; end; +if nargin < 5, SAIparam = []; end; +if nargin < 6, MIparam = []; end; +if nargin < 7, NameMI = []; end; + +if isfield(NAPparam,'fs') == 0, NAPparam.fs = []; end; +if length(NAPparam.fs) == 0, NAPparam.fs = fs; end; +if NAPparam.fs ~= fs, error('Sampling rate is inconsistent.'); end; + +% NAPparam = []; +% NAPparam.fs = fs; +% NAPparam.NumCh = 75; % default +% NAPparam.cf_afb = [100 6000]; % default +NAPparam.SubBase = 0.5; + +if isfield(STBparam,'StInfo_EventLoc') == 0, + STBparam.StInfo_EventLoc = []; +end; + +% SAIparam.Nwidth = -5; % default +% SAIparam.Pwidth = 15; % default +SAIparam.FrstepAID = 0; % Event Synchronous +% SAIparam.ImageDecay = 10; % SAI image decay / Switch of window function +SAIparam.ImageDecay = 0; % using Window function +SAIparam.SwSmthWin = 1; % Window shape #1 + +% MIparam.F0mode = 300; % default +% MIparam.TFval = [0:0.25:5]; % default +% MIparam.c_2pi = [0:0.25:20]; % default +MIparam.Mu = -0.5; % pre-emphasis of high freq. + +LenSnd = length(Snd); +% disp([NameFile ' : T= ' num2str(LenSnd/NAPparam.fs, 4) ' (sec)']); + +[NAP, NAPparam] = CalNAPghll(Snd,NAPparam); +% PlaySound(Snd,NAPparam.fs); + +[NAPPhsCmp, StrobeInfo, STBparam] = CalStrobePoint(NAP,NAPparam,STBparam); + +if length(STBparam.StInfo_EventLoc) > 0 + disp('StrobeInfo.EventLoc is replaced by STBparam.StInfo_EventLoc' ) + disp([ length(StrobeInfo.EventLoc), length(STBparam.StInfo_EventLoc) ]) + StrobeInfo.NAPpoint = []; + StrobeInfo.EventLoc = STBparam.StInfo_EventLoc; +end; +[SAI3d, RAI3d, SAIparam, StrobeInfo] = ... + CalSAIstinfo(NAPPhsCmp,NAPparam,StrobeInfo,STBparam,SAIparam); + +[MI3d, MIparam] = CalMI(SAI3d,NAPparam,SAIparam,MIparam); + +if length(NameMI) > 0, + str = ['save ' NameMI ' MI3d StrobeInfo ' ... + ' NAPparam STBparam SAIparam MIparam ; ']; + disp(str); eval(str); +end; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/For Tim/CalNAPghll.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/For Tim/CalNAPghll.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,115 @@ +% +% Calculation of NAP +% (gammatone, halfwave rectification, lowpass, log compression) +% 7 Jan 2002 +% Toshio Irino +% +function [NAP, NAPparam, BMM] = CalNAPghll(Snd, NAPparam) + +fs = NAPparam.fs; +if isfield(NAPparam,'NumCh') == 0, NAPparam.NumCh = []; end; +if length(NAPparam.NumCh) == 0, + NAPparam.NumCh = 75; +end; +if isfield(NAPparam,'cf_afb') == 0, NAPparam.cf_afb = []; end; +if length(NAPparam.cf_afb) == 0, + NAPparam.cf_afb = [100 6000]; +end; +if isfield(NAPparam,'SubBase') == 0, NAPparam.SubBase = []; end; +if length(NAPparam.SubBase) == 0, + NAPparam.SubBase = 0; +end; + +fs = NAPparam.fs; +NumCh = NAPparam.NumCh; +cf_afb = NAPparam.cf_afb; + +%%%%% Outer-Mid Ear Compensation %%%% +CmpnOutMid = OutMidCrctFilt('ELC',fs,0); +Snd_om = filter(CmpnOutMid,1,Snd); +% Snd_om = Snd; % if unnecessary + + +%%%%% BMM %%% +disp('*** BMM & NAP Calculation ***'); +disp(NAPparam) +tic; +%% dERB = (Freq2ERB(max(cf_afb))-Freq2ERB(min(cf_afb)))/(NumCh-1); +%% Frs = ERB2Freq( Freq2ERB(min(cf_afb)):dERB:Freq2ERB(max(cf_afb)) ); +Frs = FcNch2EqERB(min(cf_afb),max(cf_afb),NumCh); +NAPparam.Frs = Frs; +NAPparam.b = 1.019; % default gammatone + +% IIR implementation +% disp('BMM : Start calculation, Wait a minute'); +% fcoefs = MakeERBFilters98B(fs,Frs,[],b); % new version +% BMM = ERBFilterBank(Snd_om, fcoefs); +% disp(['BMM : elapsed_time = ' num2str(toc,3) ' (sec)']); + +%%%%% Lowpass filter for representing Phase-lock property %%% +flpcut = 1200; +[bzLP apLP] = butter(1,flpcut/(fs/2)); +bzLP2 = [bzLP(1)^2, 2*bzLP(1)*bzLP(2), bzLP(2)^2]; +apLP2 = [apLP(1)^2, 2*apLP(1)*apLP(2), apLP(2)^2]; + +%%%%% NAP %%%% +tic; +LenSnd = length(Snd_om); +bias = 0.1; +for nch = 1:NumCh + if rem(nch, 20) == 0 | nch == 1 | nch == NumCh + disp(['BMM-NAP #' int2str(nch) '/#' int2str(NumCh) ': ' ... + 'elapsed_time = ' num2str(toc,3) ' (sec)']); + end; + + gt = GammaChirp(Frs(nch),fs,4,NAPparam.b,0,0,[],'peak'); + % BMM(nch,:) = filter(gt,1,Snd_om); + BMM(nch,:) = fftfilt(gt,Snd_om); + NAPraw = log10(max(BMM(nch,:),bias)) - log10(bias); + NAP(nch,1:LenSnd) = filter(bzLP2,apLP2,NAPraw); % LP filtered + + % [Frs(nch) max(max(NAPraw)) max(max(NAP(nch,:)))] +end; + + +if NAPparam.SubBase ~= 0, +disp([ '=== Baseline subtraction : Max NAP = ' num2str( max(max(NAP))) ... + ', NAPparam.SubBase = ' num2str(NAPparam.SubBase) ' ===']); +end; + +NAP0 = NAP; +NAP = max((NAP0 - NAPparam.SubBase),0); + +NAPparam.height = max(max(NAP)); +NAPparam.tms = (0:LenSnd-1)/fs*1000; + +return + +%%%%%%%%%%%% + +if 1 + ProfNAP0 = mean(NAP0')'; + ProfNAP = mean(NAP')'; + plot(NAPparam.Frs,ProfNAP0,NAPparam.Frs,ProfNAP0) + subplot(2,1,1) + image(flipud(NAP0(:,1:100:LenSnd))*15) + subplot(2,1,2) + image(flipud(NAP(:,1:100:LenSnd))*20) +end; + + +return + +%%%%%%%%%%%%%%%%%%%% + +% [bzGT, apGT, Frs, ERBw] = MakeERBFiltersB(fs,NumCh,Frs,b); % NG for low freq + +%%Simple pre-emphasis +%%CoefPreEmph = [1, -0.97]; +%%Snd = filter(CoefPreEmph,1,Snd); + +% [frsp, freq] = freqz(bzLP,apLP,1024,fs); +% [frsp2, freq] = freqz(bzLP2,apLP2,1024,fs); +% plot(freq,20*log10(abs(frsp)),freq,20*log10(abs(frsp2))) +% axis([0 2000 -10 2]); +% grid; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/For Tim/ERB2Freq.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/For Tim/ERB2Freq.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,23 @@ +% +% ERB -> Frequency and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [cf, ERBwidth] = ERB2Freq(ERBrate) +% INPUT ERBrate: ERB rate +% OUTPUT cf: Center frequency (Hz) +% ERBwidth: ERB bandwidth (Hz) +% +% Ref: Glasberg and Moore : Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see ERB2FreqYear.m +% +% +function [cf, ERBwidth] = ERB2Freq(ERBrate), + +if nargin < 1, help ERB2Freq; end; + +cf = (10.^(ERBrate./21.4) - 1)./4.37 * 1000; +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/For Tim/FcNch2EqERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/For Tim/FcNch2EqERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,20 @@ +% +% Fc & Nch --> Frequencies which is equally spaced on ERB axis +% Toshio Irino +% 8 Jan. 2003 +% +% INPUT: FcMin : min. Fc +% FcMax : max. Fc +% NumCh : number of channels +% OUTPUT: Frs: Freuqencies +% +% +function Frs = FcNch2EqERB(FcMin, FcMax,NumCh) + +if nargin < 3, help FcNch2EqERB, end; + +dERB = (Freq2ERB(FcMax)-Freq2ERB(FcMin))/(NumCh-1); +Frs = ERB2Freq( Freq2ERB(FcMin):dERB:Freq2ERB(FcMax) ); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/For Tim/OutMidCrct.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/For Tim/OutMidCrct.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,90 @@ +% +% Correction of ELC, MAF, MAP +% IRINO Toshio +% 18 Mar 96 +% 29 Aug 96 renamed AFShapeCrct -> OutMidCrct +% 14 May 97 option of Direct Output +% +% It produces interpolated points for the ELC/MAF/MAP correction. +% +% Reference: +% Glassberg and Moore (1990) +% "Derivation of auditory filter shapes from notched noise data" +% Hearing Research, 47 , pp.103-138. +% +% function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% Npnts: Number of data points, if zero, then direct out. +% SR: Sampling Rate +% SwPlot: Switch for plot +% OUTPUT CrctLinPwr : Correction value in LINEAR POWER +% frqNpnts: Corresponding Frequency at the data point +% CrctdB: Correction value in dB +% +function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR,SwPlot); + +if nargin < 1, help OutMidCrct; end; +if nargin < 2, Npnts = 0; end; +if nargin < 3, SR = 32000; end; +if nargin < 4, SwPlot = 1; end; + +f1 = [ 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, ... + 125, 150, 177, 200, 250, 300, 350, 400, 450, 500, 550, ... + 600, 700, 800, 900, 1000, 1500, 2000, 2500, 2828, 3000, ... + 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, ... + 12748, 15000]; + +ELC = [ 31.8, 26.0, 21.7, 18.8, 17.2, 15.4, 14.0, 12.6, 11.6, 10.6, ... + 9.2, 8.2, 7.7, 6.7, 5.3, 4.6, 3.9, 2.9, 2.7, 2.3, ... + 2.2, 2.3, 2.5, 2.7, 2.9, 3.4, 3.9, 3.9, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +MAF = [ 73.4, 65.2, 57.9, 52.7, 48.0, 45.0, 41.9, 39.3, 36.8, 33.0, ... + 29.7, 27.1, 25.0, 22.0, 18.2, 16.0, 14.0, 11.4, 9.2, 8.0, ... + 6.9, 6.2, 5.7, 5.1, 5.0, 5.0, 4.4, 4.3, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +f2 = [ 125, 250, 500, 1000, 1500, 2000, 3000, ... + 4000, 6000, 8000,10000,12000,14000,16000]; +MAP = [ 30.0, 19.0, 12.0, 9.0, 11.0, 16.0, 16.0, ... + 14.0, 14.0, 9.9, 24.7, 32.7, 44.1, 63.7]; + +frqTbl = []; +CrctTbl = []; +if length(StrCrct)==3 + if strcmp(upper(StrCrct(1:3)),'ELC'), frqTbl = f1'; CrctTbl = ELC'; + elseif strcmp(upper(StrCrct(1:3)),'MAF'), frqTbl = f1'; CrctTbl = MAF'; + elseif strcmp(upper(StrCrct(1:3)),'MAP'), frqTbl = f2'; CrctTbl = MAP'; + else error('Specifiy correction: ELC / MAF / MAP or NO correction.'); + end; +elseif length(StrCrct)~=2, + error('Specifiy correction: ELC / MAF / MAP or NO correction.'); +end; + +str1 = ''; +if Npnts <= 0, + str1 = 'No interpolation. Output original table.'; + frqNpnts = frqTbl; + CrctdB = CrctTbl; +else + frqNpnts = (0:Npnts-1)'/Npnts * SR/2; + if strcmp(upper(StrCrct(1:2)), 'NO'), + CrctdB = zeros(size(frqNpnts)); + else + str1 = 'Spline interpolated value in equal frequency spacing.'; + CrctdB = spline(frqTbl,CrctTbl,frqNpnts); + end; +end; + +if SwPlot == 1, + disp(['*** Outer/Middle Ear Transfer Function ( ' ... + upper(StrCrct) ' Correction ) ***']); + disp(str1); + plot(frqTbl,CrctTbl,frqNpnts,CrctdB,'o'); +end; + +CrctLinPwr = 10.^(-CrctdB/10); % in Linear Power + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/For Tim/OutMidCrctFilt.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/For Tim/OutMidCrctFilt.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,62 @@ +% +% Produce compensation filter to simulate outer/middle ear +% IRINO Toshio +% 29 Aug. 1996 (check on 14 May 1997 ) +% 8 Jan. 2002 (Multiply Win for avoid sprious) +% 19 Nov. 2002 (remez : even integer) +% +% It is a linear phase filter for the ELC/MAF/MAP correction. +% see OutMidCrct.m +% +% function [FIRCoef] = OutMidCrctFilt(StrCrct,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% SR: Sampling Rate +% SwPlot: SwPlot +% OUTPUT FIRCoef: FIR filter coefficients +% +function [FIRCoef] = OutMidCrctFilt(StrCrct,SR,SwPlot); + +if nargin < 2, help OutMidCrctFilt; end; +if nargin < 3, SwPlot = 1; end; + +if length(StrCrct)~=3, + error('Specifiy correction in 3 characters: ELC / MAF / MAP.'); +end; +if ~(strcmp(upper(StrCrct(1:3)), 'ELC') | ... + strcmp(upper(StrCrct(1:3)),'MAF') ... + | strcmp(upper(StrCrct(1:3)),'MAP')), + error('Specifiy correction: ELC / MAF / MAP.'); +end; + +Nint = 1024; +% Nint = 0; % No spline interpolation: NG no convergence at remez +[crctPwr freq] = OutMidCrct(StrCrct,Nint,SR,0); +crct = sqrt(crctPwr); + +%% FIRCoef = remez(50/16000*SR,freq/SR*2,crct); % NG +%% FIRCoef = remez(300/16000*SR,freq/SR*2,crct); % Original +% FIRCoef = remez(LenCoef/16000*SR,freq/SR*2,crct); % when odd num : warning +%% modified on 8 Jan 2002, 19 Nov 2002 +LenCoef = 200; % ( -45 dB) <- 300 (-55 dB) +FIRCoef = remez(fix(LenCoef/16000*SR/2)*2,freq/SR*2,crct); % even number only +Win = TaperWindow(length(FIRCoef),'han',LenCoef/10); + % Necessary to avoid sprious +FIRCoef = Win.*FIRCoef; + +if SwPlot==1 + [frsp freq2] = freqz(FIRCoef,1,Nint,SR); + subplot(2,1,1) + plot(FIRCoef); + subplot(2,1,2) + plot(freq2,abs(frsp),freq,crct,'--') + % plot(freq2,20*log10(abs(frsp)),freq,20*log10(crct)) + + ELCError = mean((abs(frsp) - crct).^2)/mean(crct.^2); + ELCErrordB = 10*log10(ELCError) % corrected + if ELCErrordB > -30, + disp(['Warning: Error in ELC correction = ' ... + num2str(ELCErrordB) ' dB > -30 dB']) + end; +end; + +return; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/Fr2Fpeak.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/Fr2Fpeak.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,22 @@ +% +% Estimate fr from fpeak +% Toshio IRINO +% 10 June 98 +% +% function [fpeak, ERBw] = Fr2Fpeak(n,b,c,fr) +% INPUT: n,b,c : gammachirp param. +% fr : fr +% OUTPUT: fpeak : peak freq. +% ERBw : ERBw(fr) +% +function [fpeak, ERBw] = Fr2Fpeak(n,b,c,fr) + +if nargin < 4, help Fr2Fpeak; end; + +n = n(:); +b = b(:); +c = c(:); +fr = fr(:); + +[dummy ERBw] = Freq2ERB(fr); +fpeak = fr + c.*ERBw.*b./n; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/Freq2ERB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/Freq2ERB.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,35 @@ +% +% Frequency -> ERBrate and ERBwidth (Glasberg and Moore, 1990) +% Toshio IRINO +% 11 Mar. 1998 +% +% function [ERBrate, ERBwidth] = Freq2ERB(cf), +% INPUT cf: Center frequency +% OUTPUT ERBrate: ERB rate +% ERBwidth: ERB width +% +% Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 +% For different formulae (years), see Freq2ERBYear.m +% +function [ERBrate, ERBwidth] = Freq2ERB(cf), + +if nargin < 1, help Freq2ERB; end; + +ERBrate = 21.4.*log10(4.37*cf/1000+1); +ERBwidth = 24.7.*(4.37*cf/1000 + 1); + +%%% Warning for Freq. Range %%% +cfmin = 50; +cfmax = 12000; +if (min(cf) < cfmin | max(cf) > cfmax) + disp(['Warning : Min or max frequency exceeds the proper ERB range:']); + disp([' ' int2str(cfmin) '(Hz) <= Fc <= ' int2str(cfmax) '(Hz).']); +end; + +%if (min(cf) < 0) +% error(['Min frequency is less than 0.']); +%end; + + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/GammaChirp.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/GammaChirp.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,110 @@ +% +% Gammachirp : Theoretical auditory filter +% Toshio IRINO +% 7 Apr. 97 (additional comments) +% 20 Aug. 97 (Simplify & Carrier Selection) +% 10 Jun. 98 (SwNorm) +% 26 Nov. 98 (phase = phase + c ln fr/f0) +% 7 Jan. 2002 (adding 'envelope' option) +% 22 Nov. 2002 (debugging 'peak' option) +% +% gc(t) = t^(n-1) exp(-2 pi b ERB(Frs)) cos(2*pi*Frs*t + c ln t + phase) +% +% function [GC, LenGC, Fps, InstFreq ] ... +% = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm); +% INPUT : Frs : Asymptotic Frequency ( vector ) +% SR : Sampling Frequency +% OrderG : Order of Gamma function t^(OrderG-1) == n +% CoefERBw: Coeficient -> exp(-2*pi*CoefERBw*ERB(f)) == b +% CoefC : Coeficient -> exp(j*2*pi*Frs + CoefC*ln(t)) == c +% Phase : Start Phase(0 ~ 2*pi) +% SwCarr : Carrier ('cos','sin','complex','envelope': 3 letters) +% SwNorm : Normalization of peak spectrum level ('no', 'peak') +% OUTPUT: GC : GammaChirp ( matrix ) +% LenGC : Length of GC for each channel ( vector ) +% Fps : Peak Frequency ( vector ) +% InstFreq: Instanteneous Frequency ( matrix ) +% +% +function [GC, LenGC, Fps, InstFreq ] ... + = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm); + +if nargin < 2, help GammaChirp; return; end; +Frs = Frs(:); +NumCh = length(Frs); +if nargin < 3, OrderG = []; end; +if length(OrderG) == 0, OrderG = 4; end; % Default GammaTone +if length(OrderG) == 1, OrderG = OrderG*ones(NumCh,1); end; +if nargin < 4, CoefERBw = []; end; +if length(CoefERBw) == 0, CoefERBw = 1.019; end; % Default GammaTone +if length(CoefERBw) == 1, CoefERBw = CoefERBw*ones(NumCh,1); end; +if nargin < 5, CoefC = []; end; +if length(CoefC) == 0, CoefC = 0; end; % Default GammaTone +if length(CoefC) == 1, CoefC = CoefC*ones(NumCh,1); end; +if nargin < 6, Phase = []; end; +if length(Phase) == 0, Phase = 0; end; +if length(Phase) == 1, Phase = Phase*ones(NumCh,1); end; +if nargin < 7, SwCarr = []; end; +if length(SwCarr) == 0, SwCarr = 'cos'; end; +if nargin < 8, SwNorm = []; end; +if length(SwNorm) == 0, SwNorm = 'no'; end; + + +[ERBrate ERBw] = Freq2ERB(Frs); % G&M (1990) +LenGC1kHz = (40*max(OrderG)/max(CoefERBw) + 200)*SR/16000; % 2 Aug 96 +[dummy ERBw1kHz] = Freq2ERB(1000); + +if strcmp(SwCarr,'sin'), Phase = Phase - pi/2*ones(1,NumCh); end; +%%% Phase compensation +Phase = Phase + CoefC.*log(Frs/1000); % relative phase to 1kHz + +LenGC = fix(LenGC1kHz*ERBw1kHz./ERBw); + +%%%%% Production of GammaChirp %%%%% +GC = zeros(NumCh,max(LenGC)); +if nargout > 2, Fps = Fr2Fpeak(OrderG,CoefERBw,CoefC,Frs); end; % Peak Freq. +if nargout > 3, InstFreq = zeros(NumCh,max(LenGC)); end; + + +for nch = 1:NumCh, + t = (1:LenGC(nch)-1)/SR; + + GammaEnv = t.^(OrderG(nch)-1).*exp(-2*pi*CoefERBw(nch)*ERBw(nch)*t); + GammaEnv = [ 0 GammaEnv/max(GammaEnv)]; + + if strcmp(SwCarr(1:3),'env') % envelope + Carrier = ones(size(GammaEnv)); + elseif strcmp(SwCarr(1:3),'com') % complex + Carrier = [ 0 exp(i * (2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch)) )]; + else + Carrier = [ 0 cos(2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch))]; + end; + + GC(nch,1:LenGC(nch)) = GammaEnv.*Carrier; + + if nargout > 3, + InstFreq(nch,1:LenGC(nch)) = [0, [Frs(nch) + CoefC(nch)./(2*pi*t)]]; + end; + + if strcmp(SwNorm,'peak') == 1, % peak gain normalization + [frsp freq] = freqz(GC(nch,1:LenGC(nch)),1,LenGC(nch),SR); + fp = Fr2Fpeak(OrderG(nch),CoefERBw(nch),CoefC(nch),Frs(nch)); + [dummy np] = min(abs(freq-fp)); + GC(nch,:) = GC(nch,:)/abs(frsp(np)); + end; + +end; % nch = ... + +return + +%% ERBw = 0.128*Frs; % Complete Constant Q only for check. + +% old +% Amp = ones(NumCh,1); % No normalization +% if strcmp(SwNorm,'peak'), Amp = ERBw./ERBw1kHz; end; % Peak spectrum==const. +% when it is gammatone +% if strcmp(SwNorm,'peak'), ... +% Amp = 2.815*sqrt(4/OrderG).*CoefERBw.*ERBw/SR; end; +% Peak spectrum==const. The gain is 1.0 when filtering sinusoid at cf. +% GC(nch,:) = GC(nch,:)/max(abs(freqz(GC(nch,:),1,LenGC(nch)))); +% diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/GetF0median.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/GetF0median.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,23 @@ +% +% +% GetF0median(F0sequence,NumMed) +% +function F0median = GetF0median(F0sequence,NumMed) + +if nargin < 2, NumMed = []; end; +if length(NumMed) == 0,NumMed = 5; end; + +[NumCh, LenF0] = size(F0sequence); + +Mtx = zeros(NumMed,LenF0+NumMed); + +for nm = 1:NumMed + nnl = nm-1+(1:LenF0); + Mtx(nm,nnl) = F0sequence(:)'; +end; + +aa = median(Mtx,1); +F0median = aa(fix(NumMed/2)+(1:LenF0)); + + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/MJAra.wav Binary file aim-mat/modules/usermodule/mellin/MIpack/MJAra.wav has changed diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/MOak.wav Binary file aim-mat/modules/usermodule/mellin/MIpack/MOak.wav has changed diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/OutMidCrct.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/OutMidCrct.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,90 @@ +% +% Correction of ELC, MAF, MAP +% IRINO Toshio +% 18 Mar 96 +% 29 Aug 96 renamed AFShapeCrct -> OutMidCrct +% 14 May 97 option of Direct Output +% +% It produces interpolated points for the ELC/MAF/MAP correction. +% +% Reference: +% Glassberg and Moore (1990) +% "Derivation of auditory filter shapes from notched noise data" +% Hearing Research, 47 , pp.103-138. +% +% function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% Npnts: Number of data points, if zero, then direct out. +% SR: Sampling Rate +% SwPlot: Switch for plot +% OUTPUT CrctLinPwr : Correction value in LINEAR POWER +% frqNpnts: Corresponding Frequency at the data point +% CrctdB: Correction value in dB +% +function [CrctLinPwr, frqNpnts, CrctdB] = OutMidCrct(StrCrct,Npnts,SR,SwPlot); + +if nargin < 1, help OutMidCrct; end; +if nargin < 2, Npnts = 0; end; +if nargin < 3, SR = 32000; end; +if nargin < 4, SwPlot = 1; end; + +f1 = [ 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, ... + 125, 150, 177, 200, 250, 300, 350, 400, 450, 500, 550, ... + 600, 700, 800, 900, 1000, 1500, 2000, 2500, 2828, 3000, ... + 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, ... + 12748, 15000]; + +ELC = [ 31.8, 26.0, 21.7, 18.8, 17.2, 15.4, 14.0, 12.6, 11.6, 10.6, ... + 9.2, 8.2, 7.7, 6.7, 5.3, 4.6, 3.9, 2.9, 2.7, 2.3, ... + 2.2, 2.3, 2.5, 2.7, 2.9, 3.4, 3.9, 3.9, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +MAF = [ 73.4, 65.2, 57.9, 52.7, 48.0, 45.0, 41.9, 39.3, 36.8, 33.0, ... + 29.7, 27.1, 25.0, 22.0, 18.2, 16.0, 14.0, 11.4, 9.2, 8.0, ... + 6.9, 6.2, 5.7, 5.1, 5.0, 5.0, 4.4, 4.3, 3.9, 2.7, ... + 0.9, -1.3, -2.5, -3.2, -4.4, -4.1, -2.5, -0.5, 2.0, 5.0, ... + 10.2, 15.0, 17.0, 15.5, 11.0, 22.0]; + +f2 = [ 125, 250, 500, 1000, 1500, 2000, 3000, ... + 4000, 6000, 8000,10000,12000,14000,16000]; +MAP = [ 30.0, 19.0, 12.0, 9.0, 11.0, 16.0, 16.0, ... + 14.0, 14.0, 9.9, 24.7, 32.7, 44.1, 63.7]; + +frqTbl = []; +CrctTbl = []; +if length(StrCrct)==3 + if strcmp(upper(StrCrct(1:3)),'ELC'), frqTbl = f1'; CrctTbl = ELC'; + elseif strcmp(upper(StrCrct(1:3)),'MAF'), frqTbl = f1'; CrctTbl = MAF'; + elseif strcmp(upper(StrCrct(1:3)),'MAP'), frqTbl = f2'; CrctTbl = MAP'; + else error('Specifiy correction: ELC / MAF / MAP or NO correction.'); + end; +elseif length(StrCrct)~=2, + error('Specifiy correction: ELC / MAF / MAP or NO correction.'); +end; + +str1 = ''; +if Npnts <= 0, + str1 = 'No interpolation. Output original table.'; + frqNpnts = frqTbl; + CrctdB = CrctTbl; +else + frqNpnts = (0:Npnts-1)'/Npnts * SR/2; + if strcmp(upper(StrCrct(1:2)), 'NO'), + CrctdB = zeros(size(frqNpnts)); + else + str1 = 'Spline interpolated value in equal frequency spacing.'; + CrctdB = spline(frqTbl,CrctTbl,frqNpnts); + end; +end; + +if SwPlot == 1, + disp(['*** Outer/Middle Ear Transfer Function ( ' ... + upper(StrCrct) ' Correction ) ***']); + disp(str1); + plot(frqTbl,CrctTbl,frqNpnts,CrctdB,'o'); +end; + +CrctLinPwr = 10.^(-CrctdB/10); % in Linear Power + + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/OutMidCrctFilt.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/OutMidCrctFilt.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,62 @@ +% +% Produce compensation filter to simulate outer/middle ear +% IRINO Toshio +% 29 Aug. 1996 (check on 14 May 1997 ) +% 8 Jan. 2002 (Multiply Win for avoid sprious) +% 19 Nov. 2002 (remez : even integer) +% +% It is a linear phase filter for the ELC/MAF/MAP correction. +% see OutMidCrct.m +% +% function [FIRCoef] = OutMidCrctFilt(StrCrct,SR); +% INPUT StrCrct: String for Correction ELC/MAF/MAP +% SR: Sampling Rate +% SwPlot: SwPlot +% OUTPUT FIRCoef: FIR filter coefficients +% +function [FIRCoef] = OutMidCrctFilt(StrCrct,SR,SwPlot); + +if nargin < 2, help OutMidCrctFilt; end; +if nargin < 3, SwPlot = 1; end; + +if length(StrCrct)~=3, + error('Specifiy correction in 3 characters: ELC / MAF / MAP.'); +end; +if ~(strcmp(upper(StrCrct(1:3)), 'ELC') | ... + strcmp(upper(StrCrct(1:3)),'MAF') ... + | strcmp(upper(StrCrct(1:3)),'MAP')), + error('Specifiy correction: ELC / MAF / MAP.'); +end; + +Nint = 1024; +% Nint = 0; % No spline interpolation: NG no convergence at remez +[crctPwr freq] = OutMidCrct(StrCrct,Nint,SR,0); +crct = sqrt(crctPwr); + +%% FIRCoef = remez(50/16000*SR,freq/SR*2,crct); % NG +%% FIRCoef = remez(300/16000*SR,freq/SR*2,crct); % Original +% FIRCoef = remez(LenCoef/16000*SR,freq/SR*2,crct); % when odd num : warning +%% modified on 8 Jan 2002, 19 Nov 2002 +LenCoef = 200; % ( -45 dB) <- 300 (-55 dB) +FIRCoef = remez(fix(LenCoef/16000*SR/2)*2,freq/SR*2,crct); % even number only +Win = TaperWindow(length(FIRCoef),'han',LenCoef/10); + % Necessary to avoid sprious +FIRCoef = Win.*FIRCoef; + +if SwPlot==1 + [frsp freq2] = freqz(FIRCoef,1,Nint,SR); + subplot(2,1,1) + plot(FIRCoef); + subplot(2,1,2) + plot(freq2,abs(frsp),freq,crct,'--') + % plot(freq2,20*log10(abs(frsp)),freq,20*log10(crct)) + + ELCError = mean((abs(frsp) - crct).^2)/mean(crct.^2); + ELCErrordB = 10*log10(ELCError) % corrected + if ELCErrordB > -30, + disp(['Warning: Error in ELC correction = ' ... + num2str(ELCErrordB) ' dB > -30 dB']) + end; +end; + +return; diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/MIpack/TaperWindow.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/MIpack/TaperWindow.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,76 @@ +% +% Taper Window Generator for signal onset/offset +% 7 Apr. 1993 +% 29 Aug. 96 +% IRINO Toshio +% +% function [TaperWin, TypeTaper] = ... +% TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) +% INPUT LenWin : Length of Window (Number of points) +% TypeTaper : Type of Taper (KeyWords of 3 letters) +% (Hamming, Hanning (=cosine^2), Blackman, Gauss, Line) +% LenTaper : Length of Taper (Number of points) +% RangeSigma: Range in Sigma (default: 3) for Gauss +% SwPlot : 0) Omit plotting, 1) Plot Taper +% OUTPUT TaperWin : Taper Window Points (max==1); +% TypeTaper : Type of Taper (Full Name) +% +function [TaperWin, TypeTaper] = ... + TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) + +if nargin < 2, +help TaperWindow +error([ 'Specify Type of Taper : ' ... + ' Hamming, Hanning (=cosine^2), Blackman, Gauss, Line ']); +%TaperWin = ones(1,LenWin); +%return; +end; + +if nargin < 3, LenTaper = fix(LenWin/2); end; +if nargin < 4, RangeSigma = 3; end; + +if LenTaper*2 >= LenWin, + disp('Caution (TaperWindow.m) : No flat part. '); + if LenTaper ~= fix(LenWin/2), + disp('Caution (TaperWindow.m) : LenTaper <-- fix(LenWin/2)'); + end; + LenTaper = fix(LenWin/2); +end; + +if nargin < 5, SwPlot = 0; end; % changing default Swplot 29 Aug. 96 + +%TypeTaper = lower(TypeTaper(1:3)); + +if upper(TypeTaper(1:3)) == 'HAM', + Taper = hamming(LenTaper*2)'; + TypeTaper = 'Hamming'; +elseif upper(TypeTaper(1:3)) == 'HAN' | upper(TypeTaper(1:3)) == 'COS', + Taper = hanning(LenTaper*2)'; + TypeTaper = 'Hanning/Cosine'; +elseif upper(TypeTaper(1:3)) == 'BLA', + Taper = blackman(LenTaper*2)'; + TypeTaper = 'Blackman'; +elseif upper(TypeTaper(1:3)) == 'GAU', + if length(RangeSigma) == 0, RangeSigma = 3; end; + nn = -LenTaper+0.5:1:LenTaper-0.5; + Taper = exp(-(RangeSigma*nn/LenTaper).^2 /2); + TypeTaper = 'Gauss'; +else Taper = [1:LenTaper LenTaper:-1:1]/LenTaper; % 'line', + TypeTaper = 'Line'; +end; + +%plot(Taper) +%size(Taper); +LenTaper = fix(LenTaper); +TaperWin = [ Taper(1:LenTaper) ones(1,LenWin-LenTaper*2) ... + Taper(LenTaper+1:LenTaper*2)]; + +if SwPlot == 1, + +plot(TaperWin) +xlabel('Points'); +ylabel('Amplitude'); +title(['TypeTaper = ' TypeTaper] ); + +end; + diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/displaymellin.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/displaymellin.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,101 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Richard Turner (ret26@cam.ac.uk) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function displaymellin(mellin,options,frame_number,ax) +if nargin<4 + ax=gca; +end + +%setup the scale bar to alter to range of the colour map +%converts the exponential scale on the scale bar to a value 00) % TCW AIM2006 - fixed divide by zero warnings + matrix_of_current_frame = matrix_of_current_frame / max(max(matrix_of_current_frame)); +end + +% % maah: Maybe a threshold can help against this blur! +% if (options.threshold ~= 0) +% if (options.threshold ~= 1) +% matrix_of_current_frame(matrix_of_current_frame < options.threshold) = 0; +% else +% mean_value = mean(mean(matrix_of_current_frame)); +% matrix_of_current_frame(matrix_of_current_frame < mean_value) = 0; +% end; +% end; + +%set the range of values for the axes +coef_range=[0,max(options.c_2pi)]; +h_range=[0,max(options.TFval)]; + +%set the resolution of the axes +coef_step=(coef_range(1,2)-coef_range(1,1))/10; +%h_step=(h_range(1,2)-h_range(1,1))/10; +h_step=1; + +%sets the axis divisions +coef_axis = [coef_range(1,1):coef_step:coef_range(1,2)]; +h_axis = [h_range(1,1):h_step:h_range(1,2)]; + +%this section sets up the colormap to be the correct gray scale version that we want +colormap_name=gray(128); % maah: was = gray(128) +size_colormap=size(colormap_name); +%disp(size_colormap); +for ii=1:size_colormap(1); + rich_map(ii,:)=colormap_name((129-ii),:); +end; +colormap(rich_map); + + +%now we generate the image matlab automatically scales the colours +%note that we take the magnitude of the components +%we reset the the colourmap, scaling it's maximum to 1 +%matrix_of_current_frame = matrix_of_current_frame'; %removed the transpose +%in the display function and put it into the generating function +mellin_image = image(h_axis, coef_axis, matrix_of_current_frame,'CDataMapping','scaled','parent',ax); + +set(ax,'CLimMode','manual'); +% set(ax,'CLim',[0 options.max_value]); + +%now we scale the image so that it fills the display area +limitx=ceil(max(h_axis)); +limity=ceil(max(coef_axis)); +set(ax,'XLim',[0 limitx]); +set(ax,'YLim',[0 limity]); + +%here we setup the scale and location of the axes +set(ax,'XTick', h_axis); +set(ax,'XTickLabel', h_axis,'FontSize',8); + +set(ax,'YTick', coef_axis); +set(ax,'YTickLabel', coef_axis,'FontSize',8,'YAxisLocation','right'); + +%flip the y axis +set(ax,'YDir','normal') + +%and put on the labels +mellin_image = xlabel('Time-Interval, Peak-Frequency product, \ith','FontSize',8); +mellin_image = ylabel('Mellin variable, \it{c/2\pi}','FontSize',8); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/displaymellin2.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/displaymellin2.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,98 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003, University of Cambridge, Medical Research Council +% Richard Turner (ret26@cam.ac.uk) +% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual +% $Date: 2006/03/13 18:31:21 $ +% $Revision: 1.2 $ + +function displaymellin(mellin,options,frame_number) + +%setup the scale bar to alter to range of the colour map +%converts the exponential scale on the scale bar to a value 00) % TCW AIM2006 - fixed divide by zero warnings + matrix_of_current_frame = matrix_of_current_frame / max(max(matrix_of_current_frame)); +end + +% % maah: Maybe a threshold can help against this blur! +% if (options.threshold ~= 0) +% if (options.threshold ~= 1) +% matrix_of_current_frame(matrix_of_current_frame < options.threshold) = 0; +% else +% mean_value = mean(mean(matrix_of_current_frame)); +% matrix_of_current_frame(matrix_of_current_frame < mean_value) = 0; +% end; +% end; + +%set the range of values for the axes +coef_range=[0,max(options.c_2pi)]; +h_range=[0,max(options.TFval)]; + +%set the resolution of the axes +coef_step=(coef_range(1,2)-coef_range(1,1))/10; +%h_step=(h_range(1,2)-h_range(1,1))/10; +h_step=1; + +%sets the axis divisions +coef_axis = [coef_range(1,1):coef_step:coef_range(1,2)]; +h_axis = [h_range(1,1):h_step:h_range(1,2)]; + +%this section sets up the colormap to be the correct gray scale version that we want +colormap_name=gray(128); % maah: was = gray(128) +size_colormap=size(colormap_name); +%disp(size_colormap); +for ii=1:size_colormap(1); + rich_map(ii,:)=colormap_name((129-ii),:); +end; +colormap(rich_map); + + +%now we generate the image matlab automatically scales the colours +%note that we take the magnitude of the components +%we reset the the colourmap, scaling it's maximum to 1 +%matrix_of_current_frame = matrix_of_current_frame'; %removed the transpose +%in the display function and put it into the generating function +mellin_image = image(h_axis, coef_axis, matrix_of_current_frame,'CDataMapping','scaled'); + +set(gca,'CLimMode','manual'); +set(gca,'CLim',[0 options.max_value]); + +%now we scale the image so that it fills the display area +limitx=ceil(max(h_axis)); +limity=ceil(max(coef_axis)); +set(gca,'XLim',[0 limitx]); +set(gca,'YLim',[0 limity]); + +%here we setup the scale and location of the axes +set(gca,'XTick', h_axis); +set(gca,'XTickLabel', h_axis,'FontSize',8); + +set(gca,'YTick', coef_axis); +set(gca,'YTickLabel', coef_axis,'FontSize',8,'YAxisLocation','right'); + +%flip the y axis +set(gca,'YDir','normal') + +%and put on the labels +mellin_image = xlabel('Time-Interval, Peak-Frequency product, \ith','FontSize',8); +mellin_image = ylabel('Mellin variable, \it{c/2\pi}','FontSize',8); \ No newline at end of file diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/mellin/displaysaicol.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aim-mat/modules/usermodule/mellin/displaysaicol.m Fri May 20 12:32:31 2011 +0100 @@ -0,0 +1,77 @@ +% generating function for 'aim-mat' +% +% INPUT VALUES: +% +% RETURN VALUE: +% +% +% (c) 2003-2008, University of Cambridge, Medical Research Council +% Richard Turner (ret26@cam.ac.uk) +% http://www.pdn.cam.ac.uk/cnbh/aim2006 +% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ +% $Revision: 585 $ + +function displaysaicol(cmap,options,frame_number) + +%setup the scale bar to alter to range of the colour map +%converts the exponential scale on the scale bar to a value 0