# 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 $
+
+
+ - To install AIM-MAT, recursively add the aim-mat,
+ tools and demo
+ folders to your MATLAB path
+ - To test the installation, run demo_aim2006_gtfb
+ from the demo folder, this
+ runs the analysis of the four scaled vowel sounds seen in the documentation.
+ The script opens six figure windows, one for each stage of the model, and
+ plots the output of each stage for the four vowels.
+- To run AIM with a GUI type aim
+ at the prompt
+
+
+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:
+- Windows XP with MATLAB versions 6.5, 7.1, R2006a
+- Mac OS X (version 10.4 onwards) with MATLAB version 7.1 and R2007b
+- Ubuntu Linux with MATLAB versions 7.1, R2007b and R2008a
+
+Tips for getting started
+
+- If AIM-MAT is started from the command-line with no parameters, a file-open dialogue box will be displayed. Select the .wav or .aiff file you wish to process using this box.
+ - AIM-MAT is a MATLAB implementation of the Auditory Image Model. The buttons
+ along the top of the main AIM-MAT window correspond to stages of this model.
+ The model runs from left to right across the window. The calculation of any
+ section of the model is contingent upon the calculation of the stage before
+ it.
+ - To enable any of the buttons at the top of the AIM-MAT window, simply check
+ the 'recalculate' checkbox below that button. This will automatically check
+ any other parts of the module that need recalculating.
+
+ - If any section of the model needs calculating, the surround of the button
+ for that section will light up blue. If the section
+ needs recalculating the button surround will light up red.
+ Sections of the model which have been calculated have button surrounds in
+ dark green. The section whose output is currently
+ displayed has the button surround illumninated in bright
+ green.
+- To get the contents of the AIM-MAT workspace into the MATLAB command line workspace at any point, simply select 'Copy current data to workspace (data)' from the 'Edit' menu.
+ - The plot window will show no activity for the first few frames of the output
+ of the SAI module. This is because it takes a finite time for the stabilised
+ image to build up. Use the 'Frame #' slider in the bottom left of the GUI
+ to move on a few frames and see the image to build up.
+ - The autoscaling function should scale each plot to a reasonable level, however,
+ if the activity in the plot window looks to large or too small, you can use
+ the 'autoscale' button to re-run the autoscaling, or use the scaling slider
+ to choose a suitable scale for the plot.
+ - AIM-MAT plots are just MATLAB figures; they can be manipulated using the
+ MATLAB 7 plot tools, or command line functions.
+ - AIM-MAT stores parameters for a processed file in a subdirectory of that
+ file's directory, named after the file without the extension. If you wish
+ AIM-MAT to start afresh on working on a file, delete this subdirectory.
+
+
+
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 00.5 low pass
+SAIparam.Nwidth = 0; %sets the negative width of the window
+
+[NumCh, LenSAI, LenFrame] = size(SAI3d);
+
+%here we set up the Frs values for each channel
+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;
+
+%We initialise the SSI matrix
+SSI3d = zeros(NumCh,LenTF,LenFrame);
+
+waithand=waitbar(0,'generating the SSI');
+
+% set the frame range, the SSI 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) * SSIparam.NSAIPhsCmp;
+ shift_matrix = [zeros(1,fix(NPeriod)), SAIval(nch,:)];
+ SAIPhsCmp(nch,1:LenSAI) = shift_matrix(1:LenSAI);
+ end;
+ if SSIparam.F0mode == 0
+ else
+ F0est(nfr) = SSIparam.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
+
+ % set the range for the auditory image
+ if (options.do_all_image == 1)
+ SSIparam.RangeAudFig = [1 LenSAI];
+ else
+ SSIparam.RangeAudFig = options.audiorange;
+ end;
+ % maah: was MIparam.RangeAudFig = [ZeroLoc+[0 , (fix(NAPparam.fs/F0est(nfr))-MarginAF)]];
+
+ % Calculation of the SSI
+ [SSImtrx] = Calssicoef(SAIPhsCmp,NAPparam,SSIparam);
+
+ %Output into the 3d matrix
+ SSI3d(:,:,nfr) = SSImtrx;
+
+end;
+
+close(waithand);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/sst/Calssicoef.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/modules/usermodule/sst/Calssicoef.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,118 @@
+% 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)
+%
+% Modified for the size shape image
+% Marc A. Al-Hames
+% April 2003
+%
+% 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 [ ssi ] = Calssicoef(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;
+
+% It's worth notin what's going on here, becuase it's not completely
+% obvious. AFval contains the
+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;
+
+ssi = AFave;
+
+% 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/sst/gen_sst.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/modules/usermodule/sst/gen_sst.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,56 @@
+% Function to calculate the size-shape image (SSI)
+%
+% (c) 2003-2008, University of Cambridge, Medical Research Council
+%
+% Marc A. Al-Hames
+% April 2003
+%
+% http://www.pdn.cam.ac.uk/cnbh/aim2006
+
+function ssi=gen_ssi(sai,options)
+
+%user information; open the 'calculation in progress' dialog box
+waithand=waitbar(0,'reading in SAI');
+disp('running the SSI function...');
+
+%read in all of the frames in the SAI array - converting them into Irino's
+%3d matrix
+
+no_frames=size(sai);
+SAI3d=[];
+
+for ii=1:no_frames(2);
+ fraction_complete=ii/no_frames(2);
+ waitbar(fraction_complete);
+ current_frame=sai{ii};
+ SAI3d(:,:,ii)=getvalues(current_frame);
+ if (options.flipimage == 1)
+ SAI3d(:,:,ii) = fliplr(SAI3d(:,:,ii));
+ end;
+end;
+
+%close the dialog box
+close(waithand);
+
+%assume that the sample rate is constant
+sample_rate=getsr(sai{1});
+
+SSI3d=Calssi(SAI3d,options,sample_rate);
+
+%finally we output everything into frames
+%we have to take the transpose to put it in the correct form for the
+%display function
+
+maxfreval=max(max(sum(SSI3d,2)));
+
+for jj=1:no_frames(2);
+ current_frame=SSI3d(:,:,jj);
+ ssi{1,jj}=frame(current_frame);
+ %set the sample rate of the frames
+ ssi{1,jj}=setsr(ssi{1,jj},sample_rate);
+ ssi{1,jj}=setxaxisname(ssi{1,jj},'0');
+ ssi{1,jj}=setscalefrequency(ssi{1,jj},maxfreval);
+end;
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/modules/usermodule/sst/parameters.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/modules/usermodule/sst/parameters.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,42 @@
+%%%%%%%%%%%%%%%%%%%%%
+% usermodule sst %
+%%%%%%%%%%%%%%%%%%%%%
+
+% hidden parameters
+sst.generatingfunction = 'gen_sst';
+sst.displayname = 'Size-Shape Transform';
+% sst.displayfunction = 'displaysst';
+sst.revision = '$Revision: 1.2 $';
+
+% Sets the frames, the sst image is calculated for.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% If do_all_frames = 1
+% all frames of the auditory image are transformed to a sst image
+% If do_all_frames = 0 only the frames specified in
+% framerange = [start_frame end_frame] are transformed
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+sst.do_all_frames = 1;
+sst.framerange = [0 0];
+
+% Sets the Range for the Auditory image
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Calculation of the sst image for the points
+% audiorange = [start_point end_point]
+% if do_all_image = 1: start_point = 1, end_point = last point in the ai
+% flipimage = 1 flips the auditory image (for ti1992)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+sst.do_all_image = 1;
+sst.audiorange = [1 200];
+sst.flipimage = 0;
+
+% Sets the variables h and c
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+sst.c_2pi = [0:0.05:30];
+sst.TFval = [0:0.05:16];
+
+% TCW AIM2006
+% These should be the same as the filterbank settings
+% (this could be implemented better and will be in future versions, where
+% these will not be required).
+sst.lowest_frequency=100;
+sst.highest_frequency=6000;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@clicktrain/clicktrain.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@clicktrain/clicktrain.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,53 @@
+% constructor of class @clicktrain (derived from @signal)
+% parent class: @signal
+% function ct=clicktrain([length],[samplerate],[frequency],[amplitude])
+
+% INPUT VALUES:
+% length: length of signal in seconds [default 1]
+% samplerate: samplerate in Hz (points per seconds) [default: 1000]
+% frequency: frequency in Hz [default: 100]
+% amplitude: clicks amplitude [default: 1]
+% RETURN VALUE:
+% @signal-object
+%
+%
+%
+% (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 ct=clicktrain(length,samplerate,frequency,amplitude)
+% produces a clicktrain as a signal
+
+if nargin < 4
+ amplitude=1;
+end
+if nargin < 3
+ frequency=100;
+end
+if nargin < 2
+ samplerate=10000;
+end
+if nargin < 1
+ length=1;
+end
+
+name= sprintf('Clicktrain with %5.2f Hz',frequency);
+unit_y='amplitude';
+unit_x='time (ms)';
+start_time=0;
+
+ctt.frequency=frequency;
+ctt.amplitude=amplitude;
+
+sig=signal(length,samplerate,name,unit_x,unit_y,start_time);
+
+% f=class(struct([]),'fsignal',sig);
+ct=class(ctt,'clicktrain',sig);
+
+ct=generate(ct);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@clicktrain/generate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@clicktrain/generate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @clicktrain (derived from @signal)
+% function ct=generate(ct)
+% INPUT VALUES:
+% ct=old @clicktrain
+% RETURN VALUE:
+% ct=new @clicktrain with the correct values
+%
+%
+%
+% (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 ct=generate(ct)
+
+ct=mute(ct);
+
+df=floor(getsr(ct)/ct.frequency);
+to=time2bin(ct,getlength(ct));
+clicks=1:df:to;
+
+ct=setbinvalue(ct,clicks,ct.amplitude);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@clicktrain/getfrequency.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@clicktrain/getfrequency.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @clicktrain (derived from @signal)
+% function fre=getfrequency(ct)
+% INPUT VALUES:
+% ct: @clicktrain
+% RETURN VALUE:
+% fre=frequency of the clicktrain
+%
+%
+% (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 fre=getfrequency(ct)
+fre=ct.frequency;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@clicktrain/setfrequency.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@clicktrain/setfrequency.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @clicktrain (derived from @signal)
+% function ct=setfrequency(ct,fre)
+% INPUT VALUES:
+% fre: frequency of the clicktrain in Hz
+% RETURN VALUE:
+% ct: new clicktrain
+%
+% (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 ct=setfrequency(ct,was)
+ct.frequency=was;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/disp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/disp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+function disp(f)
+nrt=getnrpoints(f);
+nrf=getnrfrequencies(f);
+
+disp(sprintf('field: (time:)%d - by - (frequencies:)%d',nrt,nrf));
+getdata(f)
+return
+for j=1:nrt
+ row=getcolumn(f,j);
+ a=getdata(row)
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/display.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/display.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,10 @@
+function display(f)
+
+disp('Object of Class field');
+% disp(sprintf('Name: %s',fsig.name));
+disp(sprintf('Time: %5.2f sec',getduration(f)));
+disp(sprintf('maximum frequency %5.2f ',maxfre(f)));
+disp(sprintf('Sample rate: %5.2f Hz',f.samplerate));
+disp(sprintf('Time steps: %d',getnrt(f)));
+disp(sprintf('Frequency steps: %d',getnrf(f)));
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/field.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/field.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,41 @@
+function res=field(nrt,nrf,sr)
+%Konstruktor der field klasse
+% Fields sind 2D-Array einer Frequenz über Zeit
+% also ein umgedrehtes Array
+% Bei mir ist die erste Koordinate X und die zweite Y!!
+% das ist verständlicher! So, wie auf dem Schirm zu sehen:
+% disp(irgend ein Array) macht nach rechts die Zeit
+% und nach oben die Frequenz
+
+if nargin<3
+ sr=1;
+end
+
+
+if nargin==1
+ if isnumeric(nrt); % Aufruf mit einem fertigen Feld
+% x=size(nrt,2);
+% y=size(nrt,1);
+ res.werte=nrt;
+ end
+else %wenn nicht mit einem aufgerufen, dann müssen die beiden Werte Begrenzer sein
+ x=nrt;
+ y=nrf;
+ % blödes Matlab: Matrizen sind kodiert oben,rechts
+ % Der X-Wert geht nach oben, der Y-Wert geht nach rechts.
+ % Ich will Zeit nach rechts gehen lassen, also muss Zeit der zweite Parameter sein
+ res.werte=zeros(y,x);
+end
+
+% res.numbert=x;
+% res.numberf=y;
+res.samplerate=sr;
+% res.minfre=0;
+res.maxfre=0;
+res.offset=0;
+
+
+res=class(res,'field');
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/fill.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/fill.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+function f=fill(f,x1,x2,wert)
+% Fill the part of the matrix from x1 to x2 with that value
+% The size of the matrix might be increased
+
+nrfre=getnrfrequencies(f);
+for x=x1:x2
+ nullen=ones(1,nrfre)*wert;
+ sig=signal(nullen);
+ f=setcolumn(f,x,sig);
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getcolumn.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getcolumn.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,4 @@
+function sig=getcolumn(f,nr)
+
+r=f.werte(:,nr);
+sig=signal(r);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getdata.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getdata.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function res=getdata(f)
+
+res=f.werte;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getduration.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getduration.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,2 @@
+function t=getduration(field)
+t=getnrt(field)/field.samplerate;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getnrf.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getnrf.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function nrf=getnrf(f)
+vals=getvalues(f);
+nrf=size(vals,1);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getnrfrequencies.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getnrfrequencies.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function nr=getnrfrequencies(field)
+nr=size(field.werte,1);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getnrpoints.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getnrpoints.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function x=getnrpoints(field)
+
+x=size(field.werte,2);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getnrt.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getnrt.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function nrt=getnrt(f)
+vals=getvalues(f);
+nrt=size(vals,2);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getoffset.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getoffset.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,2 @@
+function startt=getoffset(f)
+startt=f.offset;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getpart.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getpart.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,14 @@
+function ret=getpart(f,t_start,t_stop)
+
+ret=f;
+
+
+vals=f.werte;
+srf=getsr(f);
+binstart=time2bin(srf,t_start);
+binstop=time2bin(srf,t_stop);
+
+retvals=vals(:,binstart:binstop);
+
+ret=setvalues(f,retvals);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getrow.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getrow.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,4 @@
+function sig=getrow(f,nr)
+
+r=f.werte(:,nr);
+sig=signal(r);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getsr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getsr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function res=getsr(f)
+
+res=f.samplerate;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/getvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/getvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function res=getvalues(f)
+
+res=f.werte;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/log.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/log.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,2 @@
+function f=log(f)
+f.werte=log(f.werte);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/maxfre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/maxfre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function f=maxfre(field)
+
+f=field.maxfre;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/minfre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/minfre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function f=minfre(field)
+
+f=field.minfre;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/mtimes.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/mtimes.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+function f=mtimes(f,b)
+% multiplikation mit *
+% einfachster Fall: Multipliziere mit konstanter Zahl
+% sonst: Multipliziere ein zweites Signal zum Zeitpunkt Null
+
+if isnumeric(b)
+ if size(b)==1
+ f.werte=f.werte*b;
+ else
+ disp('field::mtimes: too many parameters in multiplication')
+ end
+ return
+end
+
+disp('field::mtimes: multiplication with field not implemented yet')
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/plot.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/plot.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,71 @@
+function plot(f,modus)
+
+if nargin<2
+ modus='linear';
+end
+
+% maxfre=maxfre(f);
+% nrf=getnrf(f);
+% freqs=linspace(0,maxfre,nrf);
+%
+% nrt=getnrt(f);
+% sr=getsr(f);
+% maxt=sr*nrt;
+% times=linspace(0,maxt,nrt);
+% startt=getoffset(f);
+% times=times-startt;
+%
+% vals=getvalues(f);
+% imagesc(times,freqs,20*log10(vals));
+% axis xy
+% colormap(jet)
+
+
+surf(f.werte);
+% view(0,90);
+shading interp
+
+maxx=getnrt(f);
+maxy=getnrf(f);
+minx=0;
+miny=0;
+
+xstep=(maxx-minx)/10;
+tix=minx:xstep:maxx;
+ti=([minx:xstep:maxx]);
+ti=bin2time(ti,f.samplerate);
+ti=round((ti+f.offset)*10000)/10;
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+
+if strcmp(modus,'linear')
+ ystep=(maxy-miny)/10;
+ tiy=miny:ystep:maxy;
+ ti=([miny:ystep:maxy]);
+ ti=ti/maxy*f.maxfre;
+ ti=round(ti*10)/10000;
+ set(gca,'YTick',tiy);
+ set(gca,'YTickLabel',ti);
+elseif strcmp(modus,'log')
+ set(gca,'yscale','log')
+
+ max_fre=maxfre(f);
+ nr_ticks=6;
+ yticks=distributelogarithmic(maxy/power(2,nr_ticks-1),maxy,nr_ticks);
+ set(gca,'YTick',yticks);
+
+ ytickl=distributelogarithmic(max_fre/power(2,nr_ticks-1),max_fre,nr_ticks);
+ ti=[];
+ for i=1:nr_ticks
+ sadf=sprintf('%3.2f',ytickl(i)/1000);
+ ti=[ti ; sadf(1:4)];
+ end
+ set(gca,'YTickLabel',ti);
+end
+xlabel('time (ms)');
+ylabel('Frequency (kHz)');
+
+axis([1 maxx 1 maxy]);
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/plus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/plus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+function f=plus(a,b)
+% addition
+% einfachster Fall: Addiere eine konstante Zahl
+% sonst: Addiere ein zweites Feld zum Zeitpunkt Null
+
+if isnumeric(b)
+ a.werte=a.werte+b;
+ f=a;
+ return
+end
+
+if isobject(a)
+ x1=getnrpoints(a);
+ y1=getnrfrequencies(a);
+ x2=getnrpoints(b);
+ y2=getnrfrequencies(b);
+
+ if (x1~=x2) | (y1~=y2)
+ disp('Fields do not fit');
+ f=a;
+ return;
+ end
+ f=a;
+ f.werte=f.werte+b.werte;
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/setcolumn.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/setcolumn.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+function f=setcolumn(field,x,sig)
+% setze die Spalte (hoch-runter) mit den Werten aus Signal
+% erster Parameter in einem Matlab Array immer die Frequenz (oben-unten!!!)
+
+if isobject(sig)
+ nr_signal=getnrpoints(sig);
+else
+ nr_signal=size(sig,1);
+end
+
+nr_field=getnrfrequencies(field);
+if nr_signal ~= nr_field
+ disp('different number of points in field::setcolum');
+ return
+end
+
+if x>field.numbert; % das Feld kann sich bei der Aktion vergrößern
+ field.numbert=x;
+end
+f=field;
+if isobject(sig)
+ wer=getdata(sig);
+else
+ wer=sig;
+end
+f.werte(1:nr_field,x)=wer(1:nr_signal);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/setmaxfre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/setmaxfre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,2 @@
+function f=setmaxfre(f,nr)
+f.maxfre=nr;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/setoffset.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/setoffset.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,2 @@
+function f=setoffset(f,time)
+f.offset=time;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/setrow.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/setrow.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+function f=setrow(field,x,sig)
+% setze die Zeile (links rechts) mit den Werten aus Signal
+% erster Parameter in einem Matlab Array immer die Frequenz (oben-unten!!!)
+
+
+if isobject(sig)
+ nr_signal=getnrpoints(sig);
+else
+ nr_signal=size(sig,2);
+end
+
+nr_field=getnrpoints(field);
+if nr_signal ~= nr_field
+ disp('different number of points in field::setrow');
+ return
+end
+
+f=field;
+
+if isobject(sig)
+ wer=getdata(sig);
+else
+ wer=sig;
+end
+
+f.werte(x,1:nr_field)=wer(1:nr_signal);
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/setvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/setvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,3 @@
+function f=setvalues(f,B)
+
+f.werte=B;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/shift.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/shift.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+function f=shift(f,x1,x2)
+% shift the part of the matrix with the beginning x1 to x2
+% The size of the matrix might be increased
+% The rest is filled with zeros
+
+% first, shift the rest to the right
+d=getdata(f);
+s=size(d);
+stop=s(2);
+stop2=x2-x1+stop;
+d(:,x2:stop2)=d(:,x1:stop);
+
+% fill the left part with zeros
+d(:,1:x2-1)=0;
+
+f=field(d);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@field/size.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@field/size.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,2 @@
+function s=size(sig)
+s=size(sig.werte);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/bin2time.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/bin2time.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% method of class @frame
+% function res=bin2time(sig,bin)
+% calculates the time according to the value of the bin in
+%
+% INPUT VALUES:
+% sig: original @frame
+% bin: value of bin (not necessary integer)
+%
+% RETURN VALUE:
+% res: time of bin in seconds
+%
+% (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/11 10:46:32 $
+% $Revision: 1.1 $
+
+function res=bin2time(fr,val)
+% gibt die Zeit zurück, bei dem dieses Bin ist
+% Zeit immer in Sekunden
+% Samplerate immer in Bins pro Sekunde (96 kHz)
+sr=fr.samplerate;
+% eines abgezogen, weil Matlab bei 1 startet also bin 1der Anfangszeitpunkt ist
+% res=(val-1)/sr;
+res=val/sr;
+
+res=res+fr.start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/buildtent.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/buildtent.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function tent=buildtent(fr)
+
+tent=frame(fr);
+
+vals=getvalues(fr);
+vals=zeros(size(vals));
+
+nr_chan=getnrchannels(fr);
+cfs=getcf(fr);
+for i=1:nr_chan
+ fre=cfs(i);
+ dif=1/fre*2;
+ s2=getsinglechannel(fr,i);
+ env=envelope(s2,dif,0,0.05);
+ vals(i,:)=getvalues(env)';
+end
+
+tent=setvalues(tent,vals);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/chan2fre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/chan2fre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fre=chan2fre(fr,chan)
+% returns the frequency of that channel
+
+nr_chan=getnrchannels(fr);
+
+x=1:nr_chan;
+Y=getcf(fr);
+xi=chan;
+method='linear';
+
+fre=interp1(x,Y,xi,method);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/createscaleprofile.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/createscaleprofile.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,217 @@
+function ret_field=createscaleprofile(current_frame,options)
+% creates a profile with an angle to the auditory image. The angle is
+% ususally 45° and therefore the result is the collapsed Mellin image
+%
+
+% do we want debugging graphic? (very nice!!)
+grafix=0;
+
+% the angle of the profile
+if isfield(options,'angle')
+ angle=options.angle;
+else
+ angle=45; % in degrees
+end
+
+% the borders of the profiles are given by the minimum and the maximum
+% harmonic relationship:
+if isfield(options,'min_harmonic_relationship')
+ min_harmonic_relationship=options.min_harmonic_relationship;
+else
+ min_harmonic_relationship=0.5;
+end
+if isfield(options,'max_harmonic_relationship')
+ max_harmonic_relationship=options.max_harmonic_relationship;
+else
+ max_harmonic_relationship=20;
+end
+% how many points do we want to have on our profile?
+if isfield(options,'nr_points')
+ nr_points=options.nr_points;
+else
+ nr_points=200;
+end
+
+
+% if we know about the periodicity, we can restrict ourself to the
+% interesting region
+if isfield(options,'periodicity')
+ periodicity=options.periodicity;
+else
+ periodicity=0.035; % in seconds
+end
+
+% translate to radian
+angle=angle*2*pi/360;
+tanangle=tan(angle); % accelerate
+
+cfs=getcf(current_frame);
+
+vals=getvalues(current_frame);
+nr_channels=getnrchannels(current_frame);
+
+
+
+
+t_min=getminimumtime(current_frame);
+t_max=getmaximumtime(current_frame);
+
+if periodicity < t_max
+ t_max=periodicity;
+end
+
+if t_min==0
+ t_min=0.0001;
+end
+
+
+fre_min=1/t_max;
+if t_min>0
+ fre_max=1/t_min;
+else
+ fre_max=1000;
+end
+
+% das ist die niedrigste Frequenz, die auf der Basilarmembran zu finden ist
+min_fre_current_frame=cfs(1);
+% das bedeutet, dass wir über die harmonischen Grenzen rausfinden können,
+% wie groß der Bereich ist, den wir gehen müssen:
+% die untere harmonische Zahl gibt uns den oberen Wert:
+smallest_interval_value=min_harmonic_relationship/min_fre_current_frame;
+biggest_interval_value=max_harmonic_relationship/min_fre_current_frame;
+
+% wieviel cent wollen wir tatsächlich untersuchen lassen:
+% nr_cent=fre2cent(1/biggest_interval_value,1/smallest_interval_value); % so viele cent sind insgesamt im interval profile
+% wir starten von links nach rechts und gehen in Schrittweite
+% start_cent=fre2cent(fre_min,1/biggest_interval_value);
+
+% Die Schrittweite berechnet sich aus den Extremen:
+% delta_cent=nr_cent/(nr_points-1);
+
+res_vals=zeros(1,nr_points);
+for jj=1:nr_channels
+ current_channel(jj)=getsinglechannel(current_frame,jj);
+end
+if grafix
+ colors=['b','r','g','c','m','k','y'];
+ figure(2);
+ clf
+ hold on
+ str.is_log=1;
+ str.time_reversed=1;
+ str.minimum_time=t_min;
+ str.maximum_time=t_max;
+ plot(current_frame/1,str);
+end
+
+% start_harmonic_relations=linspace(min_harmonic_relationship,max_harmonic_relationship,nr_points);
+start_harmonic_relations=distributelogarithmic(min_harmonic_relationship,max_harmonic_relationship,nr_points);
+
+
+channel_step=1; % skip maybe some channels
+nr_y_dots=floor(length(cfs)/channel_step);
+% the result is a twoDfield with x=harmonic number and y=whateverthisis
+% the number of field entries is given by the given number and the number
+% of channels
+result_field=zeros(nr_points,nr_y_dots);
+
+
+for ii=1:nr_points
+ current_start_cent=fre2cent(fre_min,cfs(1)/start_harmonic_relations(ii));
+ y_count=1;
+ for jj=1:channel_step:nr_channels
+ % soviel cent ist dieser Kanal über dem ersten
+ channel_diff_cent=fre2cent(cfs(1),cfs(jj));
+ % soviel cent gehen wir nach rechts im Intervall
+ cur_cent_x=channel_diff_cent/tanangle+current_start_cent;
+ % das bedeutet diese Frequenz auf der Intervallachse:
+ cur_fre=cent2fre(fre_min,cur_cent_x);
+ cur_time=1/cur_fre;
+ if cur_time> t_min && cur_time < t_max
+ cur_val=gettimevalue(current_channel(jj),cur_time);
+ if grafix
+ col=colors(mod(ii,7)+1);
+ plot3(time2bin(current_frame,cur_time),jj,cur_val/30,'.','color',col);
+ end
+ else
+ cur_val=0;
+ end
+ result_field(ii,y_count)=cur_val;
+ y_count=y_count+1;
+ end
+end
+
+% ret_field=frame(result_field');
+% ret_field=setstarttime(ret_field,min_harmonic_relationship);
+% newsr=nr_points/(max_harmonic_relationship-min_harmonic_relationship);
+% ret_field=setsr(ret_field,newsr);
+% ret_field=setxaxisname(ret_field,'harmonic ratio');
+% return
+
+% next step: calculate the autocorrelation function in each channel:
+
+% grafix=1;
+% res_field2=result_field;
+% for ii=1:nr_points;
+% spalte=result_field(ii,:);
+% sig=signal(spalte,1);
+% acsig=autocorrelate(sig,1,getnrpoints(sig));
+% acsigvals=getvalues(acsig);
+% res_field2(ii,:)=acsigvals';
+%
+% % fftsig=powerspectrum(sig);
+% % nrs=linspace(1,getnrpoints(fftsig),getnrpoints(sig));
+% % ftsigvals=getvalues(fftsig);
+% % ftsigvals=ftsigvals(round(nrs));
+% % res_field2(ii,:)=-ftsigvals';
+%
+%
+% % if grafix
+% % figure(23423)
+% % clf
+% % hold on
+% % plot(acsig/max(acsig),'r');
+% % plot(ftsigvals/min(ftsigvals),'r');
+% % plot(sig/max(sig));
+% % end
+% p=0;
+% end
+
+% result_field=result_field';
+% result_field=result_field(end:-1:1,:);
+% result_field=result_field(:,end:-1:1);
+ret_field=frame(result_field');
+
+ret_field=setstarttime(ret_field,min_harmonic_relationship);
+newsr=nr_points/(max_harmonic_relationship-min_harmonic_relationship);
+ret_field=setsr(ret_field,newsr);
+ret_field=setxaxisname(ret_field,'harmonic ratio');
+% ret_field=setyaxisname(ret_field,'erb distance');
+
+
+% try to extract everything that is "suprising" (e.g. not click response)
+
+
+return
+
+% one dimensional profile
+profile=signal(res_vals);
+% profile=setunit_x(profile,'scaling-frequency dimension');
+
+
+% scaliere die x-achse auf das wachsende harmonische Verhältnis:
+% chr=current_harmonic_relation(end:-1:1);
+% rprof=res_vals(end:-1:1);
+% rprof=signal(rprof);
+% nr_dots=length(chr);
+% for i=1:length(chr)
+% n_y=f2f(i,1,nr_dots,min_harmonic_relationship,max_harmonic_relationship);
+% rx=interp1(chr,1:nr_dots,n_y);
+% nprof(i)=getbinvalue(rprof,rx);
+% end
+%
+% profile=signal(nprof);
+profile=setstarttime(profile,min_harmonic_relationship);
+newsr=getnrpoints(profile)/(max_harmonic_relationship-min_harmonic_relationship);
+profile=setsr(profile,newsr);
+profile=setunit_x(profile,'harmonic ratio');
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/createscaleprofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/createscaleprofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,215 @@
+function ret_field=createscaleprofile(current_frame,options)
+% creates a profile with an angle to the auditory image. The angle is
+% ususally 45° and therefore the result is the collapsed Mellin image
+%
+
+% do we want debugging graphic? (very nice!!)
+grafix=0;
+
+% the angle of the profile
+if isfield(options,'angle')
+ angle=options.angle;
+else
+ angle=45; % in degrees
+end
+
+% the borders of the profiles are given by the minimum and the maximum
+% harmonic relationship:
+if isfield(options,'min_harmonic_relationship')
+ min_harmonic_relationship=options.min_harmonic_relationship;
+else
+ min_harmonic_relationship=0.5;
+end
+if isfield(options,'max_harmonic_relationship')
+ max_harmonic_relationship=options.max_harmonic_relationship;
+else
+ max_harmonic_relationship=20;
+end
+% how many points do we want to have on our profile?
+if isfield(options,'nr_points')
+ nr_points=options.nr_points;
+else
+ nr_points=200;
+end
+
+
+% if we know about the periodicity, we can restrict ourself to the
+% interesting region
+if isfield(options,'periodicity')
+ periodicity=options.periodicity;
+else
+ periodicity=0.035; % in seconds
+end
+
+% translate to radian
+angle=angle*2*pi/360;
+tanangle=tan(angle); % accelerate
+
+cfs=getcf(current_frame);
+
+vals=getvalues(current_frame);
+nr_channels=getnrchannels(current_frame);
+
+
+
+
+t_min=getminimumtime(current_frame);
+t_max=getmaximumtime(current_frame);
+
+if periodicity < t_max
+ t_max=periodicity;
+end
+
+if t_min==0
+ t_min=0.0001;
+end
+
+
+fre_min=1/t_max;
+if t_min>0
+ fre_max=1/t_min;
+else
+ fre_max=1000;
+end
+
+% das ist die niedrigste Frequenz, die auf der Basilarmembran zu finden ist
+min_fre_current_frame=cfs(1);
+% das bedeutet, dass wir über die harmonischen Grenzen rausfinden können,
+% wie groß der Bereich ist, den wir gehen müssen:
+% die untere harmonische Zahl gibt uns den oberen Wert:
+smallest_interval_value=min_harmonic_relationship/min_fre_current_frame;
+biggest_interval_value=max_harmonic_relationship/min_fre_current_frame;
+
+% wieviel cent wollen wir tatsächlich untersuchen lassen:
+% nr_cent=fre2cent(1/biggest_interval_value,1/smallest_interval_value); % so viele cent sind insgesamt im interval profile
+% wir starten von links nach rechts und gehen in Schrittweite
+% start_cent=fre2cent(fre_min,1/biggest_interval_value);
+
+% Die Schrittweite berechnet sich aus den Extremen:
+% delta_cent=nr_cent/(nr_points-1);
+
+res_vals=zeros(1,nr_points);
+for jj=1:nr_channels
+ current_channel(jj)=getsinglechannel(current_frame,jj);
+end
+if grafix
+ colors=['b','r','g','c','m','k','y'];
+ figure(2);
+ clf
+ hold on
+ str.is_log=1;
+ str.time_reversed=1;
+ str.minimum_time=t_min;
+ str.maximum_time=t_max;
+ plot(current_frame/1,str);
+end
+
+% start_harmonic_relations=linspace(min_harmonic_relationship,max_harmonic_relationship,nr_points);
+start_harmonic_relations=distributelogarithmic(min_harmonic_relationship,max_harmonic_relationship,nr_points);
+
+
+channel_step=1; % skip maybe some channels
+nr_y_dots=floor(length(cfs)/channel_step);
+% the result is a twoDfield with x=harmonic number and y=whateverthisis
+% the number of field entries is given by the given number and the number
+% of channels
+result_field=zeros(nr_points,nr_y_dots);
+
+
+for ii=1:nr_points
+ current_start_cent=fre2cent(fre_min,cfs(1)/start_harmonic_relations(ii));
+ y_count=1;
+ for jj=1:channel_step:nr_channels
+ % soviel cent ist dieser Kanal über dem ersten
+ channel_diff_cent=fre2cent(cfs(1),cfs(jj));
+ % soviel cent gehen wir nach rechts im Intervall
+ cur_cent_x=channel_diff_cent/tanangle+current_start_cent;
+ % das bedeutet diese Frequenz auf der Intervallachse:
+ cur_fre=cent2fre(fre_min,cur_cent_x);
+ cur_time=1/cur_fre;
+ if cur_time> t_min && cur_time < t_max
+ cur_val=gettimevalue(current_channel(jj),cur_time);
+ if grafix
+ col=colors(mod(ii,7)+1);
+ plot3(time2bin(current_frame,cur_time),jj,cur_val/30,'.','color',col);
+ end
+ else
+ cur_val=0;
+ end
+ result_field(ii,y_count)=cur_val;
+ y_count=y_count+1;
+ end
+end
+
+% ret_field=frame(result_field');
+% ret_field=setstarttime(ret_field,min_harmonic_relationship);
+% newsr=nr_points/(max_harmonic_relationship-min_harmonic_relationship);
+% ret_field=setsr(ret_field,newsr);
+% ret_field=setxaxisname(ret_field,'harmonic ratio');
+% return
+
+% next step: calculate the autocorrelation function in each channel:
+
+% grafix=1;
+% res_field2=result_field;
+% for ii=1:nr_points;
+% spalte=result_field(ii,:);
+% sig=signal(spalte,1);
+% acsig=autocorrelate(sig,1,getnrpoints(sig));
+% acsigvals=getvalues(acsig);
+% res_field2(ii,:)=acsigvals';
+%
+% % fftsig=powerspectrum(sig);
+% % nrs=linspace(1,getnrpoints(fftsig),getnrpoints(sig));
+% % ftsigvals=getvalues(fftsig);
+% % ftsigvals=ftsigvals(round(nrs));
+% % res_field2(ii,:)=-ftsigvals';
+%
+%
+% % if grafix
+% % figure(23423)
+% % clf
+% % hold on
+% % plot(acsig/max(acsig),'r');
+% % plot(ftsigvals/min(ftsigvals),'r');
+% % plot(sig/max(sig));
+% % end
+% p=0;
+% end
+
+% result_field=result_field';
+% result_field=result_field(end:-1:1,:);
+% result_field=result_field(:,end:-1:1);
+ret_field=frame(result_field');
+
+ret_field=setstarttime(ret_field,min_harmonic_relationship);
+newsr=nr_points/(max_harmonic_relationship-min_harmonic_relationship);
+ret_field=setsr(ret_field,newsr);
+ret_field=setxaxisname(ret_field,'harmonic ratio');
+% ret_field=setyaxisname(ret_field,'erb distance');
+
+% supr=suprisemap(result_field);
+% ret_field=supr';
+return
+
+% one dimensional profile
+profile=signal(res_vals);
+% profile=setunit_x(profile,'scaling-frequency dimension');
+
+
+% scaliere die x-achse auf das wachsende harmonische Verhältnis:
+% chr=current_harmonic_relation(end:-1:1);
+% rprof=res_vals(end:-1:1);
+% rprof=signal(rprof);
+% nr_dots=length(chr);
+% for i=1:length(chr)
+% n_y=f2f(i,1,nr_dots,min_harmonic_relationship,max_harmonic_relationship);
+% rx=interp1(chr,1:nr_dots,n_y);
+% nprof(i)=getbinvalue(rprof,rx);
+% end
+%
+% profile=signal(nprof);
+profile=setstarttime(profile,min_harmonic_relationship);
+newsr=getnrpoints(profile)/(max_harmonic_relationship-min_harmonic_relationship);
+profile=setsr(profile,newsr);
+profile=setunit_x(profile,'harmonic ratio');
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/crosschannelinfluence.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/crosschannelinfluence.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,130 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ret=crosschannelinfluence(fr,erb)
+% usage: ret=crosschannelinfluence(fr,erb)
+% calculates the difference of the maxima from one channel to the next
+% so many channels are calculated as in erb
+
+if nargin < 2
+ erb=1;
+end
+
+break_freq=2000;
+
+ret=frame(fr);
+
+vals=getvalues(fr);
+vals=zeros(size(vals));
+
+nr_chan=getnrchannels(fr);
+cfs=getcf(fr);
+
+for i=1:nr_chan
+ chan=getsinglechannel(fr,i);
+ [maxpos{i},minpos{i},maxs{i},mins{i}]=getminmax(chan);
+end
+sig=chan; % KopieKonstruktor
+
+for i=1:nr_chan-erb
+ fre=cfs(i);
+ t_oszi=1/fre; % Die Zeitspanne zweier natürlicher peaks in dem Kanal
+
+ if fre>break_freq
+ break
+ end
+
+ nr_max=length(maxpos{i});
+ difmin=zeros(nr_max,1);
+ for k=i+1:i+erb+1
+ for j=1:nr_max;
+ xx=maxpos{i}(j);
+ maxleft=getmaximumleftof(xx+t_oszi/10,maxpos{k},minpos{k},maxs{k},mins{k});
+ maxright=getmaximumrightof(xx-t_oszi/10,maxpos{k},minpos{k},maxs{k},mins{k});
+ if isempty(maxleft)
+ difleft=t_oszi;
+ else
+ difleft=abs(xx-maxleft);
+ end
+ if isempty(maxright)
+ difright=t_oszi;
+ else
+ difright=abs(maxright-xx);
+ end
+ difmin(j)=difmin(j)+min(difleft,difright);
+ end
+ end
+% difmin=difmin*200;
+ difmin=difmin/t_oszi;
+ difmin=1-difmin;
+ difmin(find(difmin < 0))=0;
+
+ sig=buildspikesfrompoints(sig,maxpos{i},difmin);
+ vals(i,:)=getvalues(sig)';
+end
+
+ret=setvalues(ret,vals);
+
+return
+
+
+
+prev_chan=getsinglechannel(fr,1);
+[prevmaxpos,prevminpos,prevmaxs,prevmins]=getminmax(prev_chan);
+sig=prev_chan;
+
+for i=2:nr_chan
+ fre=cfs(i);
+ t_oszi=1/fre; % Die Zeitspanne zweier natürlicher peaks in dem Kanal
+
+ if fre>break_freq
+ break
+ end
+
+ now_chan=getsinglechannel(fr,i);
+ [nowmaxpos,nowminpos,nowmaxs,nowmins]=getminmax(now_chan);
+ difmin=zeros(size(nowmaxpos));
+
+ for j=1:length(nowmaxpos);
+ xx=nowmaxpos(j);
+ difleft=getmaximumleftof(xx+t_oszi/10,prevmaxpos,prevminpos,prevmaxs,prevmins);
+ difright=getmaximumrightof(xx-t_oszi/10,prevmaxpos,prevminpos,prevmaxs,prevmins);
+ if isempty(difleft)
+ difleft=inf;
+ else
+ difleft=abs(xx-difleft);
+ end
+ if isempty(difright)
+ difright=inf;
+ else
+ difright=abs(difright-xx);
+ end
+ difmin(j)=min(difleft,difright);
+ end
+ difmin=1-(difmin/t_oszi);
+ % sig=buildfrompoints(sig,nowmaxpos,difmin);
+
+ sig=buildspikesfrompoints(sig,nowmaxpos,difmin);
+
+ vals(i,:)=getvalues(sig)';
+
+ prev_chan=now_chan;
+ prevmaxpos=nowmaxpos;
+ prevminpos=nowminpos;
+ prevmaxs=nowmaxs;
+ prevmins=nowmins;
+ s=0;
+end
+
+ret=setvalues(ret,vals);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/disp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/disp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function disp(fr)
+
+disp(sprintf('start time %3.2f ms',getminimumtime(fr)*1000));
+disp(sprintf('duration: %3.2f ms',getlength(fr)*1000));
+disp(sprintf('samplerate: %3.2f ms',getsr(fr)));
+disp(sprintf('Channels: %d',getnrchannels(fr)));
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/display.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/display.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function display(fr)
+
+if max(size(fr)) > 1
+ disp(sprintf('Array of user class Frames with %d frames',max(size(fr))));;
+ disp(sprintf('start time %3.2f ms',getminimumtime(fr(1))*1000));
+ disp(sprintf('duration: %3.2f ms',getlength(fr(1))*1000));
+ disp(sprintf('samplerate: %3.2f Hz',getsr(fr(1))));
+ disp(sprintf('Channels: %d',getnrchannels(fr(1))));
+ return
+end
+
+disp('User Class Frame');
+disp(sprintf('start time %3.2f ms',getminimumtime(fr)*1000));
+disp(sprintf('duration: %3.2f ms',getlength(fr)*1000));
+disp(sprintf('samplerate: %3.2f ms',getsr(fr)));
+disp(sprintf('Channels: %d',getnrchannels(fr)));
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/displaytime2bin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/displaytime2bin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function binx=displaytime2bin(fr,time)
+% usage: binx=displaytime2bin(fr,time)
+% returns the nr of the bin in the display at this time
+% this is shifted due to logarithm etc
+
+srate=getsr(fr);
+
+minimum_time_interval=-fr.display_min_time/1000; % thats the first point we want to see on the screen
+maximum_time_interval=fr.display_max_time/1000; % thats the first point we want to see on the screen
+binx=(maximum_time_interval+time)*srate+1;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/erbdensity.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/erbdensity.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% method of class @frame
+%
+% 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/02/18 18:37:20 $
+% $Revision: 1.1 $
+
+
+function erb_density=erbdensity(fr)
+cfs=getcf(fr);
+nr_chan=getnrchannels(fr);
+erb1=21.4*log10(4.73e-3*cfs(1)+1); % from Glasberg,Moore 1990
+erb2=21.4*log10(4.73e-3*cfs(nr_chan)+1);
+nr_erbs=erb2-erb1;
+erb_density=nr_chan/nr_erbs;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/extractpitchregion.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/extractpitchregion.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,95 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=extractpitchregion(fr)
+% throws out the region to a certain periodicity in the auditory image
+
+
+global graphix;global starttime;
+graphix=0;
+
+% 0 von comps(0-2)
+% und dann langsam auf 1 bis comp(3)
+
+zerotime=1;
+attacktill=2;
+attacktodominant=4;
+dominanttime=7;
+decaytime=8;
+
+% zerotime=1.5;
+% attacktill=2.5;
+% attacktodominant=4;
+% dominanttime=7;
+% decaytime=8;
+
+dominant_scale_factor=1;
+
+
+nr_ch=getnrchannels(fr);
+cfs=getcf(fr);
+end_time=getmaximumtime(fr);
+sr=getsr(fr);
+geslen=getlength(fr);
+starttime=getminimumtime(fr);
+
+
+for i=1:nr_ch
+ ch_fre=cfs(i);
+ ch=getsinglechannel(fr,i);
+ firsttime=-1/ch_fre*zerotime; % up to the second
+ secondtime=-1/ch_fre*attacktill;
+ thirdtime=-1/ch_fre*attacktodominant;
+ sixtime=-1/ch_fre*dominanttime;
+ seventime=-1/ch_fre*decaytime;
+
+ ch=scalefun(ch,0,firsttime,0,0,'r');
+ ch=scalefun(ch,firsttime,secondtime,0,1,'g');
+ ch=scalefun(ch,secondtime,thirdtime,1,dominant_scale_factor,'k');
+ ch=scalefun(ch,thirdtime,sixtime,dominant_scale_factor,dominant_scale_factor,'y');
+ ch=scalefun(ch,sixtime,seventime,dominant_scale_factor,1,'c');
+
+ % scale the amplitude of higher cf-channels down
+% cutoff=2000;
+% db_per_octave=6;
+% scaler=getfiltervaluelowpass(ch_fre,cutoff,db_per_octave);
+% ch=ch*scaler;
+%
+% fr=setsinglechannel(fr,i,ch);
+end
+
+
+function fun=scalefun(fun,fromtime,totime,scaler2,scaler1,col)
+ global starttime;global graphix;
+ dur=abs(totime)-abs(fromtime);
+ nr_points=time2bin(fun,fromtime)-time2bin(fun,totime);
+ msig=linspace(scaler1,scaler2,nr_points);
+ if fromtime < starttime
+ return
+ end
+ if totime < starttime
+ scaler1=scaler2+(scaler2-scaler1)/(fromtime-totime)*(starttime-totime);
+ totime=starttime;
+ nr_points=time2bin(fun,fromtime)-time2bin(fun,totime);
+ msig=linspace(scaler1,scaler2,nr_points);
+ end
+ if nr_points > 0
+ fun=mult(fun,msig,totime,nr_points/getsr(fun));
+ end
+ if graphix
+ plot(fun,col);hold on;
+ end
+
+return
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/extractpitchregion2.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/extractpitchregion2.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,101 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=extractpitchregion(fr)
+
+dominant_scale_factor=1;
+
+graphix=0;
+
+nr_ch=getnrchannels(fr);
+cfs=getcf(fr);
+end_time=getmaximumtime(fr);
+sr=getsr(fr);
+geslen=getlength(fr);
+starttime=getminimumtime(fr);
+
+for i=1:nr_ch
+ ch_fre=cfs(i);
+ ch=getsinglechannel(fr,i);
+
+% firstfre=-1/ch_fre*1; % up to the second
+% firstbin=time2bin(ch,firstfre);
+% firsttime=firstbin/sr-geslen;
+
+% set all values below the first harmonic to 0
+ firsttime=-1/ch_fre*1; % up to the second
+ if graphix clf;plot(ch);hold on;end
+ ch=setvalues(ch,0,time2bin(ch,firsttime));
+ if graphix plot(ch,'r');end
+
+ % scale all values between the first and second from 0 to 1
+ secondtime=-1/ch_fre*2;
+ dur=abs(secondtime)-abs(firsttime);
+ nr_points=time2bin(ch,firsttime)-time2bin(ch,secondtime);
+ msig=linspace(1,0,nr_points);
+ ch=mult(ch,msig,secondtime,nr_points/sr);
+ if graphix plot(ch,'g');end
+
+% scale all values between the second and third from 1 to dominant_scale_factor
+ thirdtime=-1/ch_fre*3;
+ dur=abs(thirdtime)-abs(secondtime);
+ nr_points=time2bin(ch,secondtime)-time2bin(ch,thirdtime);
+ msig=linspace(dominant_scale_factor,1,nr_points);
+ ch=mult(ch,msig,thirdtime,nr_points/sr);
+ if graphix plot(ch,'k');end
+
+% scale all values between the third and six by dominant_scale_factor
+ sixtime=-1/ch_fre*6;
+ dur=abs(sixtime)-abs(thirdtime);
+ nr_points=time2bin(ch,thirdtime)-time2bin(ch,sixtime);
+ msig=ones(1,nr_points)*dominant_scale_factor;
+ if sixtime < starttime
+ sixtime=starttime;
+ nr_points=time2bin(ch,thirdtime)-time2bin(ch,sixtime);
+ msig=ones(1,nr_points)*dominant_scale_factor;
+ end
+ ch=mult(ch,msig,sixtime,nr_points/sr);
+ if graphix plot(ch,'y');end
+
+% scale all values between the six and seven from dominant_scale_factor to 1
+ seventime=-1/ch_fre*7;
+ dur=abs(seventime)-abs(sixtime);
+ nr_points=time2bin(ch,sixtime)-time2bin(ch,seventime);
+ msig=linspace(1,dominant_scale_factor,nr_points);
+ if seventime < starttime
+ seventime=starttime;
+ nr_points=time2bin(ch,sixtime)-time2bin(ch,seventime);
+ msig=linspace(1,dominant_scale_factor,nr_points);
+ end
+ if nr_points > 0
+ ch=mult(ch,msig,seventime,nr_points/sr);
+ end
+ if graphix plot(ch,'c');end
+
+
+ % scale the amplitude of higher cf-channels down
+ cutoff=2000;
+ db_per_octave=6;
+ scaler=getfiltervalue(ch_fre,cutoff,db_per_octave);
+ ch=ch*scaler;
+
+
+
+
+
+ fr=setsinglechannel(fr,i,ch);
+
+end
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/findmaxima_singlechannel.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/findmaxima_singlechannel.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function [heights,maxima] = findmaxima_singlechannel(fr)
+
+
+for i=1:fr.nr_channels
+ channel_data=getsinglechannel(fr,i);
+ [heights{i},maxima{i}]=getlocalmaxima(channel_data);
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/findmaxima_sumchannels.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/findmaxima_sumchannels.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function [heights,maxima] = findmaxima_sumchannels(fr)
+
+summe=getsum(fr);
+[heights,maxima]=getlocalmaxima(summe);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/frame.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/frame.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,132 @@
+% method of class @frame
+%
+% 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/20 18:24:22 $
+% $Revision: 1.4 $
+
+function fr=frame(val,framestruct,cf)
+% Construktor der Frameklasse
+
+ % values that are used, when called from SBreadAIFF
+ % fr.structure.totalframetime=frameLength/sampleRate;
+ % fr.structure.numWindowFrames=numWindowFrames;
+ % fr.structure.scale=scale;
+ % fr.structure.wordSize=wordSize;
+ % fr.structure.soundPosition=soundPosition;
+ % fr.structure.littleEndian=littleEndian;
+ % fr.structure.frameLength=frameLength;
+ % fr.structure.numChannels=numChannels;
+ % fr.structure.numSampleFrames=numSampleFrames;
+ % fr.structure.sampleSize=sampleSize;
+ % fr.structure.sampleRate=sampleRate;
+ % fr.structure.interleaveLevel=interleaveLevel;
+ % fr.structure.numWindowFrames=numWindowFrames;
+ % fr.structure.staticTimeFlag=staticTimeFlag;
+ % fr.structure.outputTimeOffset=outputTimeOffset;
+ % fr.structure.absoluteNormalise=absoluteNormalise;
+
+ % valus that are used when more then one frame make a movie
+ % fr.movie.scale_summe= the higest value of a sum
+ % fr.movie.current_frame_number= the current number of this frame
+ % fr.movie.current_frame_start_time; the starting time of this frame
+ % fr.movie.nr_frames_total;
+ % fr.movie.all_min_value;
+ % fr.movie.all_max_value;
+
+if nargin==0 % this must be there see help http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch14_o11.shtml#27700
+ fr.structure=[];
+ fr.movie.nr_frames_total=1;
+ fr.movie.all_min_value=0;
+ fr.movie.all_max_value=1; % important for the overall scaling of all frames
+ fr.movie.scale_summe=1;
+ fr.movie.scale_frequency=1;
+ fr.movie.current_frame_number=1;
+ fr.movie.current_frame_start_time=0;
+ fr.start_time=0;
+ fr.centerfrequencies=(1:10)*1000;
+ fr.text='';
+ fr.x_axis_label='time (ms)';
+ fr.samplerate=1000;
+ fr.values=zeros(10,1000);
+ fr.name='empty frame';
+
+elseif nargin ==1
+ if isobject(val) % KopieKontruktor
+ fr.structure=val.structure;
+ fr.movie=val.movie;
+ fr.start_time=val.start_time;
+ fr.centerfrequencies=val.centerfrequencies;
+ fr.text=val.text;
+ fr.x_axis_label='time (ms)';
+ fr.samplerate=val.samplerate;
+ fr.values=val.values;
+ fr.name=val.name;
+ elseif isstruct(val) % Aufruf von load
+ fr.structure=val.structure;
+ fr.movie=val.movie;
+ fr.start_time=val.start_time;
+ fr.centerfrequencies=val.centerfrequencies;
+ fr.text=val.text;
+ fr.x_axis_label='time (ms)';
+ fr.samplerate=val.samplerate;
+ fr.values=val.values;
+ fr.name=val.name;
+ else% Aufruf mit einem Array:
+ fr.structure=[];
+ fr.movie.nr_frames_total=1;
+ fr.movie.all_min_value=0;
+ fr.movie.all_max_value=1; % important for the overall scaling of all frames
+ fr.movie.scale_summe=1;
+ fr.movie.scale_frequency=1;
+ fr.movie.current_frame_number=1;
+ fr.movie.current_frame_start_time=0;
+
+ fr.start_time=0;
+ fr.centerfrequencies=(1:size(val,1))*1000;
+ fr.text='';
+ fr.x_axis_label='time (ms)';
+ fr.samplerate=16000;
+ %if size(val,1) > size(val,2)
+ % val=val';
+ %end
+ fr.values=val;
+ fr.name='empty frame';
+ end
+else
+ % this values come from the constructof of an SBreadAIFF
+ fr.structure=framestruct;
+
+ % values that describe the frame in comparison to all frames
+ fr.movie.nr_frames_total=1;
+ fr.movie.all_min_value=0;
+ fr.movie.all_max_value=1; % important for the overall scaling of all frames
+ fr.movie.scale_summe=1;
+ fr.movie.scale_frequency=1;
+ fr.movie.current_frame_number=1;
+ fr.movie.current_frame_start_time=0;
+
+ fr.start_time=framestruct.outputTimeOffset;
+ if nargin < 3
+ fr.centerfrequencies=1:size(val,1);
+ else
+ fr.centerfrequencies=cf;
+ end
+ % this text is plotted together with the frame
+ fr.text='';
+ fr.x_axis_label='time (ms)';
+ fr.samplerate=framestruct.sampleRate; % in pixel/sec
+ if size(val,1) > size(val,2)
+ val=val';
+ end
+ fr.values=val;
+ fr.name='generic frame';
+end % single parameter konstructor
+
+fr=class(fr,'frame');
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/frame2simulinkinput.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/frame2simulinkinput.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,31 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ret=frame2simulinkinput(fr)
+% wandelt den kompletten Frame fr in eine Struktur um, die Simulink lesen kann
+
+sr=getsr(fr);
+len=getlength(fr);
+
+nr_chan=getnrchannels(fr);
+
+ret.time=(1/sr:1/sr:len)';
+%for i=1:nr_chan
+% sig=getsinglechannel(fr,i);
+% ret.signals(i).values=getvalues(sig);
+% ret.signals(i).dimensions=1;
+%end
+
+vals=getvalues(fr);
+ret.signals.values=vals';
+ret.signals.dimensions=size(vals,1);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/fre2chan.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/fre2chan.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function chan=fre2chan(fr,fre)
+% returns the channel-nr of that frequency
+
+fres=getcf(fr);
+x=fres;
+Y=1:getnrchannels(fr);
+xi=fre;
+method='linear';
+
+chan=interp1(x,Y,xi,method);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/frequencysharpening.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/frequencysharpening.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,125 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ret=frequencysharpening(current_frame,options)
+% frequency sharpening does local lateral inhibition according to its
+% parameters
+
+
+if nargin < 2
+ options=[];
+end
+
+
+if isfield(options,'excitatory_area') % how many erbs the excitation lasts
+ excitatory_area=options.excitatory_area;
+else
+ excitatory_area=0.5;
+end
+
+if isfield(options,'grafix') % how many erbs the excitation lasts
+ grafix=options.grafix;
+else
+ grafix=0;
+end
+
+if isfield(options,'inhibitory_area') % how many erbs the inhibition lasts
+ inhibitory_area=options.inhibitory_area;
+else
+ inhibitory_area=1.5;
+end
+
+if isfield(options,'inhibitory_influence') % how strong the inhibition is
+ inhibitory_influence=options.inhibitory_influence;
+else
+ inhibitory_influence=0.2;
+end
+
+
+cfs=getcf(current_frame);
+EarQ = 9.26449; % Glasberg and Moore Parameters
+minBW = 24.7;
+order = 1;
+ERB = ((cfs/EarQ).^order + minBW^order).^(1/order);
+B=1.019*2*pi.*ERB;
+
+vals=getvalues(current_frame);
+nr_chan=size(vals,1);
+nr_dots=size(vals,2);
+new_vals=zeros(size(vals));
+
+% calculate the interchannel crossinfluence for each channel
+erb1=21.4*log10(4.73e-3*cfs(1)+1); % from Glasberg,Moore 1990
+erb2=21.4*log10(4.73e-3*cfs(nr_chan)+1);
+nr_erbs=erb2-erb1;
+erb_density=nr_chan/nr_erbs;
+neighbourinfluence=zeros(nr_chan);
+if grafix
+ figure(2)
+ clf
+end
+for i=1:nr_chan % through all channels: prepare working variable
+ count=1;
+ for j=i-nr_chan:i+nr_chan % calculate the influence of all channels
+ if j>0 & j< nr_chan
+ dist=abs(i-j); % we are symmetric
+ disterbs=dist/erb_density; % so many erbs between the channel and me
+
+ % the function(disterbs) to describe the influence of
+ % neighbouring channels:
+ % final=1/disterbs;
+
+ % Mexican hat function:
+ % p=disterbs*disterbs/(threshold_decay_halflife*threshold_decay_halflife);
+ % version with power
+ % final=(2-p)*exp(-0.5*p);
+ % version with difference from gaussians:
+ p1=disterbs*disterbs/(excitatory_area*excitatory_area);
+ p2=disterbs*disterbs/(inhibitory_area*inhibitory_area);
+ final=exp(-p1)-inhibitory_influence*exp(-p2);
+
+ neighbourinfluence(i,count)=final;
+ count=count+1;
+ end
+ end
+ % normalize it
+ % scale=1/sum(neighbourinfluence(i,:));
+ % neighbourinfluence(i,:)=neighbourinfluence(i,:)*scale;
+ if grafix
+ figure(2)
+ plot(neighbourinfluence(i,:)); hold on
+ if i==30
+ plot(neighbourinfluence(i,:),'.-r','linewidth',3); hold on
+ end
+ end
+end
+
+for i=1:nr_dots % through the time
+ for j=1:nr_chan % through all channels: prepare working variable
+ new_vals(:,i)=new_vals(:,i)+vals(:,i).*neighbourinfluence(:,j);
+ end
+end
+
+s=getfrequencysum(current_frame);
+current_frame=setvalues(current_frame,new_vals);
+
+ret=current_frame;
+
+if grafix
+ figure(3) ;clf;
+ s2=getfrequencysum(current_frame);
+ plot(s); hold on
+ ax=axis;
+ plot(s2,'.-r');
+ axis([0 58 0 40000]);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getallmaxvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getallmaxvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getallmaxvalue(fr)
+val=fr.movie.all_max_value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getallminvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getallminvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getallminvalue(fr)
+val=fr.movie.all_min_value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getamplitudemaxvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getamplitudemaxvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getamplitudemaxvalue(fr)
+
+val=fr.movie.all_max_value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getamplitudeminvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getamplitudeminvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getamplitudeminvalue(fr)
+
+val=fr.movie.all_min_value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getcf.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getcf.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ret=getcf(fr)
+
+ret=fr.centerfrequencies;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getcurrentframenumber.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getcurrentframenumber.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getcurrentframenumber(fr)
+val=fr.movie.current_frame_number;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getcurrentframestarttime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getcurrentframestarttime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getcurrentframestarttime(fr)
+val=fr.movie.current_frame_start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getfrequencyprofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getfrequencyprofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% method of class @frame
+%
+% 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/07/17 10:58:38 $
+% $Revision: 1.1 $
+
+function sig=getfrequencyprofile(fr)
+
+
+number=length(fr);
+if number==1
+ val=fr.values;
+ sval=val';
+ summe=sum(sval);
+
+ cfs=fr.centerfrequencies;
+ max_fre=max(cfs);
+
+ sig=signal(summe);
+ sig=setsr(sig,1);
+ sig=setxlabels(sig,cfs);
+ sig=setunit_x(sig,'Frequency(kHz)');
+ sig=setname(sig,'Sum of Frequencies');
+else
+ not implemented yet
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getfrequencysum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getfrequencysum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/07/17 10:56:16 $
+% $Revision: 1.4 $
+
+function sig=getfrequencsum(fr)
+% just here for downward compatibility
+sig=getfrequencyprofile(fr);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getintervalprofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getintervalprofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,58 @@
+% method of class @frame
+%
+% Accummulates the signal between "fromchannel" and "tochannel"
+% This is the famous intervalprofile
+% 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/07/09 15:24:57 $
+% $Revision: 1.1 $
+
+function sumsig=getintervalprofile(fr,fromchannel,tochannel)
+
+
+if nargin<3
+ tochannel=getnrchannels(fr(1));
+end
+if nargin < 2
+ fromchannel=1;
+end
+
+
+number=max(size(fr));
+if number==1
+ val=fr.values;
+ l=getlength(fr);
+ sr=getsr(fr);
+ if getnrchannels(fr)>1
+ summe=sum(val(fromchannel:tochannel,:));
+ sumsig=signal(summe);
+ sumsig=setsr(sumsig,sr);
+ sumsig=setname(sumsig,sprintf('Sum of Frame: %s',getname(fr)));
+ sumsig=setstarttime(sumsig,getminimumtime(fr));
+ else
+ sumsig=getsinglechannel(fr,1);
+ end
+else
+ for e=1:number
+
+ val=fr(e).values;
+
+ l=getlength(fr(e));
+ sr=getsr(fr(e));
+
+ summe(e)=sum(val(fromchannel:tochannel,:));
+
+ sumsig(e)=signal(summe);
+ sumsig(e)=setsr(sumsig(e),sr);
+
+ sumsig(e)=setstarttime(sumsig(e),getminimumtime(fr(e)))
+
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getlength.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getlength.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function len=getlength(fr)
+
+sr=getsr(fr);
+nr=size(fr.values,2);
+len=bin2time(nr,sr);
+% len=fr.structure.totalframetime;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getmaximumtime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getmaximumtime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ma=getmaximumtime(fr)
+
+ma=getminimumtime(fr)+getlength(fr);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getmaximumvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getmaximumvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ma=getmaximumvalue(fr)
+
+ma=max(max(fr.values));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getminimumtime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getminimumtime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ma=getminimumtime(fr)
+
+ma=fr.start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getminimumvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getminimumvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ma=getminimumvalue(fr)
+
+ma=min(min(fr.values));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getname.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getname.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function name=getname(fr)
+name=fr.name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getnrchannels.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getnrchannels.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function nr=getnrchannels(fr)
+
+nr=size(fr.values,1);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getnrframestotal.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getnrframestotal.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=getnrframestotal(fr)
+val=fr.movie.nr_frames_total;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getnrpoints.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getnrpoints.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function nr=getnrpoints(fr)
+
+nr=size(fr.values,2);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getpart.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getpart.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=getpart(frorg,t1,t2)
+
+tempsig=getsinglechannel(frorg,1);
+
+bin1=time2bin(tempsig,t1)+1;
+bin2=time2bin(tempsig,t2);
+
+old_data=getvalues(frorg);
+new_data=old_data(:,bin1:bin2);
+
+fr=frame(frorg);
+fr=setvalues(fr,new_data);
+fr=setstarttime(fr,t1);
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getscalefrequency.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getscalefrequency.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function s=getscalefrequency(fr)
+
+s=fr.movie.scale_frequency;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getscalesumme.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getscalesumme.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function s=getscalesumme(fr)
+
+s=fr.movie.scale_summe;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getsinglechannel.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getsinglechannel.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,31 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function sig=getsinglechannel(fr,nr)
+
+channel_data=fr.values(nr,:);
+sig=signal(channel_data);
+
+
+sig=setsr(sig,fr.samplerate);
+sig=setstarttime(sig,fr.start_time);
+sig=setunit_x(sig,'interval (ms)');
+
+cfs=getcf(fr);
+mycf=cfs(nr);
+
+if mycf<1000
+ sig=setname(sig,sprintf('Channel %d - CF: %4.0f Hz',nr,mycf));
+else
+ sig=setname(sig,sprintf('Channel %d - CF: %2.2f kHz',nr,mycf/1000));
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getspektralsum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getspektralsum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function spectal_activity=getspektralsum(cframe,nr_from,nr_to)
+
+
+number=length(cframe);
+if number==1
+ val=cframe.values;
+ sval=val';
+ spectal_activity=sum(sum(sval));
+else
+ not implemented yet
+end
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getsr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getsr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function sr=getsr(fr)
+
+if isfield(fr.structure,'sampleRate')
+ sr=fr.structure.sampleRate;
+else
+ sr=fr.samplerate;
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getstructure.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getstructure.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ma=getstructure(fr)
+
+ma=fr.structure;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getsum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getsum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,58 @@
+% method of class @frame
+%
+% Accummulates the signal between "fromchannel" and "tochannel"
+%
+% 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/01/31 19:51:07 $
+% $Revision: 1.5 $
+
+function sumsig=getsum(fr,fromchannel,tochannel)
+
+
+if nargin<3
+ tochannel=getnrchannels(fr(1));
+end
+if nargin < 2
+ fromchannel=1;
+end
+
+
+number=max(size(fr));
+if number==1
+ val=fr.values;
+ l=getlength(fr);
+ sr=getsr(fr);
+ if getnrchannels(fr)>1
+ summe=sum(val(fromchannel:tochannel,:));
+ sumsig=signal(summe);
+ sumsig=setsr(sumsig,sr);
+ sumsig=setname(sumsig,sprintf('Sum of Frame: %s',getname(fr)));
+ sumsig=setstarttime(sumsig,getminimumtime(fr));
+ else
+ sumsig=getsinglechannel(fr,1);
+ end
+else
+ for e=1:number
+
+ val=fr(e).values;
+
+ l=getlength(fr(e));
+ sr=getsr(fr(e));
+
+ summe(e)=sum(val(fromchannel:tochannel,:));
+
+ sumsig(e)=signal(summe);
+ sumsig(e)=setsr(sumsig(e),sr);
+
+ sumsig(e)=setstarttime(sumsig(e),getminimumtime(fr(e)))
+
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/gettext.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/gettext.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function te=gettext(fr)
+te=fr.text;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/gettimeintervalprofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/gettimeintervalprofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,66 @@
+% method of class @frame
+%
+% enhanced verion of getsum
+%
+% 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/11 10:46:54 $
+% $Revision: 1.1 $
+
+function sumsig=gettimeintervalprofile(fr,options)
+
+if nargin <2
+ options=[];
+end
+
+if isfield(options,'resolved_harmonic_minimum')
+ resolved_harmonics=options.resolved_harmonic_minimum;
+ if resolved_harmonics>0
+ has_resolved_harmonics=1;
+ else
+ has_resolved_harmonics=0;
+ end
+else
+ has_resolved_harmonics=0;
+end
+
+
+
+if has_resolved_harmonics==0
+ sumsig=getsum(fr);
+ return
+end
+
+
+val=fr.values;
+l=getlength(fr);
+sr=getsr(fr);
+nr_chan=getnrchannels(fr);
+cfs=getcf(fr);
+nr_len=getnrpoints(fr);
+summe=zeros(1,nr_len);
+if nr_chan > 1
+ for ii=1:nr_chan
+ current_cf=cfs(ii);
+ resolved_time=1/(current_cf/resolved_harmonics);
+% resolved_time=1/(current_cf/10);
+ resolved_bin=floor(resolved_time*sr);
+ relevant=val(ii,resolved_bin:end);
+ missing=nr_len-size(relevant,2);
+ relevant=[zeros(1,missing) relevant];
+ summe=summe+relevant;
+ end
+ sumsig=signal(summe);
+ sumsig=setsr(sumsig,sr);
+ sumsig=setname(sumsig,sprintf('Sum of unresolved harmonics of frame: %s',getname(fr)));
+ sumsig=setstarttime(sumsig,getminimumtime(fr));
+else
+ sumsig=getsinglechannel(fr,1);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function vals=getvalues(fr)
+
+vals=fr.values;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getvaluesat.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getvaluesat.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% method of class @frame
+%
+% 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/01/25 12:47:43 $
+% $Revision: 1.4 $
+
+function sig=getvaluesat(fr,where,width)
+% usage: sig=getvaluesat(fr,nr)
+% returns a signal consisting of all points along the frame vertically
+% at this point in time
+
+if nargin<3
+ width=0;
+end
+
+if where> getmaximumtime(fr) | where < getminimumtime(fr)
+ error('Frame::getvaluesat time not in range of frame');
+end
+
+nrchan=getnrchannels(fr);
+for i=1:nrchan
+ sig=getsinglechannel(fr,i);
+ psig=getpart(sig,where,where+width);
+ vals(i)=average(psig);
+end
+
+sig=signal(vals);
+sig=setsr(sig,1);
+sig=setunit_x(sig,'Frequency (kHz)');
+sig=setunit_y(sig,'Intervalstrength');
+sig=setname(sig,sprintf('Values of Frame at time %3.1f ms',where*1000));
+sig=setxlabels(sig,getcf(fr));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getweightedintervalsum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getweightedintervalsum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function sumsig=getweightedintervalsum(cframe,gauss)
+% usage: spectal_activity=getweightedspektralsum(cframe,gauss)
+% returns the sum over frequency as function of interval
+% the frame is weighted by "gauss"
+
+
+number=length(cframe);
+if number==1
+ val=cframe.values;
+ sval=val';
+ gava=getvalues(gauss);
+ for i=1:getnrpoints(cframe)
+ sval(i,:)=sval(i,:).*gava';
+ end
+ intervals=sum(sval');
+
+ sumsig=signal(intervals);
+ sumsig=setsr(sumsig,getsr(cframe));
+ sumsig=setname(sumsig,sprintf('Weighted sum of Frame: %s',getname(cframe)));
+ sumsig=setstarttime(sumsig,getminimumtime(cframe));
+
+
+else
+ not implemented yet
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getweightedsum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getweightedsum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,48 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function sumsig=getweightedsum(fr,cutoff,db_per_octave,von,bis)
+% weights the frequency with some function (usually lowpass)
+
+if nargin<5
+ bis=getnrchannels(fr);
+end
+if nargin < 4
+ von=1;
+end
+
+if nargin < 2
+ cutoff=4000;
+end
+if nargin < 3
+ db_per_octave=6; % quality above
+end
+
+
+% number=getnrchannels(fr);
+cfs=getcf(fr);
+
+samplesig=getsinglechannel(fr,1);
+sumsig=signal(samplesig);
+sumsig=mute(sumsig);
+sumsig=setname(sumsig,sprintf('weighted sum of frame: %s',getname(fr)));
+
+for i=von:bis
+ sig=getsinglechannel(fr,i);
+ cur_fre=cfs(i);
+ scaler=getfiltervalue(cur_fre,cutoff,db_per_octave);
+
+ sig=sig*scaler;
+ sumsig=sumsig+sig;
+
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/getxaxis.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/getxaxis.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/25 16:01:39 $
+% $Revision: 1.1 $
+
+function xa=getxaxis(fr)
+xa=fr.x_axis_label;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/halfwayrectify.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/halfwayrectify.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=halfwayrectify(fr)
+% sets all negative values in sig to 0
+
+vals=getvalues(fr);
+vals(find(vals<0))=0;
+fr=setvalues(fr,vals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/highpassfilter.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/highpassfilter.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=highpassfilter(fr,cutoff,dbperoctave);
+% usage:fr=highpassfilter(fr,cutoff,dbperoctave);
+% filters all channel according to its frequency
+
+
+nr_chan=getnrchannels(fr);
+cfs=getcf(fr);
+vals=getvalues(fr);
+
+for i=1:nr_chan
+ fre=cfs(i);
+ val=getfiltervaluehighpass(fre,cutoff,dbperoctave);
+ vals(i,:)=vals(i,:)*val;
+end
+
+fr=setvalues(fr,vals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/isoftype.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/isoftype.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function ret=isoftype(inp,str)
+
+if strcmp(str,'frame')
+ ret=1;
+else
+ ret=0;
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/loadobj.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/loadobj.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function b = loadobj(a)
+
+b=a;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/logcompress.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/logcompress.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,35 @@
+% method of class @frame
+%
+% 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/13 14:48:22 $
+% $Revision: 1.6 $
+
+function nap=logcompress(nap,options)
+
+%if nargin <2
+% options.dynamic_range=50;
+%end
+
+nap=halfwayrectify(nap);
+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
+vals=vals.*2.^15;
+
+%avoid log problems by making everything > 1
+vals(find(vals<1))=1;
+vals=20.*log10(vals);
+
+
+nap=setvalues(nap,vals);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/max.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/max.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function val=max(fr)
+val=max(max(fr.values));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/min.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/min.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/02/26 14:12:09 $
+% $Revision: 1.1 $
+
+function val=min(fr)
+val=min(min(fr.values));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/mrdivide.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/mrdivide.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,22 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=mrdivide(fr,b)
+% division ist einfach multiplikation mit 1/
+
+if isnumeric(b)
+ fr=fr*(1/b);
+ return
+end
+
+error('fr::mrdivide: not implemented yet');
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/mtimes.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/mtimes.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=mtimes(fr,val)
+% multiplikation mit *
+% einfachster Fall: Multipliziere mit konstanter Zahl
+
+if isnumeric(val)
+ if length(val)==1
+ fr.values=fr.values*val;
+ end
+end
+
+if isobject(val)
+ error('not implemented yet!');
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/normaliseto.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/normaliseto.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=normaliseto(fr,value)
+% usage:
+% scale all values linear so that the sum of all activity is "value"
+
+nr_ch=getnrchannels(fr);
+
+values=getvalues(fr);
+summe=sum(sum(values));
+
+values=values.*value/summe;
+
+fr=setvalues(fr,values);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/phasealign.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/phasealign.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,130 @@
+% method of class @frame
+%
+% 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/13 14:48:37 $
+% $Revision: 1.5 $
+
+function nap=phasealign(nap,options)
+
+if nargin < 2
+ options=[];
+end
+
+
+%'off','maximum_envelope','nr_cycles','envelope_finestructure'
+
+if ~isfield(options,'do_phase_alignment')%
+ options.do_phase_alignment='nr_cycles';
+end
+
+if ~isfield(options,'phase_alignment_nr_cycles')
+ options.phase_alignment_nr_cycles=3;
+end
+
+
+
+% values needed by all functions
+vals=getvalues(nap);
+new_vals=zeros(size(vals));
+nr_chan=size(vals,1);
+nr_dots=size(vals,2);
+sr=getsr(nap);
+cfs=getcf(nap);
+
+
+if strcmp(options.do_phase_alignment,'nr_cycles')
+ for ii=1:nr_chan
+ shift=options.phase_alignment_nr_cycles/cfs(ii);
+ intshift=round(shift*sr);
+ dots=vals(ii,:);
+ ndots=[dots(intshift:end) zeros(intshift-1,1)'];
+ % vals(ii,:)=ndots/log(cfs(ii));
+ vals(ii,:)=ndots;
+ end
+end
+
+
+if strcmp(options.do_phase_alignment,'envelope_finestructure')
+ % phase alignment according to Holdswoth 1988
+ EarQ = 9.26449; % Glasberg and Moore Parameters
+ minBW = 24.7;
+ order = 4;
+ ERB = ((cfs/EarQ).^order + minBW^order).^(1/order);
+ b=1.019.*ERB;
+ B=1.019*2*pi.*ERB;
+ envelopecomptime=(order-1)./B;
+ phasealign=-2*pi.*cfs.*envelopecomptime;
+ phasealign=mod(phasealign,2*pi);
+ phasealign=phasealign./(2*pi.*cfs);
+ % first align to the envelope
+ % introduce phase shift in each channel
+ for ii=1:nr_chan
+ shift=envelopecomptime(ii);
+ intshift=round(shift*sr);
+ dots=vals(ii,:);
+ ndots=[dots(intshift:end) zeros(intshift-1,1)'];
+ % vals(ii,:)=ndots/log(cfs(ii));
+ vals(ii,:)=ndots;
+ end
+ % then align to the fine structure
+ for ii=1:nr_chan
+ shift=phasealign(ii);
+ intshift=round(shift*sr);
+ dots=vals(ii,:);
+ ndots=[dots(intshift:end) zeros(intshift-1,1)'];
+ vals(ii,:)=ndots;
+ end
+end
+
+
+if strcmp(options.do_phase_alignment,'maximum_envelope')
+ % phase alignment according to Holdswoth 1988 without fine structure
+ EarQ = 9.26449; % Glasberg and Moore Parameters
+ minBW = 24.7;
+ order = 4;
+ ERB = ((cfs/EarQ).^order + minBW^order).^(1/order);
+ b=1.019.*ERB;
+ B=1.019*2*pi.*ERB;
+ envelopecomptime=(order-1)./B;
+ phasealign=-2*pi.*cfs.*envelopecomptime;
+ phasealign=mod(phasealign,2*pi);
+ phasealign=phasealign./(2*pi.*cfs);
+
+ % first align to the envelope
+ % introduce phase shift in each channel
+ for ii=1:nr_chan
+ shift=envelopecomptime(ii);
+ intshift=round(shift*sr);
+ dots=vals(ii,:);
+ ndots=[dots(intshift:end) zeros(intshift-1,1)'];
+ % vals(ii,:)=ndots/log(cfs(ii));
+ vals(ii,:)=ndots;
+ end
+end
+
+
+if strcmp(options.do_phase_alignment,'nr_cycles_freq')
+ phase_alignment_nr_cycles=0.6796.*log(cfs)-1.3836;
+
+ for ii=1:nr_chan
+ shift=phase_alignment_nr_cycles(ii)./cfs(ii);
+ intshift=round(shift*sr);
+ dots=vals(ii,:);
+ ndots=[dots(intshift:end) zeros(intshift-1,1)'];
+ % vals(ii,:)=ndots/log(cfs(ii));
+ vals(ii,:)=ndots;
+ end
+end
+
+
+
+
+
+nap=setvalues(nap,vals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plot.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plot.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,387 @@
+% method of class @frame
+%
+% 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:05:26 $
+% $Revision: 1.16 $
+
+function handlestr=plot(current_frame,options,ax)
+
+
+if nargin < 3
+ ax=gca;
+end
+if nargin < 2
+ options=[];
+end
+
+options.plotstyle='surf';
+
+% extra options from aimmodules?
+if isfield(options,'extra_options');
+ has_extra_options=1; % in this case, jump at the end to a fucntion that makes colors
+else
+ has_extra_options=0; % no extras in colors
+end
+
+% weather of not the plotting is linear
+if ~isfield(options,'is_log');
+ is_log=0;
+else
+ is_log=options.is_log;
+end
+
+% which plot type, usually: waterfall, other: surf
+if ~isfield(options,'plotstyle');
+ plotstyle='waterfall';
+else
+ plotstyle=options.plotstyle;
+end
+
+% the viewpoint in azimuth and elevation look help for view!
+if ~isfield(options,'viewpoint');
+ viewpoint=[0 80];
+else
+ viewpoint=options.viewpoint;
+end
+
+% if waterfall, the plotcolor can be more complicated
+if ~isfield(options,'plotcolor');
+ has_specified_color=0;
+else
+ plotcolor=options.plotcolor;
+ has_specified_color=1;
+end
+
+% if positive time is to the right or to the left
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+% for compatibility.
+if isfield(options,'minimum_time');
+ options.minimum_time_interval=options.minimum_time;
+end
+if isfield(options,'maximum_time');
+ options.maximum_time_interval=options.maximum_time;
+end
+if ~isfield(options,'minimum_time_interval');
+ if is_log
+ minimum_time_interval=0.001;
+ else
+ minimum_time_interval=getminimumtime(current_frame);
+ end
+else
+ minimum_time_interval=options.minimum_time_interval;
+end
+
+
+if ~isfield(options,'maximum_time_interval');
+% maximum_time_interval=0.035;
+ maximum_time_interval=getmaximumtime(current_frame);
+else
+ maximum_time_interval=options.maximum_time_interval;
+end
+
+
+if ~isfield(options,'has_x_axis');
+ has_x_axis=1;
+else
+ has_x_axis=options.has_x_axis;
+end
+
+if ~isfield(options,'has_y_axis');
+ has_y_axis=1;
+else
+ has_y_axis=options.has_y_axis;
+end
+
+
+
+current_frame_values=getvalues(current_frame);
+nr_channels=getnrchannels(current_frame);
+sr=getsr(current_frame);
+
+% prevent a matlab plotting-bug for empty matrices
+if max(max(current_frame_values))==0 && min(min(current_frame_values)) == 0
+ current_frame_values(1,400)=0.001;
+end
+
+% length=getlength(current_frame);
+start_time=getminimumtime(current_frame);
+
+if start_time < 0 % these are frames read in from ams! they start with negative times. Therefore we turn around the start and stoptime
+% temp=-maximum_time_interval;
+% maximum_time_interval=-minimum_time_interval;
+% minimum_time_interval=temp;
+% time_reversed=1-time_reversed;
+% current_frame=reverse(current_frame);
+% % max_time=getmaximumtime(current_frame);
+% fr=getpart(current_frame,start_time,0);
+% start_time=0;
+% current_frame=setstarttime(current_frame,0);
+end
+
+if is_log
+ min_x_screen=1; % im logarithmischen Fall muss ich die ersten Punkte mitnehmen, damit ich sie plotten kann!
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+else
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+end
+
+if max_x_screen>getnrpoints(current_frame)
+ max_x_screen=getnrpoints(current_frame);
+ maximum_time_interval=(max_x_screen/sr)+start_time;
+end
+
+ax=ax;
+% oldunit2=get(ax,'Units');
+% set(ax,'Units','Pixel');
+% pos=get(ax,'Position');
+% breite=pos(3);
+% % step=round((max_x_screen-min_x_screen)/breite);
+% step=1;
+% if step<1 || nr_channels==1
+% step=1;
+% end
+% set(ax,'Units',oldunit2);
+
+% if min_x_screen>2
+% current_frame_values(:,1:min_x_screen-1)=0;
+% end
+
+% min_x_screen=17;
+% max_x_screen=500;
+
+step=1;
+% cvals=current_frame_values(:,min_x_screen:step:max_x_screen);
+cvals=current_frame_values(:,min_x_screen:step:max_x_screen);
+if nr_channels==1
+ handle=plot(cvals);
+ ylabel('');
+ % set(ax,'YTick',[]);
+else
+ if strcmp(plotstyle,'surf')
+ handle=surf(ax,cvals,'LineStyle','none');
+ else
+ handle=waterfall(cvals); % do the plotting!
+ % this is a very important trick: If we plot it from directly above ([0 80])
+ % then white lines appear on the screen. To get rid of them, we have to
+ % tilt the waterfall just marginally:
+ if min(min(cvals))<0
+ view([viewpoint(1)-0.01 viewpoint(2)]);
+ else
+ view(viewpoint);
+ end
+ end
+ grid off;
+end
+
+if time_reversed
+ set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
+else
+ set(ax,'XDir','normal') % normale ausrichtung
+end
+if is_log
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ if nr_channels==1
+ axis([ min_x_screen max_x_screen 0 1]);
+ else
+ if max_x_screen == min_x_screen
+ max_x_screen = min_x_screen +1;
+ end
+ axis([ min_x_screen max_x_screen 1 nr_channels 0 50]);
+ end
+ set(ax,'XScale','log')
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)*sr; % there shell be the tix
+% tix(1)=tix(1)+1;
+ ti=(ti*1000);
+ ti=fround(ti,2);
+else % its not logarithmic!
+ set(ax,'XScale','linear')
+ nrx=size(cvals,2);
+ if nr_channels==1
+ miny=min(cvals);
+ maxy=max(cvals);
+ set(gca,'xlim',[1 nrx])
+ set(gca,'ylim',[miny*1.3 maxy*1.3])
+% axis([ 1 nrx miny*1.3 maxy*1.3]);
+ else
+ set(gca,'xlim',[1 nrx])
+ set(gca,'ylim',[1 nr_channels ])
+ set(gca,'zlim',[0 1])
+
+% axis([ 1 nrx 1 nr_channels 0 1]);
+ end
+ 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=fround(ti,1);
+ % text(min_x_screen*1.5,-scale_summe/5,'Time (ms)'); % this is at a nice position
+end
+
+if has_x_axis
+ if max(tix)>1
+ set(ax,'XTick',tix);
+ set(ax,'XTickLabel',ti);
+ end
+else
+ set(ax,'xtick',[]); % we dont want any z-Ticks!
+end % axis
+
+if has_y_axis && nr_channels>1
+ % make y-Ticks
+ nr_labels=8;
+ ystep=(nr_channels-1)/(nr_labels-1);
+ tiy=1:ystep:nr_channels;
+ ti=(current_frame.centerfrequencies(floor(tiy))/1000);
+ ti=round(ti*10)/10;
+ set(ax,'YTick',tiy);
+ set(ax,'YTickLabel',ti);
+
+% if has_x_axis
+% if is_log
+% text(min_x_screen*1.9,-2,current_frame.x_axis_label); % this is at a nice position
+% else
+% text(120,-2,current_frame.x_axis_label); % this is at a nice position
+% end
+% end
+elseif nr_channels>1
+ set(ax,'ytick',[]); % we dont want any z-Ticks!
+end
+
+set(ax,'ztick',[]); % we dont want any z-Ticks!
+
+
+if strcmp(plotstyle,'surf')
+ % which colormap should be used in case of a surf-plot
+ if ~isfield(options,'colormap');
+ clrmap=zeros(64,3);
+ else
+ clrmap=options.colormap;
+ end
+
+ % shift the colormap
+
+ % set the chosen colormap
+ colormap(clrmap);
+ % set the color limits so that it shows all colors
+ set(ax,'CLimMode','manual');
+
+ colmin=0;
+ colmax=max(max(cvals));
+ diff=colmax-colmin;
+
+ if ~isfield(options,'shiftcolormap');
+ shiftcolormap=0.8;
+ else
+ shiftcolormap=options.shiftcolormap;
+ end
+ colmin=colmax-2*shiftcolormap*diff;
+ if colmax==colmin
+ colmax=colmin+0.001;
+ end
+
+ set(ax,'CLim',[colmin colmax]);
+
+% % colorbar is 1:256
+% % actual spectrogram dynamic range is orig_dr
+% % new spectrogram dynamic range is new_dr
+% orig_dr = clrmap;
+% 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(ax,'clim',cbar_clim);
+
+
+
+ view(viewpoint);
+ shading interp
+ if isfield(options,'camlight');
+ % can be 'left','right' or a vector of [az el]
+ if isnumeric(options.camlight)
+ for i=1:size(options.camlight,1)
+ eval(sprintf('lightangle(%f,%f);',options.camlight(i,1),options.camlight(i,2)));
+ end
+ else
+ eval(sprintf('camlight(''%s'',''infinite'');',options.camlight));
+ end
+ end
+
+ material default % looks best other options: dull, metal, shiny
+
+ %
+ if isfield(options,'lighting');
+ eval(sprintf('lighting %s',options.lighting));
+ end
+
+ % wheather or not there should be a colorbar
+ % can be 'off', 'vertical, 'horizontal'
+ if isfield(options,'colorbar');
+ if ~strcmp(options.colorbar,'off')
+ colorbar(options.colorbar);
+ end
+ end
+
+else % boring waterfall plot
+ if has_specified_color==1
+ if plotcolor=='k'
+ clrmap(:,:)=0;
+ elseif plotcolor=='r'
+ clrmap(:,1)=0;
+ elseif plotcolor=='c'
+ clrmap(:,2)=0;
+ elseif plotcolor=='g'
+ clrmap(:,3)=0;
+ end
+ else
+ % if nothing is set, then set everything is set to black
+ clrmap=white;
+ clrmap(:,:)=0;
+ colormap(clrmap);
+ end
+end
+
+
+if is_log
+ x=300;y=nr_channels*1.1;
+else
+ x=300;y=nr_channels*1.1;
+end
+text(x,y,current_frame.text); % this is at a nice position
+
+if isfield(options,'display_time')
+ if options.display_time==1
+ time=getcurrentframestarttime(current_frame);
+ time=fround(time*1000,0);
+ str=num2str(time);
+ text(x,y,[str ' ms']); % this is at a nice position
+ end
+end
+
+if has_extra_options==1; % in this case, jump at the end to a fucntion that makes colors
+
+% cool_frame_plot_colors(current_frame,handle,options.extra_options);
+
+end
+
+% set(ax,'XDir',olddir)
+% set(ax,'XScale',oldscale);
+
+if nargout==1
+ handlestr=handle;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plot.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plot.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,399 @@
+% method of class @frame
+%
+% 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:05:26 $
+% $Revision: 1.16 $
+
+function handlestr=plot(current_frame,options,ax)
+
+
+if nargin < 3
+ ax=gca;
+end
+if nargin < 2
+ options=[];
+end
+
+% options.plotstyle='surf';
+
+% extra options from aimmodules?
+if isfield(options,'extra_options');
+ has_extra_options=1; % in this case, jump at the end to a fucntion that makes colors
+else
+ has_extra_options=0; % no extras in colors
+end
+
+% weather of not the plotting is linear
+if ~isfield(options,'is_log');
+ is_log=0;
+else
+ is_log=options.is_log;
+end
+
+% the viewpoint in azimuth and elevation look help for view!
+if ~isfield(options,'viewpoint');
+ viewpoint=[0 90];
+else
+ viewpoint=options.viewpoint;
+end
+
+% which plot type, usually: waterfall, other: surf
+if ~isfield(options,'plotstyle');
+ plotstyle='waterfall';
+else
+ plotstyle=options.plotstyle;
+end
+
+% if waterfall, the plotcolor can be more complicated
+if ~isfield(options,'plotcolor');
+ has_specified_color=0;
+else
+ plotcolor=options.plotcolor;
+ has_specified_color=1;
+end
+
+% if positive time is to the right or to the left
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+% for compatibility.
+if isfield(options,'minimum_time');
+ options.minimum_time_interval=options.minimum_time;
+end
+if isfield(options,'maximum_time');
+ options.maximum_time_interval=options.maximum_time;
+end
+if ~isfield(options,'minimum_time_interval');
+ if is_log
+ minimum_time_interval=0.001;
+ else
+ minimum_time_interval=getminimumtime(current_frame);
+ end
+else
+ minimum_time_interval=options.minimum_time_interval;
+end
+
+
+if ~isfield(options,'maximum_time_interval');
+% maximum_time_interval=0.035;
+ maximum_time_interval=getmaximumtime(current_frame);
+else
+ maximum_time_interval=options.maximum_time_interval;
+end
+
+
+if ~isfield(options,'has_x_axis');
+ has_x_axis=1;
+else
+ has_x_axis=options.has_x_axis;
+end
+
+if ~isfield(options,'has_y_axis');
+ has_y_axis=1;
+else
+ has_y_axis=options.has_y_axis;
+end
+
+
+
+current_frame_values=getvalues(current_frame);
+nr_channels=getnrchannels(current_frame);
+sr=getsr(current_frame);
+
+% prevent a matlab plotting-bug for empty matrices
+if max(max(current_frame_values))==0 && min(min(current_frame_values)) == 0
+ current_frame_values(1,400)=0.001;
+end
+
+% length=getlength(current_frame);
+start_time=getminimumtime(current_frame);
+
+if start_time < 0 % these are frames read in from ams! they start with negative times. Therefore we turn around the start and stoptime
+% temp=-maximum_time_interval;
+% maximum_time_interval=-minimum_time_interval;
+% minimum_time_interval=temp;
+% time_reversed=1-time_reversed;
+% current_frame=reverse(current_frame);
+% % max_time=getmaximumtime(current_frame);
+% fr=getpart(current_frame,start_time,0);
+% start_time=0;
+% current_frame=setstarttime(current_frame,0);
+end
+
+if is_log
+ min_x_screen=1; % im logarithmischen Fall muss ich die ersten Punkte mitnehmen, damit ich sie plotten kann!
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+else
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+end
+
+if max_x_screen>getnrpoints(current_frame)
+ max_x_screen=getnrpoints(current_frame);
+ maximum_time_interval=(max_x_screen/sr)+start_time;
+end
+
+step=1;
+if isequal(plotstyle,'surf')
+ step=1;
+elseif isequal(plotstyle,'waterfall')
+ oldunit2=get(ax,'Units');
+ set(ax,'Units','Pixel');
+ pos=get(ax,'Position');
+ breite=pos(3)/2;
+ step=round((max_x_screen-min_x_screen)/breite);
+ % step=1;
+ if step<1 || nr_channels==1
+ step=1;
+ end
+ set(ax,'Units',oldunit2);
+
+ if min_x_screen>2
+ current_frame_values(:,1:min_x_screen-1)=0;
+ end
+end
+
+
+cvals=current_frame_values(:,min_x_screen:step:max_x_screen);
+if nr_channels==1
+ handle=plot(ax,cvals);
+ ylabel('');
+ % set(ax,'YTick',[]);
+else
+ if strcmp(plotstyle,'surf')
+% handle=surf(ax,cvals,'LineStyle','none');
+ handle=surf(ax,cvals,'LineStyle','none');
+% view(ax,viewpoint);
+ view(ax,[0 90]);
+ else
+ handle=waterfall(ax,cvals); % do the plotting!
+ % this is a very important trick: If we plot it from directly above ([0 80])
+ % then white lines appear on the screen. To get rid of them, we have to
+ % tilt the waterfall just marginally:
+% if min(min(cvals))<0
+% view(ax,[viewpoint(1)-0.01 viewpoint(2)]);
+% else
+ view(ax,[-0.01 80]);
+% view(ax,viewpoint);
+% end
+ end
+ grid off;
+end
+
+if time_reversed
+ set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
+else
+ set(ax,'XDir','normal') % normale ausrichtung
+end
+if is_log
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ if nr_channels==1
+ set(ax,'xlim',[min_x_screen max_x_screen ])
+ set(ax,'ylim',[0 1])
+% axis([ 0 1]);
+ else
+ if max_x_screen == min_x_screen
+ max_x_screen = min_x_screen +1;
+ end
+ set(ax,'xlim',[min_x_screen max_x_screen])
+ set(ax,'ylim',[1 nr_channels])
+ set(ax,'zlim',[0 50])
+
+% axis([ min_x_screen max_x_screen 1 nr_channels 0 50]);
+ end
+ set(ax,'XScale','log')
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)*sr; % there shell be the tix
+% tix(1)=tix(1)+1;
+ ti=(ti*1000);
+ ti=fround(ti,2);
+else % its not logarithmic!
+ set(ax,'XScale','linear')
+ nrx=size(cvals,2);
+ if nr_channels==1
+ miny=min(cvals);
+ maxy=max(cvals);
+ set(ax,'xlim',[1 nrx])
+ set(ax,'ylim',[miny*1.3 maxy*1.3])
+% axis([ 1 nrx miny*1.3 maxy*1.3]);
+ else
+ set(ax,'xlim',[1 nrx])
+ set(ax,'ylim',[1 nr_channels ])
+ set(ax,'zlim',[0 1])
+
+% axis([ 1 nrx 1 nr_channels 0 1]);
+ end
+ 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=fround(ti,1);
+ % text(min_x_screen*1.5,-scale_summe/5,'Time (ms)'); % this is at a nice position
+end
+
+if has_x_axis
+ if max(tix)>1
+ set(ax,'XTick',tix);
+ set(ax,'XTickLabel',ti);
+ end
+else
+ set(ax,'xtick',[]); % we dont want any z-Ticks!
+end % axis
+
+if has_y_axis && nr_channels>1
+ % make y-Ticks
+ nr_labels=8;
+ ystep=(nr_channels-1)/(nr_labels-1);
+ tiy=1:ystep:nr_channels;
+ ti=(current_frame.centerfrequencies(floor(tiy))/1000);
+ ti=round(ti*10)/10;
+ set(ax,'YTick',tiy);
+ set(ax,'YTickLabel',ti);
+
+% if has_x_axis
+% if is_log
+% text(min_x_screen*1.9,-2,current_frame.x_axis_label); % this is at a nice position
+% else
+% text(120,-2,current_frame.x_axis_label); % this is at a nice position
+% end
+% end
+elseif nr_channels>1
+ set(ax,'ytick',[]); % we dont want any z-Ticks!
+end
+
+set(ax,'ztick',[]); % we dont want any z-Ticks!
+
+
+if strcmp(plotstyle,'surf')
+ % which colormap should be used in case of a surf-plot
+ if ~isfield(options,'colormap');
+ clrmap=zeros(64,3);
+ else
+ clrmap=options.colormap;
+ end
+
+ % shift the colormap
+
+ % set the chosen colormap
+ colormap(clrmap);
+ % set the color limits so that it shows all colors
+ set(ax,'CLimMode','manual');
+
+ colmin=0;
+ colmax=max(max(cvals));
+ diff=colmax-colmin;
+
+% if ~isfield(options,'shiftcolormap');
+% shiftcolormap=0.8;
+% else
+% shiftcolormap=options.shiftcolormap;
+% end
+% colmin=colmax-2*shiftcolormap*diff;
+% if colmax==colmin
+% colmax=colmin+0.001;
+% end
+
+% set(ax,'CLim',[colmin colmax]);
+
+% % colorbar is 1:256
+% % actual spectrogram dynamic range is orig_dr
+% % new spectrogram dynamic range is new_dr
+% orig_dr = clrmap;
+% 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(ax,'clim',cbar_clim);
+
+
+
+% view(ax,viewpoint);
+
+ % fancy graphics, takes time
+% shading interp
+% if isfield(options,'camlight');
+% % can be 'left','right' or a vector of [az el]
+% if isnumeric(options.camlight)
+% for i=1:size(options.camlight,1)
+% eval(sprintf('lightangle(%f,%f);',options.camlight(i,1),options.camlight(i,2)));
+% end
+% else
+% eval(sprintf('camlight(''%s'',''infinite'');',options.camlight));
+% end
+% end
+%
+% material default % looks best other options: dull, metal, shiny
+%
+% %
+% if isfield(options,'lighting');
+% eval(sprintf('lighting %s',options.lighting));
+% end
+
+ % wheather or not there should be a colorbar
+ % can be 'off', 'vertical, 'horizontal'
+ if isfield(options,'colorbar');
+ if ~strcmp(options.colorbar,'off')
+ colorbar(options.colorbar);
+ end
+ end
+
+else % boring waterfall plot
+ if has_specified_color==1
+ if plotcolor=='k'
+ clrmap(:,:)=0;
+ elseif plotcolor=='r'
+ clrmap(:,1)=0;
+ elseif plotcolor=='c'
+ clrmap(:,2)=0;
+ elseif plotcolor=='g'
+ clrmap(:,3)=0;
+ end
+ else
+ % if nothing is set, then set everything is set to black
+ clrmap=white;
+ clrmap(:,:)=0;
+ colormap(clrmap);
+ end
+end
+
+
+% if is_log
+% x=300;y=nr_channels*1.1;
+% else
+% x=300;y=nr_channels*1.1;
+% end
+% text(x,y,current_frame.text); % this is at a nice position
+
+% if isfield(options,'display_time')
+% if options.display_time==1
+% time=getcurrentframestarttime(current_frame);
+% time=fround(time*1000,0);
+% str=num2str(time);
+% text(x,y,[str ' ms']); % this is at a nice position
+% end
+% end
+
+if has_extra_options==1; % in this case, jump at the end to a fucntion that makes colors
+
+% cool_frame_plot_colors(current_frame,handle,options.extra_options);
+
+end
+
+% set(ax,'XDir',olddir)
+% set(ax,'XScale',oldscale);
+
+if nargout==1
+ handlestr=handle;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plotfrequencyprofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plotfrequencyprofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,174 @@
+% method of class @frame
+%
+% 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/10/21 14:14:02 $
+% $Revision: 1.9 $
+
+function hand=plotfrequencyprofile(current_frame,options,ax)
+
+if nargin<3
+ ax=gca;
+end
+if nargin<2
+ options=[];
+end
+
+start_time=getminimumtime(current_frame);
+if start_time < 0 % these are frames read in from ams
+% max_time=getmaximumtime(current_frame);
+ fr=getpart(current_frame,start_time,0);
+ current_frame=reverse(current_frame);
+ start_time=0;
+ current_frame=setstarttime(current_frame,0);
+end
+
+if isfield(options,'frequency_profile_scale');
+ frequency_profile_scale=options.frequency_profile_scale;
+else
+ frequency_profile_scale=1;
+end
+
+%shrink_range indicates, if the axis should not occupy the whole space
+if isfield(options,'shrink_range');
+ shrink_range=options.shrink_range;
+else
+ shrink_range=1;
+end
+
+if ~isfield(options,'minimum_time_interval');
+ minimum_time_interval=0;
+else
+ minimum_time_interval=options.minimum_time_interval;
+end
+
+if ~isfield(options,'maximum_time_interval');
+ maximum_time_interval=0.035;
+else
+ maximum_time_interval=options.maximum_time_interval;
+end
+
+if maximum_time_interval>getmaximumtime(current_frame)
+ maximum_time_interval=getmaximumtime(current_frame);
+end
+
+
+if ~isfield(options,'turn_axis_vertically');
+ turn_axis_vertically=1;
+else
+ turn_axis_vertically=options.turn_axis_vertically;
+end
+
+
+% frequency sum
+scale_frequency=getscalefrequency(current_frame);
+
+% channel_density=0.015; % passt für 76 channels von 100 bis 6000
+% hoehe=getnrchannels(current_frame)*channel_density;
+% if hoehe>1
+% hoehe=1;
+% end
+%
+% rect=[0.856 0.19 0.1 hoehe*0.81];
+% rect(1:2)=caxes(1:2)+(rect(1:2).*caxes(3:4));
+% rect(3:4)=rect(3:4).*caxes(3:4);
+% mysubplot(1,1,1,rect, hint);
+
+part_current_frame=getpart(current_frame,minimum_time_interval,maximum_time_interval);
+% if getxaxis(current_frame)=='0'
+% h_cutoff=3;
+% h_width=20;
+% aa=getvalues(part_current_frame);
+% aa=aa(1:601,h_cutoff*h_width:121);
+% part_current_frame=frame(aa/100);
+% end;
+
+fresumme=getfrequencysum(part_current_frame); % here it is calculated
+% fresumme=smooth(fresumme,1);% glätte die Summe
+if getxaxis(current_frame)=='0'
+ [band_location band_height]=getlocalmaxima(fresumme);
+ band_location=(band_location/601)*30;
+ band_information(:,1)=band_location';
+ band_information(:,2)=band_height';
+% disp('maxima');
+% disp(' h val height');
+% disp(band_information);
+ [min_posit min_height]=getlocalminima(fresumme);
+ min_posit=(min_posit/601)*30;
+ band_information2(:,1)=min_posit';
+ band_information2(:,2)=min_height';
+% disp('minima');
+% disp(' h val height');
+% disp(band_information2);
+end;
+
+
+if frequency_profile_scale < 0
+ mscal=max(fresumme);
+ if mscal~=0
+ frequency_profile_scale=scale_frequency/mscal*0.9;
+ else
+ frequency_profile_scale=1;
+ end
+end
+
+fresumme=setname(fresumme,'');
+fresumme=setunit_x(fresumme,'');
+fresumme=setunit_y(fresumme,'');
+
+% hand=plot(fresumme,'r'); hold on
+v=getvalues(fresumme);
+hand=plot(ax,v,'r'); hold on
+
+maxy=scale_frequency/frequency_profile_scale;
+if maxy==0
+ maxy=1;
+end
+nr=size(v,1);
+if nr==0
+ nr=1;
+end
+set(ax,'xlim',[0 nr *shrink_range]);
+set(ax,'ylim',[0 maxy]);
+
+% axis([0 nr *shrink_range 0 maxy]);
+
+if turn_axis_vertically==1
+ view(ax,-90,90);
+end
+
+
+% make y-Ticks
+cfs=getcf(current_frame);
+if length(cfs) > 1
+ nr_labels=8;
+ nr_channels=getnrpoints(fresumme);
+ xstep=(nr_channels-1)/(nr_labels-1);
+ tix=1:xstep:nr_channels;
+ ti=cfs(floor(tix))/1000;
+else
+ ti=cfs;
+ tix=0.5;
+end
+ti=round(ti*10)/10;
+
+if getxaxis(current_frame)=='0'
+ d=size(cfs);
+ ti = [0:5:30];
+ step=(d(2)/6);
+ tix = [0:step:d(2)];
+end;
+
+set(ax,'XTick',tix);
+set(ax,'XTickLabel',ti);
+if turn_axis_vertically==1
+ set(ax,'YTickLabel',[]);
+ set(ax,'XAxisLocation','top');
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plottemporalprofile.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plottemporalprofile.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,238 @@
+% method of class @frame
+%
+% 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/07/27 15:29:59 $
+% $Revision: 1.12 $
+
+function hand=plottemporalprofile(current_frame,options)
+
+if nargin <2
+ options=[];
+end
+
+start_time=getminimumtime(current_frame);
+if start_time < 0 % these are frames read in from ams
+% max_time=getmaximumtime(current_frame);
+ fr=getpart(current_frame,start_time,0);
+ current_frame=reverse(current_frame);
+ start_time=0;
+ current_frame=setstarttime(current_frame,0);
+end
+
+
+
+if ~isfield(options,'has_x_axis');
+ has_x_axis=1;
+else
+ has_x_axis=options.has_x_axis;
+end
+
+if ~isfield(options,'is_log');
+ is_log=1;
+else
+ is_log=options.is_log;
+end
+
+% for compatibility.
+if isfield(options,'minimum_time');
+ options.minimum_time_interval=options.minimum_time;
+end
+if isfield(options,'maximum_time');
+ options.maximum_time_interval=options.maximum_time;
+end
+
+if ~isfield(options,'minimum_time_interval');
+ if is_log
+ minimum_time_interval=0.001;
+ else
+ minimum_time_interval=0;
+ end
+else
+ minimum_time_interval=options.minimum_time_interval;
+end
+
+if isfield(options,'time_profile_scale');
+ time_profile_scale=options.time_profile_scale;
+else
+ time_profile_scale=1;
+end
+% if the time scale is reversed (time from left to right)
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+if ~isfield(options,'maximum_time_interval');
+ maximum_time_interval=0.035;
+else
+ maximum_time_interval=options.maximum_time_interval;
+end
+
+% if maximum_time_interval>getmaximumtime(current_frame)
+% maximum_time_interval=getmaximumtime(current_frame);
+% end
+
+
+scale_summe=getscalesumme(current_frame); %for scaling properties
+
+% start plotting:
+plot_struct.t_min=minimum_time_interval;
+plot_struct.t_max=maximum_time_interval;
+plot_struct.has_axis=0;
+plot_struct.is_log=is_log;
+plot_struct.has_y_axis=0;
+
+% interval sum
+% partframe=getpart(current_frame,minimum_time_interval,maximum_time_interval);
+% summe=getsum(partframe); % here it is calculated
+% axis off
+
+sr=getsr(current_frame);
+% start_time=getminimumtime(current_frame);
+% sumvalues=getpart(summe,(minimum_time_interval+start_time),maximum_time_interval+start_time);
+% min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+% max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+
+start_time=getminimumtime(current_frame);
+if is_log
+ min_x_screen=1;
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+else
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+end
+
+
+if max_x_screen>getnrpoints(current_frame)
+ max_x_screen=getnrpoints(current_frame);
+ maximum_time_interval=(max_x_screen/sr)+start_time;
+end
+
+
+current_frame_values=getvalues(current_frame);
+cvals=current_frame_values(:,min_x_screen:max_x_screen);
+
+if getxaxis(current_frame)=='0'
+ cvals=cvals/1000;
+end;
+
+if size(cvals,1)==1
+ sumcvals=cvals;
+else
+ sumcvals=sum(cvals)';
+end
+% cvals=getvalues(summe);
+% min_x_screen=1;
+% max_x_screen=size(cvals,1);
+hand=plot(sumcvals);
+
+maxshowy=1.1;
+if min(cvals) >= 0
+ minshowy=0;
+else
+ minshowy=-1;
+end
+
+maxy=maxshowy*scale_summe/time_profile_scale;
+if maxy==0
+ maxy=1;
+end
+if time_profile_scale==-1 % decide myself
+ maxy=1.1*max(sumcvals);
+end
+
+% save the two profiles to text files for further analysis
+% 1: freq profile
+x1=getcf(current_frame);
+y1=sum(cvals');
+A1=[x1' y1'];
+
+% 2: temp profile
+sr=getsr(current_frame);
+x2=1000/sr:1000/sr:getlength(current_frame)*1000;
+y2=sum(cvals);
+A2=[x2' y2'];
+
+
+
+
+
+if is_log
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ if max_x_screen ==min_x_screen
+ max_x_screen =min_x_screen +1;
+ end
+ try
+ axis([min_x_screen max_x_screen minshowy maxy]);
+ end
+ if time_reversed
+ set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+ end
+ set(gca,'XScale','log')
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)*sr; % there shell be the tix
+% tix(1)=tix(1)+1;
+ ti=(ti*1000);
+ ti=fround(ti,2);
+else % its not logarithmic!
+ if time_reversed
+ set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+ else
+ set(gca,'XDir','normal') % normale ausrichtung
+ end
+ nrx=size(cvals,2);
+ if scale_summe==0
+ scale_summe=1;
+ end
+ axis([1 length(sumcvals) minshowy maxy]);
+ 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=round(ti*10)/10;
+ set(gca,'XScale','linear')
+ % text(min_x_screen*1.5,-scale_summe/5,'Time (ms)'); % this is at a nice position
+end
+
+if has_x_axis
+ if max(tix)>1
+ set(gca,'XTick',tix);
+ set(gca,'XTickLabel',ti);
+ end
+else
+ set(gca,'xtick',[]); % we dont want any z-Ticks!
+end % axis
+
+% if scale_summe==0
+% axis([min_x_screen max_x_screen minshowy maxshowy]);
+% else
+% axis([min_x_screen max_x_screen minshowy maxshowy*scale_summe/time_profile_scale]);
+% end
+
+if getxaxis(current_frame)=='0'
+ d=size(cvals);
+ ti = [0:1:16];
+ step=(d(2)/16);
+ tix = [0:step:d(2)];
+end;
+
+% stefan for the scale profile
+if strcmp(getxaxis(current_frame),'harmonic ratio')
+ ti=get(gca,'XTickLabel');
+ ti=str2num(ti)/1000;
+end
+
+
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plottemporalprofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plottemporalprofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,249 @@
+% method of class @frame
+%
+% 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/07/27 15:29:59 $
+% $Revision: 1.12 $
+
+function hand=plottemporalprofile(current_frame,options,ax)
+
+if nargin <3
+ ax=gca;
+end
+if nargin <2
+ options=[];
+end
+
+start_time=getminimumtime(current_frame);
+if start_time < 0 % these are frames read in from ams
+% max_time=getmaximumtime(current_frame);
+ fr=getpart(current_frame,start_time,0);
+ current_frame=reverse(current_frame);
+ start_time=0;
+ current_frame=setstarttime(current_frame,0);
+end
+
+
+
+if ~isfield(options,'has_x_axis');
+ has_x_axis=1;
+else
+ has_x_axis=options.has_x_axis;
+end
+
+if ~isfield(options,'is_log');
+ is_log=1;
+else
+ is_log=options.is_log;
+end
+
+% for compatibility.
+if isfield(options,'minimum_time');
+ options.minimum_time_interval=options.minimum_time;
+end
+if isfield(options,'maximum_time');
+ options.maximum_time_interval=options.maximum_time;
+end
+
+if ~isfield(options,'minimum_time_interval');
+ if is_log
+ minimum_time_interval=0.001;
+ else
+ minimum_time_interval=0;
+ end
+else
+ minimum_time_interval=options.minimum_time_interval;
+end
+
+if isfield(options,'time_profile_scale');
+ time_profile_scale=options.time_profile_scale;
+else
+ time_profile_scale=1;
+end
+% if the time scale is reversed (time from left to right)
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+if ~isfield(options,'maximum_time_interval');
+ maximum_time_interval=0.035;
+else
+ maximum_time_interval=options.maximum_time_interval;
+end
+
+% if maximum_time_interval>getmaximumtime(current_frame)
+% maximum_time_interval=getmaximumtime(current_frame);
+% end
+
+
+scale_summe=getscalesumme(current_frame); %for scaling properties
+
+% start plotting:
+plot_struct.t_min=minimum_time_interval;
+plot_struct.t_max=maximum_time_interval;
+plot_struct.has_axis=0;
+plot_struct.is_log=is_log;
+plot_struct.has_y_axis=0;
+
+% interval sum
+% partframe=getpart(current_frame,minimum_time_interval,maximum_time_interval);
+% summe=getsum(partframe); % here it is calculated
+% axis off
+
+sr=getsr(current_frame);
+% start_time=getminimumtime(current_frame);
+% sumvalues=getpart(summe,(minimum_time_interval+start_time),maximum_time_interval+start_time);
+% min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+% max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+
+start_time=getminimumtime(current_frame);
+if is_log
+ min_x_screen=1;
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+else
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen
+end
+
+
+if max_x_screen>getnrpoints(current_frame)
+ max_x_screen=getnrpoints(current_frame);
+ maximum_time_interval=(max_x_screen/sr)+start_time;
+end
+
+
+current_frame_values=getvalues(current_frame);
+cvals=current_frame_values(:,min_x_screen:max_x_screen);
+
+if getxaxis(current_frame)=='0'
+ cvals=cvals/1000;
+end;
+
+if size(cvals,1)==1
+ sumcvals=cvals;
+else
+ sumcvals=sum(cvals)';
+end
+% cvals=getvalues(summe);
+% min_x_screen=1;
+% max_x_screen=size(cvals,1);
+hand=plot(ax,sumcvals);
+
+maxshowy=1.1;
+if min(cvals) >= 0
+ minshowy=0;
+else
+ minshowy=-1;
+end
+
+maxy=maxshowy*scale_summe/time_profile_scale;
+if maxy==0
+ maxy=1;
+end
+if time_profile_scale==-1 % decide myself
+ maxy=1.2*max(sumcvals);
+end
+
+% save the two profiles to text files for further analysis
+% 1: freq profile
+x1=getcf(current_frame);
+y1=sum(cvals');
+A1=[x1' y1'];
+% save freqp.txt A1 -ascii
+dlmwrite('freqprofile.txt',A1, '\t')
+
+
+% 2: temp profile
+sr=getsr(current_frame);
+x2=1000/sr:1000/sr:getlength(current_frame)*1000;
+y2=sum(cvals);
+A2=[x2' y2'];
+% save tempp.txt A1 -ascii
+% dlmwrite('tempprofile.txt',A2, '\t')
+
+
+
+
+
+if is_log
+ min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen
+ if max_x_screen ==min_x_screen
+ max_x_screen =min_x_screen +1;
+ end
+ try
+ set(ax,'xlim',[min_x_screen max_x_screen]);
+ set(ax,'ylim',[minshowy maxy]);
+
+% axis([min_x_screen max_x_screen minshowy maxy]);
+ end
+ if time_reversed
+ set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
+ end
+ set(ax,'XScale','log')
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)*sr; % there shell be the tix
+% tix(1)=tix(1)+1;
+ ti=(ti*1000);
+ ti=fround(ti,2);
+else % its not logarithmic!
+ if time_reversed
+ set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
+ else
+ set(ax,'XDir','normal') % normale ausrichtung
+ end
+ nrx=size(cvals,2);
+ if scale_summe==0
+ scale_summe=1;
+ end
+ axis([1 length(sumcvals) minshowy maxy]);
+ 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=round(ti*10)/10;
+ set(ax,'XScale','linear')
+ % text(min_x_screen*1.5,-scale_summe/5,'Time (ms)'); % this is at a nice position
+end
+
+if has_x_axis
+ if max(tix)>1
+ set(ax,'XTick',tix);
+ set(ax,'XTickLabel',ti);
+ end
+else
+ set(ax,'xtick',[]); % we dont want any z-Ticks!
+end % axis
+
+% if scale_summe==0
+% axis([min_x_screen max_x_screen minshowy maxshowy]);
+% else
+% axis([min_x_screen max_x_screen minshowy maxshowy*scale_summe/time_profile_scale]);
+% end
+
+if getxaxis(current_frame)=='0'
+ d=size(cvals);
+ ti = [0:1:16];
+ step=(d(2)/16);
+ tix = [0:step:d(2)];
+end;
+
+% stefan for the scale profile
+if strcmp(getxaxis(current_frame),'harmonic ratio')
+ ti=get(ax,'XTickLabel');
+ ti=str2num(ti)/1000;
+end
+
+
+set(ax,'XTick',tix);
+set(ax,'XTickLabel',ti);
+set(ax,'YTickLabel',[]);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plotwithstrobes.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plotwithstrobes.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function plotwithstrobes(nap,allstrobeprocesses)
+
+plot(nap);
+sr=getsr(nap);hold on
+nr_channels=getnrchannels(nap);
+start_time=getminimumtime(nap);
+for i=1:nr_channels
+ nr_strobes=length(allstrobeprocesses{i}.strobes);
+ for j=1:nr_strobes
+ x=time2bin(allstrobeprocesses{i}.strobes(j)-start_time,sr);
+ y=i;
+ z=allstrobeprocesses{i}.strobe_vals(j);
+ plot3(x,y,z,'.r');hold on
+ end
+
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/plus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/plus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @frame
+%
+% 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/11 10:46:32 $
+% $Revision: 1.1 $
+
+function fr=plus(a,b)
+% addition
+% einfachster Fall: Addiere eine konstante Zahl
+% sonst: Addiere die beiden Frames
+
+if isnumeric(b)
+ a.values=a.values+b;
+ fr=a;
+ return
+end
+
+if isobject(a)
+ a.values=a.values+b.values;
+ fr=a;
+ return
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/readaiff.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/readaiff.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function nap=readaiff(fr,aifffilename,spffilename)
+
+content_spfmodel=loadtextfile(spffilename);
+cf=DSAMGetCFs(content_spfmodel);
+
+naps=SBReadAiff(aifffilename,0); % returns all info in a struct
+
+nap=naps(1);
+nap=setcf(nap,cf);
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/reverse.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/reverse.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @frame
+%
+% 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/01/31 17:44:34 $
+% $Revision: 1.1 $
+
+function fr=reverse(frorg)
+
+dat=getvalues(frorg);
+dat=dat(:,end:-1:1);
+
+fr=setvalues(frorg,dat);
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setallmaxvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setallmaxvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setallmaxvalue(fr,val)
+fr.movie.all_max_value=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setallminvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setallminvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setallminvalue(fr,val)
+fr.movie.all_min_value=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setcf.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setcf.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setcf(fr,cf)
+
+fr.centerfrequencies=cf;
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setcurrentframenumber.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setcurrentframenumber.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setcurrentframenumber(fr,val)
+fr.movie.current_frame_number=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setcurrentframestarttime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setcurrentframestarttime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setcurrentframestarttime(fr,val)
+fr.movie.current_frame_start_time=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setdisplaymaximumtime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setdisplaymaximumtime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setdisplaymaximumtime(fr,maximum_time_interval)
+fr.display_max_time=maximum_time_interval;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setdisplayminimumtime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setdisplayminimumtime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setdisplayminimumtime(fr,minimum_time_interval)
+fr.display_min_time=minimum_time_interval;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setname.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setname.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setname(fr,name)
+fr.name=name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setnrframestotal.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setnrframestotal.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setnrframestotal(fr,val)
+fr.movie.nr_frames_total=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setscalefrequency.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setscalefrequency.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setscalefrequency(fr,val)
+fr.movie.scale_frequency=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setscalesumme.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setscalesumme.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setscalesumme(fr,val)
+fr.movie.scale_summe=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setsinglechannel.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setsinglechannel.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setsinglechannel(fr,nr,sig)
+
+if isobject(sig)
+ sig_data=getvalues(sig);
+else
+ sig_data=sig;
+end
+fr.values(nr,:)=sig_data;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setsr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setsr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setsr(fr,sr)
+
+fr.samplerate=sr;
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setstarttime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setstarttime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setstarttime(fr,start_time)
+fr.start_time=start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/settext.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/settext.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=settext(fr,te)
+fr.text=te;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=setvalues(fr,vals)
+
+fr.values=vals;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/setxaxisname.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/setxaxisname.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @frame
+%
+% 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/25 16:01:39 $
+% $Revision: 1.1 $
+
+function fr=setxaxisname(fr,name)
+
+fr.x_axis_label=name;
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/sqrt.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/sqrt.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function fr=sqrt(fr)
+
+vals=getvalues(fr);
+vals=sqrt(vals);
+fr=setvalues(fr,vals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/sumfresig.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/sumfresig.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% method of class @frame
+%
+% 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/01/17 16:57:46 $
+% $Revision: 1.3 $
+
+function sig=sumfresig(fr)
+
+number=max(size(fr));
+
+if number==1
+ val=fr.values;
+
+ summe=sum(val');
+ cfs=fr.centerfrequencies;
+ max_fre=max(cfs);
+
+ sig=signal(summe);
+ sig=setsr(sig,1);
+ sig=setxlabels(sig,cfs);
+ sig=setunit_x(sig,'Frequency(kHz)');
+ sig=setname(sig,'Sum of Frequencies');
+else
+ not implemented yet
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@frame/time2bin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@frame/time2bin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% tool
+%
+% 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/07/09 15:24:57 $
+% $Revision: 1.1 $
+
+function res=time2bin(fr,time)
+% gibt das Bin zurück, bei dem diese Zeit wäre
+% Zeit immer in Sekunden
+% Samplerate immer in Bins pro Sekunde (96 kHz)
+
+samplerate=getsr(fr);
+
+res=time*samplerate;
+
+res=round(res); % rundungsfehler!!!
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/bin2freq.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/bin2freq.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,6 @@
+function freq=bin2freq(fsig,bin)
+
+nr=fsig.df;
+freq=bin*nr;
+% bin=f/nr;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/display.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/display.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 display(fsig)
+
+disp('Frequency Spectrum');
+disp(sprintf('Name: %s',getname(fsig)));
+disp(sprintf('Points: %d',getnrpoints(fsig)));
+disp(sprintf('Frequency from 0 to %5.2f Hz',fsig.max_fre));
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/freq2bin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/freq2bin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,5 @@
+function bin=freq2bin(fsig,f)
+
+nr=fsig.df;
+bin=f/nr;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/fsignal.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/fsignal.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 f=fsignal(laenge,samplerate)
+
+start_time=0;
+unit_y='amplitude (dB)';
+unit_x='Frequency (Hz)';
+name='generic Frequencysignal';
+if nargin< 2
+ samplerate=1000;
+end
+
+% Konstruktor kann auch ein Vektor sein, dann wird direkt konstruiert.
+lang=size(laenge,1);
+if size(laenge,2)>1 %Benutzer hat falschen Vektor (Zeilenvektor) eingegeben
+ lang=size(laenge,2);
+ laenge=laenge';
+end
+if lang>1 % AHA! Ein Vektor
+ f.werte=laenge;
+ nr_points=lang;
+else
+ nr_points=laenge;
+ f.werte=zeros(round(nr_points),1);
+end
+
+f.max_fre=samplerate;
+f.df=samplerate/nr_points; %frequenzabstand
+
+sig=signal(laenge,samplerate,name,unit_x,unit_y,start_time);
+
+f=class(f,'fsignal',sig);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/getdf.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/getdf.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 nr=getdf(sig)
+% returns the smallest frequency difference
+nr=sig.df;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/getmaxfre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/getmaxfre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 nr=getmaxfre(sig)
+nr=sig.max_fre;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/isoftype.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/isoftype.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 ret=isoftype(inp,str)
+
+if strcmp(str,'fsignal')
+ ret=1;
+else
+ ret=0;
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/max.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/max.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 [m,f]=max(fsig)
+% returns the maximum as Value and Frequency!!
+%if the return frequency is 0 then the next value is searched
+
+werte=getdata(fsig);
+werteneu=werte(2:end); % ohne den Gleichanteil!
+
+[m,f]=max(werteneu);
+
+f=(f-1)*fsig.df; % umrechnung von bin zu Frequenz
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/plot.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/plot.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,105 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 plot(fsig,border,stil)
+
+if nargin==2
+ if ischar(border)
+ stil=border;
+ else
+ stil='b-';
+ end
+end
+
+maxfre=fsig.max_fre; % die höchste Frequenz im Signal
+df=fsig.df; % der Frequenzabstand
+nr=getnrpoints(fsig);
+
+werte=getdata(fsig);
+mi=min(werte);
+ma=max(werte);
+if mi==ma
+ ma=mi+1;
+end
+
+
+% minx=1;
+% maxx=nr-1;
+
+if nargin <2
+ stil='b-';
+ border=[df maxfre mi ma];
+else
+ if ischar(border)
+ border=[df maxfre mi ma];
+ else
+ nr=size(border,2);
+ if nr==2 % wenn nur die x-Werte angegeben werden
+ border=[border(1) border(2) mi ma];
+ end
+ end
+end
+
+minf=border(1);
+maxf=border(2);
+
+minx=freq2bin(fsig,minf);
+maxx=freq2bin(fsig,maxf);
+
+
+plotw=werte(2:end); % die Null vorne wird abgeschnitten!
+
+
+plotlin=1;
+
+if plotlin==0
+ semilogx(plotw,stil);
+ axis([minx maxx border(3) border(4)]);
+ xt=get(gca,'XTick');
+ xt=distributelogarithmic(minx,maxx,8);
+ set(gca,'XTick',xt);
+ xti=bin2freq(fsig,xt);
+ xti=fround(xti,1);
+ set(gca,'XTickLabel',xti);
+else
+ % to make the frequencies right, double every point...
+ plotwnew=[zeros(size(plotw));zeros(size(plotw))];
+ for i=1:length(plotw);
+ plotwnew((i-1)*2+1)=plotw(i);
+ plotwnew((i-1)*2+2)=plotw(i);
+ end
+ plot(plotwnew,stil);
+ axis([minx maxx border(3) border(4)]);
+% xt=get(gca,'XTick');
+% xt=distributelogarithmic(minx,maxx,8);
+% set(gca,'XTick',xt);
+% xti=bin2freq(fsig,xt);
+% xti=fround(xti,1);
+% set(gca,'XTickLabel',xti);
+
+end
+
+
+% xstep=(log(maxx)-log(minx))/10;
+% tix=exp(log(minx):xstep:log(maxx));
+
+% fstep=(log(maxf)-log(minf))/10;
+% ti=(log(minf):fstep:log(maxf));
+% ti=exp(ti)/1000;
+% ti=fround(ti,1);
+% semilogx(fsig.werte,stil);
+
+
+xlabel(getunit_x(fsig));
+ylabel(getunit_y(fsig));
+title(getname(fsig),'Interpreter','none');
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/setdf.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/setdf.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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=setdf(sig,nr)
+% set the smallest Frequency Difference
+sig.df=nr;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/setmaxfre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/setmaxfre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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=setmaxfre(sig,nr)
+if nargin<2
+ disp('setmaxfre(sig,nr) called with too few parameters')
+ return
+end
+sig.max_fre=nr;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@fsignal/strippowerspectrum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@fsignal/strippowerspectrum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @fsignal (derived from @signal)
+%
+% 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 nsig=strippowerspectrum(sig)
+% usage: sig=strippowerspectrum(sig)
+% returns a new fsignal, that has one fewer point and strips of the leading
+% value, because the powerspectrum adds a zero value in front
+
+
+val=getdata(sig);
+valneu=val(2:end);
+
+nsig=fsignal(valneu);
+
+nsig=setsr(nsig,getsr(sig));
+nsig=setdf(nsig,getdf(sig));
+nsig=setmaxfre(nsig,getmaxfre(sig));
+
+nsig=setname(nsig,getname(sig));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/add.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/add.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,304 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=add(param,type,text,argument4,argument5,argument6,argument7,argument8,argument9)
+% add a new parameter to the structure
+% and set its inital state variables
+
+cont=param.entries;
+newentrynr=length(cont)+1;
+
+% each entry must be one of the following types:
+% float (% floats can have an UNIT)
+% int
+% string
+% bool (checkbox)
+% button
+% radiobutton (radiobutton)
+% filename (a button and a string box)
+% directoryname (a button and a string box)
+% pop-up menu (a couple of strings)
+% slider (a float plus a slider)
+%
+% it can also be a panel that is a subpanel that contains different uicontrols for example radiobuttons
+
+if strcmp(type,'panel')
+ param.panelinfo.panelcount=0; % reset the counter because the next n entries are in this panel
+ param.panelinfo.is_in_panel=1; % flag for the next ones
+ param.panelinfo.count_panels_up_to=argument4; % so many are coming
+ param.panelinfo.current_panel=text;
+end
+
+% every entry is part of a panel. Either of type 'all' or of the given
+% subpanels
+if ~isfield(param.panelinfo,'panelcount') || ~param.panelinfo.is_in_panel
+ cont{newentrynr}.panel='all';
+else
+ cont{newentrynr}.panel=param.panelinfo.current_panel;
+ param.panelinfo.panelcount=param.panelinfo.panelcount+1;
+ if param.panelinfo.panelcount>param.panelinfo.count_panels_up_to
+ param.panelinfo.is_in_panel=0;
+ end
+end
+
+
+cont{newentrynr}.type=type;
+cont{newentrynr}.enable=1; % enable it by default
+
+% each entry has a text that characterises it uniqly:
+cont{newentrynr}.text=text;
+
+% each entry can have an callback function that is called after it looses
+% its focus or is pressed:
+cont{newentrynr}.callback='';
+
+
+% set the tooltip as the name (currently for debugging)
+cont{newentrynr}.tooltiptext=cont{newentrynr}.text;
+
+switch type
+ case {'int'}
+ % 1 2 3 4 5 6
+ % object type name val minval maxval
+ % eg params=add(params,'int','min bins above thres',2, 0, inf);
+
+ if nargin>=4
+ cont{newentrynr}.value=argument4;
+ else
+ cont{newentrynr}.value=0;
+ end
+ if nargin<5
+ cont{newentrynr}.minvalue=intmin;
+ else
+ cont{newentrynr}.minvalue=argument5;
+ end
+ if nargin<6
+ cont{newentrynr}.maxvalue=intmax;
+ else
+ cont{newentrynr}.maxvalue=argument6;
+ end
+
+ case {'float'}
+ % 1 2 3 4 5 6 7 8
+ % object type name unittype val userunit minval maxval
+ % eg params=add(params,'float','window start',unit_time,0, 'ms', 0 ,lenstim);
+ if ~isobject(argument4) % without a unit its a unit_none and argument4 is the value
+ if isnumeric(argument4)
+ cont{newentrynr}.stringvalue=num2str(argument4);
+ cont{newentrynr}.rawvalue=argument4;
+ else
+ cont{newentrynr}.stringvalue=argument4;
+ cont{newentrynr}.rawvalue=str2num(argument4);
+ end
+ cont{newentrynr}.unittype=unit_none;
+ cont{newentrynr}.orgunit=unit_none;
+ else
+ cont{newentrynr}.unittype=argument4; % the general unit (eg unit_time)
+ if ischar(argument5)
+ cont{newentrynr}.stringvalue=argument5;
+ else
+ cont{newentrynr}.stringvalue=num2str(argument5);
+ end
+ if ~isa(argument4,'unit_none')
+ cont{newentrynr}.orgunit=argument6; % the definition unit (later used in calls with set)
+ if ischar(argument5) && ~strcmp(argument5,'auto')
+ cont{newentrynr}.rawvalue=fromunits(argument4,str2num(argument5),argument6);
+ elseif ~strcmp(argument5,'auto')
+ cont{newentrynr}.rawvalue=fromunits(argument4,argument5,argument6);
+ else
+ cont{newentrynr}.rawvalue='auto';
+ end
+ else
+ if exist('argument6','var') && isnumeric(argument6)
+ temp=argument7;
+ argument7=argument6;
+ argument8=temp;
+ end
+ cont{newentrynr}.orgunit=''; % the definition unit (later used in calls with set)
+ cont{newentrynr}.rawvalue=argument5;
+ end
+ end % without unit
+ if nargin<7
+ cont{newentrynr}.minvalue=-inf;
+ else
+ cont{newentrynr}.minvalue=argument7;
+ end
+ if nargin<8
+ cont{newentrynr}.maxvalue=+inf;
+ else
+ cont{newentrynr}.maxvalue=argument8;
+ end
+
+
+ case {'slider'}
+ % 1 2 3 4 5 6 7 8 9
+ % object type name unittype val userunit minval maxval logornot
+ % eg params=add(params,'slider','slidval',unit_time, 0, 'ms', 0 , inf, islog);
+ if ~isobject(argument4) % without a unit its a unit_none and argument4 is the value
+ if isnumeric(argument4)
+ cont{newentrynr}.stringvalue=num2str(argument4);
+ cont{newentrynr}.rawvalue=argument4;
+ else
+ cont{newentrynr}.stringvalue=argument4;
+ cont{newentrynr}.rawvalue=str2num(argument4);
+ end
+ cont{newentrynr}.unittype=unit_none;
+ cont{newentrynr}.orgunit=unit_none;
+ if nargin<7 % is log or not
+ tmp=1;
+ else
+ tmp=argument7;
+ end
+ argument7=argument5; % minvalue
+ argument8=argument6; % maxvalue must be there!
+ argument9=tmp;
+ else
+ cont{newentrynr}.unittype=argument4; % the general unit (eg unit_time)
+ if ischar(argument5)
+ cont{newentrynr}.stringvalue=argument5;
+ else
+ cont{newentrynr}.stringvalue=num2str(argument5);
+ end
+ if ~isa(argument4,'unit_none')
+ cont{newentrynr}.orgunit=argument6; % the definition unit (later used in calls with set)
+ if ischar(argument5) && ~strcmp(argument5,'auto')
+ cont{newentrynr}.rawvalue=fromunits(argument4,str2num(argument5),argument6);
+ elseif ~strcmp(argument5,'auto')
+ cont{newentrynr}.rawvalue=fromunits(argument4,argument5,argument6);
+ else
+ cont{newentrynr}.rawvalue='auto';
+ end
+ else
+ if exist('argument6','var') && isnumeric(argument6)
+ temp=argument7;
+ argument7=argument6;
+ argument8=temp;
+ end
+ cont{newentrynr}.orgunit=''; % the definition unit (later used in calls with set)
+ cont{newentrynr}.rawvalue=argument5;
+ end
+ end % without unit
+ if ~exist('argument7','var')
+ cont{newentrynr}.minvalue=-inf;
+ else
+ cont{newentrynr}.minvalue=argument7;
+ end
+ if ~exist('argument8','var')
+ cont{newentrynr}.maxvalue=+inf;
+ else
+ cont{newentrynr}.maxvalue=argument8;
+ end
+ if ~exist('argument9','var')
+ cont{newentrynr}.islog=0;
+ else
+ cont{newentrynr}.islog=argument9;
+ end
+ if isa(cont{newentrynr}.orgunit,'unit_none')
+ cont{newentrynr}.editscaler=1;
+ else
+ cont{newentrynr}.editscaler=tounits(argument4,1,argument6);
+ cont{newentrynr}.minvalue=fromunits(argument4,cont{newentrynr}.minvalue,argument6);
+ cont{newentrynr}.maxvalue=fromunits(argument4,cont{newentrynr}.maxvalue,argument6);
+ end
+ cont{newentrynr}.nreditdigits=4;
+
+ % 1 2 3 4 5
+ % object type name val other value
+ % params=add(params,'bool','swap dimensions','true','othervalue');
+ case {'bool','radiobutton'}
+ if nargin<4
+ argument4='';
+ end
+ if ischar(argument4)
+ if strcmp(argument4,'true')
+ cont{newentrynr}.value=1;
+ else
+ cont{newentrynr}.value=0;
+ end
+ else
+ cont{newentrynr}.value=argument4;
+ end
+ cont{newentrynr}.tooltiptext=[cont{newentrynr}.panel ': ' cont{newentrynr}.text];
+ cont{newentrynr}.enables={}; % these are the ones that are switched on by me
+ cont{newentrynr}.enables_inbox={};
+ cont{newentrynr}.disables={}; % and these are switched off
+ cont{newentrynr}.disables_inbox={};
+ if nargin==5
+ cont{newentrynr}.userdata=argument5;
+ end
+
+
+ % 1 2 3 4 5
+ % object type name callback default
+ % params=add(params,'button','analyse','ret=fkt(d,params,''plot'');',1);
+ case 'button'
+ cont{newentrynr}.value=0;
+ if strcmp(text,'OK')
+ cont{newentrynr}.callback='close';
+ if nargin==4 && isnumeric(argument4)
+ cont{newentrynr}.isdefaultbutton=argument4;
+ else
+ cont{newentrynr}.isdefaultbutton=0;
+ end
+ else
+ cont{newentrynr}.callback=argument4;
+ end
+ cont{newentrynr}.tooltiptext=['button: ' cont{newentrynr}.text];
+ if nargin==5 && isnumeric(argument5)
+ cont{newentrynr}.isdefaultbutton=argument5;
+ else
+ if ~strcmp(text,'OK')
+ cont{newentrynr}.isdefaultbutton=0;
+ end
+ end
+
+ case 'pop-up menu'
+ cont{newentrynr}.value=argument4{1};
+ cont{newentrynr}.numeric_value=1;
+ cont{newentrynr}.possible_values=argument4;
+ cont{newentrynr}.tooltiptext=['pop-up menu: ' cont{newentrynr}.text];
+
+ % 1 2 3 4 5
+ % object type name strvalue length of window
+ % dstruct=add(dstruct,'string','comment',WHATcomment,30);
+ case 'string'
+ cont{newentrynr}.value=argument4;
+ if nargin>=5
+ cont{newentrynr}.width=argument5;
+ else
+ cont{newentrynr}.width=-1;
+ end
+ cont{newentrynr}.tooltiptext=['string: ' cont{newentrynr}.text];
+
+ % 1 2 3 4
+ % object type name nr rows
+ % dstruct=add(dstruct,'panel','unit type',10);
+ case 'panel'
+ cont{newentrynr}.panel=text;
+ cont{newentrynr}.tooltiptext=['panel: ' cont{newentrynr}.text];
+ cont{newentrynr}.nr_elements=argument4;
+ case 'filename'
+ if nargin<4
+ cont{newentrynr}.value='';
+ else
+ cont{newentrynr}.value=argument4;
+ end
+ cont{newentrynr}.tooltiptext=['file name: ' cont{newentrynr}.text];
+ case 'directoryname'
+ if nargin<4
+ cont{newentrynr}.value='';
+ else
+ cont{newentrynr}.value=argument4;
+ end
+ cont{newentrynr}.tooltiptext=['directry name: ' cont{newentrynr}.text];
+ otherwise
+ error(sprintf('dont know type ''%s''',type))
+end
+
+
+
+% save them
+param.entries=cont;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/disablefield.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/disablefield.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=disablefield(param,paramtext,enablesthese,inbox)
+% the boolean parameter paramtext switches on or off the fields in
+% enablethese
+% this is the reverse of enablefield
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<4 % search in all subsections
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,paramtext,inbox);
+inbox=param.entries{nr}.panel;
+
+if nr>0
+ cval=1-param.entries{nr}.value; % disable instead of enable
+ nre=size(enablesthese,1);
+ if nre==1
+ param.entries{nr}.disables{1}=enablesthese;
+ param.entries{nr}.disables_inbox{1}=inbox;
+ param=enable(param,enablesthese,cval,inbox);
+ else
+ for i=1:nre
+ param.entries{nr}.disables{i}=enablesthese{i};
+ param.entries{nr}.disables_inbox{i}=inbox;
+ param=enable(param,enablesthese{i},cval,inbox);
+ end
+ end
+else
+ error('setvalue::error, the entry does not exist');
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/disp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/disp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,10 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function disp(params)
+% thats what happens if you are with the mouse over it in the editor
+display(params)
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/display.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/display.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,65 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function display(param)
+% display the content of an object of the parameter class. This function is
+% called when the object is listed somewhere or the mouse is over it in the
+% editor
+
+cont=param.entries;
+nrent=length(cont);
+disp(sprintf('%s: object of class datastruct with %d entries:',param.name,nrent));
+
+for i=1:nrent
+ panel=cont{i}.panel;
+ if ~strcmp(panel,'all')
+ indent=' ';
+ else
+ indent='';
+ end
+ text=cont{i}.text;
+ switch cont{i}.type
+ case {'string','pop-up menu','filename','directoryname'}
+ val=get(param,text);
+ disp(sprintf('%s(%12s) %30s = %s',indent,cont{i}.type,cont{i}.text,val));
+ case {'int'}
+ val=getstringvalue(param,text);
+ disp(sprintf('%s(%12s) %30s = %s',indent,cont{i}.type,cont{i}.text,val));
+ case {'float','slider'}
+ strval=getstringvalue(param,text);
+ if isequal(strval,'auto')
+ disp(sprintf('%s(%12s) %30s = %s',indent,cont{i}.type,text,strval));
+ else
+ curunit=getcurrentunit(param,text);
+ uninttype=cont{i}.unittype;
+ if isa(uninttype,'unit_none')
+ disp(sprintf('%s(%12s) %30s = %s',indent,cont{i}.type,text,strval));
+ else
+ disp(sprintf('%s(%12s) %30s = %s %s',indent,cont{i}.type,text,strval,curunit));
+ end
+ end
+ case {'bool','radiobutton'}
+ val=get(param,text,cont{i}.panel);
+ if val==0
+ val='false';
+ else
+ val='true';
+ end
+ if strcmp(text,'other...') && isequal(val,'true');
+ setto=getradiobutton(param,cont{i}.panel);
+ disp(sprintf('%s(%12s) %30s = %s (%s)',indent,cont{i}.type,text,val,setto));
+ else
+ disp(sprintf('%s(%12s) %30s = %s',indent,cont{i}.type,text,val));
+ end
+ case 'button'
+ disp(sprintf('%s( button) %22s (callback:) %s',indent,cont{i}.text,cont{i}.callback));
+ case 'panel'
+ disp(sprintf('( panel) %22s with %d entries:',cont{i}.text,cont{i}.nr_elements));
+ otherwise
+ % val=[];
+ % disp(sprintf('(%s) %s ',cont{i}.type,cont{i}.text,val));
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/enable.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/enable.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=enable(param,text,disablevalue,inbox)
+% if it has a grafical representation then disable
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<4 % search in all subsections
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ param.entries{nr}.enable=disablevalue; % save the value
+ if isfield(cont{nr},'handle') && ishandle(cont{nr}.handle{1}) % and set in the gui as well
+ hands=cont{nr}.handle;
+ for i=1:length(hands)
+ switch disablevalue
+ case 1
+ set(hands{i},'enable','on');
+ case 0
+ set(hands{i},'enable','off');
+ end
+ end
+ end
+else
+ error('setvalue::error, the entry does not exist');
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/enablefield.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/enablefield.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,43 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=enablefield(param,paramtext,enablesthese,inbox)
+% the boolean parameter paramtext switches on or off the fields in
+% enablethese
+
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<4 % search in all subsections
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,paramtext,inbox);
+inbox=param.entries{nr}.panel;
+
+if nr>0
+ cval=param.entries{nr}.value;
+ if iscell(enablesthese)
+ nre=length(enablesthese);
+ else
+ nre=size(enablesthese,1);
+ end
+ if nre==1
+ param.entries{nr}.enables{1}=enablesthese;
+ param.entries{nr}.enables_inbox{1}=inbox;
+ param=enable(param,enablesthese,cval,inbox);
+ else
+ for i=1:nre
+ param.entries{nr}.enables{i}=enablesthese{i};
+ param.entries{nr}.enables_inbox{i}=inbox;
+ param=enable(param,enablesthese{i},cval,inbox);
+ end
+ end
+else
+ error('setvalue::error, the entry does not exist');
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/exist.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/exist.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function val=exist(param,text,inbox)
+% returns a boolean value that indicates if that string has a valid field
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<3 % search in all subsections
+ inbox='all';
+end
+
+
+nr=getentrynumberbytext(param,text,inbox);
+
+if nr>0
+ val=1;
+else
+ val=0; % we must return a logical value otherwise it can generate difficult errors
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/get.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/get.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,81 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function val=get(param,text,panel)
+% returns the current value of the parameter
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin <2 % in case we want the whole stucture
+ val=cont;
+ return
+end
+
+if nargin<3 % search in all subsections
+ panel='all';
+end
+
+
+nr=getentrynumberbytext(param,text,panel);
+
+if nr>0
+ type=cont{nr}.type;
+
+ handleb=gethandle(param,text,panel,1);
+ if ~isequal(handleb,0) && ishandle(handleb) % yes, there is a screen representation
+ if strcmp(get(handleb,'type'),'uipanel') && strcmp(type,'panel')
+ val=getradiobutton(param,text);
+ else
+ strval=get(handleb,'string');
+ if strcmp(type,'pop-up menu')
+ nrsel=get(handleb,'value');
+ val=strval{nrsel};
+ elseif strcmp(type,'radiobutton')
+ val=get(handleb,'value');
+ elseif strcmp(type,'bool')
+ val=get(handleb,'value');
+ elseif strcmp(type,'int')
+ if strcmp(strval,'auto');
+ val=strval;
+ else
+ val=str2num(strval);
+ end
+ elseif strcmp(type,'float')
+ unit=cont{nr}.orgunit;
+ val=getas(param,text,unit,panel); %call new with unit
+ else
+ val=strval;
+ end
+ return
+ end
+ else % no screen representation
+ if strcmp(type,'float')
+ unit=cont{nr}.orgunit;
+ val=getas(param,text,unit,panel); %call new with unit
+ return
+ elseif strcmp(type,'int')
+ valf=cont{nr}.value;
+ if ischar(valf)
+ if strcmp(valf,'auto');
+ val=valf;
+ else
+ val=str2num(valf);
+ end
+ else
+ val=valf;
+ end
+ elseif strcmp(type,'panel')
+ val=getradiobutton(param,text);
+ else
+ val=cont{nr}.value;
+ return
+ end
+ end
+else
+ error('error, the entry does not exist');
+ % val=0; % we must return a logical value otherwise it can generate difficult errors
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getas.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getas.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,64 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function val=getas(param,text,selectedunit,panel)
+% returns the current value of the parameter if its an float or an int
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<4 % search in all subsections
+ panel='all';
+end
+
+nr=getentrynumberbytext(param,text,panel);
+
+if nr>0
+ type=cont{nr}.type;
+
+ if nargin==2
+ selectedunit=cont{nr}.orgunit;
+ end
+
+ handleb=gethandle(param,text,panel,1);
+ if ~isequal(handleb,0) && ishandle(handleb) % yes, there is a screen representation
+ strvalue=get(handleb,'string'); % value is a string, lets see what we make of it
+ if ~strcmp(strvalue,'auto')
+ orgvalue=str2num(strvalue); % its a float, it must have a value
+
+ unitty=cont{nr}.unittype;
+ if isa(unitty,'unit_none')
+ rawvalue=orgvalue;
+ selectedunit='';
+ else
+ cunit=getcurrentunit(param,text);
+ rawvalue=fromunits(unitty,orgvalue,cunit); % translate to rawdata
+ testvalue=tounits(unitty,rawvalue,cont{nr}.orgunit); %the unit in which the min and max values are defined
+ val=fromunits(unitty,orgvalue,selectedunit); % translate to asked unit
+ end
+ val=tounits(unitty,rawvalue,selectedunit);
+ return
+ else
+ val='auto';
+ return
+ end
+ else % no representation on screen
+ unittype=param.entries{nr}.unittype;
+ rawval=cont{nr}.rawvalue;
+ stringval=cont{nr}.stringvalue;
+ if isequal(rawval,'auto')
+ val=rawval;
+ return
+ end
+ if isa(unittype,'unit_none')
+ val=str2num(stringval);
+ else
+ val=tounits(unittype,rawval,selectedunit);
+ end
+ end
+else
+ error('getas:: error, the entry does not exist');
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getcurrentunit.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getcurrentunit.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function [selectedunit,fullunitname]=getcurrentunit(param,text,panel)
+% returns the unit that this value is currently set to
+
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<3 % search in all subsections
+ panel='all';
+end
+
+nr=getentrynumberbytext(param,text,panel);
+if nr>0
+ type=cont{nr}.type;
+ if ~strcmp(type,'float') && ~strcmp(type,'slider')
+ selectedunit='only floats have units...';
+ fullunitname='';
+ return
+ end
+
+ handleb=gethandle(param,text,panel,1);
+ if ~isequal(handleb,0) && ishandle(handleb) % yes, there is a screen representation
+ unitty=cont{nr}.unittype;
+ if isa(unitty,'unit_none')
+ selectedunit='';
+ fullunitname='';
+ else
+ handleb2=gethandle(param,text,panel,2);
+ unitnr=get(handleb2,'value');
+ possibleunitstr=getunitstrings(unitty);
+ selectedunit=possibleunitstr{unitnr};
+ possible_units_full=getunitfullstrings(unitty);
+ fullunitname=possible_units_full{unitnr};
+ end
+ return
+ else % no representation on screen
+ selectedunit=cont{nr}.orgunit;
+ return
+ end
+else
+ error('error, the entry does not exist');
+ % val=0; % we must return a logical value otherwise it can generate difficult errors
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getdefaultbutton.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getdefaultbutton.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=getdefaultbutton(param)
+% returns the parameter that was set as the default button
+
+ents=param.entries;
+
+for i=1:length(ents)
+ if strcmp(ents{i}.type,'button')
+ if ents{i}.isdefaultbutton==1
+ param=ents{i};
+ return
+ end
+ end
+end
+
+param=[];
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getentrybyhandle.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getentrybyhandle.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+function entry=getentrybyhandle(param,hand)
+
+
+cont=param.entries;
+nrent=length(cont);
+
+% first search for the exact fit
+for i=1:nrent
+ if isfield(cont{i},'handle')
+ for j=1:length(cont{i}.handle)
+ if cont{i}.handle{j}==hand
+ entry=cont{i};
+ return
+ end
+ end
+ end
+end
+
+entry=[];
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getentrynumberbytext.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getentrynumberbytext.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,42 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function nr=getentrynumberbytext(param,text,inbox)
+
+nr=-1;
+
+
+
+if nargin<3 % search in all subsections
+ inbox='all';
+end
+
+cont=param.entries;
+nrent=length(cont);
+
+
+% text can be a string or a number
+if isstr(text) % if its a sting then look for the member number
+ % first search for the exact fit
+ for i=1:nrent
+ if strcmp(cont{i}.text,text) && (strcmp(cont{i}.panel,inbox) || strcmp(inbox,'all'))
+ nr=i;
+ return
+ end
+ end
+
+
+ % then search for the abbreviation
+ for i=1:nrent
+ if ~isempty(strfind(cont{i}.text,text)) && (strcmp(cont{i}.panel,inbox) || strcmp(inbox,'all'))
+ nr=i;
+ return
+ end
+ end
+else
+ nr=text; % in this case we wanted to access it by the number
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getfirstfocus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getfirstfocus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function val=getfirstfocus(param)
+
+val=param.firstfocus;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/gethandle.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/gethandle.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+function hand=gethandle(param,text,panel,handnr)
+% set handle of one line. A line can have more then one handle, therefore
+% nr can be bigger then one
+
+if nargin<4
+ handnr=1;
+end
+
+if nargin<3
+ panel='all';
+end
+
+nr=getentrynumberbytext(param,text,panel);
+
+if nr>0
+ if ~isfield(param.entries{nr},'handle')
+ hand=0;
+% disp('error: handle does not exist');
+ return
+ end
+ if length(param.entries{nr}.handle)>=handnr
+ hand=param.entries{nr}.handle{handnr};
+ if length(hand)>1
+ hand=hand(handnr);
+ end
+ else
+ hand=[];
+ end
+else
+ hand=0;
+ disp('error: handle does not exist');
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getmode.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getmode.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function val=getmode(param)
+
+val=param.mode;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getname.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getname.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,10 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function name=getname(param)
+name=param.name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getposition.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getposition.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function pos=getposition(param)
+% moves the figure identified by handle h to the specified screen location,
+% preserving the figure's size. The position argument can be any of the following strings:
+% north - top center edge of screen
+% south - bottom center edge of screen
+% east - right center edge of screen
+% west - left center edge of screen
+% northeast - top right corner of screen
+% northwest - top left corner of screen
+% southeast - bottom right corner of screen
+% southwest - bottom left corner
+% center - center of screen
+% onscreen - nearest location with respect to current location that is on screen The position argument can also be a two-element vector [h,v], where depending on sign, h specifies the
+
+pos=param.position;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getradiobutton.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getradiobutton.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,81 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function str=getradiobutton(param,panel)
+
+
+cont=param.entries;
+nrent=length(cont);
+
+
+for i=1:nrent
+ type=cont{i}.type;
+ if strcmp(type,'radiobutton')
+ if strcmp(cont{i}.panel,panel)
+ handleb=gethandle(param,cont{i}.text,cont{i}.panel,1);
+ if ~isequal(handleb,0) && ishandle(handleb) % yes, there is a screen representation
+ val=get(handleb,'value');
+ if val==1
+ text=cont{i}.text;
+ panel=cont{i}.panel;
+ if strcmp(text,'other...')
+ handle2=gethandle(param,text,panel,2);
+ str=get(handle2,'string');
+ else
+ str=text;
+ end
+ return
+ end
+ else
+ if cont{i}.value==1
+ str=cont{i}.text;
+ if strcmp(str,'other...')
+ str=cont{i}.userdata;
+ end
+ return
+ end
+ end
+ end
+ end
+end
+
+
+
+% if still here then non identical fit
+% search for fragment
+
+for i=1:nrent
+ type=cont{i}.type;
+ if strcmp(type,'radiobutton')
+ if ~isempty(strfind(cont{i}.panel,panel))
+ handleb=gethandle(param,cont{i}.text,cont{i}.panel,1);
+ if ishandle(handleb) % yes, there is a screen representation
+ val=get(handleb,'value');
+ if val==1
+ text=cont{i}.text;
+ panel=cont{i}.panel;
+ if strcmp(text,'other...')
+ handle2=gethandle(param,text,panel,2);
+ str=get(handle2,'string');
+ else
+ str=text;
+ end
+ return
+ end
+ else
+ if cont{i}.value==1
+ str=cont{i}.text;
+ if strcmp(str,'other...')
+ str=cont{i}.userdata;
+ end
+ return
+ end
+ end
+ end
+ end
+end
+
+str='error, the entry does not exist';
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getraw.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getraw.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,37 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function val=getraw(param,text,inbox)
+% returns the current value of the parameter as it is, no transformation
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin <2 % in case we want the whole stucture
+ val=cont;
+ return
+end
+
+if nargin<3 % search in all subsections
+ inbox='all';
+end
+
+
+nr=getentrynumberbytext(param,text,inbox);
+
+if nr>0
+ type=cont{nr}.type;
+ if strcmp(type,'float')
+ val=cont{nr}.rawvalue;
+ return
+ else
+ val=cont{nr}.value;
+ return
+ end
+else
+ error('error, the entry does not exist');
+ % val=0; % we must return a logical value otherwise it can generate difficult errors
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getstringvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getstringvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function val=getstringvalue(param,text,panel)
+% returns the current value of the parameter as a string
+% this is particulary useful for integer values in the form 1:10
+
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<3 % search in all subsections
+ panel='all';
+end
+
+nr=getentrynumberbytext(param,text,panel);
+if nr>0
+ type=cont{nr}.type;
+
+ handleb=gethandle(param,text,panel,1);
+ if ~isequal(handleb,0) && ishandle(handleb) % yes, there is a screen representation
+ val=get(handleb,'string');
+ return
+ else
+ if strcmp(type,'float')
+ val=cont{nr}.stringvalue;
+ return
+ else
+ val=cont{nr}.value;
+ if ischar(val)
+ return
+ elseif isnumeric(val)
+ val=num2str(val);
+ return
+ end
+ end
+ end
+else
+ error('error, the entry does not exist');
+ % val=0; % we must return a logical value otherwise it can generate difficult errors
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/gettext.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/gettext.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function name=gettext(param,i,inbox)
+% return the description text of the parameter with the entry number i.
+% if i is a string then return the full string of the probably abbreviated
+
+if nargin==1
+ name=param.name;
+ return
+end
+
+if isnumeric(i)
+ name=param.entries{i}.text;
+elseif ischar(i)
+ if nargin==2 % search in all subsections
+ inbox='all';
+ end
+ nr=getentrynumberbytext(param,i,inbox);
+ name=param.entries{nr}.text;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getuserdata.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getuserdata.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+function data=getuserdata(param,text,inbox)
+% the whole struct can have an user entry and every part of the structure
+% as well. These can be used by the user for example for the 'other...'
+% radiobutton
+
+if nargin <2
+ data=param.userdata;
+else
+ nr=getentrynumberbytext(param,text,inbox);
+ if nr>0
+ % cont=param.entries;
+ % nrent=length(cont);
+ % for i=1:nrent
+ % if strcmp(cont{i}.text,text) && strcmp(cont{i}.belongtobox,inbox)
+ if isfield(data.cont{nr},'userdata')
+ data=cont{nr}.userdata;
+ else
+ data=[];
+ end
+ return
+ else
+ data='error';
+ disp('error in getuserdata: text not found');
+ end
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/getversion.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/getversion.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function val=getversion(param)
+
+val=param.version;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/parameter.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/parameter.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,93 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function dstr=parameter(inp,mode,position)
+% class parameter
+
+
+if nargin<1
+ param.name='data structure';
+ param.entries=[];
+else
+ if isobject(inp)
+ param=inp;
+ else
+ if isstr(inp)
+ param.name=inp;
+ param.entries=[];
+ else
+ error('data structure must be called with a name');
+ end
+ end
+end
+
+
+
+% protected variables (only accessible through set/get)
+
+% version number.
+% Version 1.0: basic functionallity works
+param.version='1.0';
+
+
+% these values are used when a gui is used
+% that one is the default value that is given back when the gui is closed
+param.default_value='';
+
+% that one defines whether the gui is modal or not
+if nargin < 2
+ param.mode='nonmodal';
+else
+ if strcmp(mode,'modal') || strcmp(mode,'nonmodal')
+ param.mode=mode;
+ else
+ disp('mode not recognised');
+ param.mode='nonmodal';
+ end
+end
+% data that the user can use to shift it between gui and application:
+param.userdata=[];
+
+% north - top center edge of screen
+% south - bottom center edge of screen
+% east - right center edge of screen
+% west - left center edge of screen
+% northeast - top right corner of screen
+% northwest - top left corner of screen
+% southeast - bottom right corner of screen
+% southwest - bottom left corner
+% center - center of screen
+% onscreen - nearest location with respect to current location that is on
+% screen The position argument can also be a two-element vector [h,v], where depending on sign, h specifies the
+% the default position of the gui is in the top right corner
+if nargin <3
+ param.position='center';
+else
+ if strcmp(position,'north') || strcmp(position,'south') || strcmp(position,'west') || strcmp(position,'east') || strcmp(position,'northeast') || strcmp(position,'northwest') || strcmp(position,'southeast') || strcmp(position,'southwest') || strcmp(position,'center') || strcmp(position,'onscreen')
+ param.position=position;
+ elseif size(position)==2
+ param.position=position;
+ else
+ disp('position not reconised');
+ param.position='center';
+ end
+end
+
+% where the focus is directly after calling
+param.firstfocus='';
+
+% diosplayed when with the mouse over it
+param.tooltiptext='';
+
+
+% a couple of informations that are used during installations (private
+% variables
+param.panelinfo=[];
+
+dstr=class(param,'parameter');
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/set.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/set.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,60 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=set(param,text,newvalue,inbox)
+%% sets the parameter value in the parameter "text" in the panel "inbox" to
+%% the value "value".
+% if its a float then the unit is assumed to be the one with wich the
+% parameter was first defined
+
+if nargin<4
+ inbox='all';
+end
+
+cont=param.entries;
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ type=cont{nr}.type;
+ if strcmp(type,'float') || strcmp(type,'slider')
+ unit=cont{nr}.orgunit;
+ param=setas(param,text,newvalue,unit,inbox); %call new with unit
+ return
+ else
+ param.entries{nr}.value=newvalue; % set the value in the class structure
+ end
+ if isfield(cont{nr},'handle') && ishandle(cont{nr}.handle{1}) % and set in the gui as well
+ hand=cont{nr}.handle{1};
+ if strcmp(type,'float') || strcmp(type,'string') || strcmp(type,'filename') || strcmp(type,'directoryname')
+ set(hand,'String',newvalue);
+ elseif strcmp(type,'int') % ints are capped
+ if isnumeric(newvalue)
+ intnewvalue=round(newvalue);
+ if length(intnewvalue)==1
+ set(hand,'String',intnewvalue);
+ else
+ set(hand,'String',num2str(intnewvalue));
+ end
+ param.entries{nr}.value=intnewvalue; % set the value in the class structure
+ else
+ set(hand,'String',newvalue);
+ end
+ else
+ if strcmp(type,'pop-up menu')
+ cont=param.entries{nr}.possible_values;
+ for i=1:length(cont)
+ if strcmp(cont{i},newvalue)
+ set(hand,'value',i);
+ end
+ end
+ else
+ set(hand,'value',newvalue); % could be bool
+ end
+ end
+ end
+ return
+else
+ error('setvalue::error, the entry does not exist');
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setas.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setas.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,66 @@
+% method of class @parameter
+%
+% (c) 2003, University of Cambridge
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual/tools/parameter
+% $Date: 2006-01-10 14:50:30 +0000 (Tue, 10 Jan 2006) $
+function param=setas(param,text,value,unit,inbox)
+%% sets the parameter value in the parameter "text" in the panel "inbox" to
+%% the value "value".
+% param must be of type float or int
+
+if nargin<5
+ inbox='all';
+end
+
+% cont=param.entries;
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ if isequal(value,'auto');
+ param.entries{nr}.rawvalue=value;
+ param.entries{nr}.stringvalue=value; % set the string value
+ else
+ if ~ischar(value)
+ unittype=param.entries{nr}.unittype;
+ if ~isa(unittype,'unit_none')
+ rawval=fromunits(unittype,value,unit);
+ else
+ rawval=value;
+ end
+ param.entries{nr}.rawvalue=rawval; % set the value in the class structure with the raw value
+ param.entries{nr}.stringvalue=num2str(rawval); % set the string value
+ else
+ param.entries{nr}.stringvalue=value; % set the string value
+ param.entries{nr}.rawvalue=str2num(value);
+ end
+ end
+ if isfield(param.entries{nr},'handle') && ishandle(param.entries{nr}.handle{1}) % and set in the gui as well
+ if strcmp(type,'float')
+ hand=param.entries{nr}.handle{1};
+ if isequal(value,'auto');
+ set(hand,'String',value); % set the string as given
+ else
+ if ~ischar(value)
+ if length(value)==1
+ set(hand,'String',num2str(value)); % translate to string
+ else
+ set(hand,'String',param.entries{nr}.stringvalue); % set the string as given
+ end
+ if ~isa(unittype,'unit_none')
+ unitnr=findunit(unittype,unit);
+ if length(param.entries{nr}.handle)>=2 && ishandle(param.entries{nr}.handle{2}) % and set in the gui as well
+ set(param.entries{nr}.handle{2},'value',unitnr); % set the unit to the given one
+ end
+ end
+ else % its a string format
+ set(hand,'String',value); % set the string as given
+ end
+ end
+ else
+ sec=param.entries{nr}.slidereditcontrol;
+
+ end
+ return
+ else
+ error('setvalue::error, the entry does not exist');
+ end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setas.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setas.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,72 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=setas(param,text,value,unit,inbox)
+%% sets the parameter value in the parameter "text" in the panel "inbox" to
+%% the value "value".
+% param must be of type float or slider
+
+if nargin<5
+ inbox='all';
+end
+
+% cont=param.entries;
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ if isequal(value,'auto');
+ param.entries{nr}.rawvalue=value;
+ param.entries{nr}.stringvalue=value; % set the string value
+ else
+ if ~ischar(value)
+ unittype=param.entries{nr}.unittype;
+ if ~isa(unittype,'unit_none')
+ rawval=fromunits(unittype,value,unit);
+ else
+ rawval=value;
+ end
+ param.entries{nr}.rawvalue=rawval; % set the value in the class structure with the raw value
+ param.entries{nr}.stringvalue=num2str(rawval); % set the string value
+ else
+ param.entries{nr}.stringvalue=value; % set the string value
+ param.entries{nr}.rawvalue=str2num(value);
+ end
+ end
+ if isfield(param.entries{nr},'handle') && ishandle(param.entries{nr}.handle{1}) % and set in the gui as well
+ if strcmp(param.entries{nr}.type,'float')
+ hand=param.entries{nr}.handle{1};
+ if isequal(value,'auto');
+ set(hand,'String',value); % set the string as given
+ else
+ if ~ischar(value)
+ if length(value)==1
+ set(hand,'String',num2str(value)); % translate to string
+ else
+ set(hand,'String',param.entries{nr}.stringvalue); % set the string as given
+ end
+ if ~isa(unittype,'unit_none')
+ unitnr=findunit(unittype,unit);
+ set(param.entries{nr}.handle{2},'value',unitnr); % set the unit to the given one
+ end
+ else % its a string format
+ set(hand,'String',value); % set the string as given
+ end
+ end
+ else % it must be a slider
+ secombi=param.entries{nr}.slidereditcombi;
+ if ~isa(unittype,'unit_none')
+ unitnr=findunit(unittype,unit);
+ set(param.entries{nr}.handle{2},'value',unitnr); % set the unit to the given one
+ editscaler=tounits(unittype,1,unit);
+ secombi.editscaler=editscaler;
+ end
+ secombi=slidereditcontrol_set_raweditvalue(secombi,value);
+ param.entries{nr}.slidereditcontrol=secombi;
+ end
+ return
+ end
+ else
+ error('setvalue::error, the entry does not exist');
+ end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setcallback.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setcallback.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=setcallback(param,text,cback,inbox)
+% every entry can have a callback function that is called when the item
+% looses its focus
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<4
+ inbox='all';
+end
+nr=-1;
+% text can be a string or a number
+if isstr(text) % if its a sting then look for the member number
+ % first search for the exact fit
+ for i=1:nrent
+ if strcmp(cont{i}.text,text) && (strcmp(cont{i}.panel,inbox) || strcmp(inbox,'all'))
+ nr=i;
+ break
+ end
+ end
+ % then search for the abbreviation
+ for i=1:nrent
+ if ~isempty(strfind(cont{i}.text,text)) && (strcmp(cont{i}.panel,inbox) || strcmp(inbox,'all'))
+ nr=i;
+ break
+ end
+ end
+else
+ nr=text; % in this case we wanted to access it by the number
+end
+
+
+if nr>0
+ param.entries{nr}.callback=cback;
+ return
+else
+ val='setcallback:: error, the entry does not exist';
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setfirstfocus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setfirstfocus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,12 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+function params=setfirstfocus(params,where)
+% sets the first focus to an element. When the gui is opend this one gets
+% the focus
+
+params.firstfocus=where;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/sethandle.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/sethandle.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+function param=sethandle(param,text,hand,inbox,handle_nr)
+% sets the handle of this item. handles_nr is usually 1 but can be 2 in
+% cases when more then one object is on the screen (float with unit,
+% filename...)
+
+cont=param.entries;
+nrent=length(cont);
+
+if nargin<5
+ handle_nr=1;
+end
+
+if nargin<4
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ param.entries{nr}.handle{handle_nr}=hand;
+ return
+else
+ val='sethandle: error, the entry does not exist';
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setmode.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setmode.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,12 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function param=setmode(param,mode)
+% sets the mode of the gui. Can be 'modal' or 'nonmodal'
+
+param.mode=mode;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setposition.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setposition.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function param=setposition(param,mode)
+% moves the figure identified by handle h to the specified screen location,
+% preserving the figure's size. The position argument can be any of the following strings:
+% north - top center edge of screen
+% south - bottom center edge of screen
+% east - right center edge of screen
+% west - left center edge of screen
+% northeast - top right corner of screen
+% northwest - top left corner of screen
+% southeast - bottom right corner of screen
+% southwest - bottom left corner
+% center - center of screen
+% onscreen - nearest location with respect to current location that is on screen The position argument can also be a two-element vector [h,v], where depending on sign, h specifies the
+
+param.position=mode;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setradiobutton.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setradiobutton.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,36 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=setradiobutton(param,text,inbox)
+
+
+cont=param.entries;
+nrent=length(cont);
+
+
+for i=1:nrent
+ type=cont{i}.type;
+ if strcmp(type,'radiobutton') && strcmp(cont{i}.panel,inbox)
+ if strcmp(cont{i}.text,text)
+ cont{i}.value=1;
+ param.entries=cont;
+ return
+ end
+ end
+end
+
+% if still here, then it could have been an 'other' enty:
+for i=1:nrent
+ type=cont{i}.type;
+ if strcmp(type,'radiobutton') && strcmp(cont{i}.panel,inbox) && strcmp(cont{i}.text,'other...')
+ cont{i}.userdata=text;
+ cont{i}.value=1;
+ param.entries=cont;
+ return
+ end
+end
+
+val='error, the entry does not exist';
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setslidereditcontrol.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setslidereditcontrol.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=setslidereditcontrol(param,text,slidereditcombi,inbox)
+% defines the tooltio for that entry
+
+if nargin<4
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ param.entries{nr}.slidereditcombi=slidereditcombi;
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setstringvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setstringvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=setstringvalue(param,text,strvalue,inbox)
+%% sets the parameter value in the parameter "text" in the panel "inbox" to
+%% the value "strvalue" no units or anything are used
+
+if nargin<5
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ param.entries{nr}.stringvalue=strvalue;
+ if isfield(param.entries{nr},'handle') && ishandle(param.entries{nr}.handle{1}) % and set in the gui as well
+ hand=param.entries{nr}.handle{1};
+ set(hand,'String',param.entries{nr}.stringvalue); % set the string as given
+ end
+ return
+else
+ error('setvalue::error, the entry does not exist');
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/settooltip.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/settooltip.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+function param=settooltip(param,text,tooltiptext,inbox)
+% defines the tooltio for that entry
+
+if nargin<4
+ inbox='all';
+end
+
+nr=getentrynumberbytext(param,text,inbox);
+if nr>0
+ param.entries{nr}.tooltip=tooltiptext;
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@parameter/setuserdata.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@parameter/setuserdata.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @parameter
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+function param=setuserdata(param,data,text,inbox)
+% the whole struct can have an user entry and every part of the structure
+% as well. These can be used by the user for example for the 'other...'
+% radiobutton
+
+if nargin <3
+ param.userdata=data;
+else
+ cont=param.entries;
+ nrent=length(cont);
+ for i=1:nrent
+ if strcmp(cont{i}.text,text)&& strcmp(cont{i}.panel,inbox)
+ cont{i}.userdata=data;
+ param.entries=cont;
+ return
+ end
+ end
+end
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp0_4w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp0_4w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+0.000000949329790
+0.000004887659735
+0.000013455611970
+0.000028262150069
+0.000050832595310
+0.000082551860164
+0.000124602989399
+0.000177901423877
+0.000243025796176
+0.000320146513478
+0.000408953860109
+0.000508587833984
+0.000617572389470
+0.000733757163835
+0.000854270085264
+0.000975484468613
+0.001093004274733
+0.001201671118858
+0.001295596347347
+0.001368221051093
+0.001412406247122
+0.001420554644320
+0.001384764430990
+0.001297014405263
+0.001149378546900
+0.000934266840338
+0.000644687849683
+0.000274527266915
+-0.000181164542385
+-0.000725884032353
+-0.001361393918563
+-0.002087460113753
+-0.002901616060244
+-0.003798964404696
+-0.004772025664505
+-0.005810642885186
+-0.006901950282624
+-0.008030412514072
+-0.009177939551408
+-0.010324080176674
+-0.011446294932634
+-0.012520307000431
+-0.013520527012155
+-0.014420545314967
+-0.015193682767195
+-0.015813588848919
+-0.016254873792918
+-0.016493759665190
+-0.016508733919805
+-0.016281187983045
+-0.015796022937213
+-0.015042204411277
+-0.014013249363950
+-0.012707628567970
+-0.011129070257363
+-0.009286752549883
+-0.007195374854510
+-0.004875101453117
+-0.002351373725794
+0.000345409021141
+0.003180336568110
+0.006114555481901
+0.009105946858860
+0.012109900197573
+0.015080166537917
+0.017969771472060
+0.020731966603819
+0.023321196575884
+0.025694057952721
+0.027810226074898
+0.029633326502082
+0.031131728830314
+0.032279242476630
+0.033055696422928
+0.033447387834601
+0.033447387834601
+0.033055696422928
+0.032279242476630
+0.031131728830314
+0.029633326502082
+0.027810226074898
+0.025694057952721
+0.023321196575884
+0.020731966603819
+0.017969771472060
+0.015080166537917
+0.012109900197573
+0.009105946858860
+0.006114555481901
+0.003180336568110
+0.000345409021141
+-0.002351373725794
+-0.004875101453117
+-0.007195374854510
+-0.009286752549883
+-0.011129070257363
+-0.012707628567970
+-0.014013249363950
+-0.015042204411277
+-0.015796022937213
+-0.016281187983045
+-0.016508733919805
+-0.016493759665190
+-0.016254873792918
+-0.015813588848919
+-0.015193682767195
+-0.014420545314967
+-0.013520527012155
+-0.012520307000431
+-0.011446294932634
+-0.010324080176674
+-0.009177939551408
+-0.008030412514072
+-0.006901950282624
+-0.005810642885186
+-0.004772025664505
+-0.003798964404696
+-0.002901616060244
+-0.002087460113753
+-0.001361393918563
+-0.000725884032353
+-0.000181164542385
+0.000274527266915
+0.000644687849683
+0.000934266840338
+0.001149378546900
+0.001297014405263
+0.001384764430990
+0.001420554644320
+0.001412406247122
+0.001368221051093
+0.001295596347347
+0.001201671118858
+0.001093004274733
+0.000975484468613
+0.000854270085264
+0.000733757163835
+0.000617572389470
+0.000508587833984
+0.000408953860109
+0.000320146513478
+0.000243025796176
+0.000177901423877
+0.000124602989399
+0.000082551860164
+0.000050832595310
+0.000028262150069
+0.000013455611970
+0.000004887659735
+0.000000949329790
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp0_5657w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp0_5657w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+-0.000001045535353
+-0.000005655939278
+-0.000015939143645
+-0.000033747496243
+-0.000060527157520
+-0.000097168552271
+-0.000143863204215
+-0.000199973160559
+-0.000263920050860
+-0.000333101516091
+-0.000403843176026
+-0.000471394361143
+-0.000529975413634
+-0.000572883374240
+-0.000592661260175
+-0.000581333884531
+-0.000530710293678
+-0.000432749478903
+-0.000279982173841
+-0.000065977448968
+0.000214161331513
+0.000563290574716
+0.000981733421946
+0.001466825251838
+0.002012525151420
+0.002609121358657
+0.003243057862847
+0.003896907015669
+0.004549509105176
+0.005176294410329
+0.005749796405662
+0.006240356735048
+0.006617013615947
+0.006848555842685
+0.006904714962267
+0.006757458974827
+0.006382342559010
+0.005759861831397
+0.004876756478299
+0.003727199149665
+0.002313811597713
+0.000648449391734
+-0.001247297762786
+-0.003341935070389
+-0.005594255402632
+-0.007953917187286
+-0.010362414081210
+-0.012754427031292
+-0.015059532665951
+-0.017204225410435
+-0.019114195042701
+-0.020716787360330
+-0.021943563930214
+-0.022732868182829
+-0.023032299922815
+-0.022800999048012
+-0.022011642126761
+-0.020652062523807
+-0.018726415844767
+-0.016255827255163
+-0.013278475210328
+-0.009849086634433
+-0.006037840803722
+-0.001928702214236
+0.002382774418982
+0.006792102160101
+0.011188898351358
+0.015460198472003
+0.019493933323818
+0.023182446984504
+0.026425929247667
+0.029135637577942
+0.031236789963944
+0.032671021241104
+0.033398311058379
+0.033398311058379
+0.032671021241104
+0.031236789963944
+0.029135637577942
+0.026425929247667
+0.023182446984504
+0.019493933323818
+0.015460198472003
+0.011188898351358
+0.006792102160101
+0.002382774418982
+-0.001928702214236
+-0.006037840803722
+-0.009849086634433
+-0.013278475210328
+-0.016255827255163
+-0.018726415844767
+-0.020652062523807
+-0.022011642126761
+-0.022800999048012
+-0.023032299922815
+-0.022732868182829
+-0.021943563930214
+-0.020716787360330
+-0.019114195042701
+-0.017204225410435
+-0.015059532665951
+-0.012754427031292
+-0.010362414081210
+-0.007953917187286
+-0.005594255402632
+-0.003341935070389
+-0.001247297762786
+0.000648449391734
+0.002313811597713
+0.003727199149665
+0.004876756478299
+0.005759861831397
+0.006382342559010
+0.006757458974827
+0.006904714962267
+0.006848555842685
+0.006617013615947
+0.006240356735048
+0.005749796405662
+0.005176294410329
+0.004549509105176
+0.003896907015669
+0.003243057862847
+0.002609121358657
+0.002012525151420
+0.001466825251838
+0.000981733421946
+0.000563290574716
+0.000214161331513
+-0.000065977448968
+-0.000279982173841
+-0.000432749478903
+-0.000530710293678
+-0.000581333884531
+-0.000592661260175
+-0.000572883374240
+-0.000529975413634
+-0.000471394361143
+-0.000403843176026
+-0.000333101516091
+-0.000263920050860
+-0.000199973160559
+-0.000143863204215
+-0.000097168552271
+-0.000060527157520
+-0.000033747496243
+-0.000015939143645
+-0.000005655939278
+-0.000001045535353
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp0_8w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp0_8w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+-0.000001986047624
+-0.000006514842866
+-0.000010687686793
+-0.000010813464264
+-0.000002760884392
+0.000017601906621
+0.000053903875864
+0.000108734631082
+0.000183112390286
+0.000275999286425
+0.000383910412105
+0.000500663878315
+0.000617316702010
+0.000722325000401
+0.000801956436836
+0.000840968137778
+0.000823544777911
+0.000734470039326
+0.000560481454052
+0.000291735390707
+-0.000076712399583
+-0.000543522585638
+-0.001099907499859
+-0.001728812049767
+-0.002404560097413
+-0.003093069207180
+-0.003752709138394
+-0.004335842032518
+-0.004791036561067
+-0.005065896901708
+-0.005110393625977
+-0.004880531341136
+-0.004342141497596
+-0.003474552440639
+-0.002273866512301
+-0.000755569074022
+0.001043791014645
+0.003066074693975
+0.005232349737056
+0.007445108270683
+0.009591914070686
+0.011550392267690
+0.013194374469869
+0.014400916647725
+0.015057822646923
+0.015071239852832
+0.014372851474220
+0.012926176970464
+0.010731511371337
+0.007829086571387
+0.004300121746260
+0.000265542105793
+-0.004117720679811
+-0.008662784724937
+-0.013161015966894
+-0.017392005133004
+-0.021134828310565
+-0.024179988572089
+-0.026341362542747
+-0.027467442353889
+-0.027451174082956
+-0.026237749647954
+-0.023829808267231
+-0.020289641058874
+-0.015738160416732
+-0.010350584426843
+-0.004348984063748
+0.002007965395830
+0.008437510069590
+0.014646952702653
+0.020348619514297
+0.025274816776275
+0.029191922546358
+0.031912799091003
+0.033306802501012
+0.033306802501012
+0.031912799091003
+0.029191922546358
+0.025274816776275
+0.020348619514297
+0.014646952702653
+0.008437510069590
+0.002007965395830
+-0.004348984063748
+-0.010350584426843
+-0.015738160416732
+-0.020289641058874
+-0.023829808267231
+-0.026237749647954
+-0.027451174082956
+-0.027467442353889
+-0.026341362542747
+-0.024179988572089
+-0.021134828310565
+-0.017392005133004
+-0.013161015966894
+-0.008662784724937
+-0.004117720679811
+0.000265542105793
+0.004300121746260
+0.007829086571387
+0.010731511371337
+0.012926176970464
+0.014372851474220
+0.015071239852832
+0.015057822646923
+0.014400916647725
+0.013194374469869
+0.011550392267690
+0.009591914070686
+0.007445108270683
+0.005232349737056
+0.003066074693975
+0.001043791014645
+-0.000755569074022
+-0.002273866512301
+-0.003474552440639
+-0.004342141497596
+-0.004880531341136
+-0.005110393625977
+-0.005065896901708
+-0.004791036561067
+-0.004335842032518
+-0.003752709138394
+-0.003093069207180
+-0.002404560097413
+-0.001728812049767
+-0.001099907499859
+-0.000543522585638
+-0.000076712399583
+0.000291735390707
+0.000560481454052
+0.000734470039326
+0.000823544777911
+0.000840968137778
+0.000801956436836
+0.000722325000401
+0.000617316702010
+0.000500663878315
+0.000383910412105
+0.000275999286425
+0.000183112390286
+0.000108734631082
+0.000053903875864
+0.000017601906621
+-0.000002760884392
+-0.000010813464264
+-0.000010687686793
+-0.000006514842866
+-0.000001986047624
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp1_1314w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp1_1314w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+-0.000001841754824
+-0.000005027075408
+-0.000004867887939
+0.000004073105869
+0.000026732472769
+0.000066179835181
+0.000122341667551
+0.000191035477555
+0.000263522395484
+0.000326744999815
+0.000364347677654
+0.000358482947000
+0.000292296714071
+0.000152869769494
+-0.000065713808671
+-0.000359582460625
+-0.000713029663874
+-0.001097643610586
+-0.001472980725553
+-0.001789012865820
+-0.001990385107085
+-0.002022287881055
+-0.001837498039736
+-0.001403908679209
+-0.000711680924326
+0.000220954921947
+0.001344219285745
+0.002576467563514
+0.003807626837584
+0.004906603472238
+0.005732426023779
+0.006148395316111
+0.006038039262772
+0.005321276269398
+0.003968937881856
+0.002013738593543
+-0.000444059639242
+-0.003237650684246
+-0.006142117454636
+-0.008890294577414
+-0.011195208643236
+-0.012777396225865
+-0.013394656649373
+-0.012871256772288
+-0.011123352678771
+-0.008177485381462
+-0.004179465828936
+0.000608231482702
+0.005821359848003
+0.011020600962442
+0.015728278104176
+0.019472058560554
+0.021831635637600
+0.022483762917303
+0.021240859035081
+0.018078757814572
+0.013150038472393
+0.006780668529392
+-0.000550690451348
+-0.008249587971732
+-0.015656026097676
+-0.022103635460143
+-0.026982253797706
+-0.029797782343571
+-0.030223225882464
+-0.028135496240624
+-0.023633826165366
+-0.017037383911390
+-0.008861725526251
+0.000224138957343
+0.009456283539653
+0.018044570981795
+0.025244963849405
+0.030428419242262
+0.033139601183960
+0.033139601183960
+0.030428419242262
+0.025244963849405
+0.018044570981795
+0.009456283539653
+0.000224138957343
+-0.008861725526251
+-0.017037383911390
+-0.023633826165366
+-0.028135496240624
+-0.030223225882464
+-0.029797782343571
+-0.026982253797706
+-0.022103635460143
+-0.015656026097676
+-0.008249587971732
+-0.000550690451348
+0.006780668529392
+0.013150038472393
+0.018078757814572
+0.021240859035081
+0.022483762917303
+0.021831635637600
+0.019472058560554
+0.015728278104176
+0.011020600962442
+0.005821359848003
+0.000608231482702
+-0.004179465828936
+-0.008177485381462
+-0.011123352678771
+-0.012871256772288
+-0.013394656649373
+-0.012777396225865
+-0.011195208643236
+-0.008890294577414
+-0.006142117454636
+-0.003237650684246
+-0.000444059639242
+0.002013738593543
+0.003968937881856
+0.005321276269398
+0.006038039262772
+0.006148395316111
+0.005732426023779
+0.004906603472238
+0.003807626837584
+0.002576467563514
+0.001344219285745
+0.000220954921947
+-0.000711680924326
+-0.001403908679209
+-0.001837498039736
+-0.002022287881055
+-0.001990385107085
+-0.001789012865820
+-0.001472980725553
+-0.001097643610586
+-0.000713029663874
+-0.000359582460625
+-0.000065713808671
+0.000152869769494
+0.000292296714071
+0.000358482947000
+0.000364347677654
+0.000326744999815
+0.000263522395484
+0.000191035477555
+0.000122341667551
+0.000066179835181
+0.000026732472769
+0.000004073105869
+-0.000004867887939
+-0.000005027075408
+-0.000001841754824
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp1_6w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp1_6w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+0.000000300496291
+-0.000003105802753
+-0.000016001307594
+-0.000040610947867
+-0.000073048656958
+-0.000102509204330
+-0.000112823683055
+-0.000086408383226
+-0.000009950190603
+0.000119455794522
+0.000289402966377
+0.000470229172208
+0.000617356341584
+0.000678415802928
+0.000604538362095
+0.000363981075341
+-0.000044750808494
+-0.000583662886373
+-0.001173117534066
+-0.001698995649725
+-0.002029689391275
+-0.002041248470532
+-0.001646750936007
+-0.000824171715922
+0.000363818763542
+0.001764204558019
+0.003146248217552
+0.004233273880153
+0.004750467360950
+0.004481500127515
+0.003323603482096
+0.001329253560244
+-0.001276526206734
+-0.004110902087099
+-0.006682177321149
+-0.008468343744915
+-0.009013825064486
+-0.008027603201872
+-0.005463265736290
+-0.001562521722842
+0.003151335301880
+0.007935220681023
+0.011938118892333
+0.014347247913690
+0.014544155012138
+0.012241693136944
+0.007573444162033
+0.001113482054859
+-0.006184305544944
+-0.013123589147486
+-0.018460785480555
+-0.021126408399641
+-0.020433231105168
+-0.016231215113948
+-0.008976151127902
+0.000307170351047
+0.010167904513113
+0.018958948941165
+0.025116811395464
+0.027443178163042
+0.025336721044510
+0.018930145994407
+0.009102761288062
+-0.002639563309140
+-0.014401089331813
+-0.024211490294053
+-0.030365794626673
+-0.031728673755950
+-0.027947356635357
+-0.019532507094579
+-0.007789369984699
+0.005391735699747
+0.017850849544679
+0.027525284153062
+0.032803558956913
+0.032803558956913
+0.027525284153062
+0.017850849544679
+0.005391735699747
+-0.007789369984699
+-0.019532507094579
+-0.027947356635357
+-0.031728673755950
+-0.030365794626673
+-0.024211490294053
+-0.014401089331813
+-0.002639563309140
+0.009102761288062
+0.018930145994407
+0.025336721044510
+0.027443178163042
+0.025116811395464
+0.018958948941165
+0.010167904513113
+0.000307170351047
+-0.008976151127902
+-0.016231215113948
+-0.020433231105168
+-0.021126408399641
+-0.018460785480555
+-0.013123589147486
+-0.006184305544944
+0.001113482054859
+0.007573444162033
+0.012241693136944
+0.014544155012138
+0.014347247913690
+0.011938118892333
+0.007935220681023
+0.003151335301880
+-0.001562521722842
+-0.005463265736290
+-0.008027603201872
+-0.009013825064486
+-0.008468343744915
+-0.006682177321149
+-0.004110902087099
+-0.001276526206734
+0.001329253560244
+0.003323603482096
+0.004481500127515
+0.004750467360950
+0.004233273880153
+0.003146248217552
+0.001764204558019
+0.000363818763542
+-0.000824171715922
+-0.001646750936007
+-0.002041248470532
+-0.002029689391275
+-0.001698995649725
+-0.001173117534066
+-0.000583662886373
+-0.000044750808494
+0.000363981075341
+0.000604538362095
+0.000678415802928
+0.000617356341584
+0.000470229172208
+0.000289402966377
+0.000119455794522
+-0.000009950190603
+-0.000086408383226
+-0.000112823683055
+-0.000102509204330
+-0.000073048656958
+-0.000040610947867
+-0.000016001307594
+-0.000003105802753
+0.000000300496291
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp2_2627w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp2_2627w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+-0.000000119645883
+-0.000006274830613
+-0.000023232579688
+-0.000044985941115
+-0.000053657956625
+-0.000027118605241
+0.000046921630555
+0.000156945616540
+0.000262164711191
+0.000301699980562
+0.000218589909420
+-0.000008803196068
+-0.000341372250224
+-0.000674287603097
+-0.000861422200172
+-0.000767003515899
+-0.000329236347182
+0.000388975446774
+0.001188124209668
+0.001774889320409
+0.001856123369379
+0.001257964021785
+0.000027107540558
+-0.001531556867213
+-0.002911270179691
+-0.003552683656637
+-0.003047480881725
+-0.001327849515957
+0.001235210614491
+0.003881357036178
+0.005668114652644
+0.005786540332493
+0.003885283574487
+0.000282034176512
+-0.004036589345631
+-0.007662062374128
+-0.009205982236476
+-0.007804041098153
+-0.003505675404256
+0.002610238375784
+0.008674655035159
+0.012584131706272
+0.012713625121329
+0.008549217526956
+0.001003587299857
+-0.007736261401735
+-0.014827996371875
+-0.017690804678714
+-0.014926627493298
+-0.006920858659258
+0.004120141375978
+0.014760356071590
+0.021403403545965
+0.021507440923424
+0.014534779699922
+0.002286067118717
+-0.011542111085697
+-0.022478003633555
+-0.026733060566418
+-0.022518204993947
+-0.010758533247365
+0.005071472878777
+0.019982045843567
+0.029062109696994
+0.029117303360920
+0.019798851343624
+0.003821856980351
+-0.013832835808481
+-0.027496968683526
+-0.032665275832763
+-0.027504091557784
+-0.013505356031542
+0.004948846537643
+0.021983134958431
+0.032133902200591
+0.032133902200591
+0.021983134958431
+0.004948846537643
+-0.013505356031542
+-0.027504091557784
+-0.032665275832763
+-0.027496968683526
+-0.013832835808481
+0.003821856980351
+0.019798851343624
+0.029117303360920
+0.029062109696994
+0.019982045843567
+0.005071472878777
+-0.010758533247365
+-0.022518204993947
+-0.026733060566418
+-0.022478003633555
+-0.011542111085697
+0.002286067118717
+0.014534779699922
+0.021507440923424
+0.021403403545965
+0.014760356071590
+0.004120141375978
+-0.006920858659258
+-0.014926627493298
+-0.017690804678714
+-0.014827996371875
+-0.007736261401735
+0.001003587299857
+0.008549217526956
+0.012713625121329
+0.012584131706272
+0.008674655035159
+0.002610238375784
+-0.003505675404256
+-0.007804041098153
+-0.009205982236476
+-0.007662062374128
+-0.004036589345631
+0.000282034176512
+0.003885283574487
+0.005786540332493
+0.005668114652644
+0.003881357036178
+0.001235210614491
+-0.001327849515957
+-0.003047480881725
+-0.003552683656637
+-0.002911270179691
+-0.001531556867213
+0.000027107540558
+0.001257964021785
+0.001856123369379
+0.001774889320409
+0.001188124209668
+0.000388975446774
+-0.000329236347182
+-0.000767003515899
+-0.000861422200172
+-0.000674287603097
+-0.000341372250224
+-0.000008803196068
+0.000218589909420
+0.000301699980562
+0.000262164711191
+0.000156945616540
+0.000046921630555
+-0.000027118605241
+-0.000053657956625
+-0.000044985941115
+-0.000023232579688
+-0.000006274830613
+-0.000000119645883
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp3_2w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp3_2w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+-0.000002594841140
+-0.000009126473319
+-0.000004703891815
+0.000026410344499
+0.000072426112793
+0.000085938353322
+0.000017069697235
+-0.000129361106708
+-0.000263251892270
+-0.000250013573817
+-0.000015725075315
+0.000354453071071
+0.000617361990571
+0.000511381639045
+-0.000032848354644
+-0.000761789830387
+-0.001183970788737
+-0.000873795737251
+0.000177487213542
+0.001424349056188
+0.002012391725042
+0.001327476410819
+-0.000484094078124
+-0.002421847674618
+-0.003141642420480
+-0.001841961665971
+0.001033614052526
+0.003830006831458
+0.004588161993616
+0.002361293604043
+-0.001915205327769
+-0.005706283491349
+-0.006334115616564
+-0.002803586502866
+0.003214599098532
+0.008074224764394
+0.008319068471282
+0.003066299632180
+-0.004998846368457
+-0.010909352770575
+-0.010437515536587
+-0.003037403423928
+0.007299753228011
+0.014129692570654
+0.012543868574544
+0.002611308338695
+-0.010099043129223
+-0.017593611788775
+-0.014465174473947
+-0.001707207980063
+0.013318448717407
+0.021106583582881
+0.016020324189515
+0.000286653177517
+-0.016817434894015
+-0.024436986991763
+-0.017043119025469
+0.001633064993268
+0.020400137719482
+0.027339398714528
+0.017405590947757
+-0.003972693839205
+-0.023831556507188
+-0.029582336665792
+-0.017037650067293
+0.006593838959585
+0.026861348045926
+0.030976398484514
+0.015939552589431
+-0.009311164591318
+-0.029252076269503
+-0.031398422753260
+-0.014184791972223
+0.011912616492368
+0.030807776930097
+0.030807776930097
+0.011912616492368
+-0.014184791972223
+-0.031398422753260
+-0.029252076269503
+-0.009311164591318
+0.015939552589431
+0.030976398484514
+0.026861348045926
+0.006593838959585
+-0.017037650067293
+-0.029582336665792
+-0.023831556507188
+-0.003972693839205
+0.017405590947757
+0.027339398714528
+0.020400137719482
+0.001633064993268
+-0.017043119025469
+-0.024436986991763
+-0.016817434894015
+0.000286653177517
+0.016020324189515
+0.021106583582881
+0.013318448717407
+-0.001707207980063
+-0.014465174473947
+-0.017593611788775
+-0.010099043129223
+0.002611308338695
+0.012543868574544
+0.014129692570654
+0.007299753228011
+-0.003037403423928
+-0.010437515536587
+-0.010909352770575
+-0.004998846368457
+0.003066299632180
+0.008319068471282
+0.008074224764394
+0.003214599098532
+-0.002803586502866
+-0.006334115616564
+-0.005706283491349
+-0.001915205327769
+0.002361293604043
+0.004588161993616
+0.003830006831458
+0.001033614052526
+-0.001841961665971
+-0.003141642420480
+-0.002421847674618
+-0.000484094078124
+0.001327476410819
+0.002012391725042
+0.001424349056188
+0.000177487213542
+-0.000873795737251
+-0.001183970788737
+-0.000761789830387
+-0.000032848354644
+0.000511381639045
+0.000617361990571
+0.000354453071071
+-0.000015725075315
+-0.000250013573817
+-0.000263251892270
+-0.000129361106708
+0.000017069697235
+0.000085938353322
+0.000072426112793
+0.000026410344499
+-0.000004703891815
+-0.000009126473319
+-0.000002594841140
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp4_5255w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp4_5255w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+-0.000002652355966
+-0.000003689263438
+0.000017867429768
+0.000042818007041
+0.000005476936737
+-0.000094554799453
+-0.000122292280163
+0.000039467227379
+0.000256579018493
+0.000208423481740
+-0.000187565935826
+-0.000510718303326
+-0.000240726349420
+0.000495375743852
+0.000831725183910
+0.000132387413946
+-0.001003824053074
+-0.001151151603489
+0.000220320826169
+0.001717530305239
+0.001351744184779
+-0.000918488146989
+-0.002582825769990
+-0.001272643692914
+0.002031242609261
+0.003470754914719
+0.000729552942821
+-0.003560757342545
+-0.004172758183602
+0.000449129677776
+0.005409488038768
+0.004415908979679
+-0.002373981570967
+-0.007360002796350
+-0.003901097887376
+0.005042958938748
+0.009077635186769
+0.002361861132806
+-0.008299368475524
+-0.010142816083498
+0.000365073565302
+0.011813334960192
+0.010113603165734
+-0.004272143322987
+-0.015097981033230
+-0.008610912928338
+0.009133670086701
+0.017565046863748
+0.005411301508100
+-0.014495013257299
+-0.018615582346331
+-0.000527098555465
+0.019708251120170
+0.017751763085004
+-0.005746892332412
+-0.024014865629065
+-0.014688370858434
+0.012836239109820
+0.026664721437227
+0.009439337137305
+-0.019946004717445
+-0.027050649444179
+-0.002357327138151
+0.026170701877662
+0.024831893101433
+-0.005887419584481
+-0.030637500574521
+-0.020019475193190
+0.014390452597945
+0.032656093140260
+0.013002725392225
+-0.022146496074870
+-0.031845194543385
+-0.004507680847318
+0.028208995034275
+0.028208995034275
+-0.004507680847318
+-0.031845194543385
+-0.022146496074870
+0.013002725392225
+0.032656093140260
+0.014390452597945
+-0.020019475193190
+-0.030637500574521
+-0.005887419584481
+0.024831893101433
+0.026170701877662
+-0.002357327138151
+-0.027050649444179
+-0.019946004717445
+0.009439337137305
+0.026664721437227
+0.012836239109820
+-0.014688370858434
+-0.024014865629065
+-0.005746892332412
+0.017751763085004
+0.019708251120170
+-0.000527098555465
+-0.018615582346331
+-0.014495013257299
+0.005411301508100
+0.017565046863748
+0.009133670086701
+-0.008610912928338
+-0.015097981033230
+-0.004272143322987
+0.010113603165734
+0.011813334960192
+0.000365073565302
+-0.010142816083498
+-0.008299368475524
+0.002361861132806
+0.009077635186769
+0.005042958938748
+-0.003901097887376
+-0.007360002796350
+-0.002373981570967
+0.004415908979679
+0.005409488038768
+0.000449129677776
+-0.004172758183602
+-0.003560757342545
+0.000729552942821
+0.003470754914719
+0.002031242609261
+-0.001272643692914
+-0.002582825769990
+-0.000918488146989
+0.001351744184779
+0.001717530305239
+0.000220320826169
+-0.001151151603489
+-0.001003824053074
+0.000132387413946
+0.000831725183910
+0.000495375743852
+-0.000240726349420
+-0.000510718303326
+-0.000187565935826
+0.000208423481740
+0.000256579018493
+0.000039467227379
+-0.000122292280163
+-0.000094554799453
+0.000005476936737
+0.000042818007041
+0.000017867429768
+-0.000003689263438
+-0.000002652355966
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/FIR filter coefficients/bp6_4w0_2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/FIR filter coefficients/bp6_4w0_2.txt Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,154 @@
+Numerator:
+0.000000000000000
+0.000002394814687
+0.000004390433216
+-0.000023340445455
+-0.000015218637292
+0.000069950874081
+0.000028232414067
+-0.000147398492352
+-0.000038027794457
+0.000261005709191
+0.000037825501771
+-0.000416033593584
+-0.000019259458124
+0.000617361334319
+-0.000027786282773
+-0.000869059050743
+0.000115254072563
+0.001173868619562
+-0.000256866422525
+-0.001532619315290
+0.000467926260819
+0.001943616117611
+-0.000764942010166
+-0.002402047468499
+0.001165067831194
+0.002899465132079
+-0.001685363624880
+-0.003423390885153
+0.002341894853122
+0.003957102574611
+-0.003148707759102
+-0.004479645462927
+0.004116729915757
+0.004966103927966
+-0.005252657989709
+-0.005388154013157
+0.006557903083728
+0.005714899878762
+-0.008027668123371
+-0.005913977988810
+0.009650230875156
+0.005952893177277
+-0.011406500056782
+-0.005800531969051
+0.013269900730415
+0.005428782085186
+-0.015206629244147
+-0.004814174235313
+0.017176298249715
+0.003939454188936
+-0.019132969931534
+-0.002794990530034
+0.021026551925418
+0.001379926888150
+-0.022804507021892
+0.000297003143682
+0.024413806214867
+-0.002217065111844
+-0.025803036476203
+0.004351563552063
+0.026924561135382
+-0.006662355555900
+-0.027736622968670
+0.009102834904669
+0.028205278744645
+-0.011619356751574
+-0.028306059310647
+0.014153046911732
+0.028025261175594
+-0.016641916522328
+-0.027360793349507
+0.019023183695226
+0.026322525937199
+-0.021235690087601
+-0.024932113310927
+0.023222293009525
+0.023222293009525
+-0.024932113310927
+-0.021235690087601
+0.026322525937199
+0.019023183695226
+-0.027360793349507
+-0.016641916522328
+0.028025261175594
+0.014153046911732
+-0.028306059310647
+-0.011619356751574
+0.028205278744645
+0.009102834904669
+-0.027736622968670
+-0.006662355555900
+0.026924561135382
+0.004351563552063
+-0.025803036476203
+-0.002217065111844
+0.024413806214867
+0.000297003143682
+-0.022804507021892
+0.001379926888150
+0.021026551925418
+-0.002794990530034
+-0.019132969931534
+0.003939454188936
+0.017176298249715
+-0.004814174235313
+-0.015206629244147
+0.005428782085186
+0.013269900730415
+-0.005800531969051
+-0.011406500056782
+0.005952893177277
+0.009650230875156
+-0.005913977988810
+-0.008027668123371
+0.005714899878762
+0.006557903083728
+-0.005388154013157
+-0.005252657989709
+0.004966103927966
+0.004116729915757
+-0.004479645462927
+-0.003148707759102
+0.003957102574611
+0.002341894853122
+-0.003423390885153
+-0.001685363624880
+0.002899465132079
+0.001165067831194
+-0.002402047468499
+-0.000764942010166
+0.001943616117611
+0.000467926260819
+-0.001532619315290
+-0.000256866422525
+0.001173868619562
+0.000115254072563
+-0.000869059050743
+-0.000027786282773
+0.000617361334319
+-0.000019259458124
+-0.000416033593584
+0.000037825501771
+0.000261005709191
+-0.000038027794457
+-0.000147398492352
+0.000028232414067
+0.000069950874081
+-0.000015218637292
+-0.000023340445455
+0.000004390433216
+0.000002394814687
+Denominator:
+1.000000000000000
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/abs.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/abs.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+% function sig=abs(sig)
+% calculates the abs value of the signal
+%
+% INPUT VALUES:
+% sig: original @signal
+%
+% 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=abs(sig)
+
+s=abs(sig.werte);
+sig.werte=s;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/absmax.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/absmax.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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 [m,x]=absmax(sig)
+% returns the maximum absolut value of the signal
+
+val=getdata(sig);
+[m,x]=max(abs(val));
+x=bin2time(sig,x-1);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/add.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/add.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,105 @@
+% method of class @signal
+% function sigresult=add(sig1,sig2,[start_time],[duration])
+% INPUT VALUES:
+% sig1: first @signal
+% sig2: second @signal or struct
+% start_time: start time for the addition. [default: 0]
+% duration: duration of the signal, that is added [default: getlength(sig2)]
+% RETURN VALUE:
+% sigresult: @signal that is the sum of signals sig1 and sig2`
+% the resulting signal can be longer then sig1 or sig2, when start_time
+% and duration is according. sig2 can be a signal-object or an struct
+%
+%
+% (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=add(a,b,start_time,dauer)
+
+if nargin < 4
+ if isobject(b)
+ dauer=getlength(b);
+ end
+end
+if nargin < 3
+ start_time=0;
+end
+
+% wenn ein Spaltenvektor hinaufaddier werden soll
+if isnumeric(b)
+ sr=GetSR(a);
+ nr=size(b)
+ if nr>1
+ temp=signal(b,sr); % erzeuge ein neues Signal aus den Werten
+ sig=add(a,temp); % und lasse dann die beiden Signale zusammenaddieren
+ else
+ sig=a+b;
+ end
+ return;
+end
+
+
+
+% das resultierede Signal kann länger sein als die Ausgangssignale
+% erst feststellen, wie lang das nachher sein soll
+laenge1=getlength(a);
+laenge2=getlength(b); %so lang ist das zweite Signal
+if laenge2 binl2 % wenn das neue Signal länger wird
+ temp=signal(lneu,sr1,a.name,a.unit_x,a.unit_y,a.start_time);
+ % kopiere zuerst das alte Signal
+ start=1;
+ stop=time2bin(a,laenge1+getminimumtime(a));
+ temp.werte(start:stop)=a.werte(start:stop);
+ % rekursiver Aufruf, denn nun ist das Signal lang genug
+ sig=add(temp,b,start_time,dauer);
+ return;
+end
+
+% normalfall: Das Ergebnissignal ist nun höchstens genauso lang
+sig=a; %kopieren des alten Signals in das Rückgabesignal
+start1=time2bin(a,start_time)+1;
+% stop1=time2bin(a,start_time+dauer-1/sr1);
+stop1=time2bin(a,start_time+dauer);
+start2=1;
+stop2=time2bin(a,dauer+getminimumtime(a));
+
+% do some error checking:
+if stop2-start2 == stop1-start1
+ sig.werte(start1:stop1)=sig.werte(start1:stop1)+b.werte(start2:stop2);
+else
+ if start1>1
+ stop1=start1+stop2-start2;
+ sig.werte(start1:stop1)=sig.werte(start1:stop1)+b.werte(start2:stop2);
+ else
+
+ disp('signal::add problem with adding - havent added')
+ end
+end
+
+return;
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/addtimevalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/addtimevalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @signal
+% function sig=addtimevalue(sig,time,val)
+%usage: sig=addtimevalue(sig,time,val)
+% adds the double time value "time" to "val"
+%
+% INPUT VALUES:
+% sig: original @signal
+% time: time in seconds, where the value is added
+% val: value, that is added at time
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=addtimevalue(sig,time,val)
+
+nr=time2bin(sig,time);
+sig.werte(nr)=sig.werte(nr)+val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/antitilt.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/antitilt.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,48 @@
+% method of class @signal
+% usage: sigresult=tilt(sig,tilttime)
+% puts the signal upright!
+% in the auditory image model, all activities become
+% smaller with the distance
+% usually with a decrease of 100% in 40 ms
+% if you call tilt with tilt(sig,0.04), this tilt is reversed
+%
+% INPUT VALUES:
+% sig: original @signal
+% tilttime: time in seconds that the old signal is assumed to go from 100% to 0
+% [default: 0.04]
+%
+% RETURN VALUE:
+% sigresult: @signal
+%
+% (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=antitilt(sig,tilttime)
+
+if nargin<2
+ tilttime=0.04;
+end
+
+vals=sig.werte;
+
+if getminimumtime(sig)>0
+ return
+end
+durationtotilt=abs(getminimumtime(sig));
+tiltnr=time2bin(sig,0); % so viele Punkte werden getiltet
+dt=tilttime-durationtotilt; % übrige Zeit, die links aus dem Bild rausgeht
+dnull=dt/tilttime;
+ti=linspace(dnull,1,tiltnr)';
+vals(1:tiltnr)=vals(1:tiltnr)./ti;
+% figure
+% subplot(2,1,1)
+% plot(sig);
+sig.werte=vals;
+% subplot(2,1,2)
+% plot(sig);
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/append.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/append.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% method of class @signal
+% function sigresult=append(sig1,sig2)
+% appends the second signal behind the first
+%
+% INPUT VALUES:
+% sig1: first @signal
+% sig2: second @signal
+%
+% RETURN VALUE:
+% sigresult: @signal
+%
+% (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=append(sig,b)
+
+nr=max(size(b));
+
+if nr==1
+% b=setstarttime(b,getmaximumtime(sig));
+ a=[sig.werte' getvalues(b)'];
+ sig.werte=a';
+% sig=add(sig,b,getlength(sig));
+ return;
+end
+
+for i=1:nr
+ sig=add(sig,b{i},getlength(sig));
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/attenuate.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/attenuate.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,41 @@
+% method of class @signal
+%
+% INPUT VALUES:
+% sig,attenuation
+% sig is the signal
+% attenuation is the attenuation against the lowdest possible tone
+%
+%
+%
+% 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/11 10:46:32 $
+% $Revision: 1.1 $
+
+
+
+function sig=attenuate(sig,attenuation)
+
+if attenuation==0
+ return
+end
+
+dat=sig.werte;
+ma=max(dat);
+mi=min(dat);
+if -mi > ma
+ ma=-mi;
+end
+
+
+amphigh=max(sig);
+
+amp=amphigh / power(10,-attenuation/20);
+if amp>0
+ sig=scaletomaxvalue(sig,amp);
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/attenuate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/attenuate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% method of class @signal
+%
+% INPUT VALUES:
+% sig,attenuation
+% sig is the signa
+% attenuation is the attenuation against the lowdest possible tone
+% with amplitude =1
+% default=1
+%
+% 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=attenuate(sig,attenuation);
+
+amphigh=max(sig);
+amp=amphigh / power(10,-attenuation/20);
+sig=scaletomaxvalue(sig,amp);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/autocorrelate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/autocorrelate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,35 @@
+% method of class @signal
+% function sig=autocorrelate(sig,[delay_start],[delay_stop],[normalization_mode])
+%
+% calculates the auto corrlelation between of the signal sig
+% return value is a signal that covers the correlation between
+% between delay_start and delay_stop.
+%
+% INPUT VALUES:
+% sig: original @signal
+% delay_start: start of the correlation : default -length(sig)
+% delay_stop: longest delay of the correlation : default length(sig)
+% normalization_mode: normalizateion: default: 'biased' (see help 'xcorr')
+%
+% RETURN VALUE:
+% @sig: the correlation values at each delay
+%
+% (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=autocorrelate(sig,delay_start,delay_stop,normalization_mode)
+if nargin==1
+ sig=crosscorrelate(sig,sig);
+else if nargin==2
+ sig=crosscorrelate(sig,sig,delay_start);
+ else if nargin==3
+ sig=crosscorrelate(sig,sig,delay_start,delay_stop);
+ else if nargin==4
+ sig=crosscorrelate(sig,sig,delay_start,delay_stop,normalization_mode);
+ end
+ end
+ end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/average.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/average.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% method of class @signal
+% function [meansig,stdsig]=average(sig,[t_start],[t_stop])
+% calculates the average value of the signal
+%
+% INPUT VALUES:
+% sig: original @signal
+% t_start: start time in seconds [0]
+% t_stop: stop time in seconds [getlength(sig)]
+%
+% RETURN VALUE:
+% meansig: mean value of the signal
+% stdsug: standart deviation
+%
+% (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 [meana,stda]=average(sig,t_start,t_stop)
+
+
+if nargin < 2
+ t_start=getminimumtime(sig);
+end
+if nargin < 3
+ t_stop=t_start+getlength(sig);
+end
+
+intstart=time2bin(sig,t_start);
+intstop=time2bin(sig,t_stop);
+
+if intstart==0
+ intstart=1;
+end
+
+if intstart>intstop
+ error('signal::average: stoptime < starttime');
+end
+
+
+s=sig.werte(intstart:intstop);
+if max(size(s))>1
+ meana=mean(s);
+ stda=std(s);
+else
+ meana=s;
+ stda=0;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/bandpass.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/bandpass.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,120 @@
+% method of class @signal
+%
+% 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/07/17 10:56:16 $
+% $Revision: 1.2 $
+
+function filtered_sig=bandpass(sig,lowfrequency,highfrequency,stopbandwidth_low,stopbandwidth_high,ripple,stopbandatten)
+% hack for an phase true bandpassfilter with cutoff at frequency
+% used is a ButterworthFilter
+% this is all crap, but it does not work properly otherwise.
+
+grafix=0;
+
+if nargin < 7
+ stopbandatten=60; % in dB - how many dB the signal is reduced in the stopband at least
+end
+if nargin < 6
+ ripple=3; % in dB = ripple in the passband
+end
+if nargin < 5
+ stopbandwidth_high=highfrequency*2; % one octave above
+end
+if nargin < 4
+ stopbandwidth_low=lowfrequency/2; % one octave above
+end
+
+% I dont understand enough to make it work with a butterwort filer.
+% easy solution: first perform a lowpass, then a highpass filter...
+% sorry, Thanks for any help!
+if grafix
+ figure(23534)
+ plot(powerspectrum(sig),[100,getsr(sig)/2],'b')
+ hold on
+end
+
+if highfrequency>0
+ filtered_sig_low=lowpass(sig,highfrequency,highfrequency+stopbandwidth_high,ripple,stopbandatten);
+else
+ filtered_sig_low=sig;
+end
+
+if grafix
+ figure(23534)
+ plot(powerspectrum(filtered_sig_low),[100,getsr(filtered_sig_low)/2],'r')
+end
+
+
+if lowfrequency>0
+ filtered_sig=highpass(filtered_sig_low,lowfrequency,lowfrequency-stopbandwidth_low,ripple,stopbandatten);
+if grafix
+ figure(23534)
+ plot(powerspectrum(filtered_sig),[100,getsr(filtered_sig_low)/2],'g')
+end
+
+
+return
+
+
+% if nargin < 4
+% ripple=1; % in dB = ripple in the passband
+% end
+% if nargin <3
+% stopband=frequency*2; % eine Oktave drüber
+% end
+
+ripple=3;
+
+nyquist=getsr(sig)/2;
+% fre_low=2;
+% fre_high=frequency;
+
+Wpass=[lowfrequency highfrequency]/nyquist;
+Wstop=[lowfrequency-stopbandwidth highfrequency+stopbandwidth]/nyquist;
+[n,Wn] = buttord(Wpass,Wstop,ripple,stopbandatten);
+% [n,Wn] = buttord(fre_high/nyquist,(fre_high+stopband)/nyquist,ripple,stopbandatten);
+% Berechne den IIR-Filter
+[b,a] = butter(n,Wn);
+
+% zum testen:
+freqz(b,a,128,getsr(sig))
+
+vals=sig.werte';
+
+% fill the part behind the signal and in front of the signal with
+% values
+% firstval=vals(1);
+% lastval=vals(end);
+% nr_vals=length(vals);
+% vals=[ones(1,nr_vals)*firstval vals ones(1,nr_vals)*lastval];
+
+plot(vals)
+hold on
+
+nvals = filter(b,a,vals);
+% nvals = filtfilt(b,a,vals);
+% extract the values back
+% nvals=nvals(nr_vals+1:2*nr_vals);
+
+plot(nvals,'r')
+
+% filtered_sig=0;
+% return
+
+filtered_sig=sig; % a copy of the old one
+newname=sprintf('Bandpass filterd (%3.2fkHz - %3.2fkHz) Signal: %s',lowfrequency/1000,highfrequency/1000,getname(sig));
+filtered_sig=setname(filtered_sig,newname);
+filtered_sig.werte=nvals';
+
+% figure(235423)
+% plot(sig);
+% hold on
+% plot(filtered_sig,'g');
+% s=0;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/bandpass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/bandpass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,110 @@
+% method of class @signal
+%
+% 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 filtered_sig=bandpass(sig,lowfrequency,highfrequency,stopbandwidth_low,stopbandwidth_high,ripple,stopbandatten)
+% hack for an phase true bandpassfilter with cutoff at frequency
+% used is a ButterworthFilter
+% this is all crap, but it does not work properly otherwise.
+
+grafix=0;
+
+if nargin < 6
+ stopbandatten=60; % in dB - how many dB the signal is reduced in the stopband at least
+end
+if nargin < 5
+ ripple=3; % in dB = ripple in the passband
+end
+
+
+% I dont understand enough to make it work with a butterwort filer.
+% easy solution: first perform a lowpass, then a highpass filter...
+% sorry, Thanks for any help!
+if grafix
+ figure(23534)
+ plot(powerspectrum(sig),[100,getsr(sig)/2],'b')
+ hold on
+end
+
+filtered_sig_low=lowpass(sig,highfrequency,highfrequency+stopbandwidth_high,ripple,stopbandatten);
+
+if grafix
+ figure(23534)
+ plot(powerspectrum(filtered_sig_low),[100,getsr(filtered_sig_low)/2],'r')
+end
+
+
+filtered_sig=highpass(filtered_sig_low,lowfrequency,lowfrequency-stopbandwidth_low,ripple,stopbandatten);
+if grafix
+ figure(23534)
+ plot(powerspectrum(filtered_sig),[100,getsr(filtered_sig_low)/2],'g')
+end
+
+
+return
+
+
+% if nargin < 4
+% ripple=1; % in dB = ripple in the passband
+% end
+% if nargin <3
+% stopband=frequency*2; % eine Oktave drüber
+% end
+
+ripple=3;
+
+nyquist=getsr(sig)/2;
+% fre_low=2;
+% fre_high=frequency;
+
+Wpass=[lowfrequency highfrequency]/nyquist;
+Wstop=[lowfrequency-stopbandwidth highfrequency+stopbandwidth]/nyquist;
+[n,Wn] = buttord(Wpass,Wstop,ripple,stopbandatten);
+% [n,Wn] = buttord(fre_high/nyquist,(fre_high+stopband)/nyquist,ripple,stopbandatten);
+% Berechne den IIR-Filter
+[b,a] = butter(n,Wn);
+
+% zum testen:
+freqz(b,a,128,getsr(sig))
+
+vals=sig.werte';
+
+% fill the part behind the signal and in front of the signal with
+% values
+% firstval=vals(1);
+% lastval=vals(end);
+% nr_vals=length(vals);
+% vals=[ones(1,nr_vals)*firstval vals ones(1,nr_vals)*lastval];
+
+plot(vals)
+hold on
+
+nvals = filter(b,a,vals);
+% nvals = filtfilt(b,a,vals);
+% extract the values back
+% nvals=nvals(nr_vals+1:2*nr_vals);
+
+plot(nvals,'r')
+
+% filtered_sig=0;
+% return
+
+filtered_sig=sig; % a copy of the old one
+newname=sprintf('Bandpass filterd (%3.2fkHz - %3.2fkHz) Signal: %s',lowfrequency/1000,highfrequency/1000,getname(sig));
+filtered_sig=setname(filtered_sig,newname);
+filtered_sig.werte=nvals';
+
+% figure(235423)
+% plot(sig);
+% hold on
+% plot(filtered_sig,'g');
+% s=0;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/bin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/bin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+
+% calculate the binned version of the signal
+function retsig=bin(sig,binwidth)
+
+
+new_sr=1/binwidth; % the sr of the binned signal
+old_sr=getsr(sig);
+
+cvals=getvalues(sig);
+nrbinspro=old_sr/new_sr;
+nr_bins=round(getlength(sig)/binwidth);
+new_val=zeros(nr_bins,1);
+
+for k=1:nr_bins
+ start_bin=round((k-1)*nrbinspro+1);
+ stop_bin=round(k*nrbinspro);
+ stop_bin=min(stop_bin,length(cvals));
+ new_val(k)=sum(cvals(start_bin:stop_bin));
+end
+retsig=signal(new_val);
+retsig=setsr(retsig,new_sr);
+retsig=setname(retsig,sprintf('binned signal %s with binwidth %3.2fms',getname(sig),binwidth*1000));
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/bin2time.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/bin2time.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% method of class @signal
+% function res=bin2time(sig,bin)
+% calculates the time according to the value of the bin in
+%
+% INPUT VALUES:
+% sig: original @signal
+% bin: value of bin (not necessary integer)
+%
+% RETURN VALUE:
+% res: time of bin in seconds
+%
+% (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 res=bin2time(sig,val)
+% gibt die Zeit zurück, bei dem dieses Bin ist
+% Zeit immer in Sekunden
+% Samplerate immer in Bins pro Sekunde (96 kHz)
+sr=sig.samplerate;
+% eines abgezogen, weil Matlab bei 1 startet also bin 1der Anfangszeitpunkt ist
+% res=(val-1)/sr;
+res=val/sr;
+
+res=res+sig.start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/buildfrompoints.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/buildfrompoints.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,40 @@
+% method of class @signal
+% function sig=buildfrompoints(sig,xx,yy)
+% calculates a @signal from the points in x and y
+%
+% INPUT VALUES:
+% sig: original @signal
+% xx: x-values of points
+% yy: y-values of points
+%
+% RETURN VALUE:
+% sig: new @signal
+%
+% (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=buildfrompoints(sig,xx,yy)
+
+
+x1=1;
+y1=0;
+
+sig=mute(sig);
+
+nr_points=length(xx);
+for i=1:nr_points
+ x2=round(time2bin(sig,xx(i)));
+ y2=yy(i);
+
+ line=linspace(y1,y2,x2-x1+1);
+ sig=setvalues(sig,line,x1);
+
+ x1=x2+1;
+ y1=y2;
+
+end
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/buildspikesfrompoints.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/buildspikesfrompoints.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,35 @@
+% method of class @signal
+% function sig=buildspikesfrompoints(sig,xx,yy)
+% calculates a @signal from the points in x and y
+% the new signal is zero everywhere except from the points in xx
+%
+% INPUT VALUES:
+% sig: original @signal
+% xx: x-values of points
+% yy: y-values of points
+%
+% RETURN VALUE:
+% sig: new @signal
+%
+% (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=buildspikesfrompoints(sig,xx,yy)
+% uage: sig=buildspikesfrompoints(sig,xx,yy)
+% makes a dot of the hight given in yy at each point given in xx
+% all other values =0
+
+
+sig=mute(sig);
+
+nr_points=length(xx);
+for i=1:nr_points
+ oldval=gettimevalue(sig,xx(i));
+ newval=oldval+yy(i);
+ sig=addtimevalue(sig,xx(i),newval);
+end
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/calculatephase.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/calculatephase.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,45 @@
+function [phase,vectorstrength,strength]=calculatephase(stim,freq,grafix)
+
+% calculates the phase in radian for the stimulus in stim given a frequency
+% of freq.
+if nargin<3
+ grafix=0;
+end
+
+vals=getvalues(stim);
+
+nrvals=length(vals);
+modphase=time2bin(stim,1/freq);
+% vectorstrength=signal(length(modphase),1);
+vectorstrength=zeros(modphase,1);
+sr=getsr(stim);
+for i=1:nrvals
+ intphase=mod(i,modphase)+1;
+ vectorstrength(intphase)=vectorstrength(intphase)+vals(i);
+end
+
+[strength,maxintphase]=max(vectorstrength);
+phase=maxintphase/modphase*2*pi;
+
+
+if grafix
+ figure(5423)
+ clf
+ plot(vectorstrength);
+ set(gca,'ylim',[min(vectorstrength)*1.1 max(vectorstrength)*1.1]);
+ xlabel('phase')
+ phases=get(gca,'xtick');
+ phases=phases/modphase*2*pi;
+ for i=1:length(phases)
+ phasestr(i,:)=sprintf('%2.2f',phases(i));
+ end
+ set(gca,'xticklabel',phasestr);
+ hold on
+ plot(maxintphase,strength,'.','Markerfacecolor','r','Markeredgecolor','r','Markersize',25);
+ text(maxintphase,strength*1.15,sprintf('Phase: %2.2f',phase),'verticalal','bottom');
+ text(maxintphase,strength*1.15,sprintf('Freq: %3.3f Hz',freq),'verticalal','top');
+
+end
+
+
+return
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/changesr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/changesr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% method of class @signal
+% function sig=changesr(sig,sr_neu)
+% changes the sample rate of the signal to the new samplerate.
+% the number of points of the signal change!
+% new values are interpolated
+%
+% INPUT VALUES:
+% sig1: first @signal
+% sr_new: new samplerate
+%
+% RETURN VALUE:
+% sigresult: @signal `
+%
+% (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=changesr(a,sr_neu)
+
+sr_alt=a.samplerate;
+if fround(sr_alt,5)==fround(sr_neu,5) %nichts zu tun
+ sig=a;
+ return;
+end
+
+
+if sr_neu > sr_alt
+ r=round(sr_neu/sr_alt);
+% r=sr_neu/sr_alt;
+% y = interp(a.werte,r);
+ x_val_new = a.start_time+1/sr_neu:1/sr_neu:getlength(a);
+ x_val_old = a.start_time+1/sr_alt:1/sr_alt:getlength(a);
+ y = interp1(x_val_old, a.werte, x_val_new, 'cubic');
+else
+ p=sr_neu;
+ q=sr_alt;
+ y = resample(a.werte,p,q);
+end
+
+sig=signal(y);
+sig.samplerate=sr_neu;
+sig.name=a.name;
+sig.unit_x=a.unit_x;
+sig.unit_y=a.unit_y;
+sig.start_time=a.start_time;
+sig.nr_x_ticks=a.nr_x_ticks;
+sig.x_tick_labels=a.x_tick_labels;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/ci_simulate.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/ci_simulate.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,110 @@
+% method of class @signal
+% function sig=ci_simulate(signal)
+%
+% INPUT VALUES:
+% sig: @signal
+%
+% RETURN VALUE:
+% sigresult: @signal `
+%
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2003/01/20 18:33:51 $
+% $Revision: 1.4 $
+
+function sig=ci_simulate(sig)
+% stolen from AMO.m
+
+audio_sample_rate=16000;
+
+p.channel_stim_rate=900;
+p.audio_sample_rate=audio_sample_rate;
+p.analysis_rate=p.channel_stim_rate;
+p.num_selected = 10;
+p.num_bands = 22;
+p.electrodes=22:-1:1;
+
+p=Append_process(p,'FFT_filterbank_proc');
+p=Append_process(p,'Power_sum_envelope_proc');
+p=Append_process(p,'Reject_smallest_proc');
+FTM=Process(p,sig.values);
+
+
+% Parameters for Resynthesis
+% --------------------------
+pre.resynthesis_rate = audio_sample_rate;
+pre.num_bands = p.num_bands;
+pre.analysis_rate = p.channel_stim_rate;
+pre.electrodes=p.electrodes;
+
+insertion = 22; % insertion depth in mm
+cochlength=33 % length of cochlea
+elecspacing = 0.75; % spacing between electrodes in mm
+b = 0.3; % space constant in mm
+
+% prepare non-overlapping crossover frequencies according to Greenwood
+% --------------------------------------------------------------------
+for i=1:23
+ %elec_position_base(i)=insertion-elecspacing*(i-1); % position of elec in cochlea from base [mm]
+ crossover_position_base(i)=insertion - (elecspacing*(i-1) - elecspacing*0.5); % position between electrodes from base [mm]
+end
+crossover_position_apex=cochlength-crossover_position_base'; % position between electrodes from apex [mm]
+crossover_freqs_greenwood=Greenwood_x2cf(crossover_position_apex); % corresponding Greenwood frequencies
+% check if there are frequencies above 1/2 sampling rate,
+% and remove those bands from FTM, electrodes and crossover freq table
+toohigh=sum(crossover_freqs_greenwood>0.5*pre.resynthesis_rate);
+crossover_freqs_greenwood=crossover_freqs_greenwood(1:end-toohigh); % only those < half the sampling rate
+pre.electrodes=pre.electrodes(1:sum(p.electrodes>toohigh));
+FTM=FTM(1:sum(p.electrodes>toohigh),:);
+num_bands_after=length(pre.electrodes);
+if pre.num_bands~=num_bands_after
+ msgbox([num2str(pre.num_bands-num_bands_after) ' of the active basal electrodes correspond(s) to frequencies > half the sampling frequency and will be disabled.'],'Disabling electrodes','warn','modal');
+end
+pre.num_bands=num_bands_after;
+
+% resynthesize
+% ------------
+%sinusoid
+ pre.resynthesis_carrier = 'sinus';
+ if get(handles.AnalRadio,'Value')
+ pre.crossover_freqs=p.crossover_freqs; % sinusoids following crossover frequencies as in analysis
+ filename=[filename '_sinus'];
+ else
+ pre.crossover_freqs=crossover_freqs_greenwood; % sinusoids following Greenwood
+ filename=[filename '_sinus_green_' num2str(cochlength) '_' num2str(insertion)];
+ end
+else % NOISE
+ pre.resynthesis_carrier = 'noise';
+ if get(handles.AnalRadio,'Value')
+ pre.crossover_freqs=p.crossover_freqs; % noise bands following analysis freq bands, non-overlapping
+ filename=[filename '_noise'];
+ else
+ if get(handles.OverBox,'Value') % exponentially decaying, overlapping frequency bands, after Greenwood
+ for i=1:22
+ pre.resynthesis_A(i,:) = 1;
+ pre.resynthesis_B(i,:) = CISimulationFilter(insertion-elecspacing*(i-1),pre.resynthesis_rate,b,cochlength);
+ end
+ filename=[filename '_noise_green_' num2str(cochlength) '_' num2str(insertion) '_olap_' num2str(b)];
+ else % crossover frequencies after Greenwood, non-overlapping
+ pre.crossover_freqs=crossover_freqs_greenwood;
+ filename=[filename '_noise_green_' num2str(cochlength) '_' num2str(insertion)];
+ end
+ end
+end
+
+pre = resynthesis(pre);
+simul = resynthesis(pre,FTM);
+
+%Windowing and zeropadding to remove clicks
+w = risewindow(length(simul),0.01*pre.resynthesis_rate)'; %a 10 ms linear rise and fall
+simul = [zeros(1,10) w.*simul zeros(1,10)];
+
+if get(handles.NormalizeBox,'Value') % normalize output
+ amp1=sum(handles.audio.^2);
+ amp2=sum(simul.^2);
+ %simul=simul*sqrt(amp1/amp2); % normalize to input level
+ simul=0.9*simul/max(abs(simul)); % normalize to 90 %
+end
+
+return;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/ci_simulate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/ci_simulate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,92 @@
+% method of class @signal
+% function sig=ci_simulate(signal)
+%
+% INPUT VALUES:
+% sig: @signal
+%
+% RETURN VALUE:
+% sigresult: @signal `
+%
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2003/01/20 18:33:51 $
+% $Revision: 1.4 $
+
+function sig=ci_simulate(sigorg)
+% stolen from AMO.m
+
+audio_sample_rate=getsr(sigorg);
+% audio_sample_rate=16000;
+
+p.channel_stim_rate=900;
+p.audio_sample_rate=audio_sample_rate;
+p.analysis_rate=p.channel_stim_rate;
+p.num_selected = 10;
+p.num_bands = 22;
+p.electrodes=22:-1:1;
+
+p=Append_process(p,'FFT_filterbank_proc');
+p=Append_process(p,'Power_sum_envelope_proc');
+p=Append_process(p,'Reject_smallest_proc');
+
+values=getvalues(sigorg);
+FTM=Process(p,values);
+
+
+% Parameters for Resynthesis
+% --------------------------
+pre.resynthesis_rate = audio_sample_rate;
+pre.num_bands = p.num_bands;
+pre.analysis_rate = p.channel_stim_rate;
+pre.electrodes=p.electrodes;
+
+insertion = 22; % insertion depth in mm
+cochlength=33; % length of cochlea
+elecspacing = 0.75; % spacing between electrodes in mm
+b = 0.3; % space constant in mm
+
+% prepare non-overlapping crossover frequencies according to Greenwood
+% --------------------------------------------------------------------
+for i=1:23
+ %elec_position_base(i)=insertion-elecspacing*(i-1); % position of elec in cochlea from base [mm]
+ crossover_position_base(i)=insertion - (elecspacing*(i-1) - elecspacing*0.5); % position between electrodes from base [mm]
+end
+crossover_position_apex=cochlength-crossover_position_base'; % position between electrodes from apex [mm]
+crossover_freqs_greenwood=Greenwood_x2cf(crossover_position_apex); % corresponding Greenwood frequencies
+% check if there are frequencies above 1/2 sampling rate,
+% and remove those bands from FTM, electrodes and crossover freq table
+toohigh=sum(crossover_freqs_greenwood>0.5*pre.resynthesis_rate);
+crossover_freqs_greenwood=crossover_freqs_greenwood(1:end-toohigh); % only those < half the sampling rate
+pre.electrodes=pre.electrodes(1:sum(p.electrodes>toohigh));
+FTM=FTM(1:sum(p.electrodes>toohigh),:);
+num_bands_after=length(pre.electrodes);
+if pre.num_bands~=num_bands_after
+ msgbox([num2str(pre.num_bands-num_bands_after) ' of the active basal electrodes correspond(s) to frequencies > half the sampling frequency and will be disabled.'],'Disabling electrodes','warn','modal');
+end
+pre.num_bands=num_bands_after;
+
+% resynthesize
+% ------------
+%sinusoid
+% pre.resynthesis_carrier = 'sinus';
+% pre.crossover_freqs=crossover_freqs_greenwood; % sinusoids following Greenwood
+
+% noise % NOISE
+ pre.resynthesis_carrier = 'noise';
+ pre.crossover_freqs=crossover_freqs_greenwood;
+
+pre = Resynthesis(pre);
+simul = Resynthesis(pre,FTM);
+
+%Windowing and zeropadding to remove clicks
+w = risewindow(length(simul),0.01*pre.resynthesis_rate)'; %a 10 ms linear rise and fall
+simul = [zeros(1,10) w.*simul zeros(1,10)];
+
+
+ % return a signal:
+sig=signal(simul,audio_sample_rate);
+sig=setname(sig,'Convolution');
+
+
+return;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/complexfilter.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/complexfilter.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,35 @@
+% method of class @signal
+% INPUT VALUES:
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=complexfilter(sig,formant_fre,formant_fre_width,formant_amp)
+% creates an vocal by filtering the signal (wich probably is a clicktrain)
+% in different formants
+
+nr_formants=length(formant_fre);
+
+for i=1:nr_formants
+ fre=formant_fre(i);
+ wid=formant_fre_width(i);
+ fsig(i)=bandpass(sig,fre-wid,fre+wid,wid/10);
+% play(fsig(i));
+end
+% plot(powerspectrum(fsig(1)),[10,13000],'b')
+% hold on
+% plot(powerspectrum(fsig(2)),[10,13000],'r')
+% plot(powerspectrum(fsig(3)),[10,13000],'g')
+% plot(powerspectrum(fsig(4)),[10,13000],'c')
+
+sumsig=fsig(1)*formant_amp(1);
+for i=2:nr_formants
+ sumsig=sumsig+fsig(i)*formant_amp(i);
+end
+% plot(powerspectrum(sumsig),[10,13000],'k')
+sig=sumsig;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/convolute.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/convolute.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,45 @@
+% method of class @signal
+% function sig=convolute(sig1,sig2)
+%
+% calculates the convolution between the signals sig1 and sig2. The
+% return value is a signal
+%
+% INPUT VALUES:
+% sig1: original @signal
+% sig2: @signal to correlate with
+%
+% RETURN VALUE:
+% @sig: the convolution values at each delay
+%
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2003/02/12 19:08:38 $
+% $Revision: 1.2 $
+
+function sig=convolute(sig1,sig2)
+
+
+values1=getvalues(sig1);
+values2=getvalues(sig2);
+
+% do the convolution
+sr1=getsr(sig1);
+sr2=getsr(sig2);
+
+if sr1~=sr2
+ error('sample rates of both signals must be the same!');
+ return
+end
+
+corrcovs=conv(values1,values2);
+
+% return a signal:
+sig=signal(corrcovs,sr1);
+sig=setname(sig,'Convolution');
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/copy.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/copy.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,40 @@
+% method of class @signal
+% function sigresult=copy(sig1,sig2,[start_time])
+% copies the first signal in the second, also when sig2 is a struct.
+%
+% INPUT VALUES:
+% sig1: first @signal
+% sig2: second @signal or struct
+% start_time: start time for copying. [default: 0]
+% RETURN VALUE:
+% sigresult: @signal `
+%
+% (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=copy(a,b,start_time)
+
+if nargin<3
+ start_time=0;
+end
+
+if isobject(werte)
+ not implemented yet
+end
+
+if isnumeric(b)
+ sig=signal(a);
+ sig=mute(sig); % setze alle Werte auf Null
+
+ nr=size(b,1);
+ dauer=bin2time(sig,nr);
+
+ sig=add(a,b,start_time,dauer)
+end
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/createfrompoly.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/createfrompoly.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,8 @@
+function sig=createfrompoly(sig,p)
+% creates the signal from the points in the polynoms p (very useful with
+% polynomes that come from a fit
+
+sr=getsr(sig);
+xvals=getxvalues(sig);
+pvals=polyval(p,xvals);
+sig=setvalues(sig,pvals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/crosscorrelate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/crosscorrelate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,68 @@
+% method of class @signal
+% function sig=crosscorrelate(sig1,sig2,[delay_start],[delay_stop],[normalization_mode])
+%
+% calculates the cross corrlelation between the signals sig1 and sig2. The
+% return value is a signal that covers the correlation between the two
+% signals between delay_start and delay_stop.
+%
+% INPUT VALUES:
+% sig1: original @signal
+% sig2: @signal to correlate with
+% delay_start: start of the correlation : default -length(sig)
+% delay_stop: longest delay of the correlation : default length(sig)
+% normalization_mode: normalizateion: default: 'biased' (see help 'xcorr')
+%
+% RETURN VALUE:
+% @sig: the correlation values at each delay
+%
+% (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=crosscorrelate(sig1,sig2,delay_start,delay_stop,normalization_mode)
+
+if nargin < 5
+ normalization_mode='biased';
+end
+if nargin < 4
+ l1=getlength(sig1);
+ l2=getlength(sig2);
+ delay_stop=min(l1,l2); % the smaller of both length
+end
+if nargin < 3
+ delay_start=-delay_stop; % the
+end
+
+% by this time the signal is shifted
+deltatime=delay_stop+delay_start;
+
+values1=getvalues(sig1);
+values2=getvalues(sig2);
+
+sr=getsr(sig1);
+maxlags1=delay_stop*sr;
+maxlags2=-delay_start*sr;
+
+maxlags=floor(max(maxlags1,maxlags2));
+
+% do the crosscorrelation:
+corrcovs=xcorr(values1,values2,maxlags,normalization_mode);
+
+% return a signal:
+sig=signal(corrcovs,sr);
+if deltatime > 0
+ sig=getpart(sig,deltatime); % compensate for a possible asymmetric shift
+else
+ sig=getpart(sig,0,delay_stop-delay_start); % compensate for a possible asymmetric shift
+end
+sig=setstarttime(sig,delay_start);
+sig=setname(sig,'CrossCorrelation');
+sig=setunit_x(sig,'delay (ms)');
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/delay.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/delay.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,28 @@
+% method of class @signal
+% function delay(sig)
+% delays the signal by so many seconds. Fills the start with zeros and cuts
+% the end
+%
+% INPUT VALUES:
+% sig: original @signal
+%
+% (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=delay(sig,del)
+
+sr=getsr(sig);
+% nr_del=del*sr;
+nr_del=round(del*sr);
+vals=getvalues(sig);
+nvals1=zeros(1,nr_del);
+nvals2=vals(1:end-nr_del);
+
+new_vals=[nvals1 nvals2'];
+sig=setvalues(sig,new_vals);
+sig=setname(sig,sprintf('%s delayed by %f sec',getname(sig),del));
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/disp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/disp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% method of class @signal
+% function display(sig)
+% overwritten function that is called from the shell and for the tooltips
+%
+% INPUT VALUES:
+% sig: original @signal
+%
+% (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 disp(sig)
+disp(sprintf('%s',sig.name));
+if ~isempty(strfind(sig.unit_x,'ms'))
+ disp(sprintf('sr=%5.0f/s length:%4.0f ms points:%5d',sig.samplerate,getlength(sig)*1000,getnrpoints(sig)));
+elseif ~isempty(strfind(sig.unit_x,'s'))
+ disp(sprintf('sr=%5.0f/s length:%2.2f sec points:%5d',sig.samplerate,getlength(sig),getnrpoints(sig)));
+else
+ disp(sprintf('unit(x)=%s',sig.unit_x));
+ disp(sprintf('signal: sr=%5.0f length:%4.2f points:%5d',sig.samplerate,getlength(sig),getnrpoints(sig)));
+end
+% sig.werte(1:10)'
+
+vals=sig.werte;
+nans=find(isnan(vals));
+if length(nans)>0
+ disp('has NANs');
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/display.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/display.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @signal
+% function display(sig)
+% overwritten function that is called from the shell and for the tooltips
+%
+% INPUT VALUES:
+% sig: original @signal
+%
+% (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 display(sig)
+
+if max(size(sig)) > 1
+ disp(sprintf('Array of user class Signal with %d signals',max(size(sig))));;
+else
+ disp('User Signal');
+ disp(sprintf('Name: %s',sig.name));
+ l=getlength(sig);
+ if l > 1
+ disp(sprintf('Length=%3.2f sec',getlength(sig)));
+ else
+ disp(sprintf('Length=%4.1f ms',getlength(sig)*1000));
+ end
+ disp(sprintf('Points=%d',size(sig.werte,1)));
+ disp(sprintf('Samplerate=%5.2f Hz',getsr(sig)));
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/edit.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/edit.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,13 @@
+function edit(sig)
+% opens the signal in CoolEdit (if installed)
+name='temp_signal_in_edit';
+
+filename=get_new_filename(name,'wav');
+
+savewave(sig,filename);
+try
+ winopen(filename);
+catch
+ error('sorry, no wave editor installed');
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/envelope.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/envelope.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,103 @@
+% method of class @signal
+% function env=envelope(sig,[mintime],[maxtime],[mincontrast])
+%
+% retuns the envelope determined by connecting the maximum points
+% when the maxima are seperated by more then the mintime, then connect
+% minima, that lie in the middle
+% if the difference between maxima is smaller then maxtime
+% look for the next maximum, that is further away
+% if mincontrast is given, than the maxima must have at least such a
+% contrast that is the distance in height to its neighbours in % of the whole signal!!
+%
+% INPUT VALUES:
+% sig: original @signal
+% mintime: minimum time, that must be between two successive maxima
+% maxtime: maximum time, that must be between two successive maxima
+% mincontrast: minimum contrast between two maxima
+%
+% RETURN VALUE:
+% env: @signal
+%
+% (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 env=envelope(sig,mintime,maxtime,mincontrast)
+
+if nargin < 4
+ mincontrast=0;
+end
+if nargin < 3
+ maxtime=0;
+end
+if nargin < 2
+ mintime=0;
+end
+
+[maxpos,minpos,maxs,mins]=getminmax(sig);
+
+
+
+env=signal(sig);
+env=mute(env);
+env=setname(env,sprintf('Envelope of: %s',getname(sig)));
+
+if isempty(maxs)
+ return
+end
+
+threshold=max(sig)*mincontrast;
+
+nr_max=length(maxs);
+lastmax=maxpos(1);
+lastval=maxs(1);
+lastminval=getminimumleftof(lastmax,maxpos,minpos,maxs,mins);
+if isempty(lastminval)
+ lastminval=0;
+end
+for i=2:nr_max
+ newmax=maxpos(i);
+ newval=maxs(i);
+ newminval=getminimumleftof(newmax,maxpos,minpos,maxs,mins);
+
+ % wenn die maxima zu nah beeinander liegen, dann such das nächste Maximum
+ if newmax-lastmax > maxtime
+ if newval > lastminval+threshold
+ if newmax-lastmax > mintime
+ tmin=getminimumleftof(newmax,maxpos,minpos,maxs,mins);% das ist das Minimum links vom rechten Maximum
+ % wenn das Minimum zwischen den Maxima liegt, dann verbinde zwei Linien vom Maximum zum Minimum und weiter
+ if tmin>lastmax
+ % erste Gerade
+ tmitte=tmin;
+ x1=time2bin(sig,lastmax);
+ x2=time2bin(sig,tmitte);
+ y1=lastval;
+ y2=gettimevalue(sig,tmitte);
+ line=linspace(y1,y2,x2-x1+1);
+ env=setvalues(env,line,x1);
+
+ % zweite Gerade
+ x1=time2bin(sig,tmitte);
+ x2=time2bin(sig,newmax);
+ y1=gettimevalue(sig,tmitte);
+ y2=newval;
+ line=linspace(y1,y2,x2-x1+1);
+ env=setvalues(env,line,x1);
+ end
+ % maxima weit genug zusammen, also werden nur die Maxima verbunden
+ else
+ x1=time2bin(sig,lastmax);
+ x2=time2bin(sig,newmax);
+ y1=lastval;
+ y2=newval;
+ line=linspace(y1,y2,x2-x1+1);
+ env=setvalues(env,line,x1);
+ end
+ lastmax=newmax;
+ lastval=newval;
+ lastminval=newminval;
+ end
+ end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/erb2log.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/erb2log.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,46 @@
+% method of class @signal
+% function sig=erb2log(sig,cfs)
+%
+% changes the signal (that is ususally a function of frequencies, into
+% another signal with frequencies, but now the spacing is according to the
+% cf list in cfs. All points are interpolated
+%
+% INPUT VALUES:
+% sig: original @signal
+% cfs: list of frequencies
+%
+% RETURN VALUE:
+% sig: new @signal
+%
+% (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=erb2log(sig,cfs)
+
+
+min_fre=cfs(1);
+max_fre=cfs(end);
+nr_points=length(cfs);
+
+log_fres=distributelogarithmic(min_fre,max_fre,nr_points);
+
+erb_fres=cfs;
+erb_vals=sig.werte;
+
+method='cubic';
+% for i=1:nr_points
+% log_fre=log_fres(i);
+new_vals=interp1(erb_fres,erb_vals,log_fres,method);
+
+
+% end
+
+sig=setvalues(sig,new_vals);
+
+a=0;
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/exp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/exp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,6 @@
+function sig=exp(sig)
+% exp the stimulus
+
+vals=getvalues(sig);
+valnew=exp(vals);
+sig=setvalues(sig,valnew);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/expand.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/expand.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,48 @@
+% method of class @signal
+% function sig=expand(sig,newlength,[value])
+%
+% makes the signal longer (or shorter) by appending values with the value value
+% if time is negative, then expand it to the front by filling the first time with value
+%
+% INPUT VALUES:
+% sig: original @signal
+% newlength: the new length of the signal
+% value: value, with wich the new part is filled [0]
+%
+% RETURN VALUE:
+% time: time, when signal is bigger 0 for first time
+%
+% (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=expand(a,newlength,value)
+
+lenalt=getlength(a);
+sig=a; % erst mal eine Kopie des Signals
+sr=getsr(a);
+if newlength < 0 % aha, länger machen mit vorne auffüllen
+ lenneu=lenalt-newlength; % denn die newlength ist ja negativ
+ temp=a.werte;
+
+ start=time2bin(a,-newlength);
+ stop=time2bin(a,lenneu);
+
+ neuevals=ones(1,stop)*value;% erst alle mit den gewünschten Werten belegen
+ bla=time2bin(a,lenalt);
+ neuevals(start+1:stop)=temp(1:bla); % dann mit dem alten Signal überschreiben
+
+ sig.werte(1:stop)=neuevals(1:stop);
+
+else % positive neue Länge
+ if lenalt>=newlength %nothing to do
+ return;
+ end
+ start=time2bin(a,lenalt);
+ stop=time2bin(a,newlength);
+ sig.werte(start:stop)=value;
+end
+
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/fill.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/fill.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,169 @@
+% method of class @signal
+%
+% 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 rethandle=fill(sig,border,stil)
+% usage: handle=fill(sig,border,stil)
+% works as plot, but fills the content with the color of the signal
+
+
+
+if nargin<3
+ stil='b';
+end
+
+
+% if we are dealing with milliseconds (very often), then the units are in
+% ms as well
+if strfind(sig.unit_x,'(ms)')>0
+ multiplier=1000;
+else
+ multiplier=1;
+end
+
+
+
+sr=getsr(sig);
+durationbin=size(sig.werte,1);
+duration=durationbin/sr;
+if nargin<2
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+end
+
+if isstruct(border) || isempty(border)
+ options=border;
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+else
+ options=[];
+ if ischar(border)
+ stil=border;
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+ else
+ if nargin <2
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+ else
+ t1=border(1);
+ t2=border(2);
+ x1=time2bin(sig,t1);
+ x2=time2bin(sig,t2);
+ nr=size(border,2);
+ if nr==2 % wenn nur die x-Werte angegeben werden
+ border=[x1 x2 min(sig.werte(x1+1:x2)) max(sig.werte(x1+1:x2))];
+ else
+ border(1)=x1;
+ border(2)=x2;
+ end
+ end
+ end
+end
+
+if ~isfield(options,'is_log');
+ is_log=0;
+else
+ is_log=options.is_log;
+end
+
+if isfield(options,'minimum_time');
+ border(1)=time2bin(sig,options.minimum_time);
+ minimum_time=options.minimum_time;
+else
+ minimum_time=bin2time(sig,border(1));
+end
+
+if isfield(options,'maximum_time');
+ border(2)=time2bin(sig,options.maximum_time);
+ maximum_time=options.maximum_time;
+else
+ maximum_time=bin2time(sig,border(2));
+end
+
+
+% if the time scale is reversed (time from left to right)
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+start_time=getminimumtime(sig);
+
+min_x_screen=border(1); % einer wird abgezogen damit wir bei Null beginnen, nicht beim ersten bin, was blöde aussieht
+max_x_screen=border(2);
+minshowy=border(3);
+maxy=border(4);
+
+xvals=getxvalues(sig);
+
+
+xvals=xvals.*multiplier;
+yvals=getvalues(sig);
+
+
+% fill up the corners
+yvals=[0 yvals' 0];
+tstart=getminimumtime(sig);
+tstop=getmaximumtime(sig);
+% xvals=[tstart:1/sr*multiplier:tstop*multiplier+1/sr*multiplier];
+xvals=[tstart*multiplier:1/sr*multiplier:tstop*multiplier+1/sr*multiplier];
+% xvals=1:length(yvals);
+
+% this is the plotting command:
+handle=fill(xvals,yvals,stil,'facecolor',stil,'EdgeColor',stil);
+
+if time_reversed
+ set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+else
+ set(gca,'XDir','normal') % normale ausrichtung
+end
+
+if is_log
+ set(gca,'XScale','log')
+ t=minimum_time*multiplier;
+ tix=[t 2*t 4*t 8*t 16*t 32*t 64*t 128*t 256*t 512*t 1024*t];
+ if ~isempty(sig.x_tick_labels)
+ ti=sig.x_tick_labels;
+ set(gca,'XTicklabel',ti);
+ end
+ set(gca,'XTick',tix);
+else % its linear
+ set(gca,'XScale','linear')
+end
+
+miny=border(3);
+maxy=border(4);
+y=[miny maxy];
+if miny==maxy
+ maxy=miny+1;
+ miny=miny-1;
+end
+if isnan(miny) || isnan(maxy)
+else
+ axis([minimum_time*multiplier maximum_time*multiplier miny*1.05 maxy*1.05]);
+end
+
+xlabel(sig.unit_x);
+ylabel(sig.unit_y);
+title(sig.name,'Interpreter','none');
+
+if nargout==1
+ rethandle=handle;
+end
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/firsttimebiggerzero.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/firsttimebiggerzero.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% method of class @signal
+% function time=firsttimebiggerzero(sig)
+%
+% returns the time, where the signal is for the first time
+% bigger then zero
+% useful for throwing away empty parts of signals
+%
+% INPUT VALUES:
+% sig: original @signal
+%
+% RETURN VALUE:
+% time: time, when signal is bigger 0 for first time
+%
+% (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 time=firsttimebiggerzero(sig)
+
+vals=getvalues(sig);
+big=find(vals>0);
+m=min(big);
+
+time=bin2time(sig,m);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gen_complex_damp.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gen_complex_damp.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,65 @@
+% tool
+%
+% 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/01/17 16:57:44 $
+% $Revision: 1.3 $
+
+function sig=gen_complex_damp(orgsig,carriers,halflifes,reprate,amplitudes)
+
+% each combination possible
+grafix=1;
+
+for j=1:length(carriers)
+ save_sigs(j)=generatedampsinus(orgsig,carriers(j),reprate(j),amplitudes(j),halflifes(j));
+
+ if j==1
+ gsig=save_sigs(j);
+ else
+ gsig=gsig+save_sigs(j);
+ end
+end
+
+% savewave(tsig,'tsig');
+
+sig=gsig;
+
+
+
+if grafix
+ plot_w=150;
+ figure(1)
+ clf
+ subplot(3,1,[1,2])
+ hold on
+ nrc=length(carriers);
+
+ % calculate where on the y-axis we are
+ minf=100;
+ maxf=5000;
+
+
+ for i=1:nrc
+ f=carriers(i);
+ x=f2f(f,
+% offx=2*i;
+ plot(save_sigs(i)+offx);
+ end
+ set(gca,'xlim',[0 plot_w])
+ set(gca,'ylim',[0 offx+2])
+ set(gca,'ytick',[])
+ xlabel('')
+ ylabel('')
+ title('part signals')
+ subplot(3,1,3)
+ plot(sig);
+ set(gca,'xlim',[0 plot_w])
+ title('total signal')
+
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gen_complex_damp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gen_complex_damp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,68 @@
+% tool
+%
+% 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/01/17 16:57:44 $
+% $Revision: 1.3 $
+
+function sig=gen_complex_damp(orgsig,carriers,halflifes,reprate,amplitudes)
+
+% each combination possible
+grafix=1;
+
+for j=1:length(carriers)
+ save_sigs(j)=generatedampsinus(orgsig,carriers(j),reprate(j),amplitudes(j),halflifes(j));
+
+ if j==1
+ gsig=save_sigs(j);
+ else
+ gsig=gsig+save_sigs(j);
+ end
+end
+
+% savewave(tsig,'tsig');
+
+sig=gsig;
+
+
+
+if grafix
+ plot_w=150;
+ figure(1)
+ clf
+ subplot(3,1,[1,2])
+ hold on
+ nrc=length(carriers);
+
+ % calculate where on the y-axis we are
+ minf=100;
+ maxf=5000;
+
+
+ for i=1:nrc
+ f=carriers(i);
+ offx=f2f(f,minf,maxf,0,10,'loglin');
+ plot(save_sigs(i)+offx);
+ end
+ set(gca,'xlim',[0 plot_w])
+ set(gca,'ylim',[0 10])
+
+ yt=[0.1 0.2 0.5 1 2 4]*1000;
+ yt2=f2f(yt,minf,maxf,0,10,'loglin');
+ set(gca,'ytick',yt2)
+ set(gca,'yticklabel',yt)
+ xlabel('')
+ ylabel('frequency')
+ title('part signals')
+ subplot(3,1,3)
+ plot(sig);
+ set(gca,'xlim',[0 plot_w])
+ title('total signal')
+
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gen_frog.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gen_frog.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,308 @@
+% function to generate an artificial vowel
+function sig=gen_frog(sig,options)
+% vowel,pitch,scale,halflifeconstant,onsettimeconstant,pitch_jitter,formant_jitter,formant_jitter_bw);%
+
+if nargin < 2
+ options=[];
+end
+
+
+% the rise of a damped sinusoid is not instantaneous, but like a gamma
+% functin with the following power of t:
+if isfield(options,'onsettimeconstant')
+ onsettimeconstant=options.onsettimeconstant;
+else
+ onsettimeconstant=0.5;
+end% halflife of each formant is calculated by dividing this number by the
+% formant frequency:
+% if halflifeconstant<=0, then fixed to 4 ms
+if isfield(options,'halflifeconstant')
+ halflifeconstant=options.halflifeconstant;
+else
+ halflifeconstant=3;
+end
+% scaling = 1: normal speaker
+if isfield(options,'scale')
+ scale=options.scale;
+else
+ scale=1;
+end
+% f0
+if isfield(options,'pitch')
+ pitch=options.pitch;
+else
+ pitch=100;
+end
+% how long the decay should continue longer then the reprate
+if isfield(options,'carry_decay')
+ carry_decay_parameter=options.carry_decay;
+else
+ carry_decay_parameter=1;
+end
+% normal or is it the octave? In this case, we jump over each second
+if isfield(options,'do_octave')
+ do_octave=options.do_octave;
+else
+ do_octave=0;
+end
+% type of vowel: 'a','e','i','o','u'
+if isfield(options,'vowel')
+ vowel=options.vowel;
+else
+ vowel='a';
+end
+
+
+
+if nargin < 1
+ sig=signal(0.5,16000);
+end
+sr=getsr(sig);
+dur_time=getlength(sig);
+
+
+nr_formants=4;
+
+for i=1:nr_formants
+ formfre(i)=pitch*i;
+end
+level(1)=0;
+% level(2)=-18;
+% level(3)=-30;
+% level(4)=-38;
+
+level(2)=-4;
+level(3)=-6;
+level(4)=-9;
+
+
+
+% % fix all formants to the nearest harmonic of the fundamental
+% if isfield(options,'adjust_to_nearest_harmonic')
+% if options.adjust_to_nearest_harmonic==1
+% f0=options.pitch;
+% for formant=1:nr_formants
+% fre=formfre(formant);
+% newfre=round(fre/f0)*f0;
+% formfre(formant)=newfre;
+% end
+% end
+% end
+
+
+formfre=formfre.*scale;
+dur_samp=dur_time.*sr; %length of vowel defined in sample points
+sgpp=1/pitch; %standard glottal pulse period.
+pitch_jitter=0;
+t=[0:1/sr:(dur_time-(1/sr))]; %our time sequence
+dur_samp=dur_time.*sr; %length of vowel defined in sample points
+
+
+%we now generate a sequence, specified in sample points, which
+%define the spacing of glottal pulses. With zero pitch_jitter the sequence
+%is regular (1/pitch). With a pitch_jitter value of 1 the spacing of glottal
+%pulses fall in a range with an upper limit of double the period of
+%the pitch and a lower limit of 1/sampling rate.
+%The average spacing of glottal pulses is approx 1/pitch
+lwr_pth_jit=0.5-(pitch_jitter/2);
+upr_pth_jit=0.5+(pitch_jitter/2);
+
+gp=cell(nr_formants,1); %for each formant will store pulse time
+for formant=1:nr_formants
+ enough_pulses=0;
+ pulse_number=0;
+ while enough_pulses==0
+ pulse_number=pulse_number+1;
+ pulse_spacing(pulse_number)=max(1,floor(sr.*(sgpp.*2.*(lwr_pth_jit+(upr_pth_jit-lwr_pth_jit)*rand(1)))));
+ pulse_time(pulse_number)=sum(pulse_spacing)-pulse_spacing(1)+1;
+ if pulse_time(pulse_number)>=dur_samp
+ pulse_time=pulse_time(1:pulse_number-1);
+ pulse_number=pulse_number-1;
+ enough_pulses=1;
+ else
+ end
+ end
+
+ gp{formant}=pulse_time;
+ clear pulse_time;
+ clear pulse_spacing;
+ no_pulses(formant)=length(gp{formant});
+ pulse_times{formant}=gp{formant};
+end%formant
+
+formant_jitter=0;
+
+% if no gamma tone, then precalculate the damping function once for all
+% if onsettimeconstant <= 0 && halflifeconstant==0
+ hl=0.04;
+ damping=exp(t.*log(0.5)/hl); %this decays to 0.5 after hl seconds
+ damping=damping/max(damping);
+% end
+
+onsettimes=power(t,onsettimeconstant);
+
+formant_jitter_bw=0;
+%--------------------------------------------------------------------------
+for formant=1:nr_formants
+ lw_log(formant)=max(log10(150), (log10(formfre(formant))- ((formant_jitter_bw.*.3)/2) ) ); %cannot go below 150Hz
+ lw_log_adj(formant)=log10(formfre(formant))-((log10(formfre(formant))-lw_log(formant)).*formant_jitter);
+ up_log(formant)=min(log10(4500),log10(formfre(formant))+ ((formant_jitter_bw.*.3)/2)) ;
+ up_log_adj(formant)=log10(formfre(formant))+((up_log(formant)-log10(formfre(formant))).*formant_jitter);
+end
+
+
+% if we want to generate the octave, we take exactly the same pulses and
+% frequencies, but only every second one:
+if do_octave
+ pulse_step=2;
+else
+ pulse_step=1;
+end
+
+nr_points=length(t);
+final_wave=zeros(dur_samp,nr_formants);
+for formant=1:nr_formants
+ for count=1:pulse_step:no_pulses(formant)-1
+ oneortwo=randperm(2);
+ if oneortwo(1)==1
+ freq=10.^((lw_log_adj(formant)+(log10(formfre(formant))-lw_log_adj(formant))*rand(1))); %lower range
+ else
+ freq=10.^((log10(formfre(formant))+(up_log_adj(formant)-log10(formfre(formant)))*rand(1))); %upper range
+ end
+
+% if freq>1000
+% no_octave=((log10(freq)-3))/.3;
+% lev=-12.*no_octave;
+% else
+% lev=0;
+% end
+% amp=10.^(lev/20);
+
+ lev=level(formant);
+ amp=10.^(lev/20);
+
+ if halflifeconstant<=0
+ hl=0.004;
+ else
+ hl=halflifeconstant/freq;
+ end
+
+ nr_relevant_points=pulse_times{formant}(count+1)-pulse_times{formant}(count);
+
+ nr_relevant_points=nr_relevant_points*carry_decay_parameter;
+
+ if onsettimeconstant > 0
+ damping=zeros(nr_relevant_points,1);
+ for jj=1:nr_relevant_points
+ damping(jj)=onsettimes(jj)*exp(t(jj)*log(0.5)/hl); %this decays to 0.5 after hl seconds
+ end
+ damping=damping/max(damping);
+ end
+ grafix=0;
+ if grafix==1
+ figure(234)
+ plot(damping);
+ end
+
+ this_formant=zeros(nr_relevant_points,1);
+ for jj=1:nr_relevant_points
+ sinsin=sin(2*pi*freq*t(jj));
+ this_formant(jj)=amp*sinsin*damping(jj);
+ end
+ start_nr=pulse_times{formant}(count);
+ stop_nr=start_nr+nr_relevant_points-1;
+
+ if stop_nr> nr_points
+ nr_new=nr_points-start_nr+1;
+ this_formant=this_formant(1:nr_new);
+ stop_nr=nr_points;
+ final_wave(start_nr:stop_nr,formant)= final_wave(start_nr:stop_nr,formant)+this_formant;
+ else
+ final_wave(start_nr:stop_nr,formant)= final_wave(start_nr:stop_nr,formant)+this_formant;
+ end
+ end
+end
+final_wave_total=zeros(dur_samp,1);
+for formant=1:nr_formants
+ final_wave_total=final_wave_total+final_wave(:,formant);
+end
+
+% sig=signal(final_wave_total,sr);
+
+if isfield(options,'rise_time')
+ rise_time=options.rise_time;
+else
+ rise_time=0.015;
+end
+
+if isfield(options,'fall_time')
+ fall_time=options.fall_time;
+else
+ fall_time=0.1;
+end
+
+% sigvals=
+final_wave_total=gate_on_off(rise_time,fall_time,final_wave_total,sr);
+sig=signal(final_wave_total,sr);
+%
+% hold_time=length(sig)-rise_time-fall_time;
+% attack=linspace(0,1,round(rise_time*sr));
+%
+% hold=ones(1,round(hold_time*sr));
+% release=linspace(1,0,round(fall_time*sr));
+% envelope=[attack hold release];
+% envelope=envelope(1:getnrpoints(sig));
+% envelope=signal(envelope,sr);
+% sig=sig*envelope;
+
+
+function amp=calc_level(freq);
+%determines the level of a signal at a given frequency after it
+%has been filtered with a low-pass filter of 12dB/octave at 1kHz
+%first calculate if frequency is above 1kHz and if so by how many octaves
+%then multiply by slope.
+if freq>1000
+ no_octave=((log10(freq)-3))/.3;
+ lev=-12.*no_octave;
+else
+ lev=0;
+end
+amp=10.^(lev/20);
+
+
+
+function output=gate_on_off(onset,offset,input,sr)
+%check duration of signal is large enough for both the onset and offset
+%values.
+
+sig_length_samp=length(input);
+onset_length_samp=floor(onset.*sr);
+offset_length_samp=floor(offset.*sr);
+
+if (onset_length_samp+offset_length_samp)>sig_length_samp
+ output=0;
+ disp('---ERROR--- onset and offset duration too large for signal');
+ return
+else end
+
+
+%generate onset and offset amplitudes
+n_on=onset_length_samp;
+k=[1:1:n_on];
+onset_win=(1-cos(2.*pi.*(k./(2.*(n_on-1)))))./2;
+
+n_off=offset_length_samp;
+k=[1:1:n_off];
+offset_win=0.5+((cos(2.*pi.*(k./(2.*(n_off-1)))))./2);
+
+
+
+total_window=ones(sig_length_samp,1);
+total_window(1:onset_length_samp)=onset_win;
+total_window(sig_length_samp-offset_length_samp+1:sig_length_samp)=offset_win;
+
+
+
+output=input.*total_window;
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gen_jittered_clicktrains.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gen_jittered_clicktrains.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,307 @@
+function [target_signal,flanking_signal,only_regular_clicktrain,only_irregular_clicktrain]= ...
+ gen_jittered_clicktrains(orgsig,jitter,delay,target_fre,flanker_fre,Gain,FlankerMode,FlankerDelay,grafix)
+%
+% this funtion produces the stimuli needed in Krumbholz et al 2003 and
+% many other regular and irregular filted click trains
+% the clicktrain can be pure when TargetFrequency is =0 otherwise the
+% click train filted with a band pass filter around the given frequency
+%
+% input:
+% orgsig: original signal. Determines length and samperate. SR must be 25000!
+% jitter:
+% the amount of jitter in % (0=regular, 100= maximal jitter)
+% delay:
+% the repetition rate of the signal in ms
+% target_fre:
+% one of the following:
+% 0 0.4 0.5657 0.8 1.1314 1.6 2.2627 3.2 4.5255 6.4
+% if not precice, the nearest one will be taken
+% if 0, then no target will be generated
+% flanker_fre:
+% one of the following:
+% 0 0.4 0.5657 0.8 1.1314 1.6 2.2627 3.2 4.5255 6.4
+% if not precice, the nearest one will be taken
+% if 0, then no flanker will be generated
+
+% flanker_mode:
+% one of the following:
+% m: Flanker band synchronous and irregular (highest threshold)
+% t: Flanker band synchronous and regular (medium threshold)
+% td5: Flanker band synchronous and regular shifted in timepoints (lowest threshold)
+% sb1: Masker regular, flanker band irregular (Ranjnas Experiment)
+% sb2: Masker regular, flanker band regular, but time shifted (Ranjnas other stimulus)
+
+% flanker delay:
+% the delay of the synchronous clicks in ms
+% Gain:
+% the gain of the signal against the masker positiv direction: more signal
+% grafix says, if we want to see a plot of the signal or not
+
+% possible usage:
+% produce the stimulus as in the paper:
+% gen_jittered_clicktrains(signal(1,25000),0,10,1.6,3.2,10,'td5',5,1);
+% play(gen_jittered_clicktrains(signal(1,25000),0,10,3.2,0.8,3,'td5',5))
+%
+% to generate regular clicktrains use
+% [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0,10); play(c);
+%
+% to generate 20 % jitter use:
+% [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0.2,10); play(d);
+%
+% to filter at 3.2 Khz generate 20 % jitter use:
+% [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0.2,10,3.2); play(d);
+%
+% to generate one of Ranjnas stimuli (regular masker at first frequency and irregular target
+% in a different frequency band use) here: regular 40 dB louder then irregular
+% play(gen_jittered_clicktrains(signal(1,25000),1,10,1.6,3.2,40,'sb1',0,1)/20)
+%
+%
+% to generate one of Ranjnas stimuli (regular masker at first frequency and irregular target
+% in a different frequency band use) here: regular 40 dB louder then irregular
+% play(gen_jittered_clicktrains(signal(1,25000),1,10,1.6,3.2,100,'sb2',5,1)/10000)
+
+% return signals:
+% target_signal is the target band with regular clicks plus irregular clicks with the ratio of "gain"
+% flanking_signal is the flanking band which can be either regular or irregular
+% only_regular_clicktrain is the regular clicks alone
+% only_irregular_clicktrain is the irrregular clicks alone
+%
+% % no random please!
+% rand('state',0);
+
+% input variables:
+% 1 2 3 4 5 6 7 8
+%(orgsig,jitter,delay,flanker_fre,Gain,FlankerMode,FlankerDelay,grafix);
+
+
+
+
+if nargin <9 grafix=0;end
+if nargin <8 FlankerDelay=5; end
+if nargin <7 FlankerMode='td5';end
+if nargin <6 Gain=0;end
+if nargin <5 flanker_fre=3.2;end
+if nargin <4 target_fre=0;end
+if nargin <3 delay=10;end
+if nargin <2
+ jitter=1; % 100 % jitter
+end
+
+if jitter >1
+ disp('jitter must be smaller then 1 (100%)')
+ jitter=1;
+end
+
+% possible Target and Flanker frequencies:
+f(1)=0.4;
+f(2)=0.5657;
+f(3)=0.8;
+f(4)=1.1314;
+f(5)=1.6;
+f(6)=2.2627;
+f(7)=3.2;
+f(8)=4.5255;
+f(9)=6.4;
+
+% TargetFrq = 1.6; % fixed
+% change into the directory with the filter coeffiencs in
+orgdira=which('signal');
+orgdir=fileparts(orgdira);
+od=cd(fullfile(orgdir,'FIR filter coefficients'));
+
+% load filter for Target
+if target_fre==0
+ TargetFrq=0;
+else
+ % load the filter file for the appropriate frequency for the target
+ p=polyfit(1:9,log(f),1);
+ targ=round(solve(p,log(target_fre)));
+ TargetFrq = f(targ);
+ targetFIRFile = sprintf('bp%gw%g',TargetFrq,0.2);
+ targetFIRFile(findstr(targetFIRFile,'.')) = '_';
+ FId = fopen([targetFIRFile '.txt'],'rt');
+ fgetl(FId);
+ targetFIR = fscanf(FId,'%g',151)';
+ fclose(FId);
+end
+
+% load filter for Flanker
+if flanker_fre==0
+ FlankerFrq=0;
+else
+ % load the filter file for the appropriate frequency for the flanker
+ p=polyfit(1:9,log(f),1);
+ flank=round(solve(p,log(flanker_fre)));
+ FlankerFrq = f(flank);
+ flankerFIRFile = sprintf('bp%gw%g',FlankerFrq,0.2);
+ flankerFIRFile(findstr(flankerFIRFile,'.')) = '_';
+ FId = fopen([flankerFIRFile '.txt'],'rt');
+ fgetl(FId);
+ flankerFIR = fscanf(FId,'%g',151)';
+ fclose(FId);
+end
+cd(od); % go back to the old directory
+
+SR = 1000/getsr(orgsig);% all in ms
+sig_length =getlength(orgsig)*1000;
+% the filter coefficients only work when the sr is 25000!
+if getsr(orgsig)~=25000 && target_fre>0
+ disp('gen_jittered_clicktrains::warning: filtering only works for a sample rate of 25000')
+end
+
+rise_time = 25;
+timepoints = 0:SR:sig_length;
+TPts = max(size(timepoints));
+DigAmp = 1;
+SDelay = round(delay/SR);
+
+regular_clickstream = zeros(1,TPts);
+regular_clickstream(1:SDelay:TPts) = DigAmp;
+
+% RANDOMISE THE TARGET
+irregular_clickstream = zeros(1,TPts);
+% randomisation in the range of the jitter boundary
+jitter_time=SDelay*jitter;
+% Idx = ceil(rand*SDelay*2);
+idx = [];count=1;
+while isempty(idx)|| max(idx)0 && strcmp(FlankerMode,'td5')
+ flanker = [zeros(1,round(FlankerDelay/SR)) flanker(1:TPts-round(FlankerDelay/SR))];
+ end
+else
+ flanker = zeros(1,TPts);
+end
+flanker = envelope_signal(flanker,rise_time,SR);
+
+
+% filter the resulting streams in the right frequency bands
+if FlankerFrq~=0
+ f_flanker=filter(flankerFIR,1,flanker);
+else
+ f_flanker=flanker;
+end
+if target_fre>0 % only filter, when neccessary
+ f_targetReg=filter(targetFIR,1,targetReg);
+ f_targetIrr=filter(targetFIR,1,targetIrr);
+else
+ f_targetReg=targetReg;
+ f_targetIrr=targetIrr;
+end
+
+if strcmp(FlankerMode,'sb2')
+ signal_flank=signal(f_flanker);
+ signal_flank=setsr(signal_flank,1000/SR);
+ target_signal=signal(f_targetReg);
+ flanking_signal=signal(f_targetIrr);
+else
+ signal_flank=signal(f_flanker);
+ signal_flank=setsr(signal_flank,1000/SR);
+ target_signal=signal(f_targetReg);
+ flanking_signal=signal(f_targetIrr);
+end
+target_signal=setsr(target_signal,1000/SR);
+flanking_signal=setsr(flanking_signal,1000/SR);
+if strcmp(FlankerMode,'sb1') || strcmp(FlankerMode,'sb2')
+ % in this case, the target is the signal plus the flanker:
+ target_signal=target_signal+signal_flank;
+
+else
+% Signal zu Flanker addieren (stimmt von der Amplitude her wohl nicht, aber
+% für den Moment wirds tun)
+ target_signal=target_signal+signal_flank;
+ flanking_signal=flanking_signal+signal_flank;
+end
+
+%generate the pure random and regular click trains as well
+only_regular_clickstream=envelope_signal(min(max(DigAmp*10^(Gain/20),DigAmp),regular_clickstream*10^(Gain/20)),rise_time,SR);
+if target_fre>0 % only filter, when neccessary
+ only_regular_clickstream=filter(targetFIR,1,only_regular_clickstream);
+end
+only_regular_clicktrain=signal(only_regular_clickstream);
+only_regular_clicktrain=setsr(only_regular_clicktrain,1000/SR);
+only_irregular_clickstream=envelope_signal(min(max(DigAmp*10^(Gain/20),DigAmp),irregular_clickstream*10^(Gain/20)),rise_time,SR);
+if target_fre>0 % only filter, when neccessary
+ only_irregular_clickstream=filter(targetFIR,1,only_irregular_clickstream);
+end
+only_irregular_clicktrain=signal(only_irregular_clickstream);
+only_irregular_clicktrain=setsr(only_irregular_clicktrain,1000/SR);
+
+% plotte ein paar hübsche Bilder dazu
+% figure(4)
+% subplot(2,2,1)
+% plot(target_signal);
+% subplot(2,2,2)
+% plot(powerspectrum(target_signal));
+% subplot(2,2,3)
+% plot(flanking_signal);
+% subplot(2,2,4)
+% plot(powerspectrum(flanking_signal));
+% savewave(target_signal,'regular');
+% savewave(flanking_signal,'irregular');
+
+% savewave(target_signal,'stimulus');
+
+if grafix
+ figure(4)
+ subplot(2,1,1)
+ plot(target_signal);
+ subplot(2,1,2)
+ plot(powerspectrum(target_signal));
+end
+
+% ********** envelope_signal **********
+function out = envelope_signal(in,rise_time,SR)
+APts = length(in);
+GPts = round(rise_time/SR);
+if APts<2*GPts
+ error('==> Signal must be loger than 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 aim-mat/tools/@signal/gen_jittered_clicktrains.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gen_jittered_clicktrains.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,313 @@
+function [target_signal,flanking_signal,only_regular_clicktrain,only_irregular_clicktrain]= ...
+ gen_jittered_clicktrains(orgsig,jitter,delay,target_fre,flanker_fre,Gain,FlankerMode,FlankerDelay,grafix)
+%
+% this funtion produces the stimuli needed in Krumbholz et al 2003 and
+% many other regular and irregular filted click trains
+% the clicktrain can be pure when TargetFrequency is =0 otherwise the
+% click train filted with a band pass filter around the given frequency
+%
+% input:
+% orgsig: original signal. Determines length and samperate. SR must be 25000!
+% jitter:
+% the amount of jitter in % (0=regular, 100= maximal jitter)
+% delay:
+% the repetition rate of the signal in ms
+% target_fre:
+% one of the following:
+% 0 0.4 0.5657 0.8 1.1314 1.6 2.2627 3.2 4.5255 6.4
+% if not precice, the nearest one will be taken
+% if 0, then no target will be generated
+% flanker_fre:
+% one of the following:
+% 0 0.4 0.5657 0.8 1.1314 1.6 2.2627 3.2 4.5255 6.4
+% if not precice, the nearest one will be taken
+% if 0, then no flanker will be generated
+
+% flanker_mode:
+% one of the following:
+% m: Flanker band synchronous and irregular (highest threshold)
+% t: Flanker band synchronous and regular (medium threshold)
+% td5: Flanker band synchronous and regular shifted in timepoints (lowest threshold)
+% sb1: Masker regular, flanker band irregular (Ranjnas Experiment)
+% sb2: Masker regular, flanker band regular, but time shifted (Ranjnas other stimulus)
+% sb3: Masker irregular, flanker band regular,
+% sb4: NO masker, flanker band regular (returned in target_signal)
+
+% flanker delay:
+% the delay of the synchronous clicks in ms
+% Gain:
+% the gain of the signal against the masker positiv direction: more signal
+% grafix says, if we want to see a plot of the signal or not
+
+% possible usage:
+% produce the stimulus as in the paper:
+% gen_jittered_clicktrains(signal(1,25000),0,10,1.6,3.2,10,'td5',5,1);
+% play(gen_jittered_clicktrains(signal(1,25000),0,10,3.2,0.8,3,'td5',5))
+%
+% to generate regular clicktrains use
+% [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0,10); play(c);
+%
+% to generate 20 % jitter use:
+% [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0.2,10); play(d);
+%
+% to filter at 3.2 Khz generate 20 % jitter use:
+% [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0.2,10,3.2); play(d);
+%
+% to generate one of Ranjnas stimuli (regular masker at first frequency and irregular target
+% in a different frequency band use) here: regular 40 dB louder then irregular
+% play(gen_jittered_clicktrains(signal(1,25000),1,10,1.6,3.2,40,'sb1',NaN,1)/20)
+% the shift parameter is here ignored
+%
+%
+% to generate one of Ranjnas stimuli (regular masker at first frequency and shifted target
+% in a different frequency band use) here: regular 40 dB louder the shifted
+% play(gen_jittered_clicktrains(signal(1,25000),NaN,10,1.6,3.2,40,'sb2',5,1))
+% in this case the jitter is ignored
+
+% return signals:
+% target_signal is the target band with regular clicks plus irregular clicks with the ratio of "gain"
+% flanking_signal is the flanking band which can be either regular or irregular
+% only_regular_clicktrain is the regular clicks alone
+% only_irregular_clicktrain is the irrregular clicks alone
+%
+% % no random please!
+% rand('state',0);
+
+% input variables:
+% 1 2 3 4 5 6 7 8
+%(orgsig,jitter,delay,flanker_fre,Gain,FlankerMode,FlankerDelay,grafix);
+
+
+
+
+if nargin <9 grafix=0;end
+if nargin <8 FlankerDelay=5; end
+if nargin <7 FlankerMode='td5';end
+if nargin <6 Gain=0;end
+if nargin <5 flanker_fre=3.2;end
+if nargin <4 target_fre=0;end
+if nargin <3 delay=10;end
+if nargin <2
+ jitter=1; % 100 % jitter
+end
+
+if jitter >1
+ disp('jitter must be smaller then 1 (100%)')
+ jitter=1;
+end
+
+% possible Target and Flanker frequencies:
+f(1)=0.4;
+f(2)=0.5657;
+f(3)=0.8;
+f(4)=1.1314;
+f(5)=1.6;
+f(6)=2.2627;
+f(7)=3.2;
+f(8)=4.5255;
+f(9)=6.4;
+
+% TargetFrq = 1.6; % fixed
+% change into the directory with the filter coeffiencs in
+orgdira=which('signal');
+orgdir=fileparts(orgdira);
+od=cd(fullfile(orgdir,'FIR filter coefficients'));
+
+% load filter for Target
+if target_fre==0
+ TargetFrq=0;
+else
+ % load the filter file for the appropriate frequency for the target
+ p=polyfit(1:9,log(f),1);
+ targ=round(solve(p,log(target_fre)));
+ TargetFrq = f(targ);
+ targetFIRFile = sprintf('bp%gw%g',TargetFrq,0.2);
+ targetFIRFile(findstr(targetFIRFile,'.')) = '_';
+ FId = fopen([targetFIRFile '.txt'],'rt');
+ fgetl(FId);
+ targetFIR = fscanf(FId,'%g',151)';
+ fclose(FId);
+end
+
+% load filter for Flanker
+if flanker_fre==0
+ FlankerFrq=0;
+else
+ % load the filter file for the appropriate frequency for the flanker
+ p=polyfit(1:9,log(f),1);
+ flank=round(solve(p,log(flanker_fre)));
+ FlankerFrq = f(flank);
+ flankerFIRFile = sprintf('bp%gw%g',FlankerFrq,0.2);
+ flankerFIRFile(findstr(flankerFIRFile,'.')) = '_';
+ FId = fopen([flankerFIRFile '.txt'],'rt');
+ fgetl(FId);
+ flankerFIR = fscanf(FId,'%g',151)';
+ fclose(FId);
+end
+cd(od); % go back to the old directory
+
+SR = 1000/getsr(orgsig);% all in ms
+sig_length =getlength(orgsig)*1000;
+% the filter coefficients only work when the sr is 25000!
+if getsr(orgsig)~=25000 && target_fre>0
+ disp('gen_jittered_clicktrains::warning: filtering only works for a sample rate of 25000')
+end
+
+rise_time = 25;
+timepoints = 0:SR:sig_length;
+TPts = max(size(timepoints));
+DigAmp = 1;
+SDelay = round(delay/SR);
+
+regular_clickstream = zeros(1,TPts);
+regular_clickstream(1:SDelay:TPts) = DigAmp;
+
+% RANDOMISE THE TARGET
+irregular_clickstream = zeros(1,TPts);
+% randomisation in the range of the jitter boundary
+jitter_time=SDelay*jitter;
+% Idx = ceil(rand*SDelay*2);
+idx = [];count=1;
+while isempty(idx)|| max(idx)0 && strcmp(FlankerMode,'td5')
+ flanker = [zeros(1,round(FlankerDelay/SR)) flanker(1:TPts-round(FlankerDelay/SR))];
+ end
+else
+ flanker = zeros(1,TPts);
+end
+flanker = envelope_signal(flanker,rise_time,SR);
+
+
+% filter the resulting streams in the right frequency bands
+if FlankerFrq~=0
+ f_flanker=filter(flankerFIR,1,flanker);
+else
+ f_flanker=flanker;
+end
+if target_fre>0 % only filter, when neccessary
+ f_targetReg=filter(targetFIR,1,targetReg);
+ f_targetIrr=filter(targetFIR,1,targetIrr);
+else
+ f_targetReg=targetReg;
+ f_targetIrr=targetIrr;
+end
+
+signal_flank=signal(f_flanker);
+signal_flank=setsr(signal_flank,1000/SR);
+target_signal=signal(f_targetReg);
+flanking_signal=signal(f_targetIrr);
+target_signal=setsr(target_signal,1000/SR);
+flanking_signal=setsr(flanking_signal,1000/SR);
+if strcmp(FlankerMode,'sb1') || strcmp(FlankerMode,'sb2')
+ % in this case, the target is the signal plus the flanker:
+ target_signal=target_signal+signal_flank;
+else
+% Signal zu Flanker addieren (stimmt von der Amplitude her wohl nicht, aber
+% für den Moment wirds tun)
+ target_signal=target_signal+signal_flank;
+ flanking_signal=flanking_signal+signal_flank;
+end
+
+%generate the pure random and regular click trains as well
+only_regular_clickstream=envelope_signal(min(max(DigAmp*10^(Gain/20),DigAmp),regular_clickstream*10^(Gain/20)),rise_time,SR);
+if target_fre>0 % only filter, when neccessary
+ only_regular_clickstream=filter(targetFIR,1,only_regular_clickstream);
+end
+only_regular_clicktrain=signal(only_regular_clickstream);
+only_regular_clicktrain=setsr(only_regular_clicktrain,1000/SR);
+only_irregular_clickstream=envelope_signal(min(max(DigAmp*10^(Gain/20),DigAmp),irregular_clickstream*10^(Gain/20)),rise_time,SR);
+if target_fre>0 % only filter, when neccessary
+ only_irregular_clickstream=filter(targetFIR,1,only_irregular_clickstream);
+end
+only_irregular_clicktrain=signal(only_irregular_clickstream);
+only_irregular_clicktrain=setsr(only_irregular_clicktrain,1000/SR);
+
+% plotte ein paar hübsche Bilder dazu
+% figure(4)
+% subplot(2,2,1)
+% plot(target_signal);
+% subplot(2,2,2)
+% plot(powerspectrum(target_signal));
+% subplot(2,2,3)
+% plot(flanking_signal);
+% subplot(2,2,4)
+% plot(powerspectrum(flanking_signal));
+% savewave(target_signal,'regular');
+% savewave(flanking_signal,'irregular');
+
+% savewave(target_signal,'stimulus');
+
+if grafix
+ figure(4)
+ subplot(2,1,1)
+ plot(target_signal);
+ subplot(2,1,2)
+ plot(powerspectrum(target_signal));
+end
+
+% ********** envelope_signal **********
+function out = envelope_signal(in,rise_time,SR)
+APts = length(in);
+GPts = round(rise_time/SR);
+if APts<2*GPts
+ error('==> Signal must be loger than 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 aim-mat/tools/@signal/gen_vowel.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gen_vowel.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,329 @@
+% function to generate an artificial vowel
+function sig=gen_vowel(sig,options)
+% vowel,pitch,scale,halflifeconstant,onsettimeconstant,pitch_jitter,formant_jitter,formant_jitter_bw);%
+
+if nargin < 2
+ options=[];
+end
+
+
+% jitterwidth of jitter in formant frequencies
+%formant_jitter_bw=1; %bandwidth specified in octaves over which the formants are jittered
+if isfield(options,'formant_jitter_bw')
+ formant_jitter_bw=options.formant_jitter_bw;
+else
+ formant_jitter_bw=1; % in octaves
+end
+% jitter in percent of bandwidth
+%formant_jitter=0.0; %------- range is 0 to 1, representing 0% to 100%
+if isfield(options,'formant_jitter')
+ formant_jitter=options.formant_jitter;
+else
+ formant_jitter=0.03; %
+end
+% jitter in pitch
+%pitch_jitter=0.0; %------- range is 0 to 1, representing 0% to 100%
+if isfield(options,'pitch_jitter')
+ pitch_jitter=options.pitch_jitter;
+else
+ pitch_jitter=0.01;
+end
+% the rise of a damped sinusoid is not instantaneous, but like a gamma
+% functin with the following power of t:
+if isfield(options,'onsettimeconstant')
+ onsettimeconstant=options.onsettimeconstant;
+else
+ onsettimeconstant=0.5;
+end% halflife of each formant is calculated by dividing this number by the
+% formant frequency:
+% if halflifeconstant<=0, then fixed to 4 ms
+if isfield(options,'halflifeconstant')
+ halflifeconstant=options.halflifeconstant;
+else
+ halflifeconstant=3;
+end
+% scaling = 1: normal speaker
+if isfield(options,'scale')
+ scale=options.scale;
+else
+ scale=1;
+end
+% f0
+if isfield(options,'pitch')
+ pitch=options.pitch;
+else
+ pitch=100;
+end
+% how long the decay should continue longer then the reprate
+if isfield(options,'carry_decay')
+ carry_decay_parameter=options.carry_decay;
+else
+ carry_decay_parameter=1;
+end
+% normal or is it the octave? In this case, we jump over each second
+if isfield(options,'do_octave')
+ do_octave=options.do_octave;
+else
+ do_octave=0;
+end
+% type of vowel: 'a','e','i','o','u'
+if isfield(options,'vowel')
+ vowel=options.vowel;
+else
+ vowel='a';
+end
+
+
+
+if nargin < 1
+ sig=signal(0.5,16000);
+end
+sr=getsr(sig);
+dur_time=getlength(sig);
+
+
+nr_formants=4;
+
+
+switch vowel
+ case 'a';
+ formfre(1)=730; formfre(2)=1090; formfre(3)=2440; formfre(4)=3300;% standard formant freqs
+ case 'e';
+ formfre(1)=400; formfre(2)=1990; formfre(3)=2550; formfre(4)=3700; % standard formant freqs
+ case 'i';
+ formfre(1)=270; formfre(2)=2260; formfre(3)=3000; formfre(4)=3700;% standard formant freqs
+ case 'o';
+ formfre(1)=570; formfre(2)=850; formfre(3)=2430; formfre(4)=3300;% standard formant freqs
+ case 'u';
+ formfre(1)=300; formfre(2)=850; formfre(3)=2260; formfre(4)=3700;% standard formant freqs
+ otherwise
+ error('signal::gen_vowel: dont know vowel');
+end
+
+% fix all formants to the nearest harmonic of the fundamental
+if isfield(options,'adjust_to_nearest_harmonic')
+ if options.adjust_to_nearest_harmonic==1
+ f0=options.pitch;
+ for formant=1:nr_formants
+ fre=formfre(formant);
+ newfre=round(fre/f0)*f0;
+ formfre(formant)=newfre;
+ end
+ end
+end
+
+
+formfre=formfre.*scale;
+dur_samp=dur_time.*sr; %length of vowel defined in sample points
+sgpp=1/pitch; %standard glottal pulse period.
+pitch_jitter=max(0,min(1,pitch_jitter));
+t=[0:1/sr:(dur_time-(1/sr))]; %our time sequence
+dur_samp=dur_time.*sr; %length of vowel defined in sample points
+
+
+%we now generate a sequence, specified in sample points, which
+%define the spacing of glottal pulses. With zero pitch_jitter the sequence
+%is regular (1/pitch). With a pitch_jitter value of 1 the spacing of glottal
+%pulses fall in a range with an upper limit of double the period of
+%the pitch and a lower limit of 1/sampling rate.
+%The average spacing of glottal pulses is approx 1/pitch
+lwr_pth_jit=0.5-(pitch_jitter/2);
+upr_pth_jit=0.5+(pitch_jitter/2);
+
+gp=cell(nr_formants,1); %for each formant will store pulse time
+for formant=1:nr_formants
+ enough_pulses=0;
+ pulse_number=0;
+ while enough_pulses==0
+ pulse_number=pulse_number+1;
+ pulse_spacing(pulse_number)=max(1,floor(sr.*(sgpp.*2.*(lwr_pth_jit+(upr_pth_jit-lwr_pth_jit)*rand(1)))));
+ pulse_time(pulse_number)=sum(pulse_spacing)-pulse_spacing(1)+1;
+ if pulse_time(pulse_number)>=dur_samp
+ pulse_time=pulse_time(1:pulse_number-1);
+ pulse_number=pulse_number-1;
+ enough_pulses=1;
+ else
+ end
+ end
+
+
+ gp{formant}=pulse_time;
+ clear pulse_time;
+ clear pulse_spacing;
+ no_pulses(formant)=length(gp{formant});
+ pulse_times{formant}=gp{formant};
+end%formant
+
+formant_jitter=max(0,min(1,formant_jitter));
+
+% if no gamma tone, then precalculate the damping function once for all
+% if onsettimeconstant <= 0 && halflifeconstant==0
+ hl=0.04;
+ damping=exp(t.*log(0.5)/hl); %this decays to 0.5 after hl seconds
+ damping=damping/max(damping);
+% end
+
+onsettimes=power(t,onsettimeconstant);
+
+
+%--------------------------------------------------------------------------
+for formant=1:nr_formants
+ lw_log(formant)=max(log10(150), (log10(formfre(formant))- ((formant_jitter_bw.*.3)/2) ) ); %cannot go below 150Hz
+ lw_log_adj(formant)=log10(formfre(formant))-((log10(formfre(formant))-lw_log(formant)).*formant_jitter);
+ up_log(formant)=min(log10(4500),log10(formfre(formant))+ ((formant_jitter_bw.*.3)/2)) ;
+ up_log_adj(formant)=log10(formfre(formant))+((up_log(formant)-log10(formfre(formant))).*formant_jitter);
+end
+
+
+% if we want to generate the octave, we take exactly the same pulses and
+% frequencies, but only every second one:
+if do_octave
+ pulse_step=2;
+else
+ pulse_step=1;
+end
+
+nr_points=length(t);
+final_wave=zeros(dur_samp,nr_formants);
+for formant=1:nr_formants
+ for count=1:pulse_step:no_pulses(formant)-1
+ oneortwo=randperm(2);
+ if oneortwo(1)==1
+ freq=10.^((lw_log_adj(formant)+(log10(formfre(formant))-lw_log_adj(formant))*rand(1))); %lower range
+ else
+ freq=10.^((log10(formfre(formant))+(up_log_adj(formant)-log10(formfre(formant)))*rand(1))); %upper range
+ end
+
+ if freq>1000
+ no_octave=((log10(freq)-3))/.3;
+ lev=-12.*no_octave;
+ else
+ lev=0;
+ end
+ amp=10.^(lev/20);
+
+ if halflifeconstant<=0
+ hl=0.004;
+ else
+ hl=halflifeconstant/freq;
+ end
+
+ nr_relevant_points=pulse_times{formant}(count+1)-pulse_times{formant}(count);
+
+ nr_relevant_points=nr_relevant_points*carry_decay_parameter;
+
+ if onsettimeconstant > 0
+ damping=zeros(nr_relevant_points,1);
+ for jj=1:nr_relevant_points
+ damping(jj)=onsettimes(jj)*exp(t(jj)*log(0.5)/hl); %this decays to 0.5 after hl seconds
+ end
+ damping=damping/max(damping);
+ end
+ grafix=0;
+ if grafix==1
+ figure(234)
+ plot(damping);
+ end
+
+ this_formant=zeros(nr_relevant_points,1);
+ for jj=1:nr_relevant_points
+ sinsin=sin(2*pi*freq*t(jj));
+ this_formant(jj)=amp*sinsin*damping(jj);
+ end
+ start_nr=pulse_times{formant}(count);
+ stop_nr=start_nr+nr_relevant_points-1;
+
+ if stop_nr> nr_points
+ nr_new=nr_points-start_nr+1;
+ this_formant=this_formant(1:nr_new);
+ stop_nr=nr_points;
+ final_wave(start_nr:stop_nr,formant)= final_wave(start_nr:stop_nr,formant)+this_formant;
+ else
+ final_wave(start_nr:stop_nr,formant)= final_wave(start_nr:stop_nr,formant)+this_formant;
+ end
+ end
+end
+final_wave_total=zeros(dur_samp,1);
+for formant=1:nr_formants
+ final_wave_total=final_wave_total+final_wave(:,formant);
+end
+
+% sig=signal(final_wave_total,sr);
+
+if isfield(options,'rise_time')
+ rise_time=options.rise_time;
+else
+ rise_time=0.015;
+end
+
+if isfield(options,'fall_time')
+ fall_time=options.fall_time;
+else
+ fall_time=0.1;
+end
+
+% sigvals=
+final_wave_total=gate_on_off(rise_time,fall_time,final_wave_total,sr);
+sig=signal(final_wave_total,sr);
+%
+% hold_time=length(sig)-rise_time-fall_time;
+% attack=linspace(0,1,round(rise_time*sr));
+%
+% hold=ones(1,round(hold_time*sr));
+% release=linspace(1,0,round(fall_time*sr));
+% envelope=[attack hold release];
+% envelope=envelope(1:getnrpoints(sig));
+% envelope=signal(envelope,sr);
+% sig=sig*envelope;
+
+
+function amp=calc_level(freq);
+%determines the level of a signal at a given frequency after it
+%has been filtered with a low-pass filter of 12dB/octave at 1kHz
+%first calculate if frequency is above 1kHz and if so by how many octaves
+%then multiply by slope.
+if freq>1000
+ no_octave=((log10(freq)-3))/.3;
+ lev=-12.*no_octave;
+else
+ lev=0;
+end
+amp=10.^(lev/20);
+
+
+
+function output=gate_on_off(onset,offset,input,sr)
+%check duration of signal is large enough for both the onset and offset
+%values.
+
+sig_length_samp=length(input);
+onset_length_samp=floor(onset.*sr);
+offset_length_samp=floor(offset.*sr);
+
+if (onset_length_samp+offset_length_samp)>sig_length_samp
+ output=0;
+ disp('---ERROR--- onset and offset duration too large for signal');
+ return
+else end
+
+
+%generate onset and offset amplitudes
+n_on=onset_length_samp;
+k=[1:1:n_on];
+onset_win=(1-cos(2.*pi.*(k./(2.*(n_on-1)))))./2;
+
+n_off=offset_length_samp;
+k=[1:1:n_off];
+offset_win=0.5+((cos(2.*pi.*(k./(2.*(n_off-1)))))./2);
+
+
+
+total_window=ones(sig_length_samp,1);
+total_window(1:onset_length_samp)=onset_win;
+total_window(sig_length_samp-offset_length_samp+1:sig_length_samp)=offset_win;
+
+
+
+output=input.*total_window;
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/genam.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/genam.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,55 @@
+% method of class @signal
+% function sig=genam(sig,fcar,fmod,modgrad)
+%
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+% fcar: carrier frequency (Hz)
+% fmod: modulation frequency (Hz)
+% modgrad: modulation depth in (0-1)
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2003/01/25 12:47:43 $
+% $Revision: 1.4 $
+
+function sig=genam(sig,fc,f_mod,modgrad,modphase,amplitude)
+
+if nargin<6
+ amplitude=1;
+end
+if nargin<6
+ modphase=0;
+end
+if nargin<6
+ modgrad=1;
+end
+
+
+sr=getsr(sig);
+len=getlength(sig);
+
+sin1=sinus(len,sr,fc,1,0);
+sin2=sinus(len,sr,f_mod,1,modphase);
+
+sig=amplitude(modgrad*sin1+1)*sin2;
+
+
+% f1=fc-f_mod;
+% f2=fc;
+% f3=fc+f_mod;
+% sin1=sinus(len,sr,f1,modgrad/2,0);
+% sin2=sinus(len,sr,f2,1,0);
+% sin3=sinus(len,sr,f3,modgrad/2,0);
+% sig=sin1;
+% sig=sig+sin2;
+% sig=sig+sin3;
+
+name=sprintf('AM: modulation: %3.1f Hz, carrier: %4.1f kHz, modgrad: %2.1f',f_mod,fc/1000,modgrad);
+sig=setname(sig,name);
+sig=scaletomaxvalue(sig,1);
+% sig=RampAmplitude(sig,0.01); % baue eine Rampe
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/genam.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/genam.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,43 @@
+% method of class @signal
+% function sig=genam(sig,fcar,fmod,modgrad)
+%
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+% fcar: carrier frequency (Hz)
+% fmod: modulation frequency (Hz)
+% modgrad: modulation depth in (0-1)
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=genam(sig,fc,f0,modgrad)
+
+
+sr=getsr(sig);
+len=getlength(sig);
+
+f1=fc-f0;
+f2=fc;
+f3=fc+f0;
+
+
+sin1=sinus(len,sr,f1,modgrad/2,0);
+sin2=sinus(len,sr,f2,1,0);
+sin3=sinus(len,sr,f3,modgrad/2,0);
+
+
+sig=sin1;
+sig=sig+sin2;
+sig=sig+sin3;
+
+name=sprintf('AM: modulation: %3.1f Hz, carrier: %4.1f kHz, modgrad: %2.1f',f0,fc/1000,modgrad);
+sig=setname(sig,name);
+sig=scaletomaxvalue(sig,1);
+% sig=RampAmplitude(sig,0.01); % baue eine Rampe
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/genbandpassnoise.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/genbandpassnoise.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,51 @@
+% method of class @signal
+% function sig=genbandpassnoise(sig,varargin)
+% INPUT VALUES:
+% sig: @signal with length and samplerate
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=genbandpassnoise(sig,lowfrequency,highfrequency)
+% steepness is given in dB per octave (to make it compatible with Fastl)
+
+len=getlength(sig);
+sr=getsr(sig);
+
+% generate white noise:
+vals=getvalues(sig);
+
+nyquist_frequenz=sr/2;
+N=getnrpoints(sig);
+
+n1=round(lowfrequency/nyquist_frequenz*N/2);
+n2=round(highfrequency/nyquist_frequenz*N/2);
+
+if n1<=0
+ n1=1;
+end
+if n2>N
+ n2=N;
+end
+
+noise1=zeros(size(vals));
+noise2=zeros(size(vals));
+for i=n1:n2
+ noise1(i)=rand(1);
+end
+for i=N-n2:N-n1
+ noise2(i)=rand(1);
+end
+ftband=noise1+ i*noise2;
+vals=ifft(ftband);
+vals=real(vals);
+
+sig=setvalues(sig,vals);
+sig=setname(sig,sprintf('Bandpass filtered noise from %4.1f Hz to %4.1f Hz',lowfrequency,highfrequency));
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generate_kurtosis_noise.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generate_kurtosis_noise.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,122 @@
+
+function generate_kurtosis_noise(sig,kurtois
+
+v=get(glob.f);
+% variance_wanted=get(params,'Variance');
+% skwednes=get(params,'Skewedness');
+
+
+
+
+% change the kurtosis input to something meaningful
+% these values are measured for different inputs of x
+% if raw value for "Kurtosis" is inputted as:
+input_kurt=[1 0.95 0.9 0.85 .8 .7 .6 .5 .4 .3 .25 .2 .15 .125 0.1 ];
+% then the Kurtosis will be:
+output_kurt=[-.05 0.04 0.13 0.26 .4 .7 1.12 1.72 2.58 4 5.11 6.87 9.6 11.8 15];
+
+% to input the real Kurtosis, we need to turn these values around:
+% and find the "input" value for a given Kurtosis:
+kurtosis=interp1(output_kurt,input_kurt,kurtosis_wanted);
+
+% % and the same for the variance. changing the variance does not change the
+% % kurtosis
+% input_var=0:15;
+% output_var=[0.97 .68 .53 .43 .35 .3 .27 .24 .22 .2 .18 .17 .15 .14 .13 .12];
+% variance=interp1(output_var,input_var,variance_wanted);
+
+variance=1;
+
+grafix=0;
+
+if grafix
+ figure(3)
+ clf
+ hold on
+end
+
+nr_points=2000;
+
+stepx=10/nr_points;
+% generate the pdf
+x=-5:stepx:5;
+
+p_pdf=pdf('Normal',x,0,1);
+p_pdf=p_pdf/max(p_pdf);
+
+% p_cdf=cumsum(p_pdf);
+% p_cdf=p_cdf/max(p_cdf);
+% if grafix
+% plot(x,p_pdf,'b.');hold on
+% end
+
+% scale along x to change the variance:
+y=p_pdf;
+
+
+new_x=x*variance;
+ny=interp1(new_x,y,x);
+ny(isnan(ny))=0;
+
+glob.pdf_x=x; % save for plotting
+glob.pdf_y=ny;
+
+% % and the change in y to modify the Kurtosis
+%
+% generate random numbers by reversing the cdf
+new_cdf=cumsum(ny); %calculate the pdf:
+new_cdf=new_cdf/max(new_cdf); % and normalise
+
+for i=1:nr_points/2-1
+% dx=abs(x(nr_points/2-i));
+ dy=abs(0.5-new_cdf(i));
+ ndy=power((2*dy),kurtosis);
+ new_cdf(i)=0.5-ndy/2;
+ new_cdf(nr_points-i)=0.5+ndy/2;
+end
+
+
+if grafix
+
+ old_cdf=cumsum(y);
+ old_cdf=old_cdf/max(old_cdf); % and normalise
+
+ plot(x,old_cdf,'-b.');
+ plot(x,new_cdf,'-r.'); hold on
+ legend({'cumulative normal distribution';'modfied cdf'},2);
+end
+
+
+serachy=1/nr_points:1/nr_points:1;
+rev_cdf=zeros(1,nr_points-1);
+
+
+
+for i=1:nr_points-1
+ rev_cdf(i)=find(new_cdf>serachy(i),1,'first');
+end
+
+% clf
+% plot(rev_cdf,'r.');
+
+r=round(rand(length(v),1)*(nr_points-1)+0.5);
+
+rev_p=rev_cdf(r);
+
+% clf
+% hist(rev_p,100)
+
+
+% and normalise to the right output range
+rev_p=(rev_p-nr_points/2)/nr_points*10;
+
+% return
+% v=random('norm',0,sqrt(variance),length(v),1);
+
+
+glob.f=set(glob.f,rev_p');
+glob.f=scaletorms(glob.f,sqrt(get(params,('rms-value'))));
+
+assignin('base','f',glob.f);
+
+% f=scaletomaxvalue(f,1);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generate_kurtosis_noise.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generate_kurtosis_noise.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,122 @@
+
+function [sig,x_pdf,y_pdf]=generate_kurtosis_noise(sig,kurtosis_wanted)
+% generate a signal with a given kurtosis
+
+% do we want to see anything?
+grafix=0;
+
+v=get(sig);
+% variance_wanted=get(params,'Variance');
+% skwednes=get(params,'Skewedness');
+
+
+
+
+% change the kurtosis input to something meaningful
+% these values are measured for different inputs of x
+% if raw value for "Kurtosis" is inputted as:
+input_kurt=[1 0.95 0.9 0.85 .8 .7 .6 .5 .4 .3 .25 .2 .15 .125 0.1 ];
+% then the Kurtosis will be:
+output_kurt=[-.05 0.04 0.13 0.26 .4 .7 1.12 1.72 2.58 4 5.11 6.87 9.6 11.8 15];
+
+% to input the real Kurtosis, we need to turn these values around:
+% and find the "input" value for a given Kurtosis:
+kurtosis=interp1(output_kurt,input_kurt,kurtosis_wanted);
+
+% % and the same for the variance. changing the variance does not change the
+% % kurtosis
+% input_var=0:15;
+% output_var=[0.97 .68 .53 .43 .35 .3 .27 .24 .22 .2 .18 .17 .15 .14 .13 .12];
+% variance=interp1(output_var,input_var,variance_wanted);
+
+variance=1;
+
+
+
+if grafix
+ figure(3)
+ clf
+ hold on
+end
+
+nr_points=2000;
+
+stepx=10/nr_points;
+% generate the pdf
+x=-5:stepx:5;
+
+p_pdf=pdf('Normal',x,0,1);
+p_pdf=p_pdf/max(p_pdf);
+
+% p_cdf=cumsum(p_pdf);
+% p_cdf=p_cdf/max(p_cdf);
+% if grafix
+% plot(x,p_pdf,'b.');hold on
+% end
+
+% scale along x to change the variance:
+y=p_pdf;
+
+
+new_x=x*variance;
+ny=interp1(new_x,y,x);
+ny(isnan(ny))=0;
+
+x_pdf=x; % save for plotting
+y_pdf=ny;
+
+% % and the change in y to modify the Kurtosis
+%
+% generate random numbers by reversing the cdf
+new_cdf=cumsum(ny); %calculate the pdf:
+new_cdf=new_cdf/max(new_cdf); % and normalise
+
+for i=1:nr_points/2-1
+% dx=abs(x(nr_points/2-i));
+ dy=abs(0.5-new_cdf(i));
+ ndy=power((2*dy),kurtosis);
+ new_cdf(i)=0.5-ndy/2;
+ new_cdf(nr_points-i)=0.5+ndy/2;
+end
+
+
+if grafix
+
+ old_cdf=cumsum(y);
+ old_cdf=old_cdf/max(old_cdf); % and normalise
+
+ plot(x,old_cdf,'-b.');
+ plot(x,new_cdf,'-r.'); hold on
+ legend({'cumulative normal distribution';'modfied cdf'},2);
+end
+
+
+serachy=1/nr_points:1/nr_points:1;
+rev_cdf=zeros(1,nr_points-1);
+
+
+
+for i=1:nr_points-1
+ rev_cdf(i)=find(new_cdf>serachy(i),1,'first');
+end
+
+% clf
+% plot(rev_cdf,'r.');
+
+r=round(rand(length(v),1)*(nr_points-1)+0.5);
+
+rev_p=rev_cdf(r);
+
+% clf
+% hist(rev_p,100)
+
+
+% and normalise to the right output range
+rev_p=(rev_p-nr_points/2)/nr_points*10;
+
+% return
+% v=random('norm',0,sqrt(variance),length(v),1);
+
+
+sig=set(sig,rev_p');
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generateamnoise.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generateamnoise.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% method of class @signal
+% function sig=genbandpassnoise(sig,varargin)
+% INPUT VALUES:
+% sig: @signal with length and samplerate
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=generateAMnoise(sig,fre,modgrad)
+
+len=getlength(sig);
+sr=getsr(sig);
+
+% generate white noise:
+vals=getvalues(sig);
+vals=rand(size(vals)).*2-1;
+sig=setvalues(sig,vals);
+
+envelope=generatesinus(sig,fre,1,0);
+envelope=(envelope+1)/2;
+
+sig=sig*envelope;
+
+
+sig=setname(sig,sprintf('AM noise Frequency %4.1f Hz',fre));
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generateclicktrain.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generateclicktrain.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% method of class @signal
+% function sig=generateclicktrain(sig,frequency,[amplitude])
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+% frequency: frequency of the clicktrain (Hz)
+% amplitude: amplitude [1]
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=generateclicktrain(sig,frequency,amplitude)
+
+if nargin < 3
+ amplitude=1;
+end
+
+name= sprintf('Clicktrain %5.2f Hz',frequency);
+
+df=floor(getsr(sig)/frequency);
+to=time2bin(sig,getlength(sig));
+clicks=1:df:to; % start at the sampletime
+
+sig=setbinvalue(sig,clicks,amplitude);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generatedampsinus.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generatedampsinus.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,410 @@
+% method of class @signal
+% function sig=generatedampsinus(sig,carfre,modfre,amplitude,halflife)
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+% carfre: carrier frequency (Hz) [1000]
+% modfre: modulation frequency (Hz) [100]
+% amplitude: [1]
+% halflife: time for the envelope envelope to decrease exponentielly
+% to 1/2
+%
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2003/07/28 14:20:20 $
+% $Revision: 1.6 $
+
+
+function sig=generatedampsinus(sig,carfre,modfre,amplitude,halflife,jitter)
+% generates a damped sinusoid, that is a carrier pure tone modulated with a
+% exponentially decreasing envelope.
+% sig is the signal
+% carfre is the carrier frequency of the pure tone
+% modfre is the modulation frequency (in Hz)
+% amplitude is the final amplitude
+% halflife is the time in seconds, in which the envelope drops to its half value
+% if halflife is 'gamma', instead a gammaenvelope is used
+
+% jitter is how regular the pulses are (0-1) 1=100%
+% if jitter is 'repeat', only one pulse is generated and repeated
+
+
+if nargin < 6
+ jitter=0;
+end
+if nargin < 5
+ halflife=0.01;
+end
+if nargin < 4
+ amplitude=1;
+end
+
+if nargin < 3
+ modfre=100;
+end
+if nargin < 2
+ carfre=1000;
+end
+
+
+if isequal(halflife,'gamma') && isequal(jitter,'repeat')
+ % code for Tom's 2010 MSc project
+
+ sinus=generatesinus(sig,carfre,amplitude,0);
+ % calculate envelope and mult both
+ envelope=sig;
+
+ env_vals=getvalues(envelope);
+ sr=getsr(envelope);
+ reprate=1/modfre;
+
+
+ sig_len=getlength(sig);
+ % when regular, all modulataions are at the same time:
+ if jitter==0
+ pulse_times=0:reprate:sig_len;
+ else
+ nr_pulses=ceil(sig_len/reprate);
+ modulation_period=1/modfre;
+ pulse_times(1)=0;
+ for n = 2:nr_pulses
+ jittering=(rand-0.5*jitter)*modulation_period;
+ pulse_times(n) = pulse_times(n-1) + modulation_period+jittering;
+ end
+ end
+
+
+
+ % oldval=0;
+ % corr=exp(1/sr/time_const);
+ % t=0;
+ next_pulse=pulse_times(1);
+ pulse_counter=1;
+
+ % for i=1:getnrpoints(envelope);
+ % oldval=oldval/corr;
+ % t=t+1/sr;
+ % if t>next_pulse
+ % oldval=1;
+ % pulse_counter=pulse_counter+1;
+ % if length(pulse_times)>=pulse_counter
+ % next_pulse=pulse_times(pulse_counter);
+ % else
+ % next_pulse=inf;
+ % end
+ % end
+ % env_vals(i)= oldval;
+ % end
+
+ % onsettimeconstant
+ %
+ t=[0:1/sr:reprate-1/sr]*500;
+ env=power(t,4).*exp(-2*pi*t/2);
+ env=env./max(env);
+
+ % e=linspace(env(length(env)-l),0,l+1);
+ % env(length(env)-l:end)=e;
+
+ % e=linspace(1,0,l+1);
+ % env(length(env)-l:end)=env(length(env)-l:end).*e.*e;
+
+ t=0;
+ ct=1;
+ for i=1:getnrpoints(envelope);
+ t=t+1/sr;
+ ct=ct+1;
+ if t>next_pulse
+ ct=1;
+ pulse_counter=pulse_counter+1;
+ if length(pulse_times)>=pulse_counter
+ next_pulse=pulse_times(pulse_counter);
+ else
+ next_pulse=inf;
+ end
+ end
+ if ct>length(env)
+ env_vals(i)= 0;
+ else
+ env_vals(i)= env(ct);
+ end
+ end
+
+
+
+ %
+ % onsettime=0;
+ % for i=1:getnrpoints(envelope);
+ % t=t+1/sr;
+ %
+ % % env_vals(i)= exp(-(time)/time_const);
+ % env_vals(i)= power(t,onsettime)*exp(-(t)/time_const);
+ % t=mod(t,reprate);
+ %
+ % end
+ envelope=setvalues(envelope,env_vals);
+ envelope=envelope/max(envelope)*amplitude;
+ envelope=setstarttime(envelope,0);
+
+ % set the envelope and the amplitude
+ sig=sinus*envelope;
+
+ sig=setname(sig,sprintf('damped sinusoid %4.2f kHz, Modulation=%4.1f Hz, halflife=%4.1f ms',carfre/1000,modfre,halflife*1000));
+
+ % plot(sig)
+
+
+
+
+ return
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+sinus=generatesinus(sig,carfre,amplitude,0);
+
+% calculate envelope and mult both
+envelope=sig;
+
+time_const=halflife/0.69314718;
+
+env_vals=getvalues(envelope);
+sr=getsr(envelope);
+reprate=1/modfre;
+
+
+sig_len=getlength(sig);
+% when regular, all modulataions are at the same time:
+if jitter==0
+ pulse_times=0:reprate:sig_len;
+else
+ nr_pulses=ceil(sig_len/reprate);
+ modulation_period=1/modfre;
+ pulse_times(1)=0;
+ for n = 2:nr_pulses
+ jittering=(rand-0.5*jitter)*modulation_period;
+ pulse_times(n) = pulse_times(n-1) + modulation_period+jittering;
+ end
+end
+
+
+
+% oldval=0;
+% corr=exp(1/sr/time_const);
+% t=0;
+next_pulse=pulse_times(1);
+pulse_counter=1;
+
+% for i=1:getnrpoints(envelope);
+% oldval=oldval/corr;
+% t=t+1/sr;
+% if t>next_pulse
+% oldval=1;
+% pulse_counter=pulse_counter+1;
+% if length(pulse_times)>=pulse_counter
+% next_pulse=pulse_times(pulse_counter);
+% else
+% next_pulse=inf;
+% end
+% end
+% env_vals(i)= oldval;
+% end
+
+% onsettimeconstant
+%
+t=[0:1/sr:reprate-1/sr]*500;
+env=power(t,4).*exp(-2*pi*t/2);
+env=env./max(env);
+
+% e=linspace(env(length(env)-l),0,l+1);
+% env(length(env)-l:end)=e;
+
+% e=linspace(1,0,l+1);
+% env(length(env)-l:end)=env(length(env)-l:end).*e.*e;
+
+t=0;
+ct=1;
+for i=1:getnrpoints(envelope);
+ t=t+1/sr;
+ ct=ct+1;
+ if t>next_pulse
+ ct=1;
+ pulse_counter=pulse_counter+1;
+ if length(pulse_times)>=pulse_counter
+ next_pulse=pulse_times(pulse_counter);
+ else
+ next_pulse=inf;
+ end
+ end
+ if ct>length(env)
+ env_vals(i)= 0;
+ else
+ env_vals(i)= env(ct);
+ end
+end
+
+
+
+%
+% onsettime=0;
+% for i=1:getnrpoints(envelope);
+% t=t+1/sr;
+%
+% % env_vals(i)= exp(-(time)/time_const);
+% env_vals(i)= power(t,onsettime)*exp(-(t)/time_const);
+% t=mod(t,reprate);
+%
+% end
+envelope=setvalues(envelope,env_vals);
+envelope=envelope/max(envelope)*amplitude;
+envelope=setstarttime(envelope,0);
+
+% set the envelope and the amplitude
+sig=sinus*envelope;
+
+sig=setname(sig,sprintf('damped sinusoid %4.2f kHz, Modulation=%4.1f Hz, halflife=%4.1f ms',carfre/1000,modfre,halflife*1000));
+
+% plot(sig)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+%
+%
+%
+% % from here on old code, might not work!
+%
+% sinus=generatesinus(sig,carfre,amplitude,0);
+%
+% % calculate envelope and mult both
+% envelope=sig;
+%
+% time_const=halflife/0.69314718;
+%
+% env_vals=getvalues(envelope);
+% sr=getsr(envelope);
+% reprate=1/modfre;
+%
+%
+% sig_len=getlength(sig);
+% % when regular, all modulataions are at the same time:
+% if jitter==0
+% pulse_times=0:reprate:sig_len;
+% else
+% nr_pulses=ceil(sig_len/reprate);
+% modulation_period=1/modfre;
+% pulse_times(1)=0;
+% for n = 2:nr_pulses
+% jittering=(rand-0.5*jitter)*modulation_period;
+% pulse_times(n) = pulse_times(n-1) + modulation_period+jittering;
+% end
+% end
+%
+%
+%
+% % oldval=0;
+% % corr=exp(1/sr/time_const);
+% % t=0;
+% next_pulse=pulse_times(1);
+% pulse_counter=1;
+%
+% % for i=1:getnrpoints(envelope);
+% % oldval=oldval/corr;
+% % t=t+1/sr;
+% % if t>next_pulse
+% % oldval=1;
+% % pulse_counter=pulse_counter+1;
+% % if length(pulse_times)>=pulse_counter
+% % next_pulse=pulse_times(pulse_counter);
+% % else
+% % next_pulse=inf;
+% % end
+% % end
+% % env_vals(i)= oldval;
+% % end
+%
+% % onsettimeconstant
+% %
+% t=[0:1/sr:reprate-1/sr]*500;
+% env=power(t,4).*exp(-2*pi*t/2);
+% env=env./max(env);
+%
+% % e=linspace(env(length(env)-l),0,l+1);
+% % env(length(env)-l:end)=e;
+%
+% % e=linspace(1,0,l+1);
+% % env(length(env)-l:end)=env(length(env)-l:end).*e.*e;
+%
+% t=0;
+% ct=1;
+% for i=1:getnrpoints(envelope);
+% t=t+1/sr;
+% ct=ct+1;
+% if t>next_pulse
+% ct=1;
+% pulse_counter=pulse_counter+1;
+% if length(pulse_times)>=pulse_counter
+% next_pulse=pulse_times(pulse_counter);
+% else
+% next_pulse=inf;
+% end
+% end
+% if ct>length(env)
+% env_vals(i)= 0;
+% else
+% env_vals(i)= env(ct);
+% end
+% end
+%
+%
+%
+% %
+% % onsettime=0;
+% % for i=1:getnrpoints(envelope);
+% % t=t+1/sr;
+% %
+% % % env_vals(i)= exp(-(time)/time_const);
+% % env_vals(i)= power(t,onsettime)*exp(-(t)/time_const);
+% % t=mod(t,reprate);
+% %
+% % end
+% envelope=setvalues(envelope,env_vals);
+% envelope=envelope/max(envelope)*amplitude;
+% envelope=setstarttime(envelope,0);
+%
+% % set the envelope and the amplitude
+% sig=sinus*envelope;
+%
+% sig=setname(sig,sprintf('damped sinusoid %4.2f kHz, Modulation=%4.1f Hz, halflife=%4.1f ms',carfre/1000,modfre,halflife*1000));
+%
+% % plot(sig)
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generatedampsinus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generatedampsinus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,80 @@
+% method of class @signal
+% function sig=generatedampsinus(sig,carfre,modfre,amplitude,halflife)
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+% carfre: carrier frequency (Hz) [1000]
+% modfre: modulation frequency (Hz) [100]
+% amplitude: [1]
+% halflife: time for the envelope envelope to decrease exponentielly
+% to 1/2
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=generatedampsinus(sig,carfre,modfre,amplitude,halflife,onsettime)
+% generates a damped sinusoid, that is a carrier pure tone modulated with a
+% exponentially decreasing envelope.
+% sig is the signal
+% carfre is the carrier frequency of the pure tone
+% modfre is the modulation frequency (in Hz)
+% amplitude is the final amplitude
+% halflife is the time in seconds, in which the envelope drops to its half value
+% onsettime is the time in wich the envelope reaches its maximum in seconds
+% shift is a shift of the envelope in seconds
+
+
+% if nargin < 7
+% shift=0;
+% end
+if nargin < 6
+ onsettime=0;
+end
+if nargin < 5
+ halflife=0.01;
+end
+if nargin < 4
+ amplitude=1;
+end
+
+if nargin < 3
+ modfre=100;
+end
+if nargin < 2
+ carfre=1000;
+end
+
+
+sinus=generatesinus(sig,carfre,amplitude,0);
+
+% calculate envelope and mult both
+envelope=sig;
+time_const=halflife/0.69314718;
+
+env_vals=getvalues(envelope);
+time=0;
+sr=getsr(envelope);
+reprate=1/modfre;
+
+for i=1:getnrpoints(envelope);
+ time=time+1/sr;
+
+% env_vals(i)= exp(-(time)/time_const);
+ env_vals(i)= power(time,onsettime)*exp(-(time)/time_const);
+ time=mod(time,reprate);
+
+end
+envelope=setvalues(envelope,env_vals);
+envelope=envelope/max(envelope)*amplitude;
+envelope=setstarttime(envelope,0);
+
+% set the envelope and the amplitude
+sig=sinus*envelope;
+
+sig=setname(sig,sprintf('Damped Sinus %4.2f kHz, Modulation=%4.2f Hz, halflife=%4.2f ms',carfre/1000,modfre,halflife*1000));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generatefromsimulinkstructure.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generatefromsimulinkstructure.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% method of class @signal
+% function sig=generatefromsimulinkstructure(sig,struct)
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+% struct: struct, that is exported from simulink
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=generatefromsimulinkstructure(sig,struct)
+
+%sr=struct.time(2)-struct.time(1);
+sr=1;
+len=length(struct.signals(1).values)*sr;
+vals=struct.signals(1).values;
+
+if size(vals,1)>1 & size(vals,2) > 1
+ vals=vals(end,:);
+end
+
+sig=signal(size(vals,2),1/sr);
+sig=setvalues(sig,vals);
+
+%sig=signal(vals);
+%sig=setsr(sig,1/sr);
+sig=setname(sig,struct.blockName);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/generatefromspiketrain.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/generatefromspiketrain.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,12 @@
+function sig=generatefromspiketrain(sig,st)
+
+vals=zeros(size(getvalues(sig)));
+times=time2bin(sig,st);
+
+maxval=length(vals);
+selecttimes=times(find(times>0 & times max_fre
+ disp('error: genharmonics: fundamental must be smaller then highest frequency');
+ return;
+end
+
+s=signal(length,samplerate);
+if max_fre>1000
+ s=setname(s,sprintf('Harmonic Signal - f0=%4.1f Hz, type: %s (from %2.2f kHz to %2.2f kHz)',fundamental,type,min_fre/1000,max_fre/1000));
+else
+ s=setname(s,sprintf('Harmonic Signal - f0=%4.1f Hz, type: %s (from %3.0 Hz to %3.0f Hz)',fundamental,type,min_fre,max_fre));
+end
+
+if calculate_amplitude_with_slopes
+ s=setname(s,sprintf('Harmonic Signal - modfre=%4.1f Hz, type: %s (cf: %2.2f kHz, low slope: %3.0f dB/oct, high slope %3.0f dB/oct)',fundamental,type,fc/1000,lowslope,highslope));
+end
+
+% in case of sloped amplitudes, we dont want a limit on harmonics
+if calculate_amplitude_with_slopes
+ max_fre=getsr(sig)/2;
+ min_fre=0;
+end
+
+% if limit of harmonics is explicitly given
+if ~strcmp(str_highestharmonic,'')
+ max_fre=highestharmonic*fundamental;
+end
+if ~strcmp(str_lowestharmonic,'')
+ min_fre=lowestharmonic*fundamental;
+end
+
+fre=fundamental;
+count_partials=1;
+while fre <= max_fre
+ if fre >= min_fre
+ temp=signal(length,samplerate);
+ amplitude=1;
+ phase=0;
+ offset=0;
+ if strcmp(type,'mistunedharmonic') % in %
+ eval(sprintf('nr=%s;',str_harmnr{1}));
+ if count_partials==nr
+ offset=fundamental*changeby/100;
+ amplitude=1;
+ phase=0;
+ end
+ end
+ if strcmp(type,'shiftallcomponents') % in Hz
+ offset=changeby;
+ amplitude=1;
+ phase=0;
+ end
+ if strcmp(type,'decreaseoddphase')
+ % phase must be given in degree!
+ if mod(count_partials,2)==1
+ amplitude=1;
+ phase=changeby;
+ end
+ end
+
+ if strcmp(type,'decrease_amplitude_linear')
+ % the amount must be given in changeby!
+ amplitude=1*power(10,(-changeby*count_partials)/20);
+ ampscale=1;
+ else
+ ampscale=filterbandamp(fre+offset,amplitude,fc,df1,bandwidth,df2);
+ end
+ amplitude=amplitude*ampscale;
+
+
+ % stattdessen mit Slopes:
+ if calculate_amplitude_with_slopes
+ % calculate the distance from cf (in octaves)
+ % and from this the attenuation
+ distance=log2(fre/fc);
+ if distance >= 0
+ atten=distance*highslope;
+ else
+ atten=-distance*lowslope;
+ end
+ amplitude=1*power(10,-atten/20);
+ end
+
+ if strcmp(type,'decreaseoddamplitude')
+ if mod(count_partials,2)==1
+ amplitude=amplitude*power(10,changeby/20);
+ end
+ end
+ if strcmp(type,'decreaseevenamplitude')
+ if mod(count_partials,2)==0
+ amplitude=amplitude*power(10,changeby/20);
+ end
+ end
+
+
+ switch str_which_harmonics{1}
+ case 'all'
+ case 'only odd'
+ if mod(count_partials,2)==0
+ amplitude=0;
+ end
+ case 'only even'
+ if mod(count_partials,2)==1
+ amplitude=0;
+ end
+ end
+
+ % degree2rad
+ switch setphase
+ case 'random'
+ piphase=rand(1)*2*pi+pi;
+ case 'cos'
+% piphase=phase*(pi/180)+pi/2;
+ piphase=phase*(pi/180);
+ end
+% disp(sprintf('fre: %3.2f amp:%2.1f',fre,amplitude*100));
+% amplitude
+% fre
+ temp=generatesinus(temp,fre+offset,amplitude,piphase);
+
+ % add them up!
+ s=s+temp;
+ end
+ fre=fre+fundamental;
+ count_partials=count_partials+1;
+end
+
+sig=s;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/genharmonics.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/genharmonics.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,299 @@
+% method of class @signal
+% function sig=genharmonicstim(sig,varargin)
+% INPUT VALUES:
+% sig: @signal with length and samplerate
+% varargin must have several parameters:
+% fundamental (default 128) = periodicity
+% min_fre (128) = lowest possible frequency
+% max_fre (10000) = highest possible frequency
+%
+% envelope of amplitudes
+% either
+% filterprop ([256,256,1024,512]) = fc, df1, bandwidth, df2 (in Hz)
+% default values: fc=3500;
+% df1=256;
+% bandwidth=1024;
+% df2=512;
+% the amplitdes can also be given by cf and two slopes for
+% higher and lower frequencies:
+% eg 'cf',1000,'lowslope',25,'highslope',38
+% the highest and lowest possible allowed harmonic are given
+% in either case by giving 'lowestharmonic' and
+% 'highestharmonic' (default value: 1 and inf)
+%
+% type = which type (default none)
+% filtered,
+% decreaseoddamplitude,
+% decreaseoddphase
+% shiftallcomponents
+% mistunedharmonic
+% decrease_amplitude_linear
+% changeby = value, that the odd harmonics shall vary (degree or dB or whatever)
+% phases must be in degrees!
+% RETURN VALUE:
+% sig: @signal
+%
+% examples:
+% create a stimulus with certain filtercharacteristic with random
+% phase, and every second harmonic reduced by an amount
+% tone(i)=genharmonics(sig,'fundamental',chroma,...
+% 'filterprop',[toneheight,handles.df1,handles.bw,handles.df2],...
+% 'phase','random',...
+% 'type','decreaseoddamplitude',...
+% 'changeby',octheight...
+% );
+%
+
+% (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=genharmonics(sig,varargin)
+
+if mod(nargin,2)==0
+ disp('odd number of parameters - please input a full set of parameters and arguments');
+ return;
+end
+str_fundamental=getargument(varargin,'fundamental');
+str_type=getargument(varargin,'type');
+str_harmnr=getargument(varargin,'harmonicnumber');
+str_changeby=getargument(varargin,'changeby');
+str_filterprop=getargument(varargin,'filterprop');
+str_fc=getargument(varargin,'fc');
+str_lowslope=getargument(varargin,'lowslope');
+str_highslope=getargument(varargin,'highslope');
+str_lowestharmonic=getargument(varargin,'lowestharmonic');
+str_highestharmonic=getargument(varargin,'highestharmonic');
+str_bw=getargument(varargin,'bw');
+str_phase=getargument(varargin,'phase');
+str_min_fre=getargument(varargin,'min_fre');
+str_max_fre=getargument(varargin,'max_fre');
+
+% defaultvalues:
+if strcmp(str_filterprop,'')
+ if strcmp(str_changeby,'')
+ str_filterprop{1}=[256,256,1024,512];
+ fc=256;
+ df1=256;
+ bandwidth=1024;
+ df2=512;
+ else
+ min_fre=str_min_fre{1};
+ max_fre=str_max_fre{1};
+ df1=1;
+ df2=1;
+ fc=min_fre;
+ bandwidth=max_fre-min_fre;
+ end
+else
+ %eval(sprintf('filterprop=%s;',str_filterprop{1}));
+ fc=str_filterprop{1}(1);
+ df1=str_filterprop{1}(2);
+ bandwidth=str_filterprop{1}(3);
+ df2=str_filterprop{1}(4);
+end
+if strcmp(str_changeby,'')
+else
+ if isnumeric(str_changeby{1})
+ changeby=str_changeby{1};
+ else
+ eval(sprintf('changeby=%f;',str_changeby{1}));
+ end
+end
+
+% different method of defining envelope: center frequency is the
+% highest point, highslope and lowslope define the amplitude on both
+% sides for each harmonic
+if ~strcmp(str_lowslope,'') && ~strcmp(str_highslope,'')
+ lowslope=str_lowslope{1};
+ highslope=str_highslope{1};
+ calculate_amplitude_with_slopes=1;
+
+ % test with
+ % plot(powerspectrum(genharmonics(signal(0.1,16000),'fc',2000,'lowslope',30,'highslope',40,'fundamental',250)))
+else
+ calculate_amplitude_with_slopes=0;
+end
+
+if strcmp(str_type,'')
+ str_type{1}='';
+ type='';
+else
+ type=str_type{1};
+end
+
+if strcmp(str_phase,'')
+ setphase='cosine';
+else
+ setphase=str_phase{1};
+end
+
+if strcmp(str_fundamental,'')
+ str_fundamental{1}='128';
+ fundamental=128;
+else
+ if isnumeric(str_fundamental{1})
+ fundamental=str_fundamental{1};
+ else
+ eval(sprintf('fundamental=%s;',str_fundamental{1}));
+ end
+end
+
+if strcmp(str_lowestharmonic,'')
+ lowestharmonic=1;
+else
+ if isnumeric(str_lowestharmonic{1})
+ lowestharmonic=str_lowestharmonic{1};
+ else
+ eval(sprintf('lowestharmonic=%s;',lowestharmonic{1}));
+ end
+end
+if strcmp(str_highestharmonic,'')
+ highestharmonic=inf;
+else
+ if isnumeric(str_highestharmonic{1})
+ highestharmonic=str_highestharmonic{1};
+ else
+ eval(sprintf('highestharmonic=%s;',highestharmonic{1}));
+ end
+end
+
+if strcmp(str_fc,'')
+else
+ if isnumeric(str_fc{1})
+ fc=str_fc{1};
+ else
+ eval(sprintf('fc=%s;',str_fc{1}));
+ end
+end
+
+if strcmp(str_bw,'')
+else
+ if isnumeric(str_bw{1})
+ bandwidth=str_bw{1};
+ else
+ eval(sprintf('bandwidth=%s;',str_bw{1}));
+ end
+end
+
+samplerate=sig.samplerate;
+length=getlength(sig);
+
+
+% begin!
+
+max_fre=fc+bandwidth+df2;
+min_fre=fc-df1;
+if (min_fre<0) %squeese df1 to go from 0 to fc
+ df1=df1-abs(min_fre);
+% disp('df1 was reduced')
+end
+
+if fundamental > max_fre
+ disp('error: genharmonics: fundamental must be smaller then highest frequency');
+ return;
+end
+
+s=signal(length,samplerate);
+if max_fre>1000
+ s=setname(s,sprintf('Harmonic Signal - f0=%4.1f Hz, type: %s (from %2.2f kHz to %2.2f kHz)',fundamental,type,min_fre/1000,max_fre/1000));
+else
+ s=setname(s,sprintf('Harmonic Signal - f0=%4.1f Hz, type: %s (from %3.0 Hz to %3.0f Hz)',fundamental,type,min_fre,max_fre));
+end
+
+if calculate_amplitude_with_slopes
+ s=setname(s,sprintf('Harmonic Signal - modfre=%4.1f Hz, type: %s (cf: %2.2f kHz, low slope: %3.0f dB/oct, high slope %3.0f dB/oct)',fundamental,type,fc/1000,lowslope,highslope));
+end
+
+% in case of sloped amplitudes, we dont want a limit on harmonics
+if calculate_amplitude_with_slopes
+ max_fre=getsr(sig)/2;
+ min_fre=0;
+end
+
+% if limit of harmonics is explicitly given
+if ~strcmp(str_highestharmonic,'')
+ max_fre=highestharmonic*fundamental;
+end
+if ~strcmp(str_lowestharmonic,'')
+ min_fre=lowestharmonic*fundamental;
+end
+
+fre=fundamental;
+count_partials=1;
+while fre <= max_fre
+ if fre >= min_fre
+ temp=signal(length,samplerate);
+ amplitude=1;
+ phase=0;
+ offset=0;
+ if strcmp(type,'mistunedharmonic') % in %
+ eval(sprintf('nr=%s;',str_harmnr{1}));
+ if count_partials==nr
+ offset=fundamental*changeby/100;
+ amplitude=1;
+ phase=0;
+ end
+ end
+ if strcmp(type,'shiftallcomponents') % in Hz
+ offset=changeby;
+ amplitude=1;
+ phase=0;
+ end
+ if strcmp(type,'decreaseoddphase')
+ % phase must be given in degree!
+ if mod(count_partials,2)==1
+ amplitude=1;
+ phase=changeby;
+ end
+ end
+
+ if strcmp(type,'decrease_amplitude_linear')
+ % the amount must be given in changeby!
+ amplitude=1*power(10,(-changeby*count_partials)/20);
+ end
+
+ ampscale=filterbandamp(fre+offset,amplitude,fc,df1,bandwidth,df2);
+ amplitude=amplitude*ampscale;
+
+
+ % stattdessen mit Slopes:
+ if calculate_amplitude_with_slopes
+ % calculate the distance from cf (in octaves)
+ % and from this the attenuation
+ distance=log2(fre/fc);
+ if distance >= 0
+ atten=distance*highslope;
+ else
+ atten=-distance*lowslope;
+ end
+ amplitude=1*power(10,-atten/20);
+ end
+
+ if strcmp(type,'decreaseoddamplitude')
+ if mod(count_partials,2)==1
+ amplitude=amplitude*power(10,changeby/20);
+ end
+ end
+ if strcmp(type,'decreaseevenamplitude')
+ if mod(count_partials,2)==0
+ amplitude=amplitude*power(10,changeby/20);
+ end
+ end
+
+ % degree2rad
+ if strcmp(setphase,'random')
+ piphase=rand(1)*2*pi+pi;
+ else
+ piphase=phase*(pi/180)+pi/2;
+ end
+ temp=generatesinus(temp,fre+offset,amplitude,piphase); %CPH signal
+ s=s+temp;
+ end
+ fre=fre+fundamental;
+ count_partials=count_partials+1;
+end
+
+sig=s;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gennoise.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gennoise.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,50 @@
+% method of class @signal
+% function sig=gennoise
+% sig: original @signal with length and samplerate
+%
+% This function generates 1/f spatial noise, with a normal error
+% distribution (the grid must be at least 10x10 for the errors to be normal).
+% 1/f noise is scale invariant, there is no spatial scale for which the
+% variance plateaus out, so the process is non-stationary.
+%
+% BETA defines the spectral distribution.
+% Spectral density S(f) = N f^BETA
+% (f is the frequency, N is normalisation coeff).
+% BETA = 0 is random white noise.
+% BETA -1 is pink noise
+% BETA = -2 is Brownian noise
+% The fractal dimension is related to BETA by, D = (6+BETA)/2
+%
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (c) 2007 ISVR University of Southampton
+% Stefan Bleeck (bleeck@gmail.com)
+% $Date: 2003/01/25 12:47:43 $
+% $Revision: 1.4 $
+
+% function sig=gennoise(sig,beta,rms_desired)
+function sig=gennoise(sig,beta)
+
+% if nargin<3
+% rms_desired=-1; %
+% end
+if nargin<2
+ beta=0; %
+end
+
+sr=getsr(sig);
+len=getnrpoints(sig);
+
+dots=spatialPattern([1,len],beta);
+
+sig=setvalues(sig,dots);
+sig=setname(sig,sprintf('Noise with beta = %2.1f',beta));
+
+
+% if rms_desired>=0
+% sig=rms_desired*sig/rms(sig);
+% end
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gennoise.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gennoise.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,50 @@
+% method of class @signal
+% function sig=gennoise
+% sig: original @signal with length and samplerate
+%
+% This function generates 1/f spatial noise, with a normal error
+% distribution (the grid must be at least 10x10 for the errors to be normal).
+% 1/f noise is scale invariant, there is no spatial scale for which the
+% variance plateaus out, so the process is non-stationary.
+%
+% BETA defines the spectral distribution.
+% Spectral density S(f) = N f^BETA
+% (f is the frequency, N is normalisation coeff).
+% BETA = 0 is random white noise.
+% BETA -1 is pink noise
+% BETA = -2 is Brownian noise
+% The fractal dimension is related to BETA by, D = (6+BETA)/2
+%
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (c) 2007 ISVR University of Southampton
+% Stefan Bleeck (bleeck@gmail.com)
+% $Date: 2003/01/25 12:47:43 $
+% $Revision: 1.4 $
+
+% function sig=gennoise(sig,beta,rms_desired)
+function sig=gennoise(sig,beta)
+
+% if nargin<3
+% rms_desired=-1; %
+% end
+if nargin<2
+ beta=0; %
+end
+
+sr=getsr(sig);
+len=getnrpoints(sig);
+
+dots=spatialPattern([1,len],beta);
+
+sig=setvalues(sig,dots);
+sig=setname(sig,sprintf('Noise with beta = %2.1f',beta));
+
+
+% if rms_desired>=0
+% sig=rms_desired*sig/rms(sig);
+% end
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gentransposed.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gentransposed.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% method of class @signal
+% function sig=gentransposed(sig,fc,fm)
+% INPUT VALUES:
+% sig: @signal with length and samplerate
+% create a transposed stimulus according to (Hartmann, 1998, p. 106):
+
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2005/10/10 09:32:22 $
+% $Revision: 1.12 $
+
+function sig=gentransposed(sig,fc,fm,phic,phim)
+
+if nargin<5
+
+x=getxvalues(sig);
+nr=length(x);
+
+omc=2*pi/fc;
+omm=2*pi/fm;
+
+for i=1:nr
+
+ a=sin(
+
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gentransposed.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gentransposed.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,37 @@
+% method of class @signal
+% function sig=gentransposed(sig,fc,fm)
+% INPUT VALUES:
+% sig: @signal with length and samplerate
+% create a transposed stimulus according to (Hartmann, 1998, p. 106):
+
+% (c) 2003, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2005/10/10 09:32:22 $
+% $Revision: 1.12 $
+
+function sig=gentransposed(sig,fc,fm,phi_c,phi_m)
+
+if nargin<5
+ phi_m=pi;
+end
+if nargin<4
+ phi_c=0;
+end
+
+x=getxvalues(sig);
+y=zeros(size(x));
+nr=length(x);
+
+om_c=2*pi*fc;
+om_m=2*pi*fm;
+
+for i=1:nr
+ c=om_c*x(i)+phi_m;
+ m=om_m*x(i)+phi_m;
+
+ y(i)=1/pi * sin(c) + 0.5 * cos(m) * sin(c) + 2/(3*pi) * cos(2*m)*sin(c);
+
+end
+
+sig=setvalues(sig,y);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/get.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/get.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function ret=get(a)
+ret=a.werte;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getbinvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getbinvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @signal
+%
+% 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 val=getbinvalue(sig,bin)
+% usage: val=gettimevalue(sig,bin)
+% returns the value at this bin
+% if the time is not exact on one bin, than interpolate
+% correctly
+
+nr_points=getnrpoints(sig);
+x=1:nr_points;
+Y=sig.werte;
+xi=bin;
+method='linear';
+
+
+% val=sig.werte(bin);
+
+val=interp1(x,Y,xi,method);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getcenterofmass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getcenterofmass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% method of class @signal
+%
+% 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 w=getcenterofmass(sig)
+
+vals=getvalues(sig);
+nr=getnrpoints(sig);
+
+su1=0;
+su2=0;
+
+for i=1:nr
+ su1=su1+vals(i)*i;
+ su2=su2+vals(i);
+end
+
+if su2~=0
+ w=su1/su2;
+else
+ w=nr/2;
+end
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getchange.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getchange.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,82 @@
+function str=getchange(sig,start1,stop1,start2,stop2,grafix)
+% returns some information how the signal changes in the time at start1 and
+% stop1 in reference to start2 and stop2
+% this is used to define onset and offset effects of psths
+% sig=signal
+% start1= start of the part of the signal that has the effect
+% stop1= stop of the part of the signal that has the effect
+% start2= start of the part of the signal that is used as reference
+% stop2= stop of the part of the signal that is used as reference
+
+if nargin<6
+ grafix=0;
+end
+
+referencesig=getpart(sig,start2,stop2);
+meanreference=mean(getvalues(referencesig));
+% variability=std(getvalues(referencesig));
+
+searchsig=getpart(sig,start1,stop1);
+meansearchsig=mean(getvalues(searchsig));
+
+if meanreference~=0
+ str.ampeffect=meansearchsig/meanreference;
+else
+ str.ampeffect=0;
+end
+
+str.ampeffectstr=getsignificantstring(getvalues(searchsig),meanreference);
+
+if grafix==1
+% oldgraph=gcf;
+% figure(234234098)
+% clf
+ hold on
+% set(gcf,'num','off')
+% set(gcf,'name','changes in signal');
+ fill(sig,'b');
+ fill(referencesig,'r')
+ fill(searchsig,'g')
+
+
+ x0=getminimumtime(sig)*1000;
+ x1=getmaximumtime(sig)*1000;
+ line([x0 x1],[meanreference meanreference],'color','r')
+ line([x0 x1],[meansearchsig meansearchsig],'color','g')
+ set(gca,'xlim',[x0 x1]);
+% set(gca,'ylim',[0 max(sig)*1.3]);
+ set(gca,'ylim',[min(0,min(sig)*1.3) max(sig)*1.3]);
+ x=(getmaximumtime(sig)*1000-getminimumtime(sig)*1000)/2;
+ x=(stop1*1000-start1*1000)/2;
+ y=max(sig);
+ text(x,y,sprintf('effect: %3.2f (%s)',str.ampeffect*100,str.ampeffectstr),'vert','botto','hor','left')
+ legend('Signal','reference','interesting bit');
+% text(x,y,,'vert','top','hor','left')
+% figure(oldgraph);
+end
+
+function sigstr=getsignificantstring(vals1,meanvals)
+cv=ver('stats');
+if length(cv)==0
+ sigstr='no stats box';
+return
+end
+if sum(vals1)>0
+ if ttest(vals1,meanvals,0.001,1)
+ sigstr='*** more';
+ elseif ttest(vals1,meanvals,0.01,1)
+ sigstr='** more';
+ elseif ttest(vals1,meanvals,0.05,1)
+ sigstr='* more';
+ elseif ttest(vals1,meanvals,0.001,-1)
+ sigstr='*** less';
+ elseif ttest(vals1,meanvals,0.01,-1)
+ sigstr='** less';
+ elseif ttest(vals1,meanvals,0.05,-1)
+ sigstr='* less';
+ else
+ sigstr='not significant';
+ end
+else
+ sigstr='cant determine';
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getdata.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getdata.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+% function ret=getdata(sig)
+% INPUT VALUES:
+% sig: @signal
+% RETURN VALUE:
+% ret: the privat data of the signal
+%
+% (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 ret=getdata(a)
+ret=a.werte;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getlength.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getlength.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% method of class @signal
+%
+% 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 res =getlength(sig)
+% returns the length in seconds
+
+nr=size(sig.werte,1);
+% r1=bin2time(sig,0);
+% r2=bin2time(sig,nr);
+% res=r2-r1;
+
+sr=getsr(sig);
+res=nr/sr;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getlocalmaxima.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getlocalmaxima.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+%
+% 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 [t,h]=getlocalmaxima(sig)
+% returns the height and the locations of all local maxima in the signal
+
+[maxpos,minpos,maxs,mins]=getminmax(sig);
+
+h=maxs;
+t=maxpos;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getlocalminima.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getlocalminima.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+%
+% 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 [t,h]=getlocalminima(sig)
+% returns the height and the locations of all local maxima in the signal
+
+[maxpos,minpos,maxs,mins]=getminmax(sig);
+
+h=mins;
+t=minpos;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getmaximumtime.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getmaximumtime.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,22 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function ma=getmaximumtime(sig)
+
+
+
+sr=sig.samplerate;
+nr=length(sig.werte);
+len=nr/sr;
+
+ma=sig.start_time+len;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getmaximumtime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getmaximumtime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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 ma=getmaximumtime(sig)
+
+ma=sig.start_time+getlength(sig);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getminimumtime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getminimumtime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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 ma=getminimumtime(sig)
+
+ma=sig.start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getminmax.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getminmax.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% method of class @signal
+%
+% returns the height and lows in locations and time of all local maxima in the signal
+% in case of continuus maxima, the last value of the series is taken
+%
+% 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 [maxpos,minpos,maxs,mins]=getminmax(sig)
+% usage: [maxpos,minpos,maxs,mins]=getminmax(sig)
+
+
+werte=getdata(sig);
+werte=werte';
+
+% find all maxima
+% mit NULL!!
+maxpos = find((werte >= [0 werte(1:end-1)]) & (werte > [werte(2:end) 0]));
+maxs=werte(maxpos);
+
+% find all minima
+minpos = find((werte < [inf werte(1:end-1)]) & (werte <= [werte(2:end) inf]));
+mins=werte(minpos);
+
+maxpos=bin2time(sig,maxpos);
+minpos=bin2time(sig,minpos);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getminmax.old.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getminmax.old.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,114 @@
+% method of class @signal
+%
+% 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 [h_min,h_max,t_min,t_max]=getminmax(sig,distance)
+% usage: function [h,t]=getminmax(sig,distance)
+% returns the height and lows in locations and time of all local maxima in the signal
+% in case of continuus maxima, the last value of the series is taken
+% distance is the minimum percent value, that must be between
+% successive minima and maxima
+% the distance must be in percent from the maximum minus the minimum value
+% of the signal to count as a maximum
+
+h_max=[];
+t_max=[];
+h_min=[];
+t_min=[];
+
+if nargin < 2
+ distance=0; % take alle maxima
+end
+
+
+mmax=max(sig);
+mmin=min(sig);
+threshold=(mmax-mmin)*distance;
+
+
+werte=getdata(sig);
+nr= getnrpoints(sig); % so many points
+
+a=-inf;
+b=-inf;
+count_min=0;
+count_max=0;
+
+sr=getsr(sig);
+last_t=0;
+
+next_is_minimum=1; % can be both
+next_is_maximum=1;
+
+for i=1:nr
+ c=werte(i);
+
+ % lokales Minimum
+ if a > b & b <= c
+ curr_min=b;
+
+ if count_max > 0 % das erste Minimum
+ last_max=h_max(count_max);
+ else
+ last_max=+inf;
+ end
+
+ % wenn ein Minimum auftaucht, das klar eines ist, aber das Maximum
+ % dazwischen fehlte, dann wird das letzte Minimum ignoriert!
+ if (last_max - curr_min) > threshold & next_is_maximum & count_min > 0
+ count_min=count_min-1;
+ next_is_minimum=1;
+ end
+
+ if (last_max - curr_min) > threshold & next_is_minimum
+ count_min=count_min+1;
+ next_is_minimum=0; % the next must be a maximum!
+ next_is_maximum=1;
+
+ h_min(count_min) = curr_min;
+ t_min(count_min) = bin2time(sig,i-1);
+ end
+ end
+
+ % lokales Maximum
+ if a < b & b >= c
+ curr_max=b;
+
+ if count_min > 0 % das erste Maximum
+ last_min=h_min(count_min);
+ else
+ last_min=-inf;
+ end
+
+ % wenn ein Maximum auftaucht, das klar eines ist, aber das Minimum
+ % dazwischen fehlte, dann wird das letzte Maximum ignoriert!
+ if (curr_max - last_min) > threshold & next_is_minimum & count_max > 0
+ count_max=count_max-1;
+ next_is_maximum=1;
+ end
+
+
+ if (curr_max - last_min) > threshold & next_is_maximum
+ count_max=count_max+1;
+ next_is_minimum=1; % the next must be a minimum
+ next_is_maximum=0;
+
+ h_max(count_max) = curr_max;
+ t_max(count_max) = bin2time(sig,i-1);
+ end
+ end
+
+
+ % shift the last values
+ a=b;
+ b=c;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getname.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getname.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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 name=getname(sig)
+name=sig.name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getnrchannels.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getnrchannels.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%function nr=getnrchannels(sig)
+% INPUT VALUES: the signal
+%
+% RETURN VALUE:
+% this is here for compatibility to the frame class
+%
+% (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 nr=getnrchannels(sig)
+nr=1; % almost per definition
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getnrpoints.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getnrpoints.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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 nr=getnrpoints(a)
+nr=size(a.werte,1);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getoneperiod.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getoneperiod.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,77 @@
+% method of class @signal
+%
+% 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 per=getoneperiod(signal,risetime)
+% returns one period of the signal
+% to find out about periodicy, the maxima are searched
+% from risetime s after the beginning (because of the rise time)
+
+if nargin < 2
+ risetime=0.01; % default: 10 ms
+end
+
+% the maxima are received by the hilbert envelope
+h=hilbertenvelope(signal);
+maxsi=max(h);
+% to get good maxima, we need to define some threshold, when a maximum is a real maximum
+% lets take 10 percent...
+
+% [lmax,tmax]=getlocalmaxima(h,maxsi/1000000); %returns all the local maxima and the corresponding times
+[lmax,tmax]=getlocalmaxima(h,maxsi/10); %returns all the local maxima and the corresponding times
+% tmax=getzerocrossings(h,maxsi/100); %returns all the local maxima and the corresponding times
+
+% zweite Möglichkeit: mache die FFT der Hilberteinhüllenden und schaue nach dem höchsten peak
+% geht nicht, da die Auflösung viel zu schlecht ist (96kHz->10 Hz Auflösungsvermögen)
+
+nrmax=size(tmax,2);
+if nrmax < 2 % keine Periodizität
+ per=0;
+ return;
+end
+
+i=1;
+% suche in einer Schleife die ersten beiden Maxima hinter der Anstiegszeit
+while i < nrmax
+ if tmax(i) > risetime % hinter der Anstiegszeit
+ if i dazwischen ist die Periode
+ break;
+ end
+ end
+ i=i+1;
+end
+
+dauer=t2-t1; % das ist die Dauer einer Periode
+%ich will die Perioden aber nicht über die Maxima haben, weil das doof aussieht, sondern über die Minima
+% also muss ich zwischen den zweien den tiefsten Punkt suchen
+
+sr=getSR(signal);
+x1=time2bin(signal,t1);
+x2=time2bin(signal,t2);
+a=1000000;
+b=1231231;
+werte=getdata(h);
+tmin=0;
+for i=x1:x2
+ c=werte(i);
+ if a >= b & b < c
+ tmin=bin2time(signal,i);
+ break; % das erste reicht uns vollkommen
+ end
+ a=b;
+ b=c;
+end
+
+per=getpart(signal,tmin,tmin+dauer);
+per=setname(per,sprintf('One Period of Signal \n%s\n Periodlength: %5.2f ms',signal.name,getlength(per)*1000));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getpart.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getpart.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,62 @@
+% method of class @signal
+% function sig=getpart(sig,from,[to])
+%
+% INPUT VALUES:
+% @sig: original signal
+% from: from this time in seconds
+% to: to this time in seconds (default: end of signal)
+% RETURN VALUE:
+% returns a signal-object that is a copy of the original signal in the
+% range from-to
+%
+% (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=getpart(a,from,to)
+
+sr=getsr(a);
+
+if nargin<3
+ to=getlength(a);
+end
+
+if from < getminimumtime(a)
+ error('error: negative beginning in getpart');
+end
+
+if to > getmaximumtime(a)+sr
+ error('error: getpart wants part behind signal');
+end
+
+duration=to-from;
+sig=signal(duration,sr);
+
+target_nr_point=getnrpoints(sig);
+
+start=time2bin(a,from)+1;
+stop=time2bin(a,to);
+
+% realtarget=stop-start+1;
+% if realtarget~=target_nr_point
+% % seems to happen when sr=44100
+% target_nr_point=realtarget;
+% end
+
+len=length(a.werte);
+if start+target_nr_point-1 > len
+ target_nr_point=len-start+1;
+ % seems to happen when sr=44100
+ sig.werte(1:target_nr_point)=a.werte(start:start+target_nr_point-1);
+else
+ sig.werte(1:end)=a.werte(start:start+target_nr_point-1);
+end
+% sig.werte(1:end)=a.werte(start:stop);
+
+sig=setstarttime(sig,from);
+sig=setname(sig,sprintf('Part of Signal: %s',getname(a)));
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getsourceestimate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getsourceestimate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,95 @@
+% method of class @signal
+%
+% 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 sources=getsourceestimate(sig,sigma)
+% usage: sources=getsourceestimate(sig,sigma))
+% returns a struct of sources.position and sources.height
+% for each maximum in the signal sig.
+% it is assumed, that each maximum contributes to the signal with
+% a gaussian kernel of the width "sigma"
+
+
+grafix=0; % debug
+
+% nrchannels=getnrchannels(cframe);
+% smoothwidth=nrchannels/64;
+% fresumme=smooth(fresumme,smoothwidth);
+
+finished=0; % it can be finished by:
+% a) after 5 Maxima
+% b) the signal is below 30 % of original
+how_many_max_maximal=5;
+threshold_criterion=0.3;
+
+if nargin < 2
+ % wie breit jedes Maximum angenommen wird
+ sigma=3; % this is in the sr of the singal
+end
+
+current_max=1;
+start_max_hight=max(sig); % so hoch im Moment
+
+if grafix
+ plot(sig);
+ hold on;
+ a=axis;
+ a(3)=-start_max_hight*1.1;
+ a(4)=start_max_hight*1.1;
+ axis(a);
+end
+
+cols=['b';'g';'k';'y';'b';'g';'k']; % verschiedene Farben für die unterschiedlichen Dominanzregionen
+while ~finished
+ [maxpos,minpos,maxs,mins]=getminmax(sig);
+ [maxmaxhight,maxmaxpos]=max(sig);
+
+ gauss=signal(sig);
+ gauss=generategauss(gauss,maxmaxpos,maxmaxhight,sigma);
+ sig=sig-gauss;
+
+ sources{current_max}.position=maxmaxpos;
+ sources{current_max}.height=maxmaxhight;
+ sources{current_max}.sigma=sigma;
+
+
+ if grafix
+ cur_col=cols(mod(current_max,7)+1,:);
+ plot(sig,cur_col);
+ axis(a);
+ plot(maxmaxpos,maxmaxhight,'r.','MarkerSize',20);
+ end
+ current_max_hight=max(sig); % so hoch im Moment
+ if current_max_hight <= start_max_hight*threshold_criterion
+ finished=1;
+ end
+
+
+ current_max=current_max+1;
+ if current_max>how_many_max_maximal
+ finished=1;
+ end
+
+end
+if grafix
+ plot(sig,'r');
+ axis(a);
+end
+
+return
+
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getsr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getsr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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 res =getsr(sig)
+% returns the samplerate on Hz
+res=sig.samplerate;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getstarttime.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getstarttime.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function ma=getstarttu(sig)
+
+ma=sig.start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getstarttime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getstarttime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function ma=getstarttime(sig)
+
+ma=sig.start_time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/gettimevalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/gettimevalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,50 @@
+% method of class @signal
+%
+% 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 val=gettimevalue(sig,times)
+% usage: val=gettimevalue(sig,time)
+% returns the value at this point in time
+
+val=zeros(size(times));
+if isempty(times)
+ return
+end
+
+sr=1/getsr(sig);
+
+threshold=sr/100;
+nr_points=getnrpoints(sig);
+start=getminimumtime(sig);
+stop=getmaximumtime(sig);
+x=start+sr:sr:stop;
+Y=sig.werte;
+method='linear';
+
+
+for ii=1:length(times);
+ time=times(ii)-sig.start_time;
+
+ nrint=round(time/sr);
+ rint=time/sr;
+
+ if (nrint-rint)0 && nrint <= length(sig.werte)
+ val(ii)=sig.werte(nrint);
+ end
+ else
+ xi=times(ii);
+ val(ii)=interp1(x,Y,xi,method);
+ end
+end
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getunit_x.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getunit_x.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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 n=getunit_x(sig)
+n=sig.unit_x;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getunit_y.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getunit_y.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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 n=getunit_y(sig)
+n=sig.unit_y;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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 ret=getvalues(a)
+ret=a.werte;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getxlabels.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getxlabels.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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 labs=getxlabels(sig)
+labs=sig.x_tick_labels;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getxvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getxvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,10 @@
+function vals=getxvalues(sig)
+% return all x values of the signal in one vector
+
+sr=getsr(sig);
+time_null=getminimumtime(sig);
+time_max=getmaximumtime(sig);
+vals=[time_null:1/sr:time_max];
+% correction:
+vals=vals(1:length(getvalues(sig)));
+vals=vals';
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/getzerocrossings.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/getzerocrossings.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,38 @@
+% method of class @signal
+%
+% 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 t=getzerocrossings(signal,var)
+% gets the zero crossings of the signal.
+% in Case, the Signal has many zeros and only few
+% bumps, like in a klicktrain, only the last zero is counted
+% if var is there, then not real zero, but a value of var is taken
+
+if nargin < 2
+ var=0;
+end
+
+werte=getdata(signal);
+
+nr= getnrpoints(signal); % so many points
+a=0;
+count=1;
+sr=getSR(signal);
+for i=1:nr
+ b=werte(i);
+ if a <= var & b > var
+ t(count)=bin2time(signal,i);
+ count=count+1;
+ end
+ % shift the last values
+ a=b;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/halfwaverectify.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/halfwaverectify.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function sig=halfwaverectify(sig)
+% sets all negative values in sig to 0
+
+vals=getvalues(sig);
+vals(find(vals<0))=0;
+sig=setvalues(sig,vals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/halfwayrectify.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/halfwayrectify.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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=halfwayrectify(sig)
+% sets all negative values in sig to 0
+
+vals=getvalues(sig);
+vals(find(vals<0))=0;
+sig=setvalues(sig,vals);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/highpass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/highpass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,47 @@
+% method of class @signal
+%
+% 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=highpass(sig,frequency,stopband,ripple,stopbandatten)
+% hack for an phase true lowpassfilter with cutoff at frequency
+% used is a ButterworthFilter
+
+if nargin < 5
+ stopbandatten=60; % in dB - how many dB the signal is reduced in the stopband at least
+end
+if nargin < 4
+ ripple=1; % in dB = ripple in the passband
+end
+if nargin <3
+ stopband=frequency/2; % eine Oktave drunter
+end
+
+nyquist=getsr(sig)/2;
+fre_low=frequency;
+
+% passband
+wp=[fre_low/nyquist 0.98];
+
+% stopband
+ws=[(fre_low-stopband)/nyquist 0.99];
+
+% Finde raus, wieviel Punkte der Filter dafür haben muss
+[n,Wn] = buttord(wp,ws,ripple,stopbandatten);
+% Berechne den IIR-Filter
+[b,a] = butter(n,Wn);
+
+% testen:
+% freqz(b,a,512,getsr(sig));
+
+vals=sig.werte;
+nvals = filtfilt(b,a,vals);
+sig.werte=nvals;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/hilbertenvelope.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/hilbertenvelope.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @signal
+%
+% 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=hilbertenvelope(a)
+
+sr=getsr(a);
+duration=getlength(a);
+
+sig=signal(duration,sr);
+sig.name=sprintf('Hilbert Envelope of %s',a.name);
+
+b=hilbert(a.werte);
+sig.werte=abs(b);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/info.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/info.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,22 @@
+% method of class @signal
+%
+% 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 info(sig)
+disp(sprintf('Name: %s',sig.name));
+disp(sprintf('Length: %5.2f ms',GetLength(sig)*1000));
+disp(sprintf('Points: %d',size(sig.werte,1)));
+disp(sprintf('Samplerate: %5.2f kHz',sig.samplerate/1000));
+disp(sprintf('Unit X: %s',sig.unit_x));
+disp(sprintf('Unit Y: %s',sig.unit_y));
+disp(sprintf('Start time: %5.2f sec',sig.start_time));
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/isoftype.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/isoftype.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+%
+% 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 ret=isoftype(inp,str)
+
+if strcmp(str,'signal')
+ ret=1;
+else
+ ret=0;
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/kurtosis.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/kurtosis.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @signal
+%
+% INPUT VALUES: instance of signal class
+%
+% RETURN VALUE: kurtosis of signal values
+%
+%
+% (c) 2008
+% Stefan Bleeck (stefan@bleeck.de)
+
+
+function m=kurtosis(sig)
+% returns the kurtosis of the signal in the WIKIPEDIA-definition (-3)
+
+val=getdata(sig);
+m=kurtosis(val)-3;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/leakyintegrator.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/leakyintegrator.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+
+% (c) 2003-2008, University of Cambridge, Medical Research Council
+% http://www.pdn.cam.ac.uk/cnbh/aim2006
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+% $Revision: 585 $
+%
+
+function nvals=leakyintegrator(sig,lowpass_cutoff_frequency,order)
+
+
+time_constant=1/(2.*pi.*lowpass_cutoff_frequency);
+sr=getsr(sig);
+vals=getvalues(sig);
+b=exp(-1/(sr.*time_constant));
+gain=1./(1-b);
+
+
+nvals=zeros(size(vals));
+for dothis=1:order
+ xn_1=0;
+ yn_1=0;
+ for i=1:length(vals)
+ xn=vals(i);
+ yn= xn + b*yn_1 ;
+ xn_1=xn;
+ yn_1=yn;
+ nvals(i)=yn;
+ end
+ vals=nvals./gain;
+end
+
+nvals=vals;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/linearfit.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/linearfit.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,10 @@
+function [m,b]=linearfit(sig)
+% fit the signal with a streight line and return the slope (m) and the zero
+% crossing (b)
+
+y=getvalues(sig);
+x=getxvalues(sig);
+[p,s] = polyfit(x,y,1);
+
+m=p(1);
+b=p(2);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/linsigx.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/linsigx.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% method of class @signal
+%
+% 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 linsig=linsigx(sig)
+% usage: linsig=linsigx(sig)
+% transferes the signal from a signal that is in logarithmic scale
+% to a signal, that is in linear scale.
+% reverser operation from logsinx
+%
+% this is a little bit tricky since we cant take the times as measure for
+% the logarithmic part. We therefore take the labels, which must be defined
+% properly!
+
+if length(sig.x_tick_labels) > 0
+ tmin=sig.x_tick_labels(1)/1000;
+ tmax=sig.x_tick_labels(end)/1000;
+% tmin=sig.x_tick_labels(1);
+% tmax=sig.x_tick_labels(end);
+else
+ error('signal::linsig: definie x labels of signal');
+end
+
+nr_points=getnrpoints(sig);
+
+oldvals=getvalues(sig);
+newvals=zeros(nr_points,1);
+
+
+% [ntimes,scaleinfo]=distributelogarithmic(tmin,tmax,nr_points);
+ntimes=linspace(tmin,tmax,nr_points);
+mtimes=f2f(ntimes,0.001,0.035,0.001,0.035,'loglin');
+% mtimes=f2f(ntimes,tmin,tmax,tmin,tmax,'loglin');
+newvals=gettimevalue(sig,mtimes);
+
+sr=nr_points/(tmax-tmin);
+linsig=signal(newvals,sr); % copy all values
+linsig=setstarttime(linsig,tmin);
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/loadwavefile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/loadwavefile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,68 @@
+% method of class @signal
+%
+% 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 [sig1,sig2]=loadwavefile(sig,orgname,timestart,duration)
+% usage: [sig1,sig2]=loadwavefile(name,time)
+% reads in the wavefile name in the time boundaries
+% returns two signals, if signal is stereo
+
+%
+% [path,name,ext]=fileparts(name);
+% if strcmp(ext,'.wav')
+%
+% [data,sr,nbits]=wavread(name);
+% elseif strcmp(ext,'.aif') || strcmp(ext,'.aiff')
+% error('aif import not implemented yet');
+% end
+%
+% sig=signal(data);
+% sig=setsr(sig,sr);
+% sig=setname(sig,name);
+% if nargin > 2
+% sig=getpart(sig,timestart,timestart+duration);
+% end
+%
+
+[name,path,ext]=fileparts(orgname);
+if strcmp(ext,'.wav')
+ try
+ [data,sr,nbits]=wavread(orgname);
+ catch
+ error(sprintf('cant open file %s',orgname))
+ end
+ nr_sig=size(data,2);
+
+ sig1=signal(data(:,1));
+ sig1=setsr(sig1,sr);
+ sig1=setname(sig1,orgname);
+ if nargin > 2
+ sig1=getpart(sig1,timestart,timestart+duration);
+ end
+ if nr_sig==2
+ sig2=signal(data(:,2));
+ sig2=setsr(sig2,sr);
+ sig2=setname(sig2,orgname);
+ if nargin > 2
+ sig2=getpart(sig2,timestart,timestart+duration);
+ end
+
+ end
+elseif strcmp(ext,'.aif') || strcmp(ext,'.aiff')
+ [data,sr]=aifread(orgname);
+ sig=signal(data);
+ sig=setsr(sig,sr);
+ sig=setname(sig,orgname);
+ if nargin > 2
+ sig=getpart(sig,timestart,timestart+duration);
+ end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/log.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/log.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @signal
+% function sig=log(sig)
+% INPUT VALUES:
+% sig: original @signal with length and samplerate
+%
+% RETURN VALUE:
+% sig: @signal
+%
+% (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=log(sig)
+sig.werte=log(sig.werte);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/logsigx.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/logsigx.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,57 @@
+% method of class @signal
+%
+% 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 [lsig,scaleinfo]=logsigx(sig,tmin,tmax,nr_points)
+% usage: [lsig,scaler]=logsigx(sig,tmin,tmax,nr_points)
+% transferes the signal to a signal that is in logarithmic scale
+% so plotting the original signal logarithmic is identical to
+% plot the transfered signal linear
+% uses only the part of the signal between tmin and tmax
+%
+% reverse operation: linsigx(sig,tmin,tmax,nr_points)
+
+
+if nargin < 4
+ nr_points=getnrpoints(sig);
+end
+if nargin<3
+ tmax=getmaximumtime(sig);
+end
+if nargin<2
+ tmin=getminimumtime(sig);
+end
+if tmin==0
+ tmin=1/getsr(sig);
+end
+
+
+oldvals=getvalues(sig);
+newvals=zeros(nr_points,1);
+
+
+[ntimes,scaleinfo]=distributelogarithmic(tmin,tmax,nr_points);
+newvals=gettimevalue(sig,ntimes);
+if isnan(newvals(1))
+ newvals(1)=0;
+end
+
+lsig=sig; % copy all values
+lsig=setvalues(lsig,newvals,1);
+
+lsig=setnrxticks(lsig,6);
+l=distributelogarithmic(tmin,tmax,6);
+
+l=round(l*10000)/10;
+
+lsig=setxlabels(lsig,l);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/lowpass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/lowpass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,69 @@
+% method of class @signal
+%
+% 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 filtered_sig=lowpass(sig,frequency,stopband,ripple,stopbandatten)
+% hack for an phase true lowpassfilter with cutoff at frequency
+% used is a ButterworthFilter
+
+if nargin < 5
+ stopbandatten=60; % in dB - how many dB the signal is reduced in the stopband at least
+end
+if nargin < 4
+ ripple=1; % in dB = ripple in the passband
+end
+if nargin <3
+ stopband=frequency*2; % eine Oktave drüber
+end
+
+nyquist=getsr(sig)/2;
+% fre_low=2;
+fre_high=frequency;
+
+% Finde raus, wieviel Punkte der Filter dafür haben muss
+Wpass=fre_high/nyquist;
+Wstop=(fre_high+stopband)/nyquist;
+Wstop=min(Wstop,0.999999);
+try
+ [n,Wn] = buttord(Wpass,Wstop,ripple,stopbandatten);
+ % Berechne den IIR-Filter
+ [b,a] = butter(n,Wn);
+
+ vals=sig.werte';
+
+ % fill the part behind the signal and in front of the signal with
+ % values to avoid corner effects. this is probably not clever in all
+ % cases...
+ firstval=vals(1);
+ lastval=vals(end);
+ nr_vals=length(vals);
+ vals=[ones(1,nr_vals)*firstval vals ones(1,nr_vals)*lastval];
+
+ nvals = filtfilt(b,a,vals);
+ % extract the values back
+ nvals=nvals(nr_vals+1:2*nr_vals);
+
+ filtered_sig=sig; % a copy of the old one
+ newname=sprintf('Lowpass filterd (%3.2fkHz) Signal: %s',frequency/1000,getname(sig));
+ filtered_sig=setname(filtered_sig,newname);
+ filtered_sig.werte=nvals';
+
+catch
+ disp('error: cant do the low pass filtering');
+ filtered_sig=sig;
+end
+
+% figure(235423)
+% plot(sig);
+% hold on
+% plot(filtered_sig,'g');
+% s=0;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/lowpass_2003.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/lowpass_2003.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+%
+% function
+%
+% 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=lowpass_2003(sig,cutoff,order)
+
+
+if nargin<2
+ order=1;
+end
+
+
+sr=getsr(sig);
+vals=getvalues(sig);
+
+[b a] = butter(order,cutoff/(sr/2));
+
+
+sig_len = length(vals);
+
+
+filt_vals(1:sig_len) = filter(b,a,vals);
+vals=filt_vals;
+
+
+sig=setvalues(sig,vals);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/max.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/max.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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 [m,x]=max(sig)
+% returns the maximum value of the signal
+
+val=getdata(sig);
+[m,x]=max(val);
+x=bin2time(sig,x-1);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/mean.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/mean.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @signal
+%
+% 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/01/23 10:56:28 $
+% $Revision: 1.4 $
+
+function m=mean(sig)
+% returns the mean of the signal
+
+val=getdata(sig);
+m=mean(val);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/min.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/min.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @signal
+%
+% 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 [m,x]=min(sig)
+% returns the minimum value of the signal
+
+val=getdata(sig);
+[m,x]=min(val);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/minus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/minus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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=minus(a,b)
+
+sig=a+(-b);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/modtuningtilt.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/modtuningtilt.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,43 @@
+% method of class @signal
+%
+% 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=modtuningtilt(sig)
+
+sig=antitilt(sig,0.04); % mache die Neigung rückgängig
+
+
+sig=tilt(sig,0.08); % tilte, aber etwas weniger
+
+
+
+vals=sig.werte;
+
+
+cutoff=500; % Hz
+drop=0.002; % Falle bis auf Null in 2 ms
+durationtotilt=1/cutoff;
+
+tiltstart=time2bin(sig,-durationtotilt); % Hier gehts los
+tiltend=time2bin(sig,-durationtotilt+drop); % und hier hörts schon wieder auf
+tiltnr=tiltend-tiltstart;
+ti=linspace(1,0,tiltnr);
+
+vals(tiltstart+1:tiltend)=vals(tiltstart+1:tiltend).*ti(:);
+vals(tiltend:end)=0;
+% figure
+% subplot(2,1,1)
+% plot(sig);
+sig.werte=vals;
+% subplot(2,1,2)
+% plot(sig);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/mrdivide.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/mrdivide.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,22 @@
+% method of class @signal
+%
+% 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=mrdivide(sig,b)
+% division ist einfach multiplikation mit 1/
+
+if isnumeric(b)
+ sig=sig*(1/b);
+ return
+end
+
+disp('signal::mrdivide: not implemented yet');
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/mtimes.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/mtimes.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,56 @@
+% method of class @signal
+%
+% 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=mtimes(a,b)
+% multiplikation mit *
+% einfachster Fall: Multipliziere mit konstanter Zahl
+% sonst: Multipliziere ein zweites Signal zum Zeitpunkt Null
+% a muss ein Signal sein!!!
+
+if isnumeric(b) && isobject(a)
+ if size(b)==1
+ a.werte=a.werte*b;
+ sig=a;
+ else
+ d1=getnrpoints(a);
+ d2=max(size(b));
+ if d1>d2 % nimm den kleineren WErt
+ dauer=bin2time(a,d2);
+ else
+ dauer=bin2time(a,d1);
+ end
+% if dauer>getmaximumtime(a)
+% dauer=getmaximumtime(a);
+% end
+ sig=mult(a,b,0,dauer);
+ end
+
+elseif isnumeric(a) && isobject(b)
+ if size(a)==1
+ b.werte=b.werte*a;
+ sig=b;
+ else
+ d1=getnrpoints(b);
+ d2=max(size(a));
+ if d1>d2 % nimm den kleineren WErt
+ dauer=bin2time(b,d2);
+ else
+ dauer=bin2time(b,d1);
+ end
+ sig=mult(b,a,0,dauer);
+ end
+elseif isobject(a) && isobject(b)
+ dauer=getlength(a);
+ start=getminimumtime(a);
+ sig=mult(a,b,start,dauer);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/mult.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/mult.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,97 @@
+% method of class @signal
+%
+% 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=mult(a,b,start_time,dauer)
+%wenn b ein Vektor ist, werden die Werte einfach multipliziert
+% wenn b eine Struct ist, dann werden sie adäquat multipliziert
+
+if(~isobject(a))
+ disp('error: only works on signals');
+end
+if nargin < 4
+ if isobject(b)
+ dauer=GetLength(b);
+ end
+end
+if nargin < 3
+ start_time=0;
+end
+
+% wenn ein Spaltenvektor multipliziert werden soll
+if isnumeric(b)
+ sr=getsr(a);
+ nr=max(size(b));
+ if nr>1
+ temp=signal(b,sr); % erzeuge ein neues Signal aus den Werten
+ sig=mult(a,temp,start_time,dauer); % und lasse dann die beiden Signale zusammenaddieren
+ else
+ if nargin <3
+ sig=a*b; % einfache Zahl
+ else % with starttime and duration
+ start=time2bin(a,start_time)+1; % +1, because a signal starts at the first bin
+ stop=time2bin(a,start_time+dauer);
+ sig=a;
+ sig.werte(start:stop)=sig.werte(start:stop)*b;
+ end
+ end
+ return;
+end
+
+
+% das resultierede Signal kann länger sein als die Ausgangssignale
+% erst feststellen, wie lang das nachher sein soll
+laenge1=getlength(a);
+laenge2=getlength(b); %so lang ist das zweite Signal
+sr1=getsr(a);
+sampletime=1/sr1;
+sr2=getsr(b);
+
+if laenge2options.search_peak_start_search);
+indeces2=find(atmaxoptions.search_peak_start_search);
+indeces2=find(atmin=options.min_contrast_for_distinct_peak
+ % and it must have a certain height
+ if maxinfo.values(i)>=height_criterium
+ if maxinfo.activity(i)>=count_criterium
+ maxinfo.distinct_max(count).contrast=maxinfo.contrast(i);
+ maxinfo.distinct_max(count).qvalue=maxinfo.qvalue(i);
+ maxinfo.distinct_max(count).activity=maxinfo.activity(i);
+ maxinfo.distinct_max(count).hmax=hmax(i);
+ maxinfo.distinct_max(count).tmax=tmax(i);
+ count=count+1;
+ end
+ end
+ end
+end
+
+
+if grafix
+ nr_all_max=length(atmax);
+ for i=1:nr_all_max
+ plot(atmax(i)*1000,ahmax(i),'o','markersize',2,'Markerfacecolor','r','Markeredgecolor','r');
+ end
+ nr_all_min=length(atmin);
+ for i=1:nr_all_min
+ plot(atmin(i)*1000,ahmin(i),'o','markersize',2,'Markerfacecolor','g','Markeredgecolor','g');
+ end
+
+ % plot a dot for every disticnt maximum found
+ for i=1:nr_max
+ testmaxpos=maxinfo.times(i);
+ testmaxval=maxinfo.values(i);
+ contrast=maxinfo.contrast(i);
+ count=maxinfo.activity(i);
+ plot(testmaxpos*1000,testmaxval,'o','markersize',8,'Markerfacecolor','r','Markeredgecolor','r');
+ end
+ % plot a dot for every minimum found
+ for i=1:length(maxinfo.distinct_max);
+ testmaxpos=maxinfo.distinct_max(i).tmax;
+ testmaxval=maxinfo.distinct_max(i).hmax;
+ contrast=maxinfo.distinct_max(i).contrast;
+ count=maxinfo.distinct_max(i).activity;
+ text(testmaxpos*1000+1,testmaxval,sprintf('contr %3.3f',contrast),'fontsize',6,'ver','bottom');
+ text(testmaxpos*1000+1,testmaxval,sprintf('count %3.3f',count),'fontsize',6,'ver','top');
+ end
+ for i=1:nr_min
+ testminpos=mininfo.times(i);
+ testminval=mininfo.values(i);
+ plot(testminpos*1000,testminval,'o','markersize',4,'Markerfacecolor','g','Markeredgecolor','g');
+ end
+end
+return
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function plotall(fignum,lowpasssig,tmax,tmin,hmax,hmin);
+figure(fignum);
+clf
+hold on
+fill(lowpasssig,'b');
+set(gca,'xlim',[0,60]);
+for i=1:length(tmax)
+ plot(tmax(i)*1000,hmax(i),'Marker','o','MarkerSize',6,'MarkerFaceColor','r','MarkerEdgeColor','r')
+end
+for i=1:length(tmin)
+% plot(time2bin(lowpasssig,tmin(i)),hmin(i),'Marker','o','MarkerSize',6,'MarkerFaceColor','g','MarkerEdgeColor','g')
+end
+xlabel('time (ms)');
+ylabel('spikes / sweep / bin');
+title(' PSTH plus found maxima');
+% movegui(nfig,'northwest');
+return
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function [tmaxnew,tminnew,hmaxnew,hminnew]=try_reduce_maxima(tmax,tmin,hmax,hmin,options)
+% throw out the peak with the smallest contrast
+% if removed, the minimum to the right of it is removed too
+
+nr_max=length(tmax);
+
+% find the maximum with the neighbour that is closest in height and throw
+% it out!
+for i=1:nr_max
+ contrastr(i)=getrightcontrast(i,tmax,tmin,hmax,hmin);
+end
+for i=1:nr_max
+ contrastl(i)=getleftcontrast(i,tmax,tmin,hmax,hmin);
+end
+[mincontrastr,minconindexr]=min(abs(contrastr)); % thats the smallest right
+[mincontrastl,minconindexl]=min(abs(contrastl)); % thats the smallest left
+
+if mincontrastr0 && indexmin 0
+% error('cant play sounds louder then maximum, reduce attenuation!');
+ disp('warning: signal\play:: play sounds louder then maximum, reduce attenuation!');
+end
+
+
+sig=rampamplitude(sig,ramp);
+sig=attenuate(sig,attenuation);
+
+if max(sig)>1
+ disp('warning: signal\play:: clipping in signal');
+end
+sound(sig.werte,sig.samplerate);
+
+pause(getlength(sig));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/plot.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/plot.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,161 @@
+% method of class @signal
+%
+% 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 rethandle=plot(sig,border,stil,ax)
+% usage: handle=plot(sig,border,stil)
+% plots the class signal. This plot works a little bit different from usual.
+% Parameter can either be: plot(signal,stil) or plot(signal,border) or plot(signal,border,stil)
+% the border can consist of times and y-value or only the times that should be plotted (in seconeds!)
+
+if nargin<4
+ ax=gca;
+end
+if nargin<3
+ stil='b-';
+end
+
+if isfield(vargin{1}
+
+
+sr=getsr(sig);
+durationbin=size(sig.werte,1);
+duration=durationbin/sr;
+if nargin<2
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+end
+
+if isstruct(border) || isempty(border)
+ options=border;
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+else
+ options=[];
+ if ischar(border)
+ stil=border;
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+ else
+ if isempty(border)
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+ else
+ t1=border(1);
+ t2=border(2);
+ x1=time2bin(sig,t1);
+ x2=time2bin(sig,t2);
+ nr=size(border,2);
+ if nr==2 % wenn nur die x-Werte angegeben werden
+ border=[x1 x2 min(sig.werte(x1+1:x2)) max(sig.werte(x1+1:x2))];
+ else
+ border(1)=x1;
+ border(2)=x2;
+ end
+ end
+ end
+end
+
+if ~isfield(options,'is_log');
+ is_log=0;
+else
+ is_log=options.is_log;
+end
+
+if isfield(options,'minimum_time');
+ border(1)=time2bin(sig,options.minimum_time);
+ minimum_time=options.minimum_time;
+else
+ minimum_time=bin2time(sig,border(1));
+end
+
+if isfield(options,'maximum_time');
+ border(2)=time2bin(sig,options.maximum_time);
+ maximum_time=options.maximum_time;
+else
+ maximum_time=bin2time(sig,border(2));
+end
+
+
+% if the time scale is reversed (time from left to right)
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+start_time=getminimumtime(sig);
+
+min_x_screen=border(1); % einer wird abgezogen damit wir bei Null beginnen, nicht beim ersten bin, was blöde aussieht
+max_x_screen=border(2);
+minshowy=border(3);
+maxy=border(4);
+
+xvals=getxvalues(sig);
+% if we are dealing with milliseconds (very often), then the units are in
+% ms as well
+if strfind(sig.unit_x,'(ms)')>0
+ multiplier=1000;
+else
+ multiplier=1;
+end
+
+
+xvals=xvals.*multiplier;
+yvals=getvalues(sig);
+
+% this is the plotting command:
+handle=plot(ax,xvals,yvals);
+
+if time_reversed
+ set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
+else
+ set(ax,'XDir','normal') % normale ausrichtung
+end
+
+if is_log
+ set(ax,'XScale','log')
+ t=minimum_time*multiplier;
+ tix=[t 2*t 4*t 8*t 16*t 32*t 64*t 128*t 256*t 512*t 1024*t];
+ if ~isempty(sig.x_tick_labels)
+ ti=sig.x_tick_labels;
+ set(ax,'XTicklabel',ti);
+ end
+ set(ax,'XTick',tix);
+else % its linear
+ set(ax,'XScale','linear')
+end
+
+miny=border(3);
+maxy=border(4);
+y=[miny maxy];
+if miny==maxy
+ maxy=miny+1;
+ miny=miny-1;
+end
+axis([minimum_time*multiplier maximum_time*multiplier miny*1.05 maxy*1.05]);
+
+
+
+xlabel(sig.unit_x);
+ylabel(sig.unit_y);
+title(sig.name,'Interpreter','none');
+
+if nargout==1
+ rethandle=handle;
+end
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/plot.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/plot.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,169 @@
+% method of class @signal
+%
+% 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 rethandle=plot(sig,border,stil,ax)
+% usage: handle=plot(sig,border,stil)
+% plots the class signal. This plot works a little bit different from usual.
+% Parameter can either be: plot(signal,stil) or plot(signal,border) or plot(signal,border,stil)
+% the border can consist of times and y-value or only the times that should be plotted (in seconeds!)
+
+if nargin<4
+ ax=gca;
+end
+if nargin<3
+ stil='b-';
+end
+
+if nargin==2 & ishandle(border)
+ ax=border;
+end
+if nargin==3 & ishandle(stil)
+ ax=stil;
+end
+
+
+
+sr=getsr(sig);
+durationbin=size(sig.werte,1);
+% duration=durationbin/sr;
+if nargin<2
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+end
+
+if isstruct(border) || isempty(border)
+ options=border;
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+else
+ options=[];
+ if ischar(border)
+ stil=border;
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+ else
+ if isempty(border)
+ t1=1;
+ t2=durationbin;
+ border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
+ else
+ t1=border(1);
+ t2=border(2);
+ x1=time2bin(sig,t1);
+ x2=time2bin(sig,t2);
+ nr=size(border,2);
+ if nr==2 % wenn nur die x-Werte angegeben werden
+ border=[x1 x2 min(sig.werte(x1+1:x2)) max(sig.werte(x1+1:x2))];
+ else
+ border(1)=x1;
+ border(2)=x2;
+ end
+ end
+ end
+end
+
+if ~isfield(options,'is_log');
+ is_log=0;
+else
+ is_log=options.is_log;
+end
+
+if isfield(options,'minimum_time');
+ border(1)=time2bin(sig,options.minimum_time);
+ minimum_time=options.minimum_time;
+else
+ minimum_time=bin2time(sig,border(1));
+end
+
+if isfield(options,'maximum_time');
+ border(2)=time2bin(sig,options.maximum_time);
+ maximum_time=options.maximum_time;
+else
+ maximum_time=bin2time(sig,border(2));
+end
+
+
+% if the time scale is reversed (time from left to right)
+if isfield(options,'time_reversed');
+ time_reversed=options.time_reversed;
+else
+ time_reversed=0;
+end
+
+start_time=getminimumtime(sig);
+
+min_x_screen=border(1); % einer wird abgezogen damit wir bei Null beginnen, nicht beim ersten bin, was blöde aussieht
+max_x_screen=border(2);
+minshowy=border(3);
+maxy=border(4);
+
+xvals=getxvalues(sig);
+% if we are dealing with milliseconds (very often), then the units are in
+% ms as well
+if strfind(sig.unit_x,'(ms)')>0
+ multiplier=1000;
+else
+ multiplier=1;
+end
+
+
+xvals=xvals.*multiplier;
+yvals=getvalues(sig);
+
+% this is the plotting command:
+handle=plot(ax,xvals,yvals);
+
+if time_reversed
+ set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
+else
+ set(ax,'XDir','normal') % normale ausrichtung
+end
+
+if is_log
+ set(ax,'XScale','log')
+ t=minimum_time*multiplier;
+ tix=[t 2*t 4*t 8*t 16*t 32*t 64*t 128*t 256*t 512*t 1024*t];
+ if ~isempty(sig.x_tick_labels)
+ ti=sig.x_tick_labels;
+ set(ax,'XTicklabel',ti);
+ end
+ set(ax,'XTick',tix);
+else % its linear
+ set(ax,'XScale','linear')
+end
+
+miny=border(3);
+maxy=border(4);
+y=[miny maxy];
+if miny==maxy
+ maxy=miny+1;
+ miny=miny-1;
+end
+set(ax,'xlim',[minimum_time*multiplier maximum_time*multiplier ])
+set(ax,'ylim',[miny*1.05 maxy*1.05])
+% axis([minimum_time*multiplier maximum_time*multiplier miny*1.05 maxy*1.05]);
+
+
+
+xlabel(sig.unit_x);
+ylabel(sig.unit_y);
+title(sig.name,'Interpreter','none');
+
+if nargout==1
+ rethandle=handle;
+end
+
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/plotwithenvelope.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/plotwithenvelope.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% method of class @signal
+%
+% 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 plotwithenvelope(signal,border,stil)
+
+h=hilbertenvelope(signal);
+hh=GetData(h);
+plot(hh,'b-','linewidth',1.2);hold on
+
+if nargin==3
+ plot(signal,border,stil);
+end
+
+if nargin==2
+ plot(signal,border);
+end
+
+if nargin==1
+ plot(signal);
+end
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/plus.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/plus.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,42 @@
+% method of class @signal
+%
+% 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/11 10:45:20 $
+% $Revision: 1.5 $
+
+function sig=plus(a,b)
+% addition
+% einfachster Fall: Addiere eine konstante Zahl
+% sonst: Addiere ein zweites Signal zum Zeitpunkt Null
+
+if isnumeric(b)
+ a.werte=a.werte+b;
+ sig=a;
+ return
+end
+
+if isobject(b)
+ % a couple of cases possible:
+ % a==b, easy
+ % a>b, add b to a
+ % b>a, add a to b
+ dur1=getlength(a);
+ dur2=getlength(b);
+ start1=getminimumtime(a);
+ start2=getminimumtime(b);
+ if dur1==dur2 && start1==start2
+ sig=add(a,b);
+ else
+ if start1+dur1>
+
+ end
+end
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/plus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/plus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,29 @@
+% method of class @signal
+%
+% 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=plus(a,b)
+% addition
+% einfachster Fall: Addiere eine konstante Zahl
+% sonst: Addiere ein zweites Signal zum Zeitpunkt Null
+
+if isnumeric(b)
+ a.werte=a.werte+b;
+ sig=a;
+ return
+end
+
+if isobject(a)
+ dauer=getlength(b);
+ start=getminimumtime(a);
+ sig=add(a,b,start,dauer);
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/powerspectrum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/powerspectrum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,66 @@
+% method of class @signal
+%
+% 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 fsig=powerspectrum(sig,nr_fft)
+% usage: sig=powerspectrum(a)
+% returns a fsignal class containing the powerspectrum of the signal class a
+% a should have a lenght of 2^n the result however, is one point longer!
+% in the first bin is additionally the zero value
+% the result is normed, so that the highest value is 0dB
+% berechnet das Power Spektrum aus dem Signal a.
+% die Phasen werden weggeworfen
+
+if nargin < 2
+ nr_fft=1024;
+end
+
+
+
+Fs = getsr(sig);
+vals=getvalues(sig);
+y=fft(vals,nr_fft);
+py=y.*conj(y);
+%
+% % Verlängerung des Signals um einen Punkt, damit der Nullanteil noch dabei ist
+nr=round(size(py,1)/2+1); % eines mehr (der Nullanteil)
+
+
+% use the powerspectrum from the toolbox
+% [ppy,w]=periodogram(vals,[],'onesided',nr_fft,Fs); % only real values
+
+% otherwise calculate it yourself:
+ppy=py(1:nr)/nr*2;
+
+
+
+%normierung auf Energie
+%s=sum(abs(ppy));
+%energy=s*s;
+energy = sum(ppy.^2);
+if energy==0
+ ppy=1;
+else
+ ppy=ppy/energy;
+ ppy=20*log(ppy);
+ ppy=ppy-max(ppy);
+end
+
+fsig=fsignal(ppy,nr); % Signal mit der richtigen Samplerate
+fsig=setdf(fsig,Fs/(nr-1)/2); % kleinester Frequenzabstand
+
+fsig=setmaxfre(fsig,Fs/2);
+
+% sig=setsr(sig,nr); %sr bedeutet für fsignals was anderes, nämlich die Zahl der Punkte
+fsig=setname(fsig,sprintf('Power Spectrum of Signal \n%s',sig.name));
+fsig=setunit_x(fsig,'Frequency (Hz)');
+fsig=setunit_y(fsig,'Power Spectral Density (dB/Hz)');
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/qvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/qvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,71 @@
+% method of class @signal
+%
+% 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 [val,hoch,breit,widthvals]=qvalue(sig,where,howmuch)
+% usage: val=qvalue(sig,where,howmuch)
+% calculates the q-value, that is the hight divided by the width
+% of the signal at a point given by where (in seconds!)
+% howmuch is the indicator, how much the signal must be dropped 0.5 or such
+% returns the width in seconds, or 0, when the signal does not reach the value
+% widthvals has two x-values: where the width hits the signal
+
+vals=sig.werte;
+nr_bin=time2bin(sig,where);
+nr_values=getnrpoints(sig);
+howmuchdecrease=vals(nr_bin)*(1-howmuch); % value at the desired point
+val=0;
+hoch=0;
+breit=0;
+widthvals(1)=-inf;
+widthvals(2)=inf;
+
+int_time_up=nr_values+1;
+for i=nr_bin:nr_values
+ if vals(i)< howmuchdecrease
+ int_time_up=i;
+ widthvals(1)=i;
+ break;
+ end
+end
+
+int_time_down=0;
+for i=nr_bin:-1:1
+ if vals(i)< howmuchdecrease
+ int_time_down=i;
+ widthvals(2)=i;
+ break;
+ end
+end
+
+if int_time_down==0 | int_time_up==nr_values
+ hoch=vals(nr_bin);
+ breit=1000000;
+ val=hoch/breit;
+ widthvals(1)=0; widthvals(2)=0;
+ return;
+end
+
+time_up=bin2time(sig,int_time_up);
+time_down=bin2time(sig,int_time_down);
+
+hoch=vals(nr_bin);
+breit=time_up-time_down;
+if breit>0
+ val=hoch/breit;
+else
+ vals=0;
+end
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/qvalue2.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/qvalue2.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,76 @@
+% method of class @signal
+%
+% 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 [val,height,width,widthvals,base_peak_y]=qvalue2(sig,where)
+% similar to qvalue, but returns the value of height divided by width
+% when height is calculated from maximum to the nearest minimum
+
+
+vals=sig.werte;
+nr_bin=time2bin(sig,where);
+nr_values=getnrpoints(sig);
+
+[maxpos,minpos,maxs,mins]=getminmax(sig);
+
+[pos_min_left,minval_left]=getminimumleftof(where,maxpos,minpos,maxs,mins);
+[pos_min_right,minval_right]=getminimumrightof(where,maxpos,minpos,maxs,mins);
+
+if isempty(pos_min_left)
+ pos_min_left=0;
+ minimal_left=gettimevalue(sig,pos_min_left);
+end
+if isempty(pos_min_right)
+ pos_min_right=getmaximumtime(sig);
+ minval_right=gettimevalue(sig,pos_min_right);
+end
+
+if minval_left > minval_right
+ new_height=minval_left;
+ pos_left=pos_min_left;
+ widthvals(1)=pos_left;
+
+ pos_right=nr_values+1;
+ for i=nr_bin:nr_values
+ if vals(i)< minval_left
+ pos_right=bin2time(sig,i);
+ break;
+ end
+ end
+else
+ new_height=minval_right;
+ pos_right=pos_min_right;
+ widthvals(2)=bin2time(sig,pos_right);
+
+ pos_left=0;
+ for i=nr_bin:-1:1
+ if vals(i)< minval_right
+ pos_left=bin2time(sig,i);
+ break;
+ end
+ end
+end
+
+width=pos_right-pos_left;
+widthvals(1)=pos_left;
+widthvals(2)=pos_right;
+
+height=gettimevalue(sig,where)-new_height;
+
+base_peak_y=new_height;
+
+
+val=height/width;
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/rampamplitude.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/rampamplitude.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function sig=rampamplitude(sig,rt,type)
+
+if nargin < 3
+ type='linear';
+end
+if nargin < 2
+ rt=0.01;
+end
+
+if isequal(type,'linear')
+ sigvals=sig.werte;
+ nr_point=time2bin(sig,rt);
+ ramp=linspace(0,1,nr_point);
+ sigvals(1:nr_point)=sigvals(1:nr_point).*ramp';
+ damp=linspace(1,0,nr_point);
+ sigvals(end-nr_point+1:end)=sigvals(end-nr_point+1:end).*damp';
+elseif isequal(type,'Cos^2')
+ sigvals=sig.werte;
+ nr_point=time2bin(sig,rt);
+ t=1:nr_point;
+ ramp=power(1+cos(t/nr_point*pi),2)/4;
+ plot(ramp)
+ sigvals(1:nr_point)=sigvals(1:nr_point).*ramp';
+ damp=linspace(1,0,nr_point);
+ sigvals(end-nr_point+1:end)=sigvals(end-nr_point+1:end).*damp';
+end
+
+
+
+sig.werte=sigvals;
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/rampamplitude.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/rampamplitude.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,38 @@
+% method of class @signal
+%
+% 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=rampamplitude(sig,rt,type)
+
+if nargin < 3
+ type='linear';
+end
+if nargin < 2
+ rt=0.01;
+end
+
+if strcmp(type,'linear')
+ first_bin=1;
+ nr_point=time2bin(sig,rt);
+ last_bin=nr_point;
+ ramp=linspace(0,1,(last_bin-first_bin));
+ sig=sig*ramp;
+
+ first_bin=getnrpoints(sig)-nr_point;
+ start_time_hintere_rampe=bin2time(sig,first_bin);
+ last_bin=time2bin(sig,getlength(sig));
+ damp=linspace(1,0,(last_bin-first_bin));
+ try
+ sig=mult(sig,damp,start_time_hintere_rampe,rt);
+ end
+ p=1;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/rampamplitudeCopy.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/rampamplitudeCopy.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,43 @@
+% method of class @signal
+%
+% 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=rampamplitude(sig,rt,type);
+
+if nargin < 3
+ type='linear';
+end
+if nargin < 2
+ rt=0.01;
+end
+
+if strcmp(type,'linear')
+ first_bin=1;
+ nr_point=time2bin(sig,rt);
+ last_bin=nr_point;
+% l=linspace(0,1,(last_bin-first_bin)+1); %added +1 DRRS
+ l=linspace(0,1,(last_bin-first_bin));
+ sig=sig*l;
+
+% first_bin=getnrpoints(sig)-nr_point+1; %added +1 DRRS
+% start_time_hintere_rampe=bin2time(sig,first_bin+1); %added +1 DRRS
+% last_bin=time2bin(sig,getlength(sig)-1/getsr(sig)); %added -1/getsr(sig) DRRS
+% l=linspace(1,0,(last_bin-first_bin)+1); %added +1 DRRS
+% sig=mult(sig,l,start_time_hintere_rampe,rt);
+ first_bin=getnrpoints(sig)-nr_point;
+ start_time_hintere_rampe=bin2time(sig,first_bin);
+ last_bin=time2bin(sig,getlength(sig));
+ l=linspace(1,0,(last_bin-first_bin)); % build the ramp as
+ sig=mult(sig,l,start_time_hintere_rampe,rt);
+
+
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/reverse.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/reverse.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+%
+% 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=reverse(sig)
+%usage: sig=reverse(sig)
+% reverses the signal in time
+
+vals=sig.werte;
+rvals=vals(end:-1:1);
+sig.werte=rvals;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/rms.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/rms.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @signal
+%
+% 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 val=rms(sig)
+%usage: val=rms(data)
+%
+%returns rms of given vector
+%another way would be val=norm(data)/sqrt(length(data))
+% David R R Smith 22/05/02
+
+data=getvalues(sig);
+val=(mean(data.^2)).^0.5;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/savewave.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/savewave.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,41 @@
+% method of class @signal
+% savewave(sig,name[,ramp])
+% INPUT VALUES:
+% name : name of the resulting sound file
+% ramp: if given, then the signal is ramped with a linear ramp with
+% that duration
+% 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/11 10:27:46 $
+% $Revision: 1.6 $
+
+function savewave(sig,name,ramp)
+% does some things, to make a nice sound out of it
+
+if nargin < 3
+ ramp=0.0; % default ramp is off
+end
+if nargin < 2
+ name='just saved';
+end
+
+
+
+sig=rampamplitude(sig,ramp);
+sig=scaletomaxvalue(sig,0.999);
+if isempty(strfind(name,'.wav'))
+ name=sprintf('%s.wav',name);
+end
+
+fid=fopen(name,'w');
+if fid==-1
+ disp(sprintf('can''t write file ''%s'', is file open in CoolEdit? If so please close!',name));
+ error('file open in CoolEdit... Cant write');
+else
+ writetowavefile(sig,name);
+
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/savewave.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/savewave.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,43 @@
+% method of class @signal
+% savewave(sig,name[,ramp])
+% INPUT VALUES:
+% name : name of the resulting sound file
+% ramp: if given, then the signal is ramped with a linear ramp with
+% that duration
+% 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 savewave(sig,name,ramp)
+% does some things, to make a nice sound out of it
+
+if nargin < 3
+ ramp=0.0; % default ramp is off
+end
+if nargin < 2
+ name='just saved';
+end
+
+
+
+sig=rampamplitude(sig,ramp);
+sig=scaletomaxvalue(sig,0.999);
+if isempty(strfind(name,'.wav'))
+ name=sprintf('%s.wav',name);
+end
+
+fid=fopen(name, 'w');
+if fid==-1
+ disp(sprintf('can''t write file ''%s'', is file open in CoolEdit? If so please close!',name));
+ error('file open in CoolEdit... Cant write');
+else
+ % TCW AIM 2006
+ fclose(fid); % Otherwise MATLAB leaves the file open for writing for ever!
+
+ writetowavefile(sig,name);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/savewaveprescaled.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/savewaveprescaled.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @signal
+%
+% 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 savewaveprescaled(sig,name)
+% does some things, to make a nice sound out of it
+% but assumes sig has already been scaled!
+% just take out one line of savewave
+
+sig=rampamplitude(sig,0.005);
+%sig=scaletomaxvalue(sig,0.999);
+if ~strfind(name,'.wav')
+ name=sprintf('%s.wav',name);
+end
+
+writetowavefile(sig,name);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/scale.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/scale.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+%
+% 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=scale(si,a)
+%usage: sig=scale(a)
+% shifts all Values by the constant factor a
+
+sig=si;
+sig.werte(:)=sig.werte(:)*a;
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/scaletomaxvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/scaletomaxvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% method of class @signal
+%
+% 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=scaletomaxvalue(si,maxv)
+%usage: sig=scaleToMaxValue(si,maxv)
+% scales signal so, that the maximum value is maxv (usefull for saving as wav)
+
+sig=si;
+dat=sig.werte;
+ma=max(dat);
+mi=min(dat);
+if -mi > ma
+ ma=-mi;
+end
+
+sig.werte(:)=sig.werte(:)*maxv/ma;
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/scaletorms.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/scaletorms.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @signal
+%
+% 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=scaletorms(sig, value)
+
+old=rms(sig);
+
+sig=sig*(value/old);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/secondderivation.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/secondderivation.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% method of class @signal
+%
+% 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=secondderivation(sig)
+% calculates the second derivation by calculation of the differences
+
+
+val=getvalues(sig);
+
+nr=length(val);
+
+
+nval=val;
+nval(1)=0;
+nval(2)=0;
+for i=3:nr
+
+ if i==370
+ a=0;
+ end
+ nval(i)=(val(i-2)-2*val(i-1)+val(i))/2;
+end
+
+sig=setvalues(sig,nval);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/set.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/set.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,16 @@
+% method of class @signal
+%
+% 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/01/17 16:57:43 $
+% $Revision: 1.3 $
+
+function ret=set(sig,values)
+sig.werte=values;
+ret=sig;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setbinvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setbinvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @signal
+%
+% 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=setbinvalue(sig,bin,value)
+%usage: sig=setvalue(sig,bin,time,val)
+% sets the int value bin to "val"
+
+sig.werte(bin)=value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setlength.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setlength.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% method of class @signal
+%
+% 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=setlength(sig,newlen)
+
+% sig.length=newlen;
+nr_points=time2bin(sig,newlen);
+old_nr_points=getnrpoints(sig);
+if nr_points < old_nr_points
+ new_vals=sig.werte(1:nr_points);
+else
+ new_vals=zeros(nr_points,1);
+ new_vals(1:old_nr_points)=sig.werte;
+end
+clear sig.werte;
+sig.werte=new_vals;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setname.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setname.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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=setname(sig,name)
+sig.name=name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setnrxticks.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setnrxticks.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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=setnrxticks(sig,nr)
+sig.nr_x_ticks=nr;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setsr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setsr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% method of class @signal
+%
+% 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=setsr(sig,sr_neu)
+% usage: sig=setsr(a,sr_neu)
+% simply sets the sample rate to a fixed value without changing the data!
+% if you want to change the samplerate of a signal, that is already there,
+% use changesr(sig,new)!
+
+
+sig.samplerate=sr_neu;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setstarttime.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setstarttime.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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=setstarttime(sig,time)
+sig.start_time=time;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/settimevalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/settimevalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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=settimevalue(sig,time,val)
+%usage: sig=setvalue(sig,time,val)
+% sets the double time value "time" to "val"
+
+nr=time2bin(sig,time);
+sig.werte(nr)=val;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/settozeroaverage.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/settozeroaverage.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @signal
+%
+% 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=settozeroaverage(sig)
+
+m=mean(sig.werte);
+sig=sig-m;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setunit_x.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setunit_x.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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=setunit_x(sig,name)
+sig.unit_x=name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setunit_y.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setunit_y.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% method of class @signal
+%
+% 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=setunit_y(sig,name)
+sig.unit_y=name;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setvalues.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setvalues.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,41 @@
+% method of class @signal
+%
+% 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=setvalues(org_sig,new_vals,startint)
+%usage: sig=setvalues(si,new,vals)
+% sets all values of the signal org_sig to the new values
+% if only one value is given, than all vals are set to this value
+
+if getnrpoints(org_sig)~=max(size(new_vals)) & nargin < 3
+ disp('error: setvalues: different size of signal and new values');
+end
+
+if nargin < 3
+ startint=1;
+end
+
+if length(new_vals)==1
+ len=getnrpoints(org_sig)-startint+1;
+ new_vals=ones(len,1)*new_vals;
+end
+if size(new_vals,1)< size(new_vals,2)
+ new_vals=new_vals';
+end
+
+len=size(new_vals,1);
+
+nval=org_sig.werte;
+nval(startint:startint+len-1)=new_vals;
+org_sig.werte=nval;
+sig=org_sig;
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/setxlabels.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/setxlabels.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @signal
+%
+% 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=setxlabels(sig,labels)
+
+sig.x_tick_labels=labels;
+sig=setnrxticks(sig,length(labels));
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/shift.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/shift.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% method of class @signal
+%
+% 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=shift(si,a)
+%usage: sig=shift(a)
+% shifts all Values by the constant factor a
+
+sig=si;
+sig.werte(:)=sig.werte(:)+a;
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/shiftcircular.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/shiftcircular.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+function sig=shiftcircular(sig,shifttime)
+% shift the period in time circlular
+% if shifttime > 0then circle positiv, otherwise negative
+
+
+bin=time2bin(sig,shifttime);
+nrpoints=getnrpoints(sig);
+if bin<1
+ bin=nrpoints+bin;
+end
+
+vals=getvalues(sig);
+valnew=zeros(size(vals));
+
+valnew(1:bin)=vals(end-bin+1:end);
+valnew(bin+1:end)=vals(1:end-bin);
+
+sig=setvalues(sig,valnew);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/sig2simulinkinput.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/sig2simulinkinput.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% method of class @signal
+%
+% 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 ret=sig2simulinkinput(sig)
+% wandelt das signal sig in eine Struktur um, die Simulink lesen kann
+
+sr=getsr(sig);
+len=getlength(sig);
+
+ret.time=(1/sr:1/sr:len)';
+ret.signals(1).values=getvalues(sig);
+ret.signals(1).dimensions=1;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/signal.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/signal.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,87 @@
+% constructor of class @signal
+% parent class: none
+% function sig=signal(length,samplerate,name,unit_x,unit_y,start_time)
+% INPUT VALUES:
+% length: length of signal in seconds [default 1]
+% samplerate: samplerate in Hz (points per seconds) [default: 1000]
+% name: display name of the signal (string)
+% unit_x: display unit on x-axis (string)
+% unit_y: display unit on y-axis (string)
+% start_time: virtual start time of the signal (default 0)
+%
+% RETURN VALUE:
+% @signal-object
+%
+% Valid constructor-calls:
+% 1: no or any number of arguments above
+% 2: signal(@other_signal_object) : Copy-Constructor
+% 3: signal(values): copies the values in the @signal
+%
+% a signal consist of n points according to its length*sr
+% the time "0" is not associated with a bin. the first bin is time sr, the
+% second 2*sr, etc the nth bin is the signal-duration
+%
+% (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=signal(laenge,samplerate,name,unit_x,unit_y,start_time)
+
+
+if nargin < 6
+ start_time=0;
+end
+if nargin < 5
+ unit_y='amplitude';
+end
+if nargin < 4
+ unit_x='time (ms)';
+end
+if nargin < 3
+ name='generic Signal';
+end
+if nargin < 2
+ samplerate=1000;
+end
+if nargin < 1
+ laenge=1;
+end
+
+if isobject(laenge)
+ sig.werte=laenge.werte;
+ samplerate=laenge.samplerate;
+ name=laenge.name;
+ unit_x=laenge.unit_x;
+ unit_y=laenge.unit_y;
+ start_time=laenge.start_time;
+% sig.nr_x_ticks=laenge.nr_x_ticks;
+% sig.x_tick_labels=laenge.x_tick_labels;
+else
+ a1=size(laenge,1); a2=size(laenge,2);
+ if a1>1 & a2>1
+ disp('Signal Constructor Error: input vector has more than one dimension');
+ end
+ % erst Abfrage, welche Konstruktionsmethode:
+ if a2>1 %Benutzer hat Zeilenvektor eingegeben, wir wollen einen Spaltenvektor
+ laenge=laenge';
+ a1=a2;
+ end
+ if a1>1 % AHA! Ein Vektor
+ sig.werte=laenge;
+ else
+ nr_points=round(laenge*samplerate);
+ sig.werte=zeros(nr_points,1);
+ end
+end
+sig.samplerate=samplerate;
+sig.name=name;
+sig.unit_x=unit_x;
+sig.unit_y=unit_y;
+sig.start_time=start_time;
+sig.nr_x_ticks=9;
+% if the ticks shell be numbers or something else
+sig.x_tick_labels=[];
+
+sig=class(sig,'signal');
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/signal2spiketrain.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/signal2spiketrain.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,37 @@
+% method of class @signal
+% function st=signal2spiketrain(sig)
+% INPUT VALUES:
+% sig: original @signal
+% RETURN VALUE:
+% st: @spiketrain
+%
+% (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 st=signal2spiketrain(sig)
+% translates a signal in an spiketrain
+
+nr=getnrpoints(sig);
+vals=getvalues(sig);
+
+%spks=zeros(1000,1);
+
+count=1;
+for i=1:nr
+ if vals(i)>0
+ for j=1:vals(i)
+ %st=addspike(st,vals(i));
+ spks(count)=bin2time(sig,i);
+ count=count+1;
+ end
+ end
+end
+
+
+st=spiketrain(spks);
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/sim_spikes.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/sim_spikes.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,312 @@
+function ret_spikes=sim_spikes(sig,nr_sweeps,params)
+% simulates the response to a signal
+
+% % other parameters
+if isfield(params,'latency')
+ latency=params.latency;
+else
+ latency=4;
+end
+if isfield(params,'first_spike_boost')
+ first_spike_boost=params.first_spike_boost;
+else
+ first_spike_boost=2;
+end
+if isfield(params,'threshold')
+ threshold=params.threshold;
+else
+ threshold=0; % in dB
+end
+if isfield(params,'dynamic_range')
+ dynamic_range=params.dynamic_range;
+else
+ dynamic_range=20; % in dB
+end
+% if isfield(params,'start_boost_beta_length')
+% start_boost_beta_length=params.start_boost_beta_length;
+% else
+% start_boost_beta_length=15;
+% end
+% if isfield(params,'start_boost_beta_val')
+% start_boost_beta_val=params.start_boost_beta_val;
+% else
+% start_boost_beta_val=2;
+% end
+if isfield(params,'jitter_time')
+ jitter_time=params.jitter_time;
+else
+ jitter_time=0.1;
+end
+
+% calcualates an artificail spiketrain with so many sweeps
+% the important parameter are mu (the location) and beta (the scale) of the
+% distribution
+
+% changing some parameters so that the result looks good
+%jitter to reduce some effect that the odd (or even?) multiples
+%of the sr have significant and repeatable higher nr intervals
+%then the others. Cant work out why. solution: let the interval
+%jitter around the peak a bit
+
+% calculate the x values of the distribution
+% take a length of the distribution up to the point where it it 99.9 %
+% that saves a lot of time
+% maxpoint=0.999;
+% tlength=mu-beta*log(-log(maxpoint));
+
+% set the random number generator to a new value
+% rand('state', sum(100*clock));
+% dont do that because the values are too close to each other and actually
+% not random at all!
+
+binwidth=1/getsr(sig)*1000;
+sig_len=getlength(sig);
+nr_steps=getnrpoints(sig);
+
+
+% % x2=binwidth:binwidth:tlength;
+%
+% % spike_prob_function=hazard_function(x2,mu,beta); % for the full signal length
+% % spike_prob_function2=hazard_function(x2,mu,beta/start_boost_beta_val); % for the first 20 ms
+%
+% test_sig=getvalues(sig);
+% test_sig=test_sig+60; % shift it upwards
+%
+%
+% for i=1:nr_sweeps
+% spikes=[];
+% last_spike=-1; % inital condition: how long ago was the last spike
+% spikecounter=1; % spikecounter
+% for j=1:nr_steps
+% time_now=j*binwidth; % thats the global time counter
+% difft=time_now-last_spike; % how long ago is the last spike?
+% if difft<1, continue, end
+%
+% % % modify eta by the amplitude:
+% % cur_amp=test_sig(j)-threshold; % in dB above threshold
+% % if cur_amp>dynamic_range % in saturation
+% % cur_eta=eta;
+% % else
+% % cur_eta=(eta-eta_null)/dynamic_range*cur_amp+eta_null;
+% % % cur_eta=f2f(cur_amp,0,dynamic_range,eta_null,eta);
+% % end
+%
+% % z = (log(difft) - p1) ./ p2;
+% % spike_prob = exp(p3 - exp(p3)) ./ p2;
+% spike_prob = gevpdf(log(difft),p3,p2,p1);
+%
+% % weibull function
+% % spike_prob=(beta/cur_eta)*power(log(difft)/cur_eta,beta-1);
+%
+% % spike_prob=spike_prob*test_sig(j)+spont_rate; % % modulate the probability with the height of the signal
+% % spike_prob=spike_prob/(1.2+binwidth/2); %correction factor
+% if rand0);
+x2=[x2; x2(end)+binwidth];
+% figure(43)
+% cla
+% hold on
+for i=1:2
+ p1=params.recovery_parameter.fit_p(1);
+
+ p2=log(p{10}.x);
+ p3=p{10}.y;
+ if i==1
+ p2=p2/2;
+ end
+ % plot3(p1,p2,p3,'o')
+ pdf=gevpdf(log(x2),p1,p2,p3);
+ cdf=gevcdf(log(x2),p1,p2,p3);
+ spike_prob_function{i}=ones(size(x2))*inf;
+ for j=1:length(x2)
+ if cdf(j)<1
+ spike_prob_function{i}(j)=pdf(j)/(1-cdf(j))/params.acc_fac;
+ end
+ end
+end
+
+
+times=[20 250];
+
+
+% spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+
+% shift the signal by the latency to simulate the latency:
+
+
+
+% spont_rate=0.015;
+
+for i=1:nr_sweeps
+ spikes=[];
+ last_spike=-1; % inital condition: how long ago was the last spike
+ spikecounter=1; % spikecounter
+ swapc=1;
+ next_swap=times(swapc);
+ c_function=spike_prob_function{swapc};
+
+ still_in_latency=1;
+ for j=1:nr_steps
+ time_now=j*binwidth; % thats the global time counter
+
+ if still_in_latency && time_now> latency
+ if rand0);
+% x2=[x2; x2(end)+binwidth];
+% % figure(43)
+% % cla
+% % hold on
+% for i=10:-1:1
+% if isfield(p{i},'k') % otherwise no spikes
+% p1=p{i}.k;
+% p2=log(p{i}.x);
+% p3=p{i}.y;
+% % plot3(p1,p2,p3,'o')
+% pdf=gevpdf(log(x2),p1,p2,p3);
+% cdf=gevcdf(log(x2),p1,p2,p3);
+% spike_prob_function{i}=ones(size(x2))*inf;
+% for j=1:length(x2)
+% if cdf(j)<1
+% spike_prob_function{i}(j)=pdf(j)/(1-cdf(j))/params.acc_fac;
+% end
+% end
+% else
+% % otherwise take the "default" one
+% spike_prob_function{i}=spike_prob_function{10};
+% end
+% end
+%
+% times=0:10:60;
+% times=[times 100 250];
+%
+%
+% % spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+%
+% jitter_time=0;
+% latency=0;
+%
+% start_boost_beta_length=20;
+% test_sig=zeros(length(x2),1);
+% sigend=53;
+% test_sig(1:sigend/binwidth)=1;
+% % build a ramp...
+% test_sig(1:2/binwidth)=linspace(0,1,2/binwidth);
+% test_sig(sigend/binwidth-2/binwidth:sigend/binwidth)=linspace(1,0,2/binwidth+1);
+%
+% spont_rate=0;
+%
+% for i=1:nr_sweeps
+% spikes=[];
+% last_spike=-1; % inital condition: how long ago was the last spike
+% spikecounter=1; % spikecounter
+% swapc=2;
+% next_swap=times(swapc);
+% c_function=spike_prob_function{swapc};
+%
+% for j=1:nr_steps
+% time_now=j*binwidth; % thats the global time counter
+% if time_now>next_swap
+% swapc=swapc+1;
+% next_swap=times(swapc);
+% c_function=spike_prob_function{swapc};
+% end
+% % implementation of a simple solution for the first spike problem: if the spike is the first then assume a very high probability
+% if spikecounter==1 % yes, its the first
+% % if randdynamic_range % in saturation
+% % cur_eta=eta;
+% % else
+% % cur_eta=(eta-eta_null)/dynamic_range*cur_amp+eta_null;
+% % % cur_eta=f2f(cur_amp,0,dynamic_range,eta_null,eta);
+% % end
+%
+% % z = (log(difft) - p1) ./ p2;
+% % spike_prob = exp(p3 - exp(p3)) ./ p2;
+% spike_prob = gevpdf(log(difft),p3,p2,p1);
+%
+% % weibull function
+% % spike_prob=(beta/cur_eta)*power(log(difft)/cur_eta,beta-1);
+%
+% % spike_prob=spike_prob*test_sig(j)+spont_rate; % % modulate the probability with the height of the signal
+% % spike_prob=spike_prob/(1.2+binwidth/2); %correction factor
+% if rand0);
+% x2=[x2; x2(end)+binwidth];
+sr=getsr(sig);
+x2=1/sr:1/sr:0.1;
+% figure(43)
+% cla
+% hold on
+p1=params.p1;
+p2=params.p2;
+p3=params.p3;
+
+% start point=0.5 0.2 0.5
+
+pdf=gevpdf(log(x2*1000),p1,p2,p3);
+cdf=gevcdf(log(x2*1000),p1,p2,p3);
+spike_prob_function=ones(size(x2))*inf;
+for j=1:length(x2)
+ if cdf(j)<1
+ spike_prob_function(j)=pdf(j)/(1-cdf(j));
+ end
+end
+
+% normalise to a good value
+spike_prob_function=spike_prob_function/sum(spike_prob_function)/10;
+
+
+% shift the signal by the latency to simulate the latency:
+zeros_in_front=zeros(latency/binwidth,1);
+sigvalues=[zeros_in_front;sigvalues];
+
+
+
+for i=1:nr_sweeps
+ spikes=[];
+ last_spike=-1; % inital condition: how long ago was the last spike
+ spikecounter=1; % spikecounter
+ c_function=spike_prob_function;
+
+ still_in_latency=1;
+ for j=1:nr_steps
+ time_now=j*binwidth; % thats the global time counter
+
+ if still_in_latency && time_now> latency
+ if rand0);
+% x2=[x2; x2(end)+binwidth];
+% % figure(43)
+% % cla
+% % hold on
+% for i=10:-1:1
+% if isfield(p{i},'k') % otherwise no spikes
+% p1=p{i}.k;
+% p2=log(p{i}.x);
+% p3=p{i}.y;
+% % plot3(p1,p2,p3,'o')
+% pdf=gevpdf(log(x2),p1,p2,p3);
+% cdf=gevcdf(log(x2),p1,p2,p3);
+% spike_prob_function{i}=ones(size(x2))*inf;
+% for j=1:length(x2)
+% if cdf(j)<1
+% spike_prob_function{i}(j)=pdf(j)/(1-cdf(j))/params.acc_fac;
+% end
+% end
+% else
+% % otherwise take the "default" one
+% spike_prob_function{i}=spike_prob_function{10};
+% end
+% end
+%
+% times=0:10:60;
+% times=[times 100 250];
+%
+%
+% % spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+%
+% jitter_time=0;
+% latency=0;
+%
+% start_boost_beta_length=20;
+% test_sig=zeros(length(x2),1);
+% sigend=53;
+% test_sig(1:sigend/binwidth)=1;
+% % build a ramp...
+% test_sig(1:2/binwidth)=linspace(0,1,2/binwidth);
+% test_sig(sigend/binwidth-2/binwidth:sigend/binwidth)=linspace(1,0,2/binwidth+1);
+%
+% spont_rate=0;
+%
+% for i=1:nr_sweeps
+% spikes=[];
+% last_spike=-1; % inital condition: how long ago was the last spike
+% spikecounter=1; % spikecounter
+% swapc=2;
+% next_swap=times(swapc);
+% c_function=spike_prob_function{swapc};
+%
+% for j=1:nr_steps
+% time_now=j*binwidth; % thats the global time counter
+% if time_now>next_swap
+% swapc=swapc+1;
+% next_swap=times(swapc);
+% c_function=spike_prob_function{swapc};
+% end
+% % implementation of a simple solution for the first spike problem: if the spike is the first then assume a very high probability
+% if spikecounter==1 % yes, its the first
+% % if randdynamic_range % in saturation
+% % cur_eta=eta;
+% % else
+% % cur_eta=(eta-eta_null)/dynamic_range*cur_amp+eta_null;
+% % % cur_eta=f2f(cur_amp,0,dynamic_range,eta_null,eta);
+% % end
+%
+% % z = (log(difft) - p1) ./ p2;
+% % spike_prob = exp(p3 - exp(p3)) ./ p2;
+% spike_prob = gevpdf(log(difft),p3,p2,p1);
+%
+% % weibull function
+% % spike_prob=(beta/cur_eta)*power(log(difft)/cur_eta,beta-1);
+%
+% % spike_prob=spike_prob*test_sig(j)+spont_rate; % % modulate the probability with the height of the signal
+% % spike_prob=spike_prob/(1.2+binwidth/2); %correction factor
+% if rand0);
+x2=[x2; x2(end)+binwidth];
+% figure(43)
+% cla
+% hold on
+for i=1:2
+ p1=params.recovery_parameter.fit_p(1);
+ p2=params.recovery_parameter.fit_p(2);
+ p3=params.recovery_parameter.fit_p(3);
+ if i==1
+ p2=p2/2;
+ end
+ pdf=gevpdf(log(x2),p1,p2,p3);
+ cdf=gevcdf(log(x2),p1,p2,p3);
+ spike_prob_function{i}=ones(size(x2))*inf;
+ for j=1:length(x2)
+ if cdf(j)<1
+ spike_prob_function{i}(j)=pdf(j)/(1-cdf(j))/params.acc_fac;
+ end
+ end
+end
+
+
+times=[20 250];
+
+
+% spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+
+% shift the signal by the latency to simulate the latency:
+zeros_in_front=zeros(latency/binwidth,1);
+sigvalues=[zeros_in_front;sigvalues];
+
+
+
+for i=1:nr_sweeps
+ spikes=[];
+ last_spike=-1; % inital condition: how long ago was the last spike
+ spikecounter=1; % spikecounter
+ swapc=1;
+ next_swap=times(swapc);
+ c_function=spike_prob_function{swapc};
+
+ still_in_latency=1;
+ for j=1:nr_steps
+ time_now=j*binwidth; % thats the global time counter
+
+ if still_in_latency && time_now> latency
+ if rand0);
+% x2=[x2; x2(end)+binwidth];
+% % figure(43)
+% % cla
+% % hold on
+% for i=10:-1:1
+% if isfield(p{i},'k') % otherwise no spikes
+% p1=p{i}.k;
+% p2=log(p{i}.x);
+% p3=p{i}.y;
+% % plot3(p1,p2,p3,'o')
+% pdf=gevpdf(log(x2),p1,p2,p3);
+% cdf=gevcdf(log(x2),p1,p2,p3);
+% spike_prob_function{i}=ones(size(x2))*inf;
+% for j=1:length(x2)
+% if cdf(j)<1
+% spike_prob_function{i}(j)=pdf(j)/(1-cdf(j))/params.acc_fac;
+% end
+% end
+% else
+% % otherwise take the "default" one
+% spike_prob_function{i}=spike_prob_function{10};
+% end
+% end
+%
+% times=0:10:60;
+% times=[times 100 250];
+%
+%
+% % spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+%
+% jitter_time=0;
+% latency=0;
+%
+% start_boost_beta_length=20;
+% test_sig=zeros(length(x2),1);
+% sigend=53;
+% test_sig(1:sigend/binwidth)=1;
+% % build a ramp...
+% test_sig(1:2/binwidth)=linspace(0,1,2/binwidth);
+% test_sig(sigend/binwidth-2/binwidth:sigend/binwidth)=linspace(1,0,2/binwidth+1);
+%
+% spont_rate=0;
+%
+% for i=1:nr_sweeps
+% spikes=[];
+% last_spike=-1; % inital condition: how long ago was the last spike
+% spikecounter=1; % spikecounter
+% swapc=2;
+% next_swap=times(swapc);
+% c_function=spike_prob_function{swapc};
+%
+% for j=1:nr_steps
+% time_now=j*binwidth; % thats the global time counter
+% if time_now>next_swap
+% swapc=swapc+1;
+% next_swap=times(swapc);
+% c_function=spike_prob_function{swapc};
+% end
+% % implementation of a simple solution for the first spike problem: if the spike is the first then assume a very high probability
+% if spikecounter==1 % yes, its the first
+% % if randdynamic_range % in saturation
+% % cur_eta=eta;
+% % else
+% % cur_eta=(eta-eta_null)/dynamic_range*cur_amp+eta_null;
+% % % cur_eta=f2f(cur_amp,0,dynamic_range,eta_null,eta);
+% % end
+%
+% % z = (log(difft) - p1) ./ p2;
+% % spike_prob = exp(p3 - exp(p3)) ./ p2;
+% spike_prob = gevpdf(log(difft),p3,p2,p1);
+%
+% % weibull function
+% % spike_prob=(beta/cur_eta)*power(log(difft)/cur_eta,beta-1);
+%
+% % spike_prob=spike_prob*test_sig(j)+spont_rate; % % modulate the probability with the height of the signal
+% % spike_prob=spike_prob/(1.2+binwidth/2); %correction factor
+% if rand0);
+x2=[x2; x2(end)+binwidth];
+% figure(43)
+% cla
+% hold on
+for i=10:-1:1
+ if isfield(p{i},'k') % otherwise no spikes
+ p1=p{i}.k;
+ p2=log(p{i}.x)*3.2;
+ p3=p{i}.y*1.5;
+% plot3(p1,p2,p3,'o')
+ pdf=gevpdf(log(x2),p1,p2,p3);
+ cdf=gevcdf(log(x2),p1,p2,p3);
+ spike_prob_function{i}=ones(size(x2))*inf;
+ for j=1:length(x2)
+ if cdf(j)<1
+ spike_prob_function{i}(j)=pdf(j)/(1-cdf(j));
+ end
+ end
+ else
+ % otherwise take the "default" one
+ spike_prob_function{i}=spike_prob_function{10};
+ end
+end
+
+times=0:10:60;
+times=[times 100 250];
+
+
+% spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+
+jitter_time=0;
+latency=0;
+
+start_boost_beta_length=20;
+test_sig=zeros(length(x2),1);
+test_sig(1:55/binwidth)=1;
+spont_rate=0;
+
+for i=1:nr_sweeps
+ spikes=[];
+ last_spike=-1; % inital condition: how long ago was the last spike
+ spikecounter=1; % spikecounter
+ swapc=2;
+ next_swap=times(swapc);
+ c_function=spike_prob_function{swapc};
+
+ for j=1:nr_steps
+ time_now=j*binwidth; % thats the global time counter
+ if time_now>next_swap
+ swapc=swapc+1;
+ next_swap=times(swapc);
+ c_function=spike_prob_function{swapc};
+ end
+ % implementation of a simple solution for the first spike problem: if the spike is the first then assume a very high probability
+ if spikecounter==1 % yes, its the first
+% if randdynamic_range % in saturation
+% % cur_eta=eta;
+% % else
+% % cur_eta=(eta-eta_null)/dynamic_range*cur_amp+eta_null;
+% % % cur_eta=f2f(cur_amp,0,dynamic_range,eta_null,eta);
+% % end
+%
+% % z = (log(difft) - p1) ./ p2;
+% % spike_prob = exp(p3 - exp(p3)) ./ p2;
+% spike_prob = gevpdf(log(difft),p3,p2,p1);
+%
+% % weibull function
+% % spike_prob=(beta/cur_eta)*power(log(difft)/cur_eta,beta-1);
+%
+% % spike_prob=spike_prob*test_sig(j)+spont_rate; % % modulate the probability with the height of the signal
+% % spike_prob=spike_prob/(1.2+binwidth/2); %correction factor
+% if rand0);
+x2=[x2; x2(end)+binwidth];
+% figure(43)
+% cla
+% hold on
+for i=1:2
+ p1=p{10}.k;
+ p2=log(p{10}.x);
+ p3=p{10}.y;
+ if i==1
+ end
+ % plot3(p1,p2,p3,'o')
+ pdf=gevpdf(log(x2),p1,p2,p3);
+ cdf=gevcdf(log(x2),p1,p2,p3);
+ spike_prob_function{i}=ones(size(x2))*inf;
+ for j=1:length(x2)
+ if cdf(j)<1
+ spike_prob_function{i}(j)=pdf(j)/(1-cdf(j));
+ end
+ end
+end
+
+
+times=[20];
+
+
+% spike_prob_function2=gevpdf(x2,p3,p2/start_boost_beta_val,p1); % for the first 20 ms
+
+jitter_time=0;
+latency=0;
+
+start_boost_beta_length=20;
+test_sig=zeros(length(x2),1);
+test_sig(1:55/binwidth)=1;
+spont_rate=0;
+
+for i=1:nr_sweeps
+ spikes=[];
+ last_spike=-1; % inital condition: how long ago was the last spike
+ spikecounter=1; % spikecounter
+ swapc=2;
+ next_swap=times(swapc);
+ c_function=spike_prob_function{swapc};
+
+ for j=1:nr_steps
+ time_now=j*binwidth; % thats the global time counter
+ if time_now>next_swap
+ swapc=swapc+1;
+ next_swap=times(swapc);
+ c_function=spike_prob_function{swapc};
+ end
+ % implementation of a simple solution for the first spike problem: if the spike is the first then assume a very high probability
+ if spikecounter==1 % yes, its the first
+% if randlen
+ whichstop=len;
+ end
+ new_vals(i)=average(sig,whichstart,whichstop);
+ end
+ newsig=setvalues(newsig,new_vals);
+ return
+end
+
+newsig=sig;
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/std.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/std.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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/01/23 10:56:28 $
+% $Revision: 1.4 $
+
+function m=std(sig)
+% returns the mean of the signal
+
+val=getdata(sig);
+m=std(val);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/straight.asv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/straight.asv Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% mystraight
+% transforms it with two parameters: scale and fotrans
+
+function sig=straight(sig,scale,f0trans)
+
+straightCIv1('initialize');
+straightCIv1('initializeparams');
+straightCIv1('setwavedata',sig);
+straightCIv1('source',sig);
+straightCIv1('bandcorrbtn');
+straightCIv1('bypassbtn');
+
+scales(1)=scale;
+scales(1)=f0trans;
+
+straightCIv1('set_scales',scales)
+straightCIv1('synthesizegraded')
+
+sigc=sig;
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/straight.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/straight.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% mystraight
+% transforms it with two parameters: scale and fotrans
+
+function sigret=straight(sig,f0trans,freqscale,timescale)
+
+mystraight('set_grafix',0);
+mystraight('initialize');
+mystraight('initializeparams');
+mystraight('setwavedata',sig);
+mystraight('source',sig);
+mystraight('bandcorrbtn');
+mystraight('bypassbtn');
+
+scales(1)=f0trans;
+scales(2)=freqscale;
+scales(3)=timescale;
+
+mystraight('set_scales',scales);
+sigret=mystraight('synthesizegraded');
+
+
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/sum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/sum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% method of class @
+%function s=sum(sig,t_start,t_stop)
+% INPUT VALUES:
+% sig: @signal
+% t_start: start time (default: 0)
+% t_stop: sum until here (default: signal-length)
+%
+% RETURN VALUE:
+% s: sum of the signal in that region
+%
+% (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 s=sum(sig,t_start,t_stop)
+
+if nargin < 2
+ t_start=getminimumtime(sig);
+end
+if nargin < 3
+ t_stop=getmaximumtime(sig);
+end
+
+intstart=time2bin(sig,t_start)+1;
+intstop=time2bin(sig,t_stop);
+
+
+if intstart<1
+ intstart=1;
+ disp('signal::sum: starttime too small');
+end
+if intstop>getnrpoints(sig)
+ intstop=getnrpoints(sig);
+ disp('signal::sum: intstop too big!');
+end
+
+% if intstart>intstop
+% error('signal::sum: stoptime < starttime');
+% end
+
+
+s=sum(sig.werte(intstart:intstop));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/tilt.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/tilt.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,53 @@
+% method of class @signal
+%
+% 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 $
+
+
+% not jet fully tested!!!
+
+
+
+function sig=tilt(sig,tilttime)
+% usage: sig=tilt(sig,tilttime)
+% puts the signal downwards to the left!
+% in the auditory image model, all activities become
+% smaller with the distance
+% usually with a decrease of 100% in 40 ms
+
+
+
+
+
+if nargin<2
+ tilttime=0.04;
+end
+
+vals=sig.werte;
+
+if getminimumtime(sig)>0
+ return
+end
+durationtotilt=abs(getminimumtime(sig));
+tiltnr=time2bin(sig,0); % so viele Punkte werden getiltet
+dt=tilttime-durationtotilt; % übrige Zeit, die links aus dem Bild rausgeht
+dnull=dt/tilttime;
+ti=linspace(dnull,1,tiltnr)';
+vals(1:tiltnr)=vals(1:tiltnr).*ti;
+% figure
+% subplot(2,1,1)
+% plot(sig);
+sig.werte=vals;
+% subplot(2,1,2)
+% plot(sig);
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/time2bin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/time2bin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% method of class @
+%function bin=time2bin(sig,time)
+% INPUT VALUES:
+% sig: @signal
+% time: time in seconds
+% RETURN VALUE:
+% bin: interpolated bin value of that time in the signal corrected by
+% the signals start time
+%
+% (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 ret=time2bin(sig,time)
+% returns the real value of the times in bins in the signal. This must not
+% be the value that is needed to plot! (see time2plotbin)
+
+
+
+time=time-sig.start_time;
+
+ret=time*sig.samplerate;
+ret=round(ret);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/toshio_lowpass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/toshio_lowpass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+
+
+function sig=toshio_lowpass(sig,cutoff,order)
+
+%variable: order, is not used,
+% a 2nd order filter is assumed,
+% taken from Irino code: CalNAPghll.m
+
+
+if nargin<2
+ order=1;
+end
+
+
+sr=getsr(sig);
+vals=getvalues(sig);
+
+[bzLP apLP] = butter(1,cutoff/(sr/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];
+
+sig_len = length(vals);
+
+filt_vals(1:sig_len) = filter(bzLP2,apLP2,vals);
+vals=filt_vals;
+
+
+
+sig=setvalues(sig,vals);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/uminus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/uminus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+% method of class @
+%function sig=uminus(sig,b)
+% INPUT VALUES:
+% sig: original signal
+% RETURN VALUE:
+% sig: inverted signal
+%
+% (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=uminus(a,b)
+%Vorzeichenwechsel
+sig=a;
+sig.werte= -sig.werte;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/variance.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/variance.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% method of class @signal
+%
+% 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/01/23 10:56:28 $
+% $Revision: 1.4 $
+
+function m=variance(sig)
+% returns the mean of the signal
+
+val=getdata(sig);
+s=std(val);
+m=s*s;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/vocoder.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/vocoder.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% method of class @signal
+% function sig=vocoder(sig,warp_factor)
+% produces a time warped version of the signal.
+% built on the "A Phase Vocoder in Matlab" on
+% http://www.ee.columbia.edu/~dpwe/resources/matlab/pvoc/
+%
+% (c) 2005, University of Cambridge, Medical Research Council
+% Stefan Bleeck (stefan@bleeck.de)
+% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
+% $Date: 2003/01/20 18:33:51 $
+% $Revision: 1.4 $
+
+function sig=vocoder(a,warp_factor)
+
+data=get(a); % get the values
+
+newdata=pvoc(data,warp_factor); % call the warping routine
+sig=signal(newdata,getsr(a));
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/vowel_plus_octave.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/vowel_plus_octave.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,17 @@
+function sig=vowel_plus_octave(sig,options,ratio)
+% construct two artificial vowels with octaves in pitch. The imortant thing
+% is that the random generator is reset in between, so that all random
+% elements of each period is identical
+
+
+seed=sum(100*clock);
+rand('seed',seed);
+v1=gen_vowel(sig,options);
+
+options.do_octave=1;
+rand('seed',seed);
+v2=gen_vowel(sig,options);
+
+sig=ratio*v1+(1-ratio)*v2;
+sig=scaletorms(sig,0.2);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/writetofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/writetofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% method of class @
+% function writetofile(sig,name)
+% INPUT VALUES:
+% sig: signal to save
+% name: filename
+% RETURN VALUE:
+% none
+%
+% (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 writetofile(sig,name)
+%usage: writetofile(sig,name)
+%DRRSmith 28/05/02
+%readsounddata=getdata(sig);
+%fid=fopen(name,'wb');
+%fwrite(fid,readsounddata,'int16');
+%fclose(fid);
+
+if nargin<3
+
+readsounddata=getdata(sig);
+if (isunix==1)
+ fid=fopen(name,'wb','b'); %bigendian
+ fwrite(fid,readsounddata,'int16');
+ fclose(fid);
+else
+ fid=fopen(name,'wb','l'); %littleendian
+ fwrite(fid,readsounddata,'int16');
+ fclose(fid);
+end
+
+% readsounddata=getdata(sig);
+% fid=fopen(name,'wb',endian);
+% fwrite(fid,readsounddata,'int16');
+% fclose(fid);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@signal/writetowavefile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@signal/writetowavefile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% method of class @
+% function writetowavefile(sig,name)
+% INPUT VALUES:
+% sig: @signal
+% name: name of the resulting wavefile
+% RETURN VALUE:
+% none
+%
+% writetowavefile saves the signal to a wavefile without changing its
+% amplitude (contrary to savewave)
+%
+% (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 writetowavefile(sig,name)
+samplerate=getsr(sig);
+readsounddata=getdata(sig);
+wavwrite(readsounddata,samplerate,name);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@sinus/generate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@sinus/generate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% method of class @sinus (derived from @signal)
+%
+% 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 sinu=generate(sinu)
+
+
+phase=sinu.phase;
+amplitude=sinu.amplitude;
+fre=sinu.frequency;
+
+nr_points=getnrpoints(sinu);
+sr=getsr(sinu);
+length=getlength(sinu);
+
+von=0+phase;
+periode=1/fre;
+bis=2*pi*length/periode + phase;
+
+temp=linspace(von,bis,nr_points);
+data=sin(temp);
+
+data=data*amplitude;
+
+sinu=setvalues(sinu,data);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/@sinus/sinus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/@sinus/sinus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,48 @@
+% method of class @sinus (derived from @signal)
+%
+% 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 sinu=sinus(length,samplerate,frequency,amplitude,phase)
+% produces a sinus as a signal
+
+if nargin < 5
+ phase=0;
+end
+if nargin < 4
+ amplitude=1;
+end
+if nargin < 3
+ frequency=1;
+end
+if nargin < 2
+ samplerate=1000;
+end
+if nargin < 1
+ length=1;
+end
+
+name= sprintf('Sinus with %5.2f Hz',frequency);
+unit_y='amplitude';
+unit_x='time (ms)';
+start_time=0;
+
+ctt.frequency=frequency;
+ctt.amplitude=amplitude;
+ctt.phase=phase;
+
+sig=signal(length,samplerate,name,unit_x,unit_y,start_time);
+
+% f=class(struct([]),'fsignal',sig);
+sinu=class(ctt,'sinus',sig);
+
+sinu=generate(sinu);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/AIFrePtiP.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/AIFrePtiP.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,274 @@
+% tool
+%
+% 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 options=AIFrePtiP(framestruct_a);
+% plots the current frame (cframe) together with its sum of intervals
+% and the sum of frequencies
+% no pitch is calculated or plotted! for this use AIFrePtiPstress
+% all relevant data must be in the frame-object
+% the return value "pitch" is the result from the call to "calcresidualprobability"
+
+
+if ~isstruct(framestruct_a)
+ % error('AIsum must be called with a structure');
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+
+if ~isfield(framestruct,'show_time');
+ show_time=1;
+else
+ show_time=framestruct.show_time;
+end
+
+if ~isfield(framestruct,'plot_scale');
+ plot_scale=1;
+else
+ plot_scale=framestruct.plot_scale;
+end
+
+
+if ~isfield(framestruct,'minimum_time_interval');
+ minimum_time_interval=1;
+else
+ minimum_time_interval=framestruct.minimum_time_interval;
+end
+
+if ~isfield(framestruct,'is_log');
+ is_log=1;
+else
+ is_log=framestruct.is_log;;
+end
+
+if isfield(framestruct,'frequency_profile_scale');
+ frequency_profile_scale=framestruct.frequency_profile_scale;
+else
+ frequency_profile_scale=1;
+end
+if isfield(framestruct,'time_profile_scale');
+ time_profile_scale=framestruct.time_profile_scale;
+else
+ time_profile_scale=1;
+end
+% if the time scale is reversed (time from left to right)
+if isfield(framestruct,'time_reversed');
+ time_reversed=framestruct.time_reversed;
+else
+ time_reversed=0;
+end
+
+% hier wird der current frame definiert:
+current_frame=framestruct.current_frame;
+
+if ~isfield(framestruct,'maximum_time_interval');
+ maximum_time_interval=35;
+else
+ maximum_time_interval=framestruct.maximum_time_interval;
+end
+
+if maximum_time_interval/1000>getlength(current_frame)
+ maximum_time_interval=getlength(current_frame)*1000;
+end
+
+if isfield(framestruct,'options');
+ options=framestruct.options;
+else
+ options=[];
+end
+if ~isfield(options,'oldhandle1')
+ options.oldhandle1=0;
+end
+if ~isfield(options,'oldhandle2')
+ options.oldhandle2=0;
+end
+if ~isfield(options,'oldhandle3')
+ options.oldhandle3=0;
+end
+
+
+% schmeisse die physikalisch nicht sinnvollen Bereiche raus!
+% current_frame=extractpitchregion(current_frame);
+
+scale_summe=getscalesumme(current_frame);
+
+% start plotting:
+% clf;
+axis off
+caxes=get(gca,'position');
+
+channel_density=0.015; % passt für 76 channels von 100 bis 6000
+% channel_density=2*0.015; % passt für 76 channels von 100 bis 6000
+hoehe=getnrchannels(current_frame)*channel_density;
+if hoehe>1
+ hoehe=1;
+end
+if hoehe < 0.2
+ hoehe = 0.2;
+end
+
+rect=[-0.04 0.15 0.9 hoehe*0.85];
+rect(1:2)=caxes(1:2)+(rect(1:2).*caxes(3:4));
+rect(3:4)=rect(3:4).*caxes(3:4);
+
+hint=1; % this indicate that we dont want a title
+mysubplot(1,1,1,rect, hint);
+if options.oldhandle1~=0
+ delete(options.oldhandle1);
+end
+options.oldhandle1=gca;
+
+plot_struct.t_min=minimum_time_interval/1000;
+plot_struct.t_max=maximum_time_interval/1000;
+plot_struct.has_axis=0;
+plot_struct.is_log=is_log;
+plot_struct.has_y_axis=0;
+axis off
+
+plot(current_frame,plot_struct);
+set(gca,'zlim',[0 1/plot_scale]);
+
+if show_time
+ srate=getsr(current_frame);
+ text_x=0.8*maximum_time_interval*srate/1000;
+ text_y=getnrchannels(current_frame)*1.1;
+ frame_number=getcurrentframenumber(current_frame);
+ frame_time=getcurrentframestarttime(current_frame);
+ text(text_x,text_y,sprintf('%3d : %4.0fms',frame_number,frame_time*1000),'FontSize',8);
+ % text(text_x,text_y,sprintf('%d',frame_number),'FontSize',8);
+end
+
+% interval sum
+rect=[-0.04 0 0.9 0.2];
+rect(1:2)=caxes(1:2)+(rect(1:2).*caxes(3:4));
+rect(3:4)=rect(3:4).*caxes(3:4);
+mysubplot(1,1,1,rect, hint);
+if options.oldhandle2~=0
+ delete(options.oldhandle2);
+end
+options.oldhandle2=gca;
+
+summe=getsum(current_frame); % here it is calculated
+axis off
+
+srate=getsr(current_frame);
+if is_log
+ t=minimum_time_interval;
+ if t<=0
+ error('in logarithmic plots, the minimum time interval must be positiv!');
+ end
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)/1000*srate; % there shell be the tix
+ ti=(ti);
+ ti=round(ti*100)/100;
+ if getminimumtime(summe) <0
+ psumme=getpart(summe,getminimumtime(summe),0);
+ else
+ psumme=getpart(summe,getminimumtime(summe),maximum_time_interval/1000);
+ end
+% rsumme=reverse(psumme);
+ rsumme=psumme;
+ sumvalues=getvalues(rsumme);
+ min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
+ max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
+else % its not logarithmic!
+ frame_start_time=getminimumtime(current_frame);
+ if maximum_time_interval>0
+ summe=getpart(summe,(minimum_time_interval/1000+frame_start_time),maximum_time_interval/1000+frame_start_time);
+ else
+ summe=getpart(summe,(-maximum_time_interval/1000+frame_start_time),-minimum_time_interval/1000+frame_start_time);
+ end
+ nr_labels=8;
+ xbis=getnrpoints(summe);
+ tix=0:xbis/nr_labels:xbis;
+ xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
+ xstep=round(xstep);
+ ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000])/1000;
+ ti=round(ti*10)/10;
+% sumvalues=getvalues(reverse(summe));
+ sumvalues=getvalues(summe);
+
+ min_x_screen=0;
+ max_x_screen=(maximum_time_interval-minimum_time_interval)/1000*srate; % thats the first point we want to see on the screen
+
+end
+
+h=plot(sumvalues); hold on
+if scale_summe==0
+ axis([min_x_screen max_x_screen 0 1]);
+else
+ axis([min_x_screen max_x_screen 0 scale_summe/time_profile_scale]);
+end
+
+% set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+if is_log
+ set(gca,'XScale','log')
+end
+
+if time_reversed
+ ti=ti(end:-1:1);
+end
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+%
+if is_log
+ text(max_x_screen*0.5,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+else
+ text(500,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+end
+
+
+
+% frequency sum
+scale_frequency=getscalefrequency(current_frame);
+
+hoehe=getnrchannels(current_frame)*channel_density;
+if hoehe>1
+ hoehe=1;
+end
+
+rect=[0.856 0.19 0.1 hoehe*0.81];
+rect(1:2)=caxes(1:2)+(rect(1:2).*caxes(3:4));
+rect(3:4)=rect(3:4).*caxes(3:4);
+mysubplot(1,1,1,rect, hint);
+if options.oldhandle3~=0
+ delete(options.oldhandle3);
+end
+options.oldhandle3=gca;
+fresumme=getfrequencysum(current_frame); % here it is calculated
+% fresumme=smooth(fresumme,1);% glätte die Summe
+
+% fresumme=fresumme/frequency_profile_scale;
+
+fresumme=setname(fresumme,'');
+fresumme=setunit_x(fresumme,'');
+fresumme=setunit_y(fresumme,'');
+
+plot(fresumme,'r'); hold on
+v=getvalues(fresumme);
+axis([0 size(v,1)*47/42 0 scale_frequency/frequency_profile_scale]);
+view(-90,90);
+% make y-Ticks
+nr_labels=8;
+nr_channels=getnrpoints(fresumme);
+xstep=(nr_channels-1)/(nr_labels-1);
+tix=1:xstep:nr_channels;
+cfs=getcf(current_frame);
+ti=cfs(floor(tix))/1000;
+ti=round(ti*10)/10;
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+set(gca,'XAxisLocation','top');
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/AIFrePtiPStress.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/AIFrePtiPStress.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,305 @@
+% tool
+%
+% 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 pitch=AIFrePtiPStress2(framestruct_a);
+% plots the current frame (cframe) together with its sum of intervals
+% and the sum of frequencies
+% all relevant data must be in the frame-object
+% the return value "pitch" is the result from the call to "calcresidualprobability"
+
+if ~isstruct(framestruct_a)
+ % error('AIsum must be called with a structure');
+ framestruct.current_frame=framestruct_a;
+ current_frame_number=1;
+else
+ framestruct=framestruct_a;
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Different Parameters
+% if the label of the time should be shown in the upper left corner
+if ~isfield(framestruct,'show_time');
+ show_time=1;
+else
+ show_time=framestruct.show_time;
+end
+
+% if any grafic should be displayed. Otherwise only the value is returned
+if ~isfield(framestruct,'show_graphic');
+ show_graphic=1;
+else
+ show_graphic=framestruct.show_graphic;
+end
+
+% both profiles can be scaled to a higher value
+if ~isfield(framestruct,'profile_scale');
+ profile_scale=1;
+else
+ profile_scale=framestruct.profile_scale;
+end
+
+% the picture can be scaled overall to a higher value
+if ~isfield(framestruct,'plot_scale');
+ plot_scale=1;
+else
+ plot_scale=framestruct.plot_scale;
+end
+
+% the minimum time interval (usually 1 ms) on the right
+if ~isfield(framestruct,'minimum_time_interval');
+ minimum_time_interval=1;
+else
+ minimum_time_interval=framestruct.minimum_time_interval;
+end
+
+% the maximum time interval (usually 35 ms) on the left
+if ~isfield(framestruct,'maximum_time_interval');
+ maximum_time_interval=35;
+else
+ maximum_time_interval=framestruct.maximum_time_interval;
+end
+
+% linear or logarithmic structure
+if ~isfield(framestruct,'is_log');
+ is_log=1;
+else
+ is_log=framestruct.is_log;;
+end
+current_frame=framestruct.current_frame;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Parameter für die PitchBerechnung
+dot_scaler=200; % wie gross Punkte dargestellt werden sollen in Punkt
+grafix=0;
+% wie weit die Intervallsumme runterskaliert werden muss, damit die Zahlen vernünftigt werden
+norm_intervalhight=1/1e4;
+% wie weit die spektrale Summe runterskaliert werden muss, damit die Zahlen vernünftigt werden
+norm_spektralhight=1.5/1e5;
+
+% how big must the contrast of the envelope be to be recognised as one pitch
+envcontrast_threshold=0.15;
+
+% A single factor, that can vary between
+% 0 = complete attention to temporal structure
+% 1 = complete attention to spectral structure
+spectral_attention_factor=0.5;
+
+pitch_current_frame=current_frame;
+% schmeisse die physikalisch nicht sinnvollen Bereiche raus!
+current_frame=extractpitchregion(current_frame);
+
+% berechne die pitches vom Orginal
+parameters.norm_intervalhight=norm_intervalhight;
+parameters.norm_spektralhight=norm_spektralhight;
+parameters.graphix=grafix;
+parameters.dot_scaler=dot_scaler;
+parameters.spectral_attention_factor=spectral_attention_factor;
+parameters.extract_pitch_region=1; % schmeiss die Ecke unten rechts raus
+parameters.use_whole_spektral_profile=1; % nimm das gesamte Profil zum mitteln!
+
+
+% Berechnet den Pitch
+pitch=calcresidualprobability(pitch_current_frame,parameters);
+% if we dont need any graphic, than return here
+if ~show_graphic
+ return;
+end
+
+% start plotting:
+clf;
+rect=[-0.04 0.15 0.9 0.85];
+hint=1; % this indicate that we dont want a title
+mysubplot(1,1,1,rect, hint);
+plot_struct.t_min=minimum_time_interval/1000;
+plot_struct.t_max=maximum_time_interval/1000;
+% current_frame=setdisplayminimumtime(current_frame,minimum_time_interval);
+% current_frame=setdisplaymaximumtime(current_frame,maximum_time_interval);
+
+plot_struct.has_axis=0;
+plot_struct.is_log=is_log;
+plot_struct.has_y_axis=0;
+
+rethand=plot(current_frame,plot_struct);
+set(gca,'zlim',[0 1/plot_scale]);
+
+% if show_time
+% srate=getsr(current_frame);
+% text_x=0.9*maximum_time_interval*srate/1000;
+% text_y=getnrchannels(current_frame)+5;
+% str=getstructure(current_frame);
+% if ~isfield(str,'current_frame_start_time')
+% str.current_frame_start_time=0.0;
+% end
+% frame_number=str.current_frame_number;
+% frame_time=str.current_frame_start_time*1000;
+% text(text_x,text_y,sprintf('%d : %4.0fms',frame_number,frame_time),'FontSize',8);
+% % text(text_x,text_y,sprintf('%d',frame_number),'FontSize',8);
+% end
+
+% and the sum
+rect=[-0.04 0 0.9 0.2];
+mysubplot(1,1,1,rect, hint);
+summe=getsum(current_frame); % here it is calculated
+
+srate=getsr(current_frame);
+if is_log
+
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)/1000*srate; % there shell be the tix
+
+ ti=(ti);
+ ti=round(ti*100)/100;
+
+ psumme=getpart(summe,getminimumtime(summe),getmaximumtime(summe));
+ rsumme=reverse(psumme);
+ sumvalues=getvalues(rsumme);
+
+ min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
+ max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
+
+else % its not logarithmic!
+ summe=getpart(summe,-maximum_time_interval/1000,-minimum_time_interval/1000);
+
+ nr_labels=8;
+ xbis=getnrpoints(summe);
+ tix=0:xbis/nr_labels:xbis;
+ xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
+ xstep=round(xstep);
+ ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000])/1000;
+ ti=round(ti*10)/10;
+ sumvalues=getvalues(reverse(summe));
+
+ min_x_screen=0;
+ max_x_screen=(maximum_time_interval-minimum_time_interval)/1000*srate; % thats the first point we want to see on the screen
+
+end
+
+% alle Werte sind auf empirische Werte genormt, so dass sie immer gleich hoch sind
+sumvalues=sumvalues*norm_intervalhight;
+% alle Werte auf die Benutzerscalierung scalen
+sumvalues=sumvalues*profile_scale;
+
+summe=setvalues(summe,sumvalues,floor(min_x_screen));
+h=plot(sumvalues); hold on
+
+axis([min_x_screen max_x_screen 0 1]);
+sr=getsr(current_frame);
+
+% % Ein roter Punkt dort, wo der pitch vermutet wird
+n=length(pitch);
+for i=n:-1:1
+ peak=pitch{i};
+ timex=peak.interval_profile.time;
+
+% binx=displaytime2bin(current_frame,timex)-2;
+ binx=time2bin(timex,sr)-2;
+ hei=getbinvalue(summe,max_x_screen-binx+min_x_screen);
+ % hei=gettimevalue(summe,getminimumtime(summe)-timex);
+ % bin=time2bin(summe,timex);
+ if i==1
+ radius=max(5,dot_scaler*peak.residuumpitchstrength);
+ plot(max_x_screen-binx,hei,'r.','MarkerSize',radius);
+ texthei=hei*1.2;
+ if texthei>max(summe)/1.4
+ texthei=max(summe)/1.4;
+ end
+ if peak.interval_profile.envcontrast > envcontrast_threshold
+ % text(binx/1.06,texthei*1.2,sprintf('%3.0f Hz %5.3f',peak.fre,peak.pitchstrength)); % this is at a nice position
+ text((max_x_screen-binx)/1.06,texthei*1.2,sprintf('%3.0f Hz',peak.interval_profile.fre)); % this is at a nice position
+ end
+ else
+ radius=max(5,dot_scaler*peak.residuumpitchstrength);
+ plot(max_x_screen-binx,hei,'b.','MarkerSize',radius);
+ end
+end
+%
+set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+if is_log
+ set(gca,'XScale','log')
+end
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+%
+% if is_log
+% scale_summe=getfrequencysum(current_frame);
+% text(min_x_screen*1.9,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+% else
+% text(120,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+% end
+
+
+
+% and the other sum on the y-axis
+rect=[0.857 0.2 0.10 0.75];
+mysubplot(1,1,1,rect, hint);
+fresumme=getfrequencysum(current_frame); % here it is calculated
+% fresumme=smooth(fresumme,1);% glätte die Summe
+
+% alle Werte auf den empirischen Wert skalieren und auf den Benutzerwert
+fresumme=fresumme*norm_spektralhight;
+fresumme=fresumme*profile_scale;
+
+fresumme=setname(fresumme,'');
+fresumme=setunit_x(fresumme,'');
+fresumme=setunit_y(fresumme,'');
+
+plot(fresumme,'r'); hold on
+v=getvalues(fresumme);
+x1=0;
+x2=size(v,1)*47/42;
+y1=0;
+y2=1;
+axis([x1 x2 y1 y2]);
+view(-90,90);
+% make y-Ticks
+nr_labels=8;
+nr_channels=getnrpoints(fresumme);
+xstep=(nr_channels-1)/(nr_labels-1);
+tix=1:xstep:nr_channels;
+cfs=getcf(current_frame);
+ti=cfs(floor(tix))/1000;
+ti=round(ti*10)/10;
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+set(gca,'XAxisLocation','top');
+
+n=length(pitch);
+for i=n:-1:1
+ peak=pitch{i};
+ x=peak.spektral_profile.position;
+ hei=peak.spektral_profile.hight/2;
+ radius=max(5,dot_scaler*hei);
+ y=getbinvalue(fresumme,x);
+ plot(x,y,'r.','MarkerSize',radius);
+end
+
+% Special Effect: Make Region cool!
+n=length(pitch);
+cdat=get(rethand,'cdata');
+cdat=zeros(size(cdat));
+
+bereich=n:-1:1;
+% bereich=1;
+for i=bereich
+ peak=pitch{i};
+ cdat=coolregion(current_frame,cdat,peak);
+end
+
+set(rethand,'cdata',cdat);
+% erzeuge eine Colormap, die genausoviel Farben hat, wie wir Quellen
+colmap=hsv(n+1);
+colmap(1,:)=0.85;
+colormap(colmap);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/AIpitch.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/AIpitch.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,247 @@
+% tool
+%
+% 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 pitch=AIpitch(framestruct_a);
+% plots the current frame (cframe) together with its sum
+% all relevant data must be in the frame-object
+% the return value "pitch" is the result from the call to "calcresidualprobability"
+
+if ~isstruct(framestruct_a)
+ % error('AIsum must be called with a structure');
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+
+if ~isfield(framestruct,'show_time');
+ show_time=1;
+else
+ show_time=framestruct.show_time;
+end
+
+if ~isfield(framestruct,'plot_scale');
+ plot_scale=1;
+else
+ plot_scale=framestruct.plot_scale;
+end
+
+
+if ~isfield(framestruct,'minimum_time_interval');
+ minimum_time_interval=1;
+else
+ minimum_time_interval=framestruct.minimum_time_interval;
+end
+
+if ~isfield(framestruct,'maximum_time_interval');
+ maximum_time_interval=35;
+else
+ maximum_time_interval=framestruct.maximum_time_interval;
+end
+
+if ~isfield(framestruct,'is_log');
+ is_log=1;
+else
+ is_log=framestruct.is_log;;
+end
+current_frame=framestruct.current_frame;
+
+
+% schmeisse die physikalisch nicht sinnvollen Bereiche raus!
+% current_frame=extractpitchregion(current_frame);
+
+pitch=calcresidualprobability(current_frame,0);
+
+% max_pitch_strength=pitch(1).pitchstrength;
+% max_pitch_fre=pitch(1).fre;
+
+scale_summe=getsumscale(current_frame);
+
+% start plotting:
+clf;
+rect=[-0.04 0.15 0.9 0.85];
+hint=1; % this indicate that we dont want a title
+mysubplot(1,1,1,rect, hint);
+plot_struct.t_min=minimum_time_interval/1000;
+plot_struct.t_max=maximum_time_interval/1000;
+plot_struct.has_axis=0;
+plot_struct.is_log=is_log;
+plot_struct.has_y_axis=0;
+
+plot(current_frame,plot_struct);
+set(gca,'zlim',[0 1/plot_scale]);
+
+if show_time
+ srate=getsr(current_frame);
+ text_x=0.9*maximum_time_interval*srate/1000;
+ text_y=getnrchannels(current_frame)+5;
+ str=getstructure(current_frame);
+ if ~isfield(str,'current_frame_start_time')
+ str.current_frame_start_time=0.0;
+ end
+ frame_number=str.current_frame_number;
+ frame_time=str.current_frame_start_time*1000;
+ text(text_x,text_y,sprintf('%d : %4.0fms',frame_number,frame_time),'FontSize',8);
+ % text(text_x,text_y,sprintf('%d',frame_number),'FontSize',8);
+end
+
+% and the sum
+rect=[-0.04 0 0.9 0.2];
+mysubplot(1,1,1,rect, hint);
+summe=getsum(current_frame); % here it is calculated
+
+srate=getsr(current_frame);
+if is_log
+
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)/1000*srate; % there shell be the tix
+
+ ti=(ti);
+ ti=round(ti*100)/100;
+
+ psumme=getpart(summe,getminimumtime(summe),0);
+ rsumme=reverse(psumme);
+ sumvalues=getvalues(rsumme);
+
+ min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
+ max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
+
+else % its not logarithmic!
+ summe=getpart(summe,-maximum_time_interval/1000,-minimum_time_interval/1000);
+
+ nr_labels=8;
+ xbis=getnrpoints(summe);
+ tix=0:xbis/nr_labels:xbis;
+ xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
+ xstep=round(xstep);
+ ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000])/1000;
+ ti=round(ti*10)/10;
+ sumvalues=getvalues(reverse(summe));
+
+ min_x_screen=0;
+ max_x_screen=(maximum_time_interval-minimum_time_interval)/1000*srate; % thats the first point we want to see on the screen
+
+end
+
+h=plot(sumvalues); hold on
+axis([min_x_screen max_x_screen 0 scale_summe]);
+
+% Ein roter Punkt dort, wo der pitch vermutet wird
+% maximal n verschiedene Punkte
+n=length(pitch.fre);
+% pfre(1)=pitch.fre(1); % das ist die höchtste
+%
+% nr_res2=length(res);
+% for i=1:nr_res2
+% if pitch(fre(i
+% end
+
+for i=n:-1:1
+ timex=-1/pitch.fre(i);
+ hei=gettimevalue(summe,timex);
+ bin=time2bin(summe,timex);
+ if i==1
+ radius=max(1,20*pitch.pitchstrength(i));
+ if pitch.pitchstrength(i) > pitch.domfre(i)
+ plot(max_x_screen-bin+2,hei,'r.','MarkerSize',radius);
+ else
+ plot(max_x_screen-bin+2,hei,'b.','MarkerSize',radius);
+ end
+ texthei=hei*1.2;
+ if texthei>max(summe)/1.4
+ texthei=max(summe)/1.4;
+ end
+ text((max_x_screen-bin)/1.06,texthei*1.2,sprintf('%3.0f Hz %5.3f',pitch.fre(1),pitch.pitchstrength(i))); % this is at a nice position
+ else
+ radius=max(2,10*pitch.pitchstrength(i));
+ plot(max_x_screen-bin+2,hei,'b.','MarkerSize',radius);
+ end
+end
+
+set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+if is_log
+ set(gca,'XScale','log')
+end
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+
+if is_log
+ text(min_x_screen*1.9,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+else
+ text(120,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+end
+
+
+
+% and the other sum on the y-axis
+rect=[0.856 0.19 0.1 0.81];
+mysubplot(1,1,1,rect, hint);
+fresumme=sumfresig(current_frame); % here it is calculated
+fresumme=smooth(fresumme,1);% glätte die Summe
+
+fresumme=setname(fresumme,'');
+fresumme=setunit_x(fresumme,'');
+fresumme=setunit_y(fresumme,'');
+
+plot(fresumme); hold on
+v=getvalues(fresumme);
+x1=0;
+x2=size(v,1)*47/42;
+y1=0;
+y2=100000;
+axis([x1 x2 y1 y2]);
+view(-90,90);
+% make y-Ticks
+nr_labels=8;
+nr_channels=getnrpoints(fresumme);
+xstep=(nr_channels-1)/(nr_labels-1);
+tix=1:xstep:nr_channels;
+cfs=getcf(current_frame);
+ti=cfs(floor(tix))/1000;
+ti=round(ti*10)/10;
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+set(gca,'XAxisLocation','top');
+
+% [fremins,fremaxs,frewomin,frewomax]=getminmax(fresumme,0.0);
+fremins=pitch.fresum.fremins;
+fremaxs=pitch.fresum.fremaxs;
+frewomin=pitch.fresum.frewomins;
+frewomax=pitch.fresum.frewomaxs;
+contrasts=pitch.fresum.contrasts;
+
+nr=size(fremaxs,2);
+for i=1:nr
+ x1=time2bin(fresumme,frewomax(i));
+ y1=fremaxs(i);
+ % plot(x1,y1,'r.','MarkerSize',contr);
+
+ radius=max(1,10*pitch.fresum.spektralpitch(i));
+% if pitch.pitchstrength(1) < pitch.fresum.spektralpitch(i)
+ plot(x1,y1,'r.','MarkerSize',radius);
+ text(x1-2,y1,sprintf('%5.3f',pitch.fresum.spektralpitch(i))); % this is at a nice position
+
+% else
+% plot(x1,y1,'b.','MarkerSize',radius);
+% end
+
+end
+nr=size(fremins,2);
+for i=1:nr
+ x2=time2bin(fresumme,frewomin(i));
+ y2=fremins(i);
+ plot(x2,y2,'g.','MarkerSize',5);
+end
+hold off
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/AIsum.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/AIsum.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,170 @@
+% tool
+%
+% 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 AIsum(framestruct_a);
+% plots the current frame (cframe) together with its sum
+% all relevant data must be in the frame-object
+
+% framestruct.current_frame = current_frame;
+% framestruct.maximum_time_interval = maximum_time_interval; in ms!!!!
+% framestruct.minimum_time_interval= minimum_time_interval;in ms!!!!
+% framestruct.is_log='log' or 'linear';
+
+if ~isstruct(framestruct_a)
+ % error('AIsum must be called with a structure');
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+
+if ~isfield(framestruct,'show_time');
+ show_time=0;
+else
+ show_time=framestruct.show_time;
+end
+
+if ~isfield(framestruct,'plot_scale');
+ plot_scale=1;
+else
+ plot_scale=framestruct.plot_scale;
+end
+
+if ~isfield(framestruct,'minimum_time_interval');
+ minimum_time_interval=1;
+else
+ minimum_time_interval=framestruct.minimum_time_interval;
+end
+
+if ~isfield(framestruct,'maximum_time_interval');
+ maximum_time_interval=35;
+else
+ maximum_time_interval=framestruct.maximum_time_interval;
+end
+
+if ~isfield(framestruct,'is_log');
+ is_log=1;
+else
+ is_log=framestruct.is_log;;
+end
+current_frame=framestruct.current_frame;
+
+scale_summe=getsumscale(current_frame);
+
+% start plotting:
+clf;
+rect=[-0.04 0.15 0.97 0.85];
+hint=1; % this indicate that we dont want a title
+mysubplot(1,1,1,rect, hint);
+plot_struct.t_min=minimum_time_interval/1000;
+plot_struct.t_max=maximum_time_interval/1000;
+plot_struct.has_axis=0;
+plot_struct.is_log=is_log;
+
+cax=plot(current_frame,plot_struct);
+set(gca,'zlim',[0 1/plot_scale]);
+
+% xaxisxticklabel=get(gca,'XTickLabel');
+% xaxisxtick=get(gca,'XTick');
+
+set(gca,'XTickLabel',[]);
+
+if show_time
+ srate=getsr(current_frame);
+ text_x=0.9*maximum_time_interval*srate/1000;
+ text_y=getnrchannels(current_frame)+5;
+ str=getstructure(current_frame);
+ if ~isfield(str,'current_frame_start_time')
+ str.current_frame_start_time=0.0;
+ end
+ frame_number=str.current_frame_number;
+ frame_time=str.current_frame_start_time*1000;
+ text(text_x,text_y,sprintf('%d : %4.0fms',frame_number,frame_time),'FontSize',8);
+ % text(text_x,text_y,sprintf('%d',frame_number),'FontSize',8);
+end
+
+% and the sum
+rect=[-0.04 0 0.97 0.2];
+mysubplot(1,1,1,rect, hint);
+summe=getsum(current_frame); % here it is calculated
+
+srate=getsr(current_frame);
+if is_log
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)/1000*srate; % there shell be the tix
+ ti=(ti);
+ ti=round(ti*100)/100;
+ psumme=getpart(summe,getminimumtime(summe),0);
+ rsumme=reverse(psumme);
+ sumvalues=getvalues(rsumme);
+ min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
+ max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
+else % its not logarithmic!
+ logstruc=getstructure(current_frame);
+ if isfield(logstruc,'samplerate')
+ if logstruc.samplerate==-1 % special case for logarithmic frames
+ scale_summe=max(summe);
+ else
+ summe=getpart(summe,-maximum_time_interval/1000,-minimum_time_interval/1000);
+ end
+ else
+% summe=getpart(summe,-maximum_time_interval/1000,-minimum_time_interval/1000);
+ end
+ nr_labels=7;
+ xbis=getnrpoints(summe);
+ tix=0:xbis/nr_labels:xbis;
+ xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
+ xstep=round(xstep);
+ ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000])/1000;
+ ti=round(ti*10)/10;
+ sumvalues=getvalues(reverse(summe));
+
+ min_x_screen=0;
+ max_x_screen=(maximum_time_interval-minimum_time_interval)/1000*srate; % thats the first point we want to see on the screen
+
+end
+
+
+h=plot(sumvalues);
+% set(h,'LineWidth',1);
+
+axis([min_x_screen max_x_screen 0 scale_summe]);
+
+set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+if is_log
+ set(gca,'XScale','log')
+end
+
+if isstruct('logstruct')
+ if logstruct.samplerate==-1 % special case for logarithmic frames
+ nr_labels=6;
+ tix=0:max_x_screen/(nr_labels-1):max_x_screen;
+ tix(1)=1;
+ min_time=(logstruct.min_time*1000);
+ max_time=abs(logstruct.max_time*1000);
+ ti=distributelogarithmic(min_time,max_time,nr_labels);
+ text(30,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+ end
+else
+ if is_log
+ text(min_x_screen*1.9,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+ else
+ text(120,-scale_summe/5,'time interval (ms)'); % this is at a nice position
+ end
+end
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+
+% set(gca,'XTick',xaxisxtick);
+% set(gca,'XTickLabel',xaxisxticklabel);
+set(gca,'YTickLabel',[]);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/AIsurface.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/AIsurface.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,123 @@
+% tool
+%
+% 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 AIsurface(framestruct_a);
+% plots the current frame (cframe)
+% all relevant data must be in the frame-object
+
+% framestruct.current_frame = current_frame;
+% framestruct.scale_summe = scale_summe;
+% framestruct.maximum_time_interval = maximum_time_interval; in ms!!!!
+% framestruct.minimum_time_interval= minimum_time_interval;in ms!!!!
+% framestruct.is_log='log' or 'linear';
+
+if ~isstruct(framestruct_a)
+% error('AIsum must be called with a structure');
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+
+if ~isfield(framestruct,'show_time');
+ show_time=1;
+else
+ show_time=framestruct.show_time;
+end
+
+if ~isfield(framestruct,'minimum_time_interval');
+ minimum_time_interval=1;
+else
+ minimum_time_interval=framestruct.minimum_time_interval;
+end
+
+if ~isfield(framestruct,'maximum_time_interval');
+ maximum_time_interval=35;
+else
+ maximum_time_interval=framestruct.maximum_time_interval;
+end
+
+if ~isfield(framestruct,'is_log');
+ is_log=1;
+else
+ is_log=framestruct.is_log;;
+end
+current_frame=framestruct.current_frame;
+
+srate=getsr(current_frame);
+if is_log
+
+ t=minimum_time_interval;
+ ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
+ tix=(ti)/1000*srate; % there shell be the tix
+
+ ti=(ti);
+ ti=round(ti*100)/100;
+
+
+ min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
+ max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
+
+else % its not logarithmic!
+ nr_labels=8;
+ xbis=getnrpoints(summe);
+ tix=0:xbis/nr_labels:xbis;
+ xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
+ xstep=round(xstep);
+ ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000]);
+ ti=round(ti*10)/10;
+
+ min_x_screen=0;
+ max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
+
+end
+% start plotting:
+clf;
+vals=getvalues(current_frame);
+rvals=vals(:,end:-1:1);
+
+h=surf(rvals,'LineStyle','none');
+view([0 90]);
+shading interp
+% set the position of the axis so that it looks nice
+set(gca,'Position',[0 0.06 0.92 0.96]);
+set(gca,'YAxisLocation','right');
+
+nr_channels=getnrchannels(current_frame);
+axis([ min_x_screen max_x_screen 1 nr_channels ]);
+
+% axis([min_x_screen max_x_screen 0 scale_summe]);
+
+set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
+if is_log
+ set(gca,'XScale','log')
+end
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+set(gca,'YTickLabel',[]);
+if is_log
+ text(min_x_screen*1.9,-200/5,'time interval (ms)'); % this is at a nice position
+else
+ text(120,-200/5,'time interval (ms)'); % this is at a nice position
+end
+
+% make y-Ticks
+nr_labels=8;
+ystep=(nr_channels-1)/(nr_labels-1);
+tiy=1:ystep:nr_channels;
+cfs=getcf(current_frame);
+ti=cfs(floor(tiy))/1000;
+ti=round(ti*10)/10;
+set(gca,'YTick',tiy);
+set(gca,'YTickLabel',ti);
+
+text(30,-2,'time interval (ms)'); % this is at a nice position
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/GenerateSpiralFrom.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/GenerateSpiralFrom.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,198 @@
+% tool
+%
+% 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 sp=GenerateSpiralFrom(input,spiral_struct)
+
+global threshold;
+
+if ~isfield(spiral_struct,'threshold');
+ threshold=20; % all pitches below this value are cut off
+else
+ threshold=spiral_struct.threshold;
+end
+
+if ~isfield(spiral_struct,'tilt_amount');
+ tilt_amount=0; % bedeutet fall of 2500% per second, eg 100% in 40 ms
+else
+ tilt_amount=spiral_struct.tilt_amount;
+end
+
+if ~isfield(spiral_struct,'max_frequency');
+ max_frequency=5000; % the outer end of the pitch spiral
+else
+ max_frequency=spiral_struct.max_frequency;
+ max_time=-1/max_frequency;
+end
+
+if ~isfield(spiral_struct,'overlap');
+ overlap=0; % the outer end of the pitch spiral
+else
+ overlap=spiral_struct.overlap;
+end
+
+if ~isfield(spiral_struct,'tilt');
+ tilt=0; % the outer end of the pitch spiral
+else
+ tilt=spiral_struct.tilt;
+end
+
+if ~isfield(spiral_struct,'start_radius');
+ start_radius=3; % the outer end of the pitch spiral
+else
+ start_radius=spiral_struct.start_radius;
+end
+
+if ~isfield(spiral_struct,'biggest_dot');
+ biggest_dot=10; % points
+else
+ biggest_dot=spiral_struct.biggest_dot;
+end
+
+
+if ~isfield(spiral_struct,'min_frequency');
+ fr=input;
+ max_time=getmaximumtime(fr);
+ min_time=getminimumtime(fr);
+
+ absmax_time=getmaximumtime(fr);
+ absmin_time=getminimumtime(fr);
+
+ if min_time < 0 & max_time > 0 % normalfall: -35 bis 5
+ absmin_time=abs(min_time); % die ist normalerweise -35 ms
+ absmax_time=1/max_frequency; % Standartwert, entspricht 5 kHz
+ max_time=-absmax_time;
+ end
+
+ if absmin_time<0
+ error('generatefrom(frame): minimum time must be greater 0!');
+ end
+ if absmax_time<0
+ error('generatefrom(frame): maximum time must be greater 0!');
+ end
+
+ min_frequency=1/absmin_time;
+ max_frequency=1/absmax_time;
+else
+ min_frequency=spiral_struct.min_frequency;
+ min_time=-1/min_frequency;
+end
+
+if min_frequency>max_frequency
+ error('generateSpiralFrom: minfre > maxfre!')
+end
+
+sp=spiral(min_frequency,max_frequency);
+sp=setoverlap(sp,overlap);
+sp=settilt(sp,tilt);
+sp=setstartradius(sp,start_radius);
+heightscaler=getnroctaves(sp);
+sp=setscaleheight(sp,heightscaler);
+sp=setorginalvalues(sp,input);
+
+if ~isfield(spiral_struct,'plotwithdots');
+ sp=setplotwithdots(sp,'y'); % all pitches below this value are cut off
+else
+ sp=setplotwithdots(sp,spiral_struct.plotwithdots); % all pitches below this value are cut off
+end
+
+
+if isoftype(input,'frame')
+ nr_chan=getnrchannels(input);
+ for i=1:nr_chan
+ sig=getsinglechannel(input,i);
+ if tilt_amount>0
+ sig=tilt(sig,tilt_amount);
+ end
+ [heights,maxima]=getlocalmaxima(sig);
+
+ nr=length(heights);
+ for j=1:nr
+ if maxima(j) > min_time & maxima(j) < max_time
+ shift=1-(i-1)/(nr_chan+1);
+ sp=addmax(sp,shift,heights(j),maxima(j));
+ end
+ end
+ end
+end
+
+if isoftype(input,'signal')
+ if tilt_amount>0
+ sig=tilt(input,tilt_amount);
+ else
+ sig=input;
+ end
+ [heights,maxima]=getlocalmaxima(sig,min_time,max_time);
+ sp=addmax(sp,0,heights,maxima);
+end
+
+
+% now all points are there, but we have to find out about the real size
+lmin=log(getminimumfrequency(sp));
+lmax=log(getmaximumfrequency(sp));
+step=(lmax-lmin)/200;
+ran=lmin:step:lmax;
+range=exp(ran);
+
+[x,y,z]=getcoordinates(sp,getmaximumfrequency(sp));
+if abs(y) > abs(x)
+ maxscale=abs(y);
+else
+ maxscale=abs(x);
+end
+
+% first find the size of the unscaled version
+scale_x=0.15*(getscreensize(sp)-2*getedgemargin(sp))/maxscale;
+scale_y=0.15*(getscreensize(sp)-2*getedgemargin(sp))/maxscale;
+% and set this as the scale
+sp=setscalex(sp,scale_x);
+sp=setscaley(sp,scale_y);
+
+
+% add the spiral itself
+
+[x1,y1,z1]=getcoordinates(sp,range); % inner circel
+[x2,y2,z2]=getcoordinates(sp,range,1); % outer circel
+
+cords.x=[];cords.y=[];cords.z=[];
+nr=max(size(y1));
+
+for i=1:nr
+ cords.x=[cords.x; x1(i) x2(i)];
+ cords.y=[cords.y; y1(i) y2(i)];
+ cords.z=[cords.z; z1(i) z2(i)];
+end
+
+obj.coordinates=cords;
+obj.type='spiral';
+
+sp=addsurfobject(sp,obj);
+
+return
+
+
+function sp=addmax(sp,shift,heights,maxima)
+global threshold;
+nr=size(heights,2);
+for i=1:nr
+ if heights(i) > threshold
+ mafre=maxima(i);
+ if mafre > 0
+ error('GenerateSpiralFrom: addmax: error: frequency negativ');
+ end
+ newdot.frequency=1/-mafre;
+ newdot.pitchstrength=heights(i);
+ newdot.octave_shift=shift;
+ newdot.color='r';
+ sp=adddots(sp,newdot);
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/MakeQTMovie.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/MakeQTMovie.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,933 @@
+% 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: 2009-11-10 10:53:59 +0000 (Tue, 10 Nov 2009) $
+% $Revision: 706 $
+
+function MakeQTMovie(cmd,arg, arg2)
+% function MakeQTMovie(cmd, arg, arg2)
+% Create a QuickTime movie from a bunch of figures (and an optional sound).
+%
+% Syntax: MakeQTMovie cmd [arg]
+% The following commands are supported:
+% addfigure - Add snapshot of current figure to movie
+% addaxes - Add snapshot of current axes to movie
+% addmatrix data - Add a matrix to movie (convert to jpeg with imwrite)
+% addmatrixsc data - Add a matrix to movie (convert to jpeg with imwrite)
+% (automatically scales image data)
+% addsound data [sr] - Add sound to movie (only monaural for now)
+% (third argument is the sound's sample rate.)
+% cleanup - Remove the temporary files
+% demo - Create a demonstration movie
+% finish - Finish movie, write out QT file
+% framerate fps - Set movies frame rate [Default is 10 fps]
+% quality # - Set JPEG quality (between 0 and 1)
+% size [# #] - Set plot size to [width height]
+% start filename - Start creating a movie with this name
+% The start command must be called first to provide a movie name.
+% The finish command must be called last to write out the movie
+% data. All other commands can be called in any order. Only one
+% movie can be created at a time.
+%
+% This code is published as Interval Technical Report #1999-066
+% The latest copy can be found at
+% http://web.interval.com/papers/1999-066/
+% SB: no, unfortunatly not...
+% (c) Copyright Malcolm Slaney, Interval Research, March 1999.
+
+% This is experimental software and is being provided to Licensee
+% 'AS IS.' Although the software has been tested on Macintosh, SGI,
+% Linux, and Windows machines, Interval makes no warranties relating
+% to the software's performance on these or any other platforms.
+%
+% Disclaimer
+% THIS SOFTWARE IS BEING PROVIDED TO YOU 'AS IS.' INTERVAL MAKES
+% NO EXPRESS, IMPLIED OR STATUTORY WARRANTY OF ANY KIND FOR THE
+% SOFTWARE INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
+% PERFORMANCE, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+% IN NO EVENT WILL INTERVAL BE LIABLE TO LICENSEE OR ANY THIRD
+% PARTY FOR ANY DAMAGES, INCLUDING LOST PROFITS OR OTHER INCIDENTAL
+% OR CONSEQUENTIAL DAMAGES, EVEN IF INTERVAL HAS BEEN ADVISED OF
+% THE POSSIBLITY THEREOF.
+%
+% This software program is owned by Interval Research
+% Corporation, but may be used, reproduced, modified and
+% distributed by Licensee. Licensee agrees that any copies of the
+% software program will contain the same proprietary notices and
+% warranty disclaimers which appear in this software program.
+
+% This program uses the Matlab imwrite routine to convert each image
+% frame into JPEG. After first reserving 8 bytes for a header that points
+% to the movie description, all the compressed images and the sound are
+% added to the movie file. When the 'finish' method is called then the
+% first 8 bytes of the header are rewritten to indicate the size of the
+% movie data, and then the movie header ('moov structure') is written
+% to the output file.
+%
+% This routine creates files according to the QuickTime file format as
+% described in the appendix of
+% "Quicktime (Inside MacIntosh)," Apple Computer Incorporated,
+% Addison-Wesley Pub Co; ISBN: 0201622017, April 1993.
+% I appreciate help that I received from Lee Fyock (MathWorks) and Aaron
+% Hertzmann (Interval) in debugging and testing this work.
+
+% Changes:
+% July 5, 1999 - Removed stss atom since it upset PC version of QuickTime
+% November 11, 1999 - Fixed quality bug in addmatrix. Added addmatrixsc.
+% March 7, 2000 - by Jordan Rosenthal (jr@ece.gatech.edu), Added truecolor
+% capability when running in Matlab 5.3 changed some help comments, fixed
+% some bugs, vectorized some code.
+% April 7, 2000 - by Malcolm. Cleaned up axis/figure code and fixed(?) SGI
+% playback problems. Added user data atom to give version information.
+% Fixed sound format problems.
+% April 10, 2000 - by Malcolm. Fixed problem with SGI (at least) and B&W
+% addmatrix.
+% July 2004 - By Stefan Bleeck. Added some lines for MATLAB 7 support
+
+if nargin < 1
+ fprintf('Syntax: MakeQTMovie cmd [arg]\n')
+ fprintf('The following commands are supported:\n');
+ fprintf('addfigure - Add snapshot of current figure to movie\n')
+ fprintf('addaxes - Add snapshot of current axes to movie\n')
+ fprintf('addmatrix data - Add a matrix to movie ');
+ fprintf('(convert to jpeg)\n')
+ fprintf('addmatrixsc data - Add a matrix to movie ');
+ fprintf('(scale and convert to jpeg)\n')
+ fprintf('addsound data - Add sound samples ');
+ fprintf('(with optional rate)\n')
+ fprintf('demo - Show this program in action\n');
+ fprintf('finish - Finish movie, write out QT file\n');
+ fprintf('framerate # - Set movie frame rate ');
+ fprintf('(default is 10fps)\n');
+ fprintf('quality # - Set JPEG quality (between 0 and 1)\n');
+ fprintf('size [# #] - Set plot size to [width height]\n');
+ fprintf('start filename - Start making a movie with ');
+ fprintf('this name\n');
+ return;
+end
+
+global MakeQTMovieStatus
+
+global count
+% if isempty(count)
+% count=1
+% else
+% count=count+1
+% end
+% disp(cmd)
+% MakeQTMovieStatus
+
+
+MakeDefaultQTMovieStatus; % Needed first time, ignored otherwise
+
+switch lower(cmd)
+ case 'clear'
+ MakeQTMovieStatus=[]; % sb:change to force new values
+ count=1;
+ case {'addframe','addplot','addfigure','addaxes'}
+ switch lower(cmd)
+ case {'addframe','addfigure'}
+ hObj = gcf; % Add the entire figure (with all axes)
+ otherwise
+ hObj = gca; % Add what's inside the current axis
+ end
+ frame = getframe(hObj);
+ [I,map] = frame2im(frame);
+ if ImageSizeChanged(size(I)) > 0
+ return;
+ end
+ if isempty(map)
+ % RGB image
+ imwrite(I,MakeQTMovieStatus.imageTmp, 'jpg', 'Quality', ...
+ MakeQTMovieStatus.spatialQual*100);
+ else
+ % Indexed image
+ writejpg_map(MakeQTMovieStatus.imageTmp, I, map);
+ end
+ [pos, len] = AddFileToMovie;
+ n = MakeQTMovieStatus.frameNumber + 1;
+ MakeQTMovieStatus.frameNumber = n;
+ MakeQTMovieStatus.frameStarts(n) = pos;
+ MakeQTMovieStatus.frameLengths(n) = len;
+
+
+
+ %% Allow images to be added by doing:
+ %% MakeQTMovie('addimage', '/path/to/file.jpg');
+ %% This case adapted from addmatrix. Thanks to
+ %% Stephen Eglen for this idea.
+ case 'addimage'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a filename with ');
+ fprintf('the image command.\n');
+ return;
+ end
+
+ %% Check to see that the image is the correct size. Do
+ %% this by reading in the image and then checking its size.
+ %% tim - temporary image.
+ tim = imread(arg); tim_size = size(tim);
+
+ fprintf('Image %s size %d %d\n', arg, tim_size(1), tim_size(2));
+ if ImageSizeChanged(tim_size) > 0
+ return;
+ end
+ [pos, len] = AddFileToMovie(arg);
+ n = MakeQTMovieStatus.frameNumber + 1;
+ MakeQTMovieStatus.frameNumber = n;
+ MakeQTMovieStatus.frameStarts(n) = pos;
+ MakeQTMovieStatus.frameLengths(n) = len;
+
+ case 'addmatrix'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a matrix with ');
+ fprintf('the addmatrix command.\n');
+ return;
+ end
+ if ImageSizeChanged(size(arg)) > 0
+ return;
+ end
+ % Work around a bug, at least on the
+ % SGIs, which causes JPEGs to be
+ % written which can't be read with the
+ % SGI QT. Turn the B&W image into a
+ % color matrix.
+ if ndims(arg) < 3
+ arg(:,:,2) = arg;
+ arg(:,:,3) = arg(:,:,1);
+ end
+ imwrite(arg, MakeQTMovieStatus.imageTmp, 'jpg', 'Quality', ...
+ MakeQTMovieStatus.spatialQual*100);
+ [pos, len] = AddFileToMovie;
+ n = MakeQTMovieStatus.frameNumber + 1;
+ MakeQTMovieStatus.frameNumber = n;
+ MakeQTMovieStatus.frameStarts(n) = pos;
+ MakeQTMovieStatus.frameLengths(n) = len;
+
+ case 'addmatrixsc'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a matrix with ');
+ fprintf('the addmatrix command.\n');
+ return;
+ end
+ if ImageSizeChanged(size(arg)) > 0
+ return;
+ end
+ arg = arg - min(min(arg));
+ arg = arg / max(max(arg));
+ % Work around a bug, at least on the
+ % SGIs, which causes JPEGs to be
+ % written which can't be read with the
+ % SGI QT. Turn the B&W image into a
+ % color matrix.
+ if ndims(arg) < 3
+ arg(:,:,2) = arg;
+ arg(:,:,3) = arg(:,:,1);
+ end
+ imwrite(arg, MakeQTMovieStatus.imageTmp, 'jpg', 'Quality', ...
+ MakeQTMovieStatus.spatialQual*100);
+ [pos, len] = AddFileToMovie;
+ n = MakeQTMovieStatus.frameNumber + 1;
+ MakeQTMovieStatus.frameNumber = n;
+ MakeQTMovieStatus.frameStarts(n) = pos;
+ MakeQTMovieStatus.frameLengths(n) = len;
+
+ case 'addsound'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a sound array ');
+ fprintf('with the addsound command.\n');
+ return;
+ end
+ % Do stereo someday???
+ OpenMovieFile
+ MakeQTMovieStatus.soundLength = length(arg);
+ arg = round(arg/max(max(abs(arg)))*32765);
+ negs = find(arg<0);
+ arg(negs) = arg(negs) + 65536;
+
+ sound = mb16(arg);
+ MakeQTMovieStatus.soundStart = ftell(MakeQTMovieStatus.movieFp);
+ MakeQTMovieStatus.soundLen = length(sound);
+ fwrite(MakeQTMovieStatus.movieFp, sound, 'uchar');
+ if nargin < 3
+ arg2 = 22050;
+ end
+ MakeQTMovieStatus.soundRate = arg2;
+
+ case 'cleanup'
+ if isstruct(MakeQTMovieStatus)
+ if isfield(MakeQTMovieStatus,'movieFp') && ~isempty(MakeQTMovieStatus.movieFp)
+ fclose(MakeQTMovieStatus.movieFp);
+ MakeQTMovieStatus.movieFp = [];
+ end
+ if isfield(MakeQTMovieStatus,'imageTmp') && ~isempty(MakeQTMovieStatus.imageTmp) && isfield(MakeQTMovieStatus.imageTmp,'file') && exist(MakeQTMovieStatus.imageTmp,'file') > 0
+ delete(MakeQTMovieStatus.imageTmp);
+ MakeQTMovieStatus.imageTmp = [];
+ end
+ end
+ MakeQTMovieStatus = [];
+
+ case 'debug'
+ fprintf('Current Movie Data:\n');
+ fprintf(' %d frames at %d fps\n', MakeQTMovieStatus.frameNumber, ...
+ MakeQTMovieStatus.frameRate);
+ starts = MakeQTMovieStatus.frameStarts;
+ if length(starts) > 10, starts = starts(1:10);, end;
+ lens = MakeQTMovieStatus.frameLengths;
+ if length(lens) > 10, lens = lens(1:10);, end;
+ fprintf(' Start: %6d Size: %6d\n', [starts; lens]);
+ fprintf(' Movie Image Size: %dx%d\n', ...
+ MakeQTMovieStatus.imageSize(2), ...);
+ MakeQTMovieStatus.imageSize(1));
+ if length(MakeQTMovieStatus.soundStart) > 0
+ fprintf(' Sound: %d samples at %d Hz sampling rate ', ...
+ MakeQTMovieStatus.soundLength, ...
+ MakeQTMovieStatus.soundRate);
+ fprintf('at %d.\n', MakeQTMovieStatus.soundStart);
+ else
+ fprintf(' Sound: No sound track\n');
+ end
+ fprintf(' Temporary files for images: %s\n', ...
+ MakeQTMovieStatus.imageTmp);
+ fprintf(' Final movie name: %s\n', MakeQTMovieStatus.movieName);
+ fprintf(' Compression Quality: %g\n', ...
+ MakeQTMovieStatus.spatialQual);
+
+
+ case 'demo'
+ clf
+ fps = 10;
+ movieLength = 10;
+ sr = 22050;
+ fn = 'test.mov';
+ fprintf('Creating the movie %s.\n', fn);
+ MakeQTMovie('start',fn);
+ MakeQTMovie('size', [160 120]);
+ MakeQTMovie('quality', 1.0);
+ theSound = [];
+ for i=1:movieLength
+ plot(sin((1:100)/4+i));
+ MakeQTMovie('addaxes');
+ theSound = [theSound sin(440/sr*2*pi*(2^(i/12))*(1:sr/fps))];
+ end
+ MakeQTMovie('framerate', fps);
+ MakeQTMovie('addsound', theSound, sr);
+ MakeQTMovie('finish');
+
+ case {'finish','close'}
+ AddQTHeader;
+ MakeQTMovie('cleanup') % Remove temporary files
+
+ case 'framerate'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify the ');
+ fprintf('frames/second with the framerate command.\n');
+ return;
+ end
+ MakeQTMovieStatus.frameRate = arg;
+
+ case 'help'
+ MakeQTMovie % To get help message.
+
+ case 'size'
+ % Size is off by one on the
+ % Mac.
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a vector with ');
+ fprintf('the size command.\n');
+ return;
+ end
+ if length(arg) ~= 2
+ error('MakeQTMovie: Error, must supply 2 element size.');
+ end
+ oldUnits = get(gcf,'units');
+ set(gcf,'units','pixels');
+ cursize = get(gcf, 'position');
+ cursize(3) = arg(1);
+ cursize(4) = arg(2);
+ set(gcf, 'position', cursize);
+ set(gcf,'units',oldUnits);
+
+ case 'start'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a file name ');
+ fprintf('with start command.\n');
+ return;
+ end
+ MakeQTMovie('cleanup');
+ MakeDefaultQTMovieStatus;
+
+ % SB: sorry, dont understadt that, but it works. try without...
+ pause(0.1);
+ MakeQTMovieStatus.movieName = arg;
+
+ case 'test'
+ clf
+ MakeQTMovieStatus = [];
+ MakeQTMovie('start','test.mov');
+ MakeQTMovie('size', [320 240]);
+ MakeQTMovie('quality', 1.0);
+ subplot(2,2,1);
+ for i=1:10
+ plot(sin((1:100)/4+i));
+ MakeQTMovie('addfigure');
+ end
+ MakeQTMovie('framerate', 10);
+ MakeQTMovie('addsound', sin(1:5000), 22050);
+ MakeQTMovie('debug');
+ MakeQTMovie('finish');
+
+ case 'quality'
+ if nargin < 2
+ fprintf('MakeQTMovie error: Need to specify a quality ');
+ fprintf('(between 0-1) with the quality command.\n');
+ return;
+ end
+ MakeQTMovieStatus.spatialQual = arg;
+
+ otherwise
+ fprintf('MakeQTMovie: Unknown method %s.\n', cmd);
+end
+
+%%%%%%%%%%%%%%% MakeDefaultQTMovieStatus %%%%%%%%%%%%%%%%%
+% Make the default movie status structure.
+function MakeDefaultQTMovieStatus
+global MakeQTMovieStatus
+if isempty(MakeQTMovieStatus)
+ MakeQTMovieStatus = struct(...
+ 'frameRate', 10, ... % frames per second
+ 'frameStarts', [], ... % Starting byte position
+ 'frameLengths', [], ...
+ 'timeScale', 10, ... % How much faster does time run?
+ 'soundRate', 22050, ... % Sound Sample Rate
+ 'soundStart', [], ... % Starting byte position
+ 'soundLength', 0, ...
+ 'soundChannels', 1, ... % Number of channels
+ 'frameNumber', 0, ...
+ 'movieFp', [], ... % File pointer
+ 'imageTmp', tempname, ...
+ 'movieName', 'output.mov', ...
+ 'imageSize', [0 0], ...
+ 'trackNumber', 0, ...
+ 'timeScaleExpansion', 100, ...
+ 'spatialQual', 1.0); % Between 0.0 and 1.0
+end
+
+
+%%%%%%%%%%%%%%% ImageSizeChanged %%%%%%%%%%%%%%%%%
+% Check to see if the image size has changed. This m-file can't
+% deal with that, so we'll return an error.
+function err = ImageSizeChanged(newsize)
+global MakeQTMovieStatus
+
+newsize = newsize(1:2); % Don't care about RGB info, if present
+oldsize = MakeQTMovieStatus.imageSize;
+err = 0;
+
+if sum(oldsize) == 0
+ MakeQTMovieStatus.imageSize = newsize;
+else
+ if sum(newsize ~= oldsize) > 0
+ fprintf('MakeQTMovie Error: New image size');
+ fprintf('(%dx%d) doesn''t match old size (%dx%d)\n', ...
+ newsize(1), newsize(2), oldsize(1), oldsize(2));
+ fprintf(' Can''t add this image to the movie.\n');
+ err = 1;
+ end
+end
+
+%%%%%%%%%%%%%%% AddFileToMovie %%%%%%%%%%%%%%%%%
+% OK, we've saved out an image file. Now add it to the end of the movie
+% file we are creating.
+% We'll copy the JPEG file in 16kbyte chunks to the end of the movie file.
+% Keep track of the start and end byte position in the file so we can put
+% the right information into the QT header.
+function [pos, len] = AddFileToMovie(imageTmp)
+global MakeQTMovieStatus
+OpenMovieFile
+if nargin < 1
+ imageTmp = MakeQTMovieStatus.imageTmp;
+end
+fp = fopen(imageTmp, 'rb');
+if fp < 0
+ error('Could not reopen QT image temporary file.');
+end
+
+len = 0;
+pos = ftell(MakeQTMovieStatus.movieFp);
+while 1
+ data = fread(fp, 1024*16, 'uchar');
+ if isempty(data)
+ break;
+ end
+ cnt = fwrite(MakeQTMovieStatus.movieFp, data, 'uchar');
+ len = len + cnt;
+end
+fclose(fp);
+
+%%%%%%%%%%%%%%% AddQTHeader %%%%%%%%%%%%%%%%%
+% Go back and write the atom information that allows
+% QuickTime to skip the image and sound data and find
+% its movie description information.
+function AddQTHeader()
+global MakeQTMovieStatus
+
+pos = ftell(MakeQTMovieStatus.movieFp);
+header = moov_atom;
+cnt = fwrite(MakeQTMovieStatus.movieFp, header, 'uchar');
+fseek(MakeQTMovieStatus.movieFp, 0, -1);
+cnt = fwrite(MakeQTMovieStatus.movieFp, mb32(pos), 'uchar');
+fclose(MakeQTMovieStatus.movieFp);
+MakeQTMovieStatus.movieFp = [];
+
+%%%%%%%%%%%%%%% OpenMovieFile %%%%%%%%%%%%%%%%%
+% Open a new movie file. Write out the initial QT header. We'll fill in
+% the correct length later.
+function OpenMovieFile
+global MakeQTMovieStatus
+if isempty(MakeQTMovieStatus.movieFp)
+ fp = fopen(MakeQTMovieStatus.movieName, 'wb');
+ if fp < 0
+ error('Could not open QT movie output file.');
+ end
+ MakeQTMovieStatus.movieFp = fp;
+ cnt = fwrite(fp, [mb32(0) mbstring('mdat')], 'uchar');
+end
+
+%%%%%%%%%%%%%%% writejpg_map %%%%%%%%%%%%%%%%%
+% Like the imwrite routine, but first pass the image data through the indicated
+% RGB map.
+function writejpg_map(name,I,map)
+global MakeQTMovieStatus
+
+[y,x] = size(I);
+
+% Force values to be valid indexes. This fixes a bug that occasionally
+% occurs in frame2im in Matlab 5.2 which incorrectly produces values of I
+% equal to zero.
+I = max(1,min(I,size(map,1)));
+
+rgb = zeros(y, x, 3);
+t = zeros(y,x);
+t(:) = map(I(:),1)*255; rgb(:,:,1) = t;
+t(:) = map(I(:),2)*255; rgb(:,:,2) = t;
+t(:) = map(I(:),3)*255; rgb(:,:,3) = t;
+
+imwrite(uint8(rgb),name,'jpeg','Quality',MakeQTMovieStatus.spatialQual*100);
+
+%%%%%%%%%%%%%%% SetAtomSize %%%%%%%%%%%%%%%%%
+% Fill in the size of the atom
+function y=SetAtomSize(x)
+y = x;
+y(1:4) = mb32(length(x));
+
+%%%%%%%%%%%%%%% mb32 %%%%%%%%%%%%%%%%%
+% Make a vector from a 32 bit integer
+function y = mb32(x)
+if size(x,1) > size(x,2)
+ x = x';
+end
+x=uint32(x);
+y = [bitand(bitshift(x,-24),255); ...
+ bitand(bitshift(x,-16),255); ...
+ bitand(bitshift(x, -8),255); ...
+ bitand(x, 255)];
+y = y(:)';
+
+%%%%%%%%%%%%%%% mb16 %%%%%%%%%%%%%%%%%
+% Make a vector from a 16 bit integer
+function y = mb16(x)
+if size(x,1) > size(x,2)
+ x = x';
+end
+
+y = [bitand(bitshift(x, -8),255); ...
+ bitand(x, 255)];
+y = y(:)';
+
+%%%%%%%%%%%%%%% mb8 %%%%%%%%%%%%%%%%%
+% Make a vector from a 8 bit integer
+function y = mb8(x)
+if size(x,1) > size(x,2)
+ x = x';
+end
+
+y = [bitand(x, 255)];
+y = y(:)';
+
+%
+% The following routines all create atoms necessary
+% to describe a QuickTime Movie. The basic idea is to
+% fill in the necessary data, all converted to 8 bit
+% characters, then fix it up later with SetAtomSize so
+% that it has the correct header. (This is easier than
+% counting by hand.)
+
+%%%%%%%%%%%%%%% mbstring %%%%%%%%%%%%%%%%%
+% Make a vector from a character string
+function y = mbstring(s)
+y = double(s);
+
+
+%%%%%%%%%%%%%%% dinf_atom %%%%%%%%%%%%%%%%%
+function y = dinf_atom()
+y = SetAtomSize([mb32(0) mbstring('dinf') dref_atom]);
+
+%%%%%%%%%%%%%%% dref_atom %%%%%%%%%%%%%%%%%
+function y = dref_atom()
+y = SetAtomSize([mb32(0) mbstring('dref') mb32(0) mb32(1) ...
+ mb32(12) mbstring('alis') mb32(1)]);
+
+%%%%%%%%%%%%%%% edts_atom %%%%%%%%%%%%%%%%%
+function y = edts_atom(add_sound_p)
+global MakeQTMovieStatus
+fixed1 = bitshift(1,16); % Fixed point 1
+if add_sound_p > 0
+ duration = MakeQTMovieStatus.soundLength / ...
+ MakeQTMovieStatus.soundRate * ...
+ MakeQTMovieStatus.timeScale;
+else
+ duration = MakeQTMovieStatus.frameNumber / ...
+ MakeQTMovieStatus.frameRate * ...
+ MakeQTMovieStatus.timeScale;
+end
+duration = ceil(duration);
+
+y = [mb32(0) ... % Atom Size
+ mbstring('edts') ... % Atom Name
+ SetAtomSize([mb32(0) ... % Atom Size
+ mbstring('elst') ... % Atom Name
+ mb32(0) ... % Version/Flags
+ mb32(1) ... % Number of entries
+ mb32(duration) ... % Length of this track
+ mb32(0) ... % Time
+ mb32(fixed1)])]; % Rate
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% hdlr_atom %%%%%%%%%%%%%%%%%
+function y = hdlr_atom(component_type, sub_type)
+if strcmp(sub_type, 'vide')
+ type_string = 'Apple Video Media Handler';
+elseif strcmp(sub_type, 'alis')
+ type_string = 'Apple Alias Data Handler';
+elseif strcmp(sub_type, 'soun')
+ type_string = 'Apple Sound Media Handler';
+end
+
+y = [mb32(0) ... % Atom Size
+ mbstring('hdlr') ... % Atom Name
+ mb32(0) ... % Version and Flags
+ mbstring(component_type) ... % Component Name
+ mbstring(sub_type) ... % Sub Type Name
+ mbstring('appl') ... % Component manufacturer
+ mb32(0) ... % Component flags
+ mb32(0) ... % Component flag mask
+ mb8(length(type_string)) ... % Type Name byte count
+ mbstring(type_string)]; % Type Name
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% mdhd_atom %%%%%%%%%%%%%%%%%
+function y = mdhd_atom(add_sound_p)
+global MakeQTMovieStatus
+
+if add_sound_p
+ data = [mb32(MakeQTMovieStatus.soundRate) ...
+ mb32(MakeQTMovieStatus.soundLength)];
+else
+ data = [mb32(MakeQTMovieStatus.frameRate * ...
+ MakeQTMovieStatus.timeScaleExpansion) ...
+ mb32(MakeQTMovieStatus.frameNumber * ...
+ MakeQTMovieStatus.timeScaleExpansion)];
+end
+
+y = [mb32(0) mbstring('mdhd') ... % Atom Header
+ mb32(0) ...
+ mb32(round(now*3600*24)) ... % Creation time
+ mb32(round(now*3600*24)) ... % Modification time
+ data ...
+ mb16(0) mb16(0)];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% mdia_atom %%%%%%%%%%%%%%%%%
+function y = mdia_atom(add_sound_p)
+global MakeQTMovieStatus
+
+if add_sound_p
+ hdlr = hdlr_atom('mhlr', 'soun');
+else
+ hdlr = hdlr_atom('mhlr', 'vide');
+end
+
+y = [mb32(0) mbstring('mdia') ... % Atom Header
+ mdhd_atom(add_sound_p) ...
+ hdlr ... % Handler Atom
+ minf_atom(add_sound_p)];
+y = SetAtomSize(y);
+
+
+%%%%%%%%%%%%%%% minf_atom %%%%%%%%%%%%%%%%%
+function y = minf_atom(add_sound_p)
+global MakeQTMovieStatus
+
+if add_sound_p
+ data = smhd_atom;
+else
+ data = vmhd_atom;
+end
+
+y = [mb32(0) mbstring('minf') ... % Atom Header
+ data ...
+ hdlr_atom('dhlr','alis') ...
+ dinf_atom ...
+ stbl_atom(add_sound_p)];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% moov_atom %%%%%%%%%%%%%%%%%
+function y=moov_atom
+global MakeQTMovieStatus
+MakeQTMovieStatus.timeScale = MakeQTMovieStatus.frameRate * ...
+ MakeQTMovieStatus.timeScaleExpansion;
+
+if MakeQTMovieStatus.soundLength > 0
+ sound = trak_atom(1);
+else
+ sound = [];
+end
+
+y = [mb32(0) mbstring('moov') ...
+ mvhd_atom udat_atom sound trak_atom(0) ];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% mvhd_atom %%%%%%%%%%%%%%%%%
+function y=mvhd_atom
+global MakeQTMovieStatus
+
+fixed1 = bitshift(1,16); % Fixed point 1
+frac1 = bitshift(1,30); % Fractional 1
+if length(MakeQTMovieStatus.soundStart) > 0
+ NumberOfTracks = 2;
+else
+ NumberOfTracks = 1;
+end
+
+% Need to make sure its longer
+% of movie and sound lengths
+MovieDuration = max(MakeQTMovieStatus.frameNumber / ...
+ MakeQTMovieStatus.frameRate, ...
+ MakeQTMovieStatus.soundLength / ...
+ MakeQTMovieStatus.soundRate);
+MovieDuration = ceil(MovieDuration * MakeQTMovieStatus.timeScale);
+
+y = [mb32(uint8(0)) ... % Size
+ mbstring('mvhd') ... % Movie Data
+ mb32(uint8(0)) ... % Version and Flags
+ mb32(uint8(0)) ... % Creation Time (unknown)
+ mb32(uint8(0)) ... % Modification Time (unknown)
+ mb32(uint32(MakeQTMovieStatus.timeScale)) ... % Movie's Time Scale
+ mb32(MovieDuration) ... % Movie Duration
+ mb32(fixed1) ... % Preferred Rate
+ mb16(255) ... % Preferred Volume
+ mb16(uint8(0)) ... % Fill
+ mb32(uint8(0)) ... % Fill
+ mb32(uint8(0)) ... % Fill
+ mb32(fixed1) mb32(uint8(0)) mb32(uint8(0)) ... % Transformation matrix (identity)
+ mb32(uint8(0)) mb32(fixed1) mb32(uint8(0)) ...
+ mb32(uint8(0)) mb32(uint8(0)) mb32(frac1) ...
+ mb32(uint8(0)) ... % Preview Time
+ mb32(uint8(0)) ... % Preview Duration
+ mb32(uint8(0)) ... % Poster Time
+ mb32(uint8(0)) ... % Selection Time
+ mb32(uint8(0)) ... % Selection Duration
+ mb32(uint8(0)) ... % Current Time
+ mb32(NumberOfTracks)]; % Video and/or Sound?
+
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% raw_image_description %%%%%%%%%%%%%%%%%
+function y = raw_image_description()
+global MakeQTMovieStatus
+
+fixed1 = bitshift(1,16); % Fixed point 1
+codec = [12 'Photo - JPEG '];
+
+y = [mb32(0) mbstring('jpeg') ... % Atom Header
+ mb32(0) mb16(0) mb16(0) mb16(0) mb16(1) ...
+ mbstring('appl') ...
+ mb32(1023) ... % Temporal Quality (perfect)
+ mb32(floor(1023*MakeQTMovieStatus.spatialQual)) ...
+ mb16(MakeQTMovieStatus.imageSize(2)) ...
+ mb16(MakeQTMovieStatus.imageSize(1)) ...
+ mb32(fixed1 * 72) mb32(fixed1 * 72) ...
+ mb32(0) ...
+ mb16(0) ...
+ mbstring(codec) ...
+ mb16(24) mb16(65535)];
+y = SetAtomSize(y);
+
+
+%%%%%%%%%%%%%%% raw_sound_description %%%%%%%%%%%%%%%%%
+function y = raw_sound_description()
+global MakeQTMovieStatus
+y = [mb32(0) mbstring('twos') ... % Atom Header
+ mb32(0) mb16(0) mb16(0) mb16(0) mb16(0) ...
+ mb32(0) ...
+ mb16(MakeQTMovieStatus.soundChannels) ...
+ mb16(16) ... % 16 bits per sample
+ mb16(0) mb16(0) ...
+ mb32(round(MakeQTMovieStatus.soundRate*65536))];
+y = SetAtomSize(y);
+
+
+%%%%%%%%%%%%%%% smhd_atom %%%%%%%%%%%%%%%%%
+function y = smhd_atom()
+y = SetAtomSize([mb32(0) mbstring('smhd') mb32(0) mb16(0) mb16(0)]);
+
+%%%%%%%%%%%%%%% stbl_atom %%%%%%%%%%%%%%%%%
+% Removed the stss atom since it seems to upset the PC version of QT
+% and it is empty so it doesn't add anything.
+% Malcolm - July 5, 1999
+function y = stbl_atom(add_sound_p)
+y = [mb32(0) mbstring('stbl') ... % Atom Header
+ stsd_atom(add_sound_p) ...
+ stts_atom(add_sound_p) ...
+ stsc_atom(add_sound_p) ...
+ stsz_atom(add_sound_p) ...
+ stco_atom(add_sound_p)];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% stco_atom %%%%%%%%%%%%%%%%%
+function y = stco_atom(add_sound_p)
+global MakeQTMovieStatus
+if add_sound_p
+ y = [mb32(0) mbstring('stco') mb32(0) mb32(1) ...
+ mb32(MakeQTMovieStatus.soundStart)];
+else
+ y = [mb32(0) mbstring('stco') mb32(0) ...
+ mb32(MakeQTMovieStatus.frameNumber) ...
+ mb32(MakeQTMovieStatus.frameStarts)];
+end
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% stsc_atom %%%%%%%%%%%%%%%%%
+function y = stsc_atom(add_sound_p)
+global MakeQTMovieStatus
+if add_sound_p
+ samplesperchunk = MakeQTMovieStatus.soundLength;
+else
+ samplesperchunk = 1;
+end
+
+y = [mb32(0) mbstring('stsc') mb32(0) mb32(1) ...
+ mb32(1) mb32(samplesperchunk) mb32(1)];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% stsd_atom %%%%%%%%%%%%%%%%%
+function y = stsd_atom(add_sound_p)
+if add_sound_p
+ desc = raw_sound_description;
+else
+ desc = raw_image_description;
+end
+
+y = [mb32(0) mbstring('stsd') mb32(0) mb32(1) desc];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% stss_atom %%%%%%%%%%%%%%%%%
+function y = stss_atom()
+y = SetAtomSize([mb32(0) mbstring('stss') mb32(0) mb32(0)]);
+
+%%%%%%%%%%%%%%% stsz_atom %%%%%%%%%%%%%%%%%
+function y = stsz_atom(add_sound_p)
+global MakeQTMovieStatus
+if add_sound_p
+ y = [mb32(0) mbstring('stsz') mb32(0) mb32(2) ...
+ mb32(MakeQTMovieStatus.soundLength)];
+else
+ y = [mb32(0) mbstring('stsz') mb32(0) mb32(0) ...
+ mb32(MakeQTMovieStatus.frameNumber) ...
+ mb32(MakeQTMovieStatus.frameLengths)];
+end
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% stts_atom %%%%%%%%%%%%%%%%%
+function y = stts_atom(add_sound_p)
+global MakeQTMovieStatus
+if add_sound_p
+ count_duration = [mb32(MakeQTMovieStatus.soundLength) mb32(1)];
+else
+ count_duration = [mb32(MakeQTMovieStatus.frameNumber) ...
+ mb32(MakeQTMovieStatus.timeScaleExpansion)];
+end
+
+y = SetAtomSize([mb32(0) mbstring('stts') mb32(0) mb32(1) count_duration]);
+
+%%%%%%%%%%%%%%% trak_atom %%%%%%%%%%%%%%%%%
+function y = trak_atom(add_sound_p)
+global MakeQTMovieStatus
+
+y = [mb32(uint8(0)) mbstring('trak') ... % Atom Header
+ tkhd_atom(add_sound_p) ... % Track header
+ edts_atom(add_sound_p) ... % Edit List
+ mdia_atom(add_sound_p)];
+y = SetAtomSize(y);
+
+%%%%%%%%%%%%%%% tkhd_atom %%%%%%%%%%%%%%%%%
+function y = tkhd_atom(add_sound_p)
+global MakeQTMovieStatus
+
+fixed1 = bitshift(1,16); % Fixed point 1
+frac1 = bitshift(1,30); % Fractional 1 (CHECK THIS)
+
+if add_sound_p > 0
+ duration = MakeQTMovieStatus.soundLength / ...
+ MakeQTMovieStatus.soundRate * ...
+ MakeQTMovieStatus.timeScale;
+else
+ duration = MakeQTMovieStatus.frameNumber / ...
+ MakeQTMovieStatus.frameRate * ...
+ MakeQTMovieStatus.timeScale;
+end
+duration = ceil(duration);
+
+y = [mb32(0) mbstring('tkhd') ... % Atom Header
+ mb32(15) ... % Version and flags
+ mb32(round(now*3600*24)) ... % Creation time
+ mb32(round(now*3600*24)) ... % Modification time
+ mb32(MakeQTMovieStatus.trackNumber) ...
+ mb32(0) ...
+ mb32(duration) ... % Track duration
+ mb32(0) mb32(0) ... % Offset and priority
+ mb16(0) mb16(0) mb16(255) mb16(0) ... % Layer, Group, Volume, fill
+ mb32(fixed1) mb32(0) mb32(0) ... % Transformation matrix (identity)
+ mb32(0) mb32(fixed1) mb32(0) ...
+ mb32(0) mb32(0) mb32(frac1)];
+
+if add_sound_p
+ y = [y mb32(0) mb32(0)]; % Zeros for sound
+else
+ y = [y mb32(fliplr(MakeQTMovieStatus.imageSize)*fixed1)];
+end
+y= SetAtomSize(y);
+
+MakeQTMovieStatus.trackNumber = MakeQTMovieStatus.trackNumber + 1;
+
+%%%%%%%%%%%%%%% udat_atom %%%%%%%%%%%%%%%%%
+function y = udat_atom()
+atfmt = [64 double('fmt')];
+atday = [64 double('day')];
+
+VersionString = 'Matlab MakeQTMovie version April 7, 2000';
+
+y = [mb32(0) mbstring('udta') ...
+ SetAtomSize([mb32(0) atfmt mbstring(['Created ' VersionString])]) ...
+ SetAtomSize([mb32(0) atday ' ' date])];
+y = SetAtomSize(y);
+
+
+%%%%%%%%%%%%%%% vmhd_atom %%%%%%%%%%%%%%%%%
+function y = vmhd_atom()
+
+y = SetAtomSize([mb32(0) mbstring('vmhd') mb32(0) ...
+ mb16(64) ... % Graphics Mode
+ mb16(0) mb16(0) mb16(0)]); % Op Color
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/Read16Bits.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/Read16Bits.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: Read16Bits.m
+% Purpose: Read two 8 bit bytes and combine according to the machine's
+% endian architecture.
+% Comments:
+% Author: L. P. O'Mard
+% Revised by:
+% Created:
+% Updated:
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function data=Read16Bits(fid, littleEndian)
+
+first = fread(fid, 1, 'uint8');
+second = fread(fid, 1, 'uint8');
+if (littleEndian == 0)
+ data = bitshift(first, 8) + second;
+else
+ data = bitshift(second, 8) + first;
+end;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/Read32Bits.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/Read32Bits.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: Read32Bits.m
+% Purpose: Read four 8 bit bytes and combine according to the machine's
+% endian architecture.
+% Comments:
+% Author: L. P. O'Mard
+% Revised by:
+% Created:
+% Updated:
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function data=Read32Bits(fid, littleEndian)
+
+first = Read16Bits(fid, littleEndian);
+second = Read16Bits(fid, littleEndian);
+if (littleEndian == 0)
+ data = bitshift(first, 16) + second;
+else
+ data = bitshift(second, 16) + first;
+end;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ReadBytes.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ReadBytes.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: ReadBytes.m
+% Purpose: Reads a number of bytes from file.
+% Comments:
+% Author: L. P. O'Mard
+% Revised by:
+% Created:
+% Updated:
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function bytes = ReadBytes(fid, n, swapBytes)
+
+bytes=fread(fid, n, 'char');
+
+if (swapBytes ~= 0)
+ for i = 1:n/2
+ temp = bytes(i);
+ swapIndex = n - i + 1;
+ bytes(i) = bytes(swapIndex);
+ bytes(swapIndex) = temp;
+ end;
+end;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ReadIEEE2.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ReadIEEE2.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,41 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: ReadIEEE.m
+% Purpose: Reads an IEEE float from a file.
+% Comments: The calculation is for big-endian format, so little-endian must
+% be converted to big-endian format.
+% Author: L. P. O'Mard
+% Revised by:
+% Created:
+% Updated:
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function value = ReadIEEE(fid, littleEndian);
+
+if littleEndian == 0
+ swapBytes = 0;
+else
+ swapBytes = 1;
+end;
+bytes = ReadBytes(fid, 10, swapBytes);
+
+expon = bitand(bytes(1), 127) * 2^8 + bytes(2);
+hiMant = bytes(3) * 2^24 + bytes(4) * 2^16 + bytes(5) * 2^8 + bytes(6);
+loMant = bytes(7) * 2^24 + bytes(8) * 2^16 + bytes(9) * 2^8 + bytes(10);
+expon = expon - 16383;
+value = hiMant * 2^(expon - 31);
+expon = expon - 31;
+value = value + (loMant * 2^(expon - 32));
+
+if bitand(bytes(1), 128) ~= 0
+ value = -value;
+end;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ReadSNDChunk.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ReadSNDChunk.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: Read16Bits.m
+% Purpose: Read two 8 bit bytes and combine according to the machine's
+% endian architecture.
+% Comments:
+% Author: L. P. O'Mard
+% Revised by:
+% Created:
+% Updated:
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function data=Read16Bits(fid, littleEndian)
+
+first = fread(fid, 1, 'uint8');
+second = fread(fid, 1, 'uint8');
+if (littleEndian ~= 0)
+ data = bitshift(first, 8) + second;
+else
+ data = bitshift(second, 8) + first;
+end;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ReadWinFrame.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ReadWinFrame.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,50 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: ReadWinFrame.m
+% Purpose: Reads a window from from an AIFF file.
+% Comments:
+% Author: L. P. O'Mard
+% Revised by:
+% Created:
+% Updated:
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function frame=ReadWinFrame(fid, numChannels, frameLen, wordSize, littleEndian)
+
+switch wordSize
+ case 1
+ frame = fread(fid, [numChannels, frameLen], 'char');
+ case 2
+ for i = 1:frameLen
+ for j = 1:numChannels
+ data = Read16Bits(fid, littleEndian);
+ if (data >= 32768)
+ frame(j, i) = data - 65536;
+ else
+ frame(j, i) = data;
+ end
+ end;
+ end;
+ case 4
+ for i = 1:frameLen
+ for j = 1:numChannels
+ data = Read32Bits(fid, littleEndian);
+ if (data >= 2147483648)
+ frame(j, i) = data - 4294967296;
+ else
+ frame(j, i) = data;
+ end
+ end;
+ end;
+
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ReadWinFrame2.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ReadWinFrame2.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,82 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: ReadWinFrame2.m
+% Purpose: Reads a window from from an AIFF file.
+% Comments:
+% Author: L. P. O'Mard
+% Revised by: M.Tsuzaki (ATR SLT)
+% Created:
+% Updated: 31,Oct.,2001
+% Copyright: (c) 2000, University of Essex
+% changed by Stefan Bleeck to produce stars
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+% $Revision: 585 $
+function signal=ReadWinFrame2(fid, frameId, numWindowFrames, numChannels, frameLen, wordSize,echo)
+if nargin < 7
+ echo=1
+end
+p_bias = ftell(fid);
+if numWindowFrames == 1
+ top = frameId(1);
+ if length(frameId) > 1
+ bot = frameId(end);
+ else
+ bot = frameLen;
+ end
+else
+ frameId=frameId(find(frameId>=1 & frameId<=numWindowFrames));
+end
+if isempty(frameId)
+ warning(sprintf('FrameID should be in the range of [1 %d]',numWindowFrames));
+ signal = [];
+ return
+end
+switch wordSize
+ case 1
+ if numWindowFrames == 1
+ fseek(fid,top-1,'cof');
+ nn = bot - top + 1;
+ signal = fread(fid, [numChannels, nn], 'char');
+ else
+ for kk=1:length(frameId)
+ fseek(fid,p_bais+(frameId(kk)-1)*numChannels*frameLen,'bof');
+ signal(:,:,kk)=fread(fid,[numChannels, frameLen],'char');
+ end
+ end
+ case 2
+ if numWindowFrames == 1
+ fseek(fid,2*(top-1),'cof');
+ nn = bot - top + 1;
+ signal = fread(fid,[numChannels, nn], 'short');
+ else
+ for kk=1:length(frameId)
+ if echo fprintf('*'); end
+
+ fseek(fid,p_bias+2*(frameId(kk)-1)*numChannels*frameLen,'bof');
+ signal(:,:,kk)=fread(fid,[numChannels, frameLen],'short');
+% signal(:,:,kk)=fread(fid,[numChannels, frameLen],'int');
+ end
+ end
+ case 4
+ if numWindowFrames == 1
+ fseek(fid,4*(top-1),'cof');
+ nn = bot - top + 1;
+% signal = fread(fid,[numChannels, nn], 'float32');
+ signal = fread(fid,[numChannels, nn], 'uint32');
+ else
+ for kk=1:length(frameId)
+ fseek(fid,p_bias+4*(frameId(kk)-1)*numChannels*frameLen,'bof');
+% signal(:,:,kk)=fread(fid,[numChannels, frameLen],'float32');
+ signal(:,:,kk)=fread(fid,[numChannels, frameLen],'uint32');
+ end
+ end
+
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/SBReadAiff.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/SBReadAiff.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,100 @@
+% tool
+%
+% 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)
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+% $Revision: 585 $
+
+function ret=SBReadAiff(aifffile,echo)
+% usage SBReadAiff(aifffile,echo)
+%
+% returns all info in a struct
+% if echo =0, than no screen output is created
+if nargin<2
+ echo=1;
+end
+
+
+aiffstruct=getAIFFinfo(aifffile);
+if echo
+fprintf('read %d frames with %d channels...',aiffstruct.numWindowFrames,aiffstruct.numChannels);end
+
+ende=0;
+n=0;
+nap=zeros(aiffstruct.numChannels,aiffstruct.frameLength,aiffstruct.numWindowFrames);
+
+if aiffstruct.littleEndian
+ fid=fopen(aifffile,'r','l');
+else
+ fid=fopen(aifffile,'r','b');
+end
+
+while ~ende
+ von=n*30+1;
+ bis=(n+1)*30;
+ n=n+1;
+ if bis>aiffstruct.numWindowFrames
+ bis=aiffstruct.numWindowFrames;
+ ende=1;
+ end
+
+ status = fseek(fid, aiffstruct.soundPosition, 'bof');
+ tnap = ReadWinFrame2(fid, von:bis, aiffstruct.numWindowFrames,...
+ aiffstruct.numChannels,aiffstruct.frameLength, aiffstruct.wordSize,echo);
+
+ if bis>=aiffstruct.numWindowFrames;
+ ende=1;
+ end
+
+ if echo
+ fprintf('\n'); end
+
+ tnap = tnap .* aiffstruct.scale;
+
+ % tnap = myReadAIFF(aifffile,von:bis);
+ nap(:,:,von:bis)=tnap;
+end
+
+[nr_channels,nr_points,nr_frames]=size(nap);
+
+high=-inf;low=inf;
+sumhigh=-inf;
+frehigh=-inf;
+% do some controlling of the values
+for i=1:nr_frames
+ vals=nap(:,:,i);
+ fr=frame(vals,aiffstruct); % construct the frame
+ ret(i)=fr;
+
+ % find the maximum and the minimum values of each frame. this is useful for scaling
+ ma=getmaximumvalue(fr);
+ high=max([high ma]);
+ mi=getminimumvalue(fr);
+ low=min([low mi]);
+
+
+ maxs=max(getsum(fr));
+ sumhigh=max([maxs sumhigh]);
+
+ maxf=max(getfrequencysum(fr));
+ frehigh=max([maxf frehigh]);
+
+end
+
+% sr=getsr(ret(1));
+
+for i=1:nr_frames
+ ret(i)=setallmaxvalue(ret(i),high);
+ ret(i)=setallminvalue(ret(i),low);
+ ret(i)=setnrframestotal(ret(i),nr_frames);
+ ret(i)=setscalesumme(ret(i),sumhigh);
+ ret(i)=setscalefrequency(ret(i),frehigh);
+ ret(i)=setcurrentframenumber(ret(i),i);
+ frame_duration=aiffstruct.frameLength/aiffstruct.sampleRate;
+ ret(i)=setcurrentframestarttime(ret(i),(i-1)*frame_duration);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/adaptivthreshold.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/adaptivthreshold.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,399 @@
+% tool
+%
+% 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 [newsig,strobe_points,threshold]=adaptivthreshold(sig,options)
+
+if nargin < 2
+ options=[];
+end
+
+% the way, in which the strobes are calculated
+if isfield(options,'strobe_decay_time')
+ strobe_decay_time=options.strobe_decay_time;
+else
+ strobe_decay_time=0.04;
+end
+
+% the time constant of the strobe decay
+if isfield(options,'strobe_decay_time')
+ strobe_decay_time=options.strobe_decay_time;
+else
+ strobe_decay_time=0.04;
+end
+
+% the timeout, after that time a strobe must occure
+if isfield(options,'timeout')
+ timeout=options.timeout;
+else
+ strobe_decay_time=0.01;
+end
+
+% the strobe lag, ie the time that is waited for the next strobe to occure
+if isfield(options,'strobe_lag')
+ strobe_lag=options.strobe_lag;
+else
+ strobe_lag=0.005;
+end
+
+% the threshold of a strobe
+if isfield(options,'threshold')
+ threshold=options.threshold;
+else
+ threshold=0.04;
+end
+
+% if we want to start with a different threshold
+if isfield(options,'startingthreshold')
+ current_threshold=options.startingthreshold;
+else
+ current_threshold=0;
+end
+
+% if some graphic should be displayed during run
+if isfield(options,'grafix')
+ grafix=options.grafix;
+else
+ grafix=0; %
+end
+
+% % if the result shell be filtered by this lowpass filter:
+% if isfield(options,'lowpass')
+% lowpassvalue=options.lowpass;
+% else
+% lowpassvalue=-1; %
+% end
+
+sr=getsr(sig);
+newsig=sig;
+newsig=setname(newsig,sprintf('adaptive threshold of %s',getname(sig)));
+% newvals=getvalues(sig);
+threshold=sig;
+tresval=getvalues(sig);
+
+
+sigvals=getvalues(sig);
+options.current_threshold=current_threshold;
+options.sr=sr;
+
+switch options.strobe_criterion
+ case 'parabola'
+ [strobe_points,tresval,newvals]=doadaptivethresholdparabola(sigvals,options);
+ case 'threshold'
+ case 'peak'
+ [strobe_points,tresval,newvals]=doadaptivethresholdpeak(sigvals,options);
+ case 'peak_shadow+'
+ [strobe_points,tresval,newvals]=doadaptivethresholdpeakshadowplus(sigvals,options);
+ case 'peak_shadow-'
+ case 'delta_gamma'
+ case 'adaptive'
+ [strobe_points,tresval,newvals]=doadaptivethresholdadaptive(sigvals,options);
+ case 'bunt'
+ [strobe_points,tresval,newvals]=doadaptivethresholdbunt(sigvals,options);
+end
+
+strobe_points=bin2time(sig,strobe_points);
+
+newsig=setvalues(newsig,newvals);
+threshold=setvalues(threshold,tresval);
+
+% % do a low pass filtering of the result to smooth it
+% if lowpassvalue > -1
+% if lowpassvalue > 2000
+% lowpassvalue=2000;
+% end
+% newsig=lowpass(newsig,lowpassvalue);
+% newsig=halfwayrectify(newsig);
+% end
+
+
+if grafix
+ clf
+ plot(sig); hold on
+ ax=axis;
+ plot(newsig,'r');
+ plot(threshold,'g');
+ axis(ax);
+end
+return
+
+
+function [strobe_points,tresval,newvals]=doadaptivethresholdparabola(sigvals,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
+
+current_threshold=options.current_threshold;
+sr=options.sr;
+last_strobe=-inf;
+
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(100,1);
+
+%when the last strobe occured
+% last_strobe=-inf;
+last_threshold_value=0;
+
+% copy options to save time
+h=options.parabel_heigth;
+w=options.parabel_width;
+% w=options.parabel_width_in_cycles*1/options.current_cf;
+strobe_decay_time=options.strobe_decay_time;
+
+counter=1;
+for ii=1:nr
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+
+ if current_val>current_threshold
+ new_val=current_val-current_threshold;
+ current_threshold=current_val;
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ last_strobe=ii;
+ last_threshold_value=current_threshold;
+ else
+ new_val=0;
+ end
+ tresval(ii)=current_threshold;
+
+ time_since_last_strobe=(ii-last_strobe)/sr;
+ if time_since_last_strobe > w % linear falling threshold
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ else % parabel for the first time y=a(x+b)^2+c
+ a=4*(1-h)/(w*w);
+ b=-w/2;
+ c=h;
+ factor=a*(time_since_last_strobe + b) ^2+c;
+ current_threshold=last_threshold_value*factor;
+ end
+
+ current_threshold=max(0,current_threshold); % cant be smaller then 0
+
+ newvals(ii)=new_val;
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval,newvals]=doadaptivethresholdpeak(sigvals,options)
+% finds every single local maximum
+sr=options.sr;
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+strobe_points=zeros(100,1);
+sig=signal(sigvals);
+sig=setsr(sig,sr);
+[t,h]=getlocalmaxima(sig);
+strobe_points=t*sr;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval,newvals]=doadaptivethresholdpeakshadowplus(sigvals,options)
+% finds every single peak and starts from that an falling threshold
+
+current_threshold=options.current_threshold;
+sr=options.sr;
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(100,1);
+strobe_decay_time=options.strobe_decay_time;
+last_strobe=-inf;
+counter=1;
+last_threshold_value=0;
+
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+
+ if current_val>current_threshold
+ if sigvals(ii) > sigvals(ii-1) && sigvals(ii) > sigvals(ii+1)
+ new_val=current_val-current_threshold;
+ current_threshold=current_val;
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ last_strobe=ii;
+ last_threshold_value=current_threshold;
+ end
+ end
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ tresval(ii)=current_threshold;
+end
+
+
+function [strobe_points,tresval,newvals]=doadaptivethresholdadaptive(sigvals,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
+
+current_threshold=options.current_threshold;
+sr=options.sr;
+last_strobe=-inf;
+
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(100,1);
+
+%when the last strobe occured
+% last_strobe=-inf;
+last_threshold_value=0;
+
+% copy options to save time
+strobe_decay_time=options.strobe_decay_time;
+
+bunt=0.5;
+
+% decay_time=options.strobe_decay_time;
+% threshold_decay_constant=power(0.5,1./(options.strobe_decay_time*sr));
+
+slope_coefficient=options.slope_coefficient;
+slope_coefficient=0.0005;
+minoffset=0.2;
+
+threshold_decay_offset=-1/(options.strobe_decay_time*sr);
+default_threshold_decay_offset=threshold_decay_offset;
+
+counter=1;
+for ii=1:nr
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+
+ if current_val>current_threshold
+ new_val=current_val-current_threshold;
+ current_threshold=current_val;
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ time_offset=ii-last_strobe; % time since last strobe
+ last_strobe=ii;
+
+ amplitude_offset=current_threshold-last_threshold_value;
+
+ last_threshold_value=current_threshold;
+
+ current_bunt=0;
+ % if amplitude_offset>0
+ % current_bunt=amplitude_offset/1;
+ % else
+ % current_bunt=0;
+ % end
+ current_threshold=current_threshold+current_bunt+minoffset;
+
+ offset=amplitude_offset/time_offset*slope_coefficient;
+
+ threshold_decay_offset=threshold_decay_offset+offset;
+ % threshold_decay_constant=power(0.5,1./(decay_time*sr));
+ else
+ new_val=0;
+ end
+ tresval(ii)=current_threshold;
+ time_since_last_strobe=(ii-last_strobe)/sr;
+
+
+ % current_threshold=current_threshold*threshold_decay_constant;
+ current_threshold=current_threshold+threshold_decay_offset;
+ current_threshold=max(current_threshold,0);
+
+ if time_since_last_strobe>0.035
+ current_threshold=0;
+ threshold_decay_offset=default_threshold_decay_offset;
+ end
+
+ newvals(ii)=new_val;
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% BUNT
+function [strobe_points,tresval,newvals]=doadaptivethresholdbunt(sigvals,options)
+% the bunt is relative to the last peak hight
+
+current_threshold=options.current_threshold;
+sr=options.sr;
+last_strobe=-inf;
+
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(100,1);
+
+%when the last strobe occured
+last_strobe_time=-inf;
+last_threshold_value=0;
+
+% copy options to save time
+strobe_decay_time=options.strobe_decay_time;
+
+% wait that many cycles to confirm a strobe
+wait_time=options.wait_cycles/options.cf;
+
+% if waited for too long, then strobe anyhow after some passed candidates:
+wait_candidate_max=options.nr_strobe_candidates;
+current_jumped_candidates=1;
+
+
+bunt=options.bunt;
+
+strobe_decay_time=options.strobe_decay_time;
+last_val=sigvals(1);
+
+counter=1;
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ next_val=sigvals(ii+1);
+ current_time=ii/sr;
+ if current_val>=current_threshold % above threshold -> criterium for strobe
+ current_threshold=current_val;
+ if current_val > last_val && current_val > next_val % only strobe on local maxima
+
+ % so far its a candidate, but is it a real strobe?
+ % look if there was a strobe in the past, that is deleted
+ if (counter>1 && current_time-strobe_time(counter-1)last_threshold_value
+ % if its too long in the past, fire anyway
+ if current_jumped_candidates > wait_candidate_max
+ current_jumped_candidates=1; % reset counter
+ else
+ current_jumped_candidates=current_jumped_candidates+1;
+ counter=counter-1; % delete the last one
+ end
+ else
+ current_jumped_candidates=current_jumped_candidates+1;
+ end
+
+
+ % take this one as a new one
+ strobe_points(counter)=ii;
+ strobe_time(counter)=ii/sr;
+ counter=counter+1; % strobecounter
+ current_threshold=current_threshold*options.bunt; %increase threshold
+
+ last_strobe_time=ii/sr; % anyhow, its a candidate
+ last_threshold_value=current_threshold;
+
+ end
+ end
+ tresval(ii)=current_threshold;
+
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+
+ current_threshold=max(current_threshold,0);
+ last_val=current_val;
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/aifcwrite.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/aifcwrite.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,64 @@
+% 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 ok=aifcwrite(x,fs,nbits,fname)
+
+% function ok=aiffwrite(x,fs,nbits,fname)
+% Write AIFF and AIFF-C file
+% This is a reduced version and does not fulfill the
+% AIFF-C standard.
+
+% Coded by Hideki Kawahara based on "Audio Interchange file format AIFF-C draft"
+% by Apple Computer inc. 8/26/91
+% 14/Feb./1998
+
+ok=1;
+[nr,nc]=size(x);
+if nc>nr
+ ok=[];
+ disp('Data must be a set of column vector.');
+ return;
+end;
+nex=floor(log(fs)/log(2));
+vv=fs/2^(nex+1)*2^(4*16);
+nex2=nex+16383;
+
+fid=fopen(fname,'w');
+fwrite(fid,'FORM','char')
+cksize=82+nr*nc*(nbits/8);
+fwrite(fid,cksize,'int32');
+fwrite(fid,'AIFC','char');
+
+fwrite(fid,'FVER','char');
+fwrite(fid,4,'int32');
+fwrite(fid,2726318400,'uint32');
+
+fwrite(fid,'COMM','char');
+fwrite(fid,38,'int32');
+fwrite(fid,nc,'int16');
+fwrite(fid,nr,'int32');
+fwrite(fid,nbits,'int16');
+fwrite(fid,nex2,'uint16');
+fwrite(fid,vv,'uint64');
+fwrite(fid,'NONE','char');
+fwrite(fid,14,'uint8');
+fwrite(fid,'not compressed','char');
+fwrite(fid,0,'char');
+
+fwrite(fid,'SSND','char');
+fwrite(fid,nr*nc*(nbits/8)+8,'int32');
+fwrite(fid,0,'int32');
+fwrite(fid,0,'int32');
+y=x';
+switch(nbits)
+ case 8
+ fwrite(fid,y(:),'int8');
+ case 16
+ fwrite(fid,y(:),'int16');
+end;
+fclose(fid);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/aiffread.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/aiffread.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,103 @@
+% 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 [x,fs]=aiffread(fname)
+
+
+% function [x,fs]=aiffread(fname)
+% Read AIFF and AIFF-C file
+% This is a reduced version and does not fulfill the
+% AIFF-C standard.
+
+% Coded by Hideki Kawahara based on "Audio Interchange file format AIFF-C draft"
+% by Apple Computer inc. 8/26/91
+% 14/Feb./1998
+% 17/Feb./1998
+% 14/Jan./1999 bug fix for Windows
+
+fid=fopen(fname,'r','ieee-be.l64');
+id.form=fread(fid,4,'char');
+id.formcksz=fread(fid,1,'int32');
+id.formtp=fread(fid,4,'char');
+x=[];fs=44100;
+if ~strcmp(char(id.form),['F';'O';'R';'M'])
+ char(id.form)
+ disp('This is not a proper AIFF file.');
+ return;
+end;
+if ~strcmp(char(id.formtp),['A';'I';'F';'F']) & ~strcmp(char(id.formtp),['A';'I';'F';'C'])
+ char(id.formtp)
+ disp('This is not a proper AIFF file.');
+ return;
+end;
+[id.comm,na]=fread(fid,4,'uchar');
+while na>3
+switch(strcat(char(id.comm)'))
+case 'FVER'
+ id.fsize=fread(fid,1,'int32');
+ id.timesta=fread(fid,1,'uint32');
+ if id.timesta ~= 2726318400
+ disp(['I cannot recognize timestump ' num2str(id.timesta)]);
+ end;
+ [id.comm,na]=fread(fid,4,'uchar');
+ if na==0
+ if isempty(x); disp('End of file reached!');fclose(fid);return;end;
+ end;
+case 'COMM'
+ id.commsz=fread(fid,1,'int32');
+ id.commnch=fread(fid,1,'int16');
+ id.commdsz=fread(fid,1,'uint32');
+ id.samplesize=fread(fid,1,'int16');
+ id.srex1=fread(fid,1,'uint16');
+ id.srex2=fread(fid,1,'uint64');
+ if strcmp(char(id.formtp),['A';'I';'F';'C'])
+ id.compress=fread(fid,4,'char');
+ if ~strcmp(char(id.compress),['N';'O';'N';'E'])
+ disp('Compression is not supported.');
+ return;
+ end;
+ dummy=fread(fid,id.commsz-22,'char');
+ end;
+ fs=2^(id.srex1-16383)*id.srex2/hex2dec('8000000000000000');
+ [id.comm,na]=fread(fid,4,'uchar');
+ if na==0
+ if isempty(x); disp('End of file reached!');fclose(fid);return;end;
+ end;
+case 'SSND'
+ id.ckdatasize=fread(fid,1,'uint32');
+ id.offset=fread(fid,1,'int32');
+ id.blksz=fread(fid,1,'int32');
+ switch(id.samplesize)
+ case 8
+ x=fread(fid,id.ckdatasize-8,'int8');
+ x=reshape(x,id.commnch,id.commsz)';
+ case 16
+ x=fread(fid,(id.ckdatasize-8)/2,'int16');
+ x=reshape(x,id.commnch,id.commdsz)';
+ case 24
+ x=fread(fid,(id.ckdatasize-8)/3,'bit24');
+ x=reshape(x,id.commnch,id.commdsz)';
+ end;
+ [id.comm,na]=fread(fid,4,'uchar');
+ if na==0
+ if isempty(x); disp('End of file reached!');fclose(fid);return;end;
+ end;
+otherwise
+ id.fsize=fread(fid,1,'int32');
+ if feof(fid) | id.fsize > id.formcksz | id.fsize <=0
+ fclose(fid);
+ return;
+ end;
+ id.skip=fread(fid,id.fsize,'char');
+ [id.comm,na]=fread(fid,4,'uchar');
+ if na==0
+ if isempty(x); disp('End of file reached!');fclose(fid);return;end;
+ end;
+end;
+end;
+%id
+fclose(fid);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/aiffwrite.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/aiffwrite.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,59 @@
+% 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 ok=aiffwrite(x,fs,nbits,fname)
+
+% function ok=aiffwrite(x,fs,nbits,fname)
+% Write AIFF file
+% This is a reduced version and does not fulfill the
+% AIFF standard.
+
+% Coded by Hideki Kawahara based on "Audio Interchange file format AIFF-C draft"
+% by Apple Computer inc. 8/26/91
+% 14/Feb./1998
+% 14/Jan./1999 bug fix for Windows
+
+ok=1;
+[nr,nc]=size(x);
+if nc>nr
+ ok=[];
+ disp('Data must be a set of column vector.');
+ return;
+end;
+nex=floor(log(fs)/log(2));
+vv=fs/2^(nex+1)*2^(4*16);
+nex2=nex+16383;
+
+fid=fopen(fname,'w','ieee-be.l64');
+fwrite(fid,'FORM','char');
+cksize=46+nr*nc*(nbits/8);
+fwrite(fid,cksize,'int32');
+fwrite(fid,'AIFF','char');
+
+fwrite(fid,'COMM','char');
+fwrite(fid,18,'int32');
+fwrite(fid,nc,'int16');
+fwrite(fid,nr,'int32');
+fwrite(fid,nbits,'int16');
+fwrite(fid,nex2,'uint16');
+fwrite(fid,vv,'uint64');
+
+fwrite(fid,'SSND','char');
+fwrite(fid,nr*nc*(nbits/8)+8,'int32');
+fwrite(fid,0,'int32');
+fwrite(fid,0,'int32');
+y=x';
+switch(nbits)
+ case 8
+ fwrite(fid,y(:),'int8');
+ case 16
+ fwrite(fid,y(:),'int16');
+ case 24
+ fwrite(fid,y(:),'bit24');
+end;
+fclose(fid);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/appendwaves.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/appendwaves.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,25 @@
+% tool
+%
+% 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 sumwaves = appendwaves (varargin)
+
+numwav=length(varargin);
+
+for i=1:numwav
+ sig(i)=loadwavefile(signal,varargin{i});
+end
+
+sumwaves=sig(1);
+for i=2:numwav
+ sumwaves=append(sumwaves,sig(i));
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/arrow.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/arrow.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,1275 @@
+function [h,yy,zz] = arrow(varargin)
+% ARROW Draw a line with an arrowhead.
+%
+% ARROW(Start,Stop) draws a line with an arrow from Start to Stop (points
+% should be vectors of length 2 or 3, or matrices with 2 or 3
+% columns), and returns the graphics handle of the arrow(s).
+%
+% ARROW uses the mouse (click-drag) to create an arrow.
+%
+% ARROW DEMO & ARROW DEMO2 show 3-D & 2-D demos of the capabilities of ARROW.
+%
+% ARROW may be called with a normal argument list or a property-based list.
+% ARROW(Start,Stop,Length,BaseAngle,TipAngle,Width,Page,CrossDir) is
+% the full normal argument list, where all but the Start and Stop
+% points are optional. If you need to specify a later argument (e.g.,
+% Page) but want default values of earlier ones (e.g., TipAngle),
+% pass an empty matrix for the earlier ones (e.g., TipAngle=[]).
+%
+% ARROW('Property1',PropVal1,'Property2',PropVal2,...) creates arrows with the
+% given properties, using default values for any unspecified or given as
+% 'default' or NaN. Some properties used for line and patch objects are
+% used in a modified fashion, others are passed directly to LINE, PATCH,
+% or SET. For a detailed properties explanation, call ARROW PROPERTIES.
+%
+% Start The starting points. B
+% Stop The end points. /|\ ^
+% Length Length of the arrowhead in pixels. /|||\ |
+% BaseAngle Base angle in degrees (ADE). //|||\\ L|
+% TipAngle Tip angle in degrees (ABC). ///|||\\\ e|
+% Width Width of the base in pixels. ////|||\\\\ n|
+% Page Use hardcopy proportions. /////|D|\\\\\ g|
+% CrossDir Vector || to arrowhead plane. //// ||| \\\\ t|
+% NormalDir Vector out of arrowhead plane. /// ||| \\\ h|
+% Ends Which end has an arrowhead. //<----->|| \\ |
+% ObjectHandles Vector of handles to update. / base ||| \ V
+% E angle||<-------->C
+% ARROW(H,'Prop1',PropVal1,...), where H is a |||tipangle
+% vector of handles to previously-created arrows |||
+% and/or line objects, will update the previously- |||
+% created arrows according to the current view -->|A|<-- width
+% and any specified properties, and will convert
+% two-point line objects to corresponding arrows. ARROW(H) will update
+% the arrows if the current view has changed. Root, figure, or axes
+% handles included in H are replaced by all descendant Arrow objects.
+%
+% A property list can follow any specified normal argument list, e.g.,
+% ARROW([1 2 3],[0 0 0],36,'BaseAngle',60) creates an arrow from (1,2,3) to
+% the origin, with an arrowhead of length 36 pixels and 60-degree base angle.
+%
+% The basic arguments or properties can generally be vectorized to create
+% multiple arrows with the same call. This is done by passing a property
+% with one row per arrow, or, if all arrows are to have the same property
+% value, just one row may be specified.
+%
+% You may want to execute AXIS(AXIS) before calling ARROW so it doesn't change
+% the axes on you; ARROW determines the sizes of arrow components BEFORE the
+% arrow is plotted, so if ARROW changes axis limits, arrows may be malformed.
+%
+% This version of ARROW uses features of MATLAB 5 and is incompatible with
+% earlier MATLAB versions (ARROW for MATLAB 4.2c is available separately);
+% some problems with perspective plots still exist.
+% Copyright (c)1995-2002, Dr. Erik A. Johnson , 11/15/02
+% Revision history:
+% 11/15/02 EAJ Accomodate how MATLAB 6.5 handles NaN and logicals
+% 7/28/02 EAJ Tried (but failed) work-around for MATLAB 6.x / OpenGL bug
+% if zero 'Width' or not double-ended
+% 11/10/99 EAJ Add logical() to eliminate zero index problem in MATLAB 5.3.
+% 11/10/99 EAJ Corrected warning if axis limits changed on multiple axes.
+% 11/10/99 EAJ Update e-mail address.
+% 2/10/99 EAJ Some documentation updating.
+% 2/24/98 EAJ Fixed bug if Start~=Stop but both colinear with viewpoint.
+% 8/14/97 EAJ Added workaround for MATLAB 5.1 scalar logical transpose bug.
+% 7/21/97 EAJ Fixed a few misc bugs.
+% 7/14/97 EAJ Make arrow([],'Prop',...) do nothing (no old handles)
+% 6/23/97 EAJ MATLAB 5 compatible version, release.
+% 5/27/97 EAJ Added Line Arrows back in. Corrected a few bugs.
+% 5/26/97 EAJ Changed missing Start/Stop to mouse-selected arrows.
+% 5/19/97 EAJ MATLAB 5 compatible version, beta.
+% 4/13/97 EAJ MATLAB 5 compatible version, alpha.
+% 1/31/97 EAJ Fixed bug with multiple arrows and unspecified Z coords.
+% 12/05/96 EAJ Fixed one more bug with log plots and NormalDir specified
+% 10/24/96 EAJ Fixed bug with log plots and NormalDir specified
+% 11/13/95 EAJ Corrected handling for 'reverse' axis directions
+% 10/06/95 EAJ Corrected occasional conflict with SUBPLOT
+% 4/24/95 EAJ A major rewrite.
+% Fall 94 EAJ Original code.
+% Things to be done:
+% - segment parsing, computing, and plotting into separate subfunctions
+% - change computing from Xform to Camera paradigms
+% + this will help especially with 3-D perspective plots
+% + if the WarpToFill section works right, remove warning code
+% + when perpsective works properly, remove perspective warning code
+% - add cell property values and struct property name/values (like get/set)
+% - get rid of NaN as the "default" data label
+% + perhaps change userdata to a struct and don't include (or leave
+% empty) the values specified as default; or use a cell containing
+% an empty matrix for a default value
+% - add functionality of GET to retrieve current values of ARROW properties
+% Many thanks to Keith Rogers for his many excellent
+% suggestions and beta testing. Check out his shareware package MATDRAW
+% (at ftp://ftp.mathworks.com/pub/contrib/v5/graphics/matdraw/) -- he has
+% permission to distribute ARROW with MATDRAW.
+% Permission is granted to distribute ARROW with the toolboxes for the book
+% "Solving Solid Mechanics Problems with MATLAB 5", by F. Golnaraghi et al.
+% (Prentice Hall, 1999).
+% global variable initialization
+global ARROW_PERSP_WARN ARROW_STRETCH_WARN ARROW_AXLIMITS
+if isempty(ARROW_PERSP_WARN ), ARROW_PERSP_WARN =1; end;
+if isempty(ARROW_STRETCH_WARN), ARROW_STRETCH_WARN=1; end;
+% Handle callbacks
+if (nargin>0 & isstr(varargin{1}) & strcmp(lower(varargin{1}),'callback')),
+ arrow_callback(varargin{2:end}); return;
+end;
+% Are we doing the demo?
+c = sprintf('\n');
+if (nargin==1 & isstr(varargin{1})),
+ arg1 = lower(varargin{1});
+ if strncmp(arg1,'prop',4), arrow_props;
+ elseif strncmp(arg1,'demo',4)
+ clf reset
+ demo_info = arrow_demo;
+ if ~strncmp(arg1,'demo2',5),
+ hh=arrow_demo3(demo_info);
+ else,
+ hh=arrow_demo2(demo_info);
+ end;
+ if (nargout>=1), h=hh; end;
+ elseif strncmp(arg1,'fixlimits',3),
+ arrow_fixlimits(ARROW_AXLIMITS);
+ ARROW_AXLIMITS=[];
+ elseif strncmp(arg1,'help',4),
+ disp(help(mfilename));
+ else,
+ error([upper(mfilename) ' got an unknown single-argument string ''' deblank(arg1) '''.']);
+ end;
+ return;
+end;
+% Check # of arguments
+if (nargout>3), error([upper(mfilename) ' produces at most 3 output arguments.']); end;
+% find first property number
+firstprop = nargin+1;
+for k=1:length(varargin), if ~isnumeric(varargin{k}), firstprop=k; break; end; end;
+lastnumeric = firstprop-1;
+% check property list
+if (firstprop<=nargin),
+ for k=firstprop:2:nargin,
+ curarg = varargin{k};
+ if ~isstr(curarg) | sum(size(curarg)>1)>1,
+ error([upper(mfilename) ' requires that a property name be a single string.']);
+ end;
+ end;
+ if (rem(nargin-firstprop,2)~=1),
+ error([upper(mfilename) ' requires that the property ''' ...
+ varargin{nargin} ''' be paired with a property value.']);
+ end;
+end;
+% default output
+if (nargout>0), h=[]; end;
+if (nargout>1), yy=[]; end;
+if (nargout>2), zz=[]; end;
+% set values to empty matrices
+start = [];
+stop = [];
+len = [];
+baseangle = [];
+tipangle = [];
+wid = [];
+page = [];
+crossdir = [];
+ends = [];
+ax = [];
+oldh = [];
+ispatch = [];
+defstart = [NaN NaN NaN];
+defstop = [NaN NaN NaN];
+deflen = 16;
+defbaseangle = 90;
+deftipangle = 16;
+defwid = 0;
+defpage = 0;
+defcrossdir = [NaN NaN NaN];
+defends = 1;
+defoldh = [];
+defispatch = 1;
+% The 'Tag' we'll put on our arrows
+ArrowTag = 'Arrow';
+% check for oldstyle arguments
+if (firstprop==2),
+ % assume arg1 is a set of handles
+ oldh = varargin{1}(:);
+ if isempty(oldh), return; end;
+elseif (firstprop>9),
+ error([upper(mfilename) ' takes at most 8 non-property arguments.']);
+elseif (firstprop>2),
+ s = str2mat('start','stop','len','baseangle','tipangle','wid','page','crossdir');
+ for k=1:firstprop-1, eval([deblank(s(k,:)) '=varargin{k};']); end;
+end;
+% parse property pairs
+extraprops={};
+for k=firstprop:2:nargin,
+ prop = varargin{k};
+ val = varargin{k+1};
+ prop = [lower(prop(:)') ' '];
+ if strncmp(prop,'start' ,5), start = val;
+ elseif strncmp(prop,'stop' ,4), stop = val;
+ elseif strncmp(prop,'len' ,3), len = val(:);
+ elseif strncmp(prop,'base' ,4), baseangle = val(:);
+ elseif strncmp(prop,'tip' ,3), tipangle = val(:);
+ elseif strncmp(prop,'wid' ,3), wid = val(:);
+ elseif strncmp(prop,'page' ,4), page = val;
+ elseif strncmp(prop,'cross' ,5), crossdir = val;
+ elseif strncmp(prop,'norm' ,4), if (isstr(val)), crossdir=val; else, crossdir=val*sqrt(-1); end;
+ elseif strncmp(prop,'end' ,3), ends = val;
+ elseif strncmp(prop,'object',6), oldh = val(:);
+ elseif strncmp(prop,'handle',6), oldh = val(:);
+ elseif strncmp(prop,'type' ,4), ispatch = val;
+ elseif strncmp(prop,'userd' ,5), %ignore it
+ else,
+ % make sure it is a valid patch or line property
+ eval('get(0,[''DefaultPatch'' varargin{k}]);err=0;','err=1;'); errstr=lasterr;
+ if (err), eval('get(0,[''DefaultLine'' varargin{k}]);err=0;','err=1;'); end;
+ if (err),
+ errstr(1:max(find(errstr==setstr(13)|errstr==setstr(10)))) = '';
+ error([upper(mfilename) ' got ' errstr]);
+ end;
+ extraprops={extraprops{:},varargin{k},val};
+ end;
+end;
+% Check if we got 'default' values
+start = arrow_defcheck(start ,defstart ,'Start' );
+stop = arrow_defcheck(stop ,defstop ,'Stop' );
+len = arrow_defcheck(len ,deflen ,'Length' );
+baseangle = arrow_defcheck(baseangle,defbaseangle,'BaseAngle' );
+tipangle = arrow_defcheck(tipangle ,deftipangle ,'TipAngle' );
+wid = arrow_defcheck(wid ,defwid ,'Width' );
+crossdir = arrow_defcheck(crossdir ,defcrossdir ,'CrossDir' );
+page = arrow_defcheck(page ,defpage ,'Page' );
+ends = arrow_defcheck(ends ,defends ,'' );
+oldh = arrow_defcheck(oldh ,[] ,'ObjectHandles');
+ispatch = arrow_defcheck(ispatch ,defispatch ,'' );
+% check transpose on arguments
+[m,n]=size(start ); if any(m==[2 3])&(n==1|n>3), start = start'; end;
+[m,n]=size(stop ); if any(m==[2 3])&(n==1|n>3), stop = stop'; end;
+[m,n]=size(crossdir); if any(m==[2 3])&(n==1|n>3), crossdir = crossdir'; end;
+% convert strings to numbers
+if ~isempty(ends) & isstr(ends),
+ endsorig = ends;
+ [m,n] = size(ends);
+ col = lower([ends(:,1:min(3,n)) ones(m,max(0,3-n))*' ']);
+ ends = NaN*ones(m,1);
+ oo = ones(1,m);
+ ii=find(all(col'==['non']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*0; end;
+ ii=find(all(col'==['sto']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*1; end;
+ ii=find(all(col'==['sta']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*2; end;
+ ii=find(all(col'==['bot']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*3; end;
+ if any(isnan(ends)),
+ ii = min(find(isnan(ends)));
+ error([upper(mfilename) ' does not recognize ''' deblank(endsorig(ii,:)) ''' as a valid ''Ends'' value.']);
+ end;
+else,
+ ends = ends(:);
+end;
+if ~isempty(ispatch) & isstr(ispatch),
+ col = lower(ispatch(:,1));
+ patchchar='p'; linechar='l'; defchar=' ';
+ mask = col~=patchchar & col~=linechar & col~=defchar;
+ if any(mask),
+ error([upper(mfilename) ' does not recognize ''' deblank(ispatch(min(find(mask)),:)) ''' as a valid ''Type'' value.']);
+ end;
+ ispatch = (col==patchchar)*1 + (col==linechar)*0 + (col==defchar)*defispatch;
+else,
+ ispatch = ispatch(:);
+end;
+oldh = oldh(:);
+% check object handles
+if ~all(ishandle(oldh)), error([upper(mfilename) ' got invalid object handles.']); end;
+% expand root, figure, and axes handles
+if ~isempty(oldh),
+ ohtype = get(oldh,'Type');
+ mask = strcmp(ohtype,'root') | strcmp(ohtype,'figure') | strcmp(ohtype,'axes');
+ if any(mask),
+ oldh = num2cell(oldh);
+ for ii=find(mask)',
+ oldh(ii) = {findobj(oldh{ii},'Tag',ArrowTag)};
+ end;
+ oldh = cat(1,oldh{:});
+ if isempty(oldh), return; end; % no arrows to modify, so just leave
+ end;
+end;
+% largest argument length
+[mstart,junk]=size(start); [mstop,junk]=size(stop); [mcrossdir,junk]=size(crossdir);
+argsizes = [length(oldh) mstart mstop ...
+ length(len) length(baseangle) length(tipangle) ...
+ length(wid) length(page) mcrossdir length(ends) ];
+args=['length(ObjectHandle) '; ...
+ '#rows(Start) '; ...
+ '#rows(Stop) '; ...
+ 'length(Length) '; ...
+ 'length(BaseAngle) '; ...
+ 'length(TipAngle) '; ...
+ 'length(Width) '; ...
+ 'length(Page) '; ...
+ '#rows(CrossDir) '; ...
+ '#rows(Ends) '];
+if (any(imag(crossdir(:))~=0)),
+ args(9,:) = '#rows(NormalDir) ';
+end;
+if isempty(oldh),
+ narrows = max(argsizes);
+else,
+ narrows = length(oldh);
+end;
+if (narrows<=0), narrows=1; end;
+% Check size of arguments
+ii = find((argsizes~=0)&(argsizes~=1)&(argsizes~=narrows));
+if ~isempty(ii),
+ s = args(ii',:);
+ while ((size(s,2)>1)&((abs(s(:,size(s,2)))==0)|(abs(s(:,size(s,2)))==abs(' ')))),
+ s = s(:,1:size(s,2)-1);
+ end;
+ s = [ones(length(ii),1)*[upper(mfilename) ' requires that '] s ...
+ ones(length(ii),1)*[' equal the # of arrows (' num2str(narrows) ').' c]];
+ s = s';
+ s = s(:)';
+ s = s(1:length(s)-1);
+ error(setstr(s));
+end;
+% check element length in Start, Stop, and CrossDir
+if ~isempty(start),
+ [m,n] = size(start);
+ if (n==2),
+ start = [start NaN*ones(m,1)];
+ elseif (n~=3),
+ error([upper(mfilename) ' requires 2- or 3-element Start points.']);
+ end;
+end;
+if ~isempty(stop),
+ [m,n] = size(stop);
+ if (n==2),
+ stop = [stop NaN*ones(m,1)];
+ elseif (n~=3),
+ error([upper(mfilename) ' requires 2- or 3-element Stop points.']);
+ end;
+end;
+if ~isempty(crossdir),
+ [m,n] = size(crossdir);
+ if (n<3),
+ crossdir = [crossdir NaN*ones(m,3-n)];
+ elseif (n~=3),
+ if (all(imag(crossdir(:))==0)),
+ error([upper(mfilename) ' requires 2- or 3-element CrossDir vectors.']);
+ else,
+ error([upper(mfilename) ' requires 2- or 3-element NormalDir vectors.']);
+ end;
+ end;
+end;
+% fill empty arguments
+if isempty(start ), start = [Inf Inf Inf]; end;
+if isempty(stop ), stop = [Inf Inf Inf]; end;
+if isempty(len ), len = Inf; end;
+if isempty(baseangle ), baseangle = Inf; end;
+if isempty(tipangle ), tipangle = Inf; end;
+if isempty(wid ), wid = Inf; end;
+if isempty(page ), page = Inf; end;
+if isempty(crossdir ), crossdir = [Inf Inf Inf]; end;
+if isempty(ends ), ends = Inf; end;
+if isempty(ispatch ), ispatch = Inf; end;
+% expand single-column arguments
+o = ones(narrows,1);
+if (size(start ,1)==1), start = o * start ; end;
+if (size(stop ,1)==1), stop = o * stop ; end;
+if (length(len )==1), len = o * len ; end;
+if (length(baseangle )==1), baseangle = o * baseangle ; end;
+if (length(tipangle )==1), tipangle = o * tipangle ; end;
+if (length(wid )==1), wid = o * wid ; end;
+if (length(page )==1), page = o * page ; end;
+if (size(crossdir ,1)==1), crossdir = o * crossdir ; end;
+if (length(ends )==1), ends = o * ends ; end;
+if (length(ispatch )==1), ispatch = o * ispatch ; end;
+ax = o * gca;
+% if we've got handles, get the defaults from the handles
+if ~isempty(oldh),
+ for k=1:narrows,
+ oh = oldh(k);
+ ud = get(oh,'UserData');
+ ax(k) = get(oh,'Parent');
+ ohtype = get(oh,'Type');
+ if strcmp(get(oh,'Tag'),ArrowTag), % if it's an arrow already
+ if isinf(ispatch(k)), ispatch(k)=strcmp(ohtype,'patch'); end;
+ % arrow UserData format: [start' stop' len base tip wid page crossdir' ends]
+ start0 = ud(1:3);
+ stop0 = ud(4:6);
+ if (isinf(len(k))), len(k) = ud( 7); end;
+ if (isinf(baseangle(k))), baseangle(k) = ud( 8); end;
+ if (isinf(tipangle(k))), tipangle(k) = ud( 9); end;
+ if (isinf(wid(k))), wid(k) = ud(10); end;
+ if (isinf(page(k))), page(k) = ud(11); end;
+ if (isinf(crossdir(k,1))), crossdir(k,1) = ud(12); end;
+ if (isinf(crossdir(k,2))), crossdir(k,2) = ud(13); end;
+ if (isinf(crossdir(k,3))), crossdir(k,3) = ud(14); end;
+ if (isinf(ends(k))), ends(k) = ud(15); end;
+ elseif strcmp(ohtype,'line')|strcmp(ohtype,'patch'), % it's a non-arrow line or patch
+ convLineToPatch = 1; %set to make arrow patches when converting from lines.
+ if isinf(ispatch(k)), ispatch(k)=convLineToPatch|strcmp(ohtype,'patch'); end;
+ x=get(oh,'XData'); x=x(~isnan(x(:))); if isempty(x), x=NaN; end;
+ y=get(oh,'YData'); y=y(~isnan(y(:))); if isempty(y), y=NaN; end;
+ z=get(oh,'ZData'); z=z(~isnan(z(:))); if isempty(z), z=NaN; end;
+ start0 = [x(1) y(1) z(1) ];
+ stop0 = [x(end) y(end) z(end)];
+ else,
+ error([upper(mfilename) ' cannot convert ' ohtype ' objects.']);
+ end;
+ ii=find(isinf(start(k,:))); if ~isempty(ii), start(k,ii)=start0(ii); end;
+ ii=find(isinf(stop( k,:))); if ~isempty(ii), stop( k,ii)=stop0( ii); end;
+ end;
+end;
+% convert Inf's to NaN's
+start( isinf(start )) = NaN;
+stop( isinf(stop )) = NaN;
+len( isinf(len )) = NaN;
+baseangle( isinf(baseangle)) = NaN;
+tipangle( isinf(tipangle )) = NaN;
+wid( isinf(wid )) = NaN;
+page( isinf(page )) = NaN;
+crossdir( isinf(crossdir )) = NaN;
+ends( isinf(ends )) = NaN;
+ispatch( isinf(ispatch )) = NaN;
+% set up the UserData data (here so not corrupted by log10's and such)
+ud = [start stop len baseangle tipangle wid page crossdir ends];
+% Set Page defaults
+page = ~isnan(page) & trueornan(page);
+% Get axes limits, range, min; correct for aspect ratio and log scale
+axm = zeros(3,narrows);
+axr = zeros(3,narrows);
+axrev = zeros(3,narrows);
+ap = zeros(2,narrows);
+xyzlog = zeros(3,narrows);
+limmin = zeros(2,narrows);
+limrange = zeros(2,narrows);
+oldaxlims = zeros(narrows,7);
+oneax = all(ax==ax(1));
+if (oneax),
+ T = zeros(4,4);
+ invT = zeros(4,4);
+else,
+ T = zeros(16,narrows);
+ invT = zeros(16,narrows);
+end;
+axnotdone = logical(ones(size(ax)));
+while (any(axnotdone)),
+ ii = min(find(axnotdone));
+ curax = ax(ii);
+ curpage = page(ii);
+ % get axes limits and aspect ratio
+ axl = [get(curax,'XLim'); get(curax,'YLim'); get(curax,'ZLim')];
+ oldaxlims(min(find(oldaxlims(:,1)==0)),:) = [curax reshape(axl',1,6)];
+ % get axes size in pixels (points)
+ u = get(curax,'Units');
+ axposoldunits = get(curax,'Position');
+ really_curpage = curpage & strcmp(u,'normalized');
+ if (really_curpage),
+ curfig = get(curax,'Parent');
+ pu = get(curfig,'PaperUnits');
+ set(curfig,'PaperUnits','points');
+ pp = get(curfig,'PaperPosition');
+ set(curfig,'PaperUnits',pu);
+ set(curax,'Units','pixels');
+ curapscreen = get(curax,'Position');
+ set(curax,'Units','normalized');
+ curap = pp.*get(curax,'Position');
+ else,
+ set(curax,'Units','pixels');
+ curapscreen = get(curax,'Position');
+ curap = curapscreen;
+ end;
+ set(curax,'Units',u);
+ set(curax,'Position',axposoldunits);
+ % handle non-stretched axes position
+ str_stretch = { 'DataAspectRatioMode' ; ...
+ 'PlotBoxAspectRatioMode' ; ...
+ 'CameraViewAngleMode' };
+ str_camera = { 'CameraPositionMode' ; ...
+ 'CameraTargetMode' ; ...
+ 'CameraViewAngleMode' ; ...
+ 'CameraUpVectorMode' };
+ notstretched = strcmp(get(curax,str_stretch),'manual');
+ manualcamera = strcmp(get(curax,str_camera),'manual');
+ if ~arrow_WarpToFill(notstretched,manualcamera,curax),
+ % give a warning that this has not been thoroughly tested
+ if 0 & ARROW_STRETCH_WARN,
+ ARROW_STRETCH_WARN = 0;
+ strs = {str_stretch{1:2},str_camera{:}};
+ strs = [char(ones(length(strs),1)*sprintf('\n ')) char(strs)]';
+ warning([upper(mfilename) ' may not yet work quite right ' ...
+ 'if any of the following are ''manual'':' strs(:).']);
+ end;
+ % find the true pixel size of the actual axes
+ texttmp = text(axl(1,[1 2 2 1 1 2 2 1]), ...
+ axl(2,[1 1 2 2 1 1 2 2]), ...
+ axl(3,[1 1 1 1 2 2 2 2]),'');
+ set(texttmp,'Units','points');
+ textpos = get(texttmp,'Position');
+ delete(texttmp);
+ textpos = cat(1,textpos{:});
+ textpos = max(textpos(:,1:2)) - min(textpos(:,1:2));
+ % adjust the axes position
+ if (really_curpage),
+ % adjust to printed size
+ textpos = textpos * min(curap(3:4)./textpos);
+ curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos];
+ else,
+ % adjust for pixel roundoff
+ textpos = textpos * min(curapscreen(3:4)./textpos);
+ curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos];
+ end;
+ end;
+ if ARROW_PERSP_WARN & ~strcmp(get(curax,'Projection'),'orthographic'),
+ ARROW_PERSP_WARN = 0;
+ warning([upper(mfilename) ' does not yet work right for 3-D perspective projection.']);
+ end;
+ % adjust limits for log scale on axes
+ curxyzlog = [strcmp(get(curax,'XScale'),'log'); ...
+ strcmp(get(curax,'YScale'),'log'); ...
+ strcmp(get(curax,'ZScale'),'log')];
+ if (any(curxyzlog)),
+ ii = find([curxyzlog;curxyzlog]);
+ if (any(axl(ii)<=0)),
+ error([upper(mfilename) ' does not support non-positive limits on log-scaled axes.']);
+ else,
+ axl(ii) = log10(axl(ii));
+ end;
+ end;
+ % correct for 'reverse' direction on axes;
+ curreverse = [strcmp(get(curax,'XDir'),'reverse'); ...
+ strcmp(get(curax,'YDir'),'reverse'); ...
+ strcmp(get(curax,'ZDir'),'reverse')];
+ ii = find(curreverse);
+ if ~isempty(ii),
+ axl(ii,[1 2])=-axl(ii,[2 1]);
+ end;
+ % compute the range of 2-D values
+ curT = get(curax,'Xform');
+ lim = curT*[0 1 0 1 0 1 0 1;0 0 1 1 0 0 1 1;0 0 0 0 1 1 1 1;1 1 1 1 1 1 1 1];
+ lim = lim(1:2,:)./([1;1]*lim(4,:));
+ curlimmin = min(lim')';
+ curlimrange = max(lim')' - curlimmin;
+ curinvT = inv(curT);
+ if (~oneax),
+ curT = curT.';
+ curinvT = curinvT.';
+ curT = curT(:);
+ curinvT = curinvT(:);
+ end;
+ % check which arrows to which cur corresponds
+ ii = find((ax==curax)&(page==curpage));
+ oo = ones(1,length(ii));
+ axr(:,ii) = diff(axl')' * oo;
+ axm(:,ii) = axl(:,1) * oo;
+ axrev(:,ii) = curreverse * oo;
+ ap(:,ii) = curap(3:4)' * oo;
+ xyzlog(:,ii) = curxyzlog * oo;
+ limmin(:,ii) = curlimmin * oo;
+ limrange(:,ii) = curlimrange * oo;
+ if (oneax),
+ T = curT;
+ invT = curinvT;
+ else,
+ T(:,ii) = curT * oo;
+ invT(:,ii) = curinvT * oo;
+ end;
+ axnotdone(ii) = zeros(1,length(ii));
+end;
+oldaxlims(oldaxlims(:,1)==0,:)=[];
+% correct for log scales
+curxyzlog = xyzlog.';
+ii = find(curxyzlog(:));
+if ~isempty(ii),
+ start( ii) = real(log10(start( ii)));
+ stop( ii) = real(log10(stop( ii)));
+ if (all(imag(crossdir)==0)), % pulled (ii) subscript on crossdir, 12/5/96 eaj
+ crossdir(ii) = real(log10(crossdir(ii)));
+ end;
+end;
+% correct for reverse directions
+ii = find(axrev.');
+if ~isempty(ii),
+ start( ii) = -start( ii);
+ stop( ii) = -stop( ii);
+ crossdir(ii) = -crossdir(ii);
+end;
+% transpose start/stop values
+start = start.';
+stop = stop.';
+% take care of defaults, page was done above
+ii=find(isnan(start(:) )); if ~isempty(ii), start(ii) = axm(ii)+axr(ii)/2; end;
+ii=find(isnan(stop(:) )); if ~isempty(ii), stop(ii) = axm(ii)+axr(ii)/2; end;
+ii=find(isnan(crossdir(:) )); if ~isempty(ii), crossdir(ii) = zeros(length(ii),1); end;
+ii=find(isnan(len )); if ~isempty(ii), len(ii) = ones(length(ii),1)*deflen; end;
+ii=find(isnan(baseangle )); if ~isempty(ii), baseangle(ii) = ones(length(ii),1)*defbaseangle; end;
+ii=find(isnan(tipangle )); if ~isempty(ii), tipangle(ii) = ones(length(ii),1)*deftipangle; end;
+ii=find(isnan(wid )); if ~isempty(ii), wid(ii) = ones(length(ii),1)*defwid; end;
+ii=find(isnan(ends )); if ~isempty(ii), ends(ii) = ones(length(ii),1)*defends; end;
+% transpose rest of values
+len = len.';
+baseangle = baseangle.';
+tipangle = tipangle.';
+wid = wid.';
+page = page.';
+crossdir = crossdir.';
+ends = ends.';
+ax = ax.';
+% given x, a 3xN matrix of points in 3-space;
+% want to convert to X, the corresponding 4xN 2-space matrix
+%
+% tmp1=[(x-axm)./axr; ones(1,size(x,1))];
+% if (oneax), X=T*tmp1;
+% else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
+% tmp2=zeros(4,4*N); tmp2(:)=tmp1(:);
+% X=zeros(4,N); X(:)=sum(tmp2)'; end;
+% X = X ./ (ones(4,1)*X(4,:));
+% for all points with start==stop, start=stop-(verysmallvalue)*(up-direction);
+ii = find(all(start==stop));
+if ~isempty(ii),
+ % find an arrowdir vertical on screen and perpendicular to viewer
+ % transform to 2-D
+ tmp1 = [(stop(:,ii)-axm(:,ii))./axr(:,ii);ones(1,length(ii))];
+ if (oneax), twoD=T*tmp1;
+ else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,ii).*tmp1;
+ tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:);
+ twoD=zeros(4,length(ii)); twoD(:)=sum(tmp2)'; end;
+ twoD=twoD./(ones(4,1)*twoD(4,:));
+ % move the start point down just slightly
+ tmp1 = twoD + [0;-1/1000;0;0]*(limrange(2,ii)./ap(2,ii));
+ % transform back to 3-D
+ if (oneax), threeD=invT*tmp1;
+ else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT(:,ii).*tmp1;
+ tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:);
+ threeD=zeros(4,length(ii)); threeD(:)=sum(tmp2)'; end;
+ start(:,ii) = (threeD(1:3,:)./(ones(3,1)*threeD(4,:))).*axr(:,ii)+axm(:,ii);
+end;
+% compute along-arrow points
+% transform Start points
+ tmp1=[(start-axm)./axr;ones(1,narrows)];
+ if (oneax), X0=T*tmp1;
+ else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
+ tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
+ X0=zeros(4,narrows); X0(:)=sum(tmp2)'; end;
+ X0=X0./(ones(4,1)*X0(4,:));
+% transform Stop points
+ tmp1=[(stop-axm)./axr;ones(1,narrows)];
+ if (oneax), Xf=T*tmp1;
+ else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
+ tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
+ Xf=zeros(4,narrows); Xf(:)=sum(tmp2)'; end;
+ Xf=Xf./(ones(4,1)*Xf(4,:));
+% compute pixel distance between points
+ D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*(ap./limrange)).^2));
+ D = D + (D==0); %eaj new 2/24/98
+% compute and modify along-arrow distances
+ len1 = len;
+ len2 = len - (len.*tan(tipangle/180*pi)-wid/2).*tan((90-baseangle)/180*pi);
+ slen0 = zeros(1,narrows);
+ slen1 = len1 .* ((ends==2)|(ends==3));
+ slen2 = len2 .* ((ends==2)|(ends==3));
+ len0 = zeros(1,narrows);
+ len1 = len1 .* ((ends==1)|(ends==3));
+ len2 = len2 .* ((ends==1)|(ends==3));
+ % for no start arrowhead
+ ii=find((ends==1)&(D0), set(H,extraprops{:}); end;
+ % handle choosing arrow Start and/or Stop locations if unspecified
+ [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims);
+ if ~isempty(errstr), error([upper(mfilename) ' got ' errstr]); end;
+ % set the output
+ if (nargout>0), h=H; end;
+ % make sure the axis limits did not change
+ if isempty(oldaxlims),
+ ARROW_AXLIMITS = [];
+ else,
+ lims = get(oldaxlims(:,1),{'XLim','YLim','ZLim'})';
+ lims = reshape(cat(2,lims{:}),6,size(lims,2));
+ mask = arrow_is2DXY(oldaxlims(:,1));
+ oldaxlims(mask,6:7) = lims(5:6,mask)';
+ ARROW_AXLIMITS = oldaxlims(find(any(oldaxlims(:,2:7)'~=lims)),:);
+ if ~isempty(ARROW_AXLIMITS),
+ warning(arrow_warnlimits(ARROW_AXLIMITS,narrows));
+ end;
+ end;
+else,
+ % don't create the patch, just return the data
+ h=x;
+ yy=y;
+ zz=z;
+end;
+function out = arrow_defcheck(in,def,prop)
+% check if we got 'default' values
+ out = in;
+ if ~isstr(in), return; end;
+ if size(in,1)==1 & strncmp(lower(in),'def',3),
+ out = def;
+ elseif ~isempty(prop),
+ error([upper(mfilename) ' does not recognize ''' in(:)' ''' as a valid ''' prop ''' string.']);
+ end;
+function [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims)
+% handle choosing arrow Start and/or Stop locations if necessary
+ errstr = '';
+ if isempty(H)|isempty(ud)|isempty(x), return; end;
+ % determine which (if any) need Start and/or Stop
+ needStart = all(isnan(ud(:,1:3)'))';
+ needStop = all(isnan(ud(:,4:6)'))';
+ mask = any(needStart|needStop);
+ if ~any(mask), return; end;
+ ud(~mask,:)=[]; ax(:,~mask)=[];
+ x(:,~mask)=[]; y(:,~mask)=[]; z(:,~mask)=[];
+ % make them invisible for the time being
+ set(H,'Visible','off');
+ % save the current axes and limits modes; set to manual for the time being
+ oldAx = gca;
+ limModes=get(ax(:),{'XLimMode','YLimMode','ZLimMode'});
+ set(ax(:),{'XLimMode','YLimMode','ZLimMode'},{'manual','manual','manual'});
+ % loop over each arrow that requires attention
+ jj = find(mask);
+ for ii=1:length(jj),
+ h = H(jj(ii));
+ axes(ax(ii));
+ % figure out correct call
+ if needStart(ii), prop='Start'; else, prop='Stop'; end;
+ [wasInterrupted,errstr] = arrow_click(needStart(ii)&needStop(ii),h,prop,ax(ii));
+ % handle errors and control-C
+ if wasInterrupted,
+ delete(H(jj(ii:end)));
+ H(jj(ii:end))=[];
+ oldaxlims(jj(ii:end),:)=[];
+ break;
+ end;
+ end;
+ % restore the axes and limit modes
+ axes(oldAx);
+ set(ax(:),{'XLimMode','YLimMode','ZLimMode'},limModes);
+function [wasInterrupted,errstr] = arrow_click(lockStart,H,prop,ax)
+% handle the clicks for one arrow
+ fig = get(ax,'Parent');
+ % save some things
+ oldFigProps = {'Pointer','WindowButtonMotionFcn','WindowButtonUpFcn'};
+ oldFigValue = get(fig,oldFigProps);
+ oldArrowProps = {'EraseMode'};
+ oldArrowValue = get(H,oldArrowProps);
+ set(H,'EraseMode','background'); %because 'xor' makes shaft invisible unless Width>1
+ global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z
+ ARROW_CLICK_H=H; ARROW_CLICK_PROP=prop; ARROW_CLICK_AX=ax;
+ ARROW_CLICK_USE_Z=~arrow_is2DXY(ax)|~arrow_planarkids(ax);
+ set(fig,'Pointer','crosshair');
+ % set up the WindowButtonMotion so we can see the arrow while moving around
+ set(fig,'WindowButtonUpFcn','set(gcf,''WindowButtonUpFcn'','''')', ...
+ 'WindowButtonMotionFcn','');
+ if ~lockStart,
+ set(H,'Visible','on');
+ set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']);
+ end;
+ % wait for the button to be pressed
+ [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig);
+ % if we wanted to click-drag, set the Start point
+ if lockStart & ~wasInterrupted,
+ pt = arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z);
+ feval(mfilename,H,'Start',pt,'Stop',pt);
+ set(H,'Visible','on');
+ ARROW_CLICK_PROP='Stop';
+ set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']);
+ % wait for the mouse button to be released
+ eval('waitfor(fig,''WindowButtonUpFcn'','''');','wasInterrupted=1;');
+ if wasInterrupted, errstr=lasterr; end;
+ end;
+ if ~wasInterrupted, feval(mfilename,'callback','motion'); end;
+ % restore some things
+ set(gcf,oldFigProps,oldFigValue);
+ set(H,oldArrowProps,oldArrowValue);
+function arrow_callback(varargin)
+% handle redrawing callbacks
+ if nargin==0, return; end;
+ str = varargin{1};
+ if ~isstr(str), error([upper(mfilename) ' got an invalid Callback command.']); end;
+ s = lower(str);
+ if strcmp(s,'motion'),
+ % motion callback
+ global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z
+ feval(mfilename,ARROW_CLICK_H,ARROW_CLICK_PROP,arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z));
+ drawnow;
+ else,
+ error([upper(mfilename) ' does not recognize ''' str(:).' ''' as a valid Callback option.']);
+ end;
+function out = arrow_point(ax,use_z)
+% return the point on the given axes
+ if nargin==0, ax=gca; end;
+ if nargin<2, use_z=~arrow_is2DXY(ax)|~arrow_planarkids(ax); end;
+ out = get(ax,'CurrentPoint');
+ out = out(1,:);
+ if ~use_z, out=out(1:2); end;
+function [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig)
+% wait for button down ignoring object ButtonDownFcn's
+ if nargin==0, fig=gcf; end;
+ errstr = '';
+ % save ButtonDownFcn values
+ objs = findobj(fig);
+ buttonDownFcns = get(objs,'ButtonDownFcn');
+ mask=~strcmp(buttonDownFcns,''); objs=objs(mask); buttonDownFcns=buttonDownFcns(mask);
+ set(objs,'ButtonDownFcn','');
+ % save other figure values
+ figProps = {'KeyPressFcn','WindowButtonDownFcn'};
+ figValue = get(fig,figProps);
+ % do the real work
+ set(fig,'KeyPressFcn','set(gcf,''KeyPressFcn'','''',''WindowButtonDownFcn'','''');', ...
+ 'WindowButtonDownFcn','set(gcf,''WindowButtonDownFcn'','''')');
+ lasterr('');
+ wasInterrupted=0; eval('waitfor(fig,''WindowButtonDownFcn'','''');','wasInterrupted=1;');
+ wasKeyPress = ~wasInterrupted & strcmp(get(fig,'KeyPressFcn'),'');
+ if wasInterrupted, errstr=lasterr; end;
+ % restore ButtonDownFcn and other figure values
+ set(objs,'ButtonDownFcn',buttonDownFcns);
+ set(fig,figProps,figValue);
+function [out,is2D] = arrow_is2DXY(ax)
+% check if axes are 2-D X-Y plots
+ % may not work for modified camera angles, etc.
+ out = logical(zeros(size(ax))); % 2-D X-Y plots
+ is2D = out; % any 2-D plots
+ views = get(ax(:),{'View'});
+ views = cat(1,views{:});
+ out(:) = abs(views(:,2))==90;
+ is2D(:) = out(:) | all(rem(views',90)==0)';
+function out = arrow_planarkids(ax)
+% check if axes descendents all have empty ZData (lines,patches,surfaces)
+ out = logical(ones(size(ax)));
+ allkids = get(ax(:),{'Children'});
+ for k=1:length(allkids),
+ kids = get([findobj(allkids{k},'flat','Type','line')
+ findobj(allkids{k},'flat','Type','patch')
+ findobj(allkids{k},'flat','Type','surface')],{'ZData'});
+ for j=1:length(kids),
+ if ~isempty(kids{j}), out(k)=logical(0); break; end;
+ end;
+ end;
+function arrow_fixlimits(axlimits)
+% reset the axis limits as necessary
+ if isempty(axlimits), disp([upper(mfilename) ' does not remember any axis limits to reset.']); end;
+ for k=1:size(axlimits,1),
+ if any(get(axlimits(k,1),'XLim')~=axlimits(k,2:3)), set(axlimits(k,1),'XLim',axlimits(k,2:3)); end;
+ if any(get(axlimits(k,1),'YLim')~=axlimits(k,4:5)), set(axlimits(k,1),'YLim',axlimits(k,4:5)); end;
+ if any(get(axlimits(k,1),'ZLim')~=axlimits(k,6:7)), set(axlimits(k,1),'ZLim',axlimits(k,6:7)); end;
+ end;
+function out = arrow_WarpToFill(notstretched,manualcamera,curax)
+% check if we are in "WarpToFill" mode.
+ out = strcmp(get(curax,'WarpToFill'),'on');
+ % 'WarpToFill' is undocumented, so may need to replace this by
+ % out = ~( any(notstretched) & any(manualcamera) );
+function out = arrow_warnlimits(axlimits,narrows)
+% create a warning message if we've changed the axis limits
+ msg = '';
+ switch (size(axlimits,1))
+ case 1, msg='';
+ case 2, msg='on two axes ';
+ otherwise, msg='on several axes ';
+ end;
+ msg = [upper(mfilename) ' changed the axis limits ' msg ...
+ 'when adding the arrow'];
+ if (narrows>1), msg=[msg 's']; end;
+ out = [msg '.' sprintf('\n') ' Call ' upper(mfilename) ...
+ ' FIXLIMITS to reset them now.'];
+function arrow_copyprops(fm,to)
+% copy line properties to patches
+ props = {'EraseMode','LineStyle','LineWidth','Marker','MarkerSize',...
+ 'MarkerEdgeColor','MarkerFaceColor','ButtonDownFcn', ...
+ 'Clipping','DeleteFcn','BusyAction','HandleVisibility', ...
+ 'Selected','SelectionHighlight','Visible'};
+ lineprops = {'Color', props{:}};
+ patchprops = {'EdgeColor',props{:}};
+ patch2props = {'FaceColor',patchprops{:}};
+ fmpatch = strcmp(get(fm,'Type'),'patch');
+ topatch = strcmp(get(to,'Type'),'patch');
+ set(to( fmpatch& topatch),patch2props,get(fm( fmpatch& topatch),patch2props)); %p->p
+ set(to(~fmpatch&~topatch),lineprops, get(fm(~fmpatch&~topatch),lineprops )); %l->l
+ set(to( fmpatch&~topatch),lineprops, get(fm( fmpatch&~topatch),patchprops )); %p->l
+ set(to(~fmpatch& topatch),patchprops, get(fm(~fmpatch& topatch),lineprops) ,'FaceColor','none'); %l->p
+function arrow_props
+% display further help info about ARROW properties
+ c = sprintf('\n');
+ disp([c ...
+ 'ARROW Properties: Default values are given in [square brackets], and other' c ...
+ ' acceptable equivalent property names are in (parenthesis).' c c ...
+ ' Start The starting points. For N arrows, B' c ...
+ ' this should be a Nx2 or Nx3 matrix. /|\ ^' c ...
+ ' Stop The end points. For N arrows, this /|||\ |' c ...
+ ' should be a Nx2 or Nx3 matrix. //|||\\ L|' c ...
+ ' Length Length of the arrowhead (in pixels on ///|||\\\ e|' c ...
+ ' screen, points on a page). [16] (Len) ////|||\\\\ n|' c ...
+ ' BaseAngle Angle (degrees) of the base angle /////|D|\\\\\ g|' c ...
+ ' ADE. For a simple stick arrow, use //// ||| \\\\ t|' c ...
+ ' BaseAngle=TipAngle. [90] (Base) /// ||| \\\ h|' c ...
+ ' TipAngle Angle (degrees) of tip angle ABC. //<----->|| \\ |' c ...
+ ' [16] (Tip) / base ||| \ V' c ...
+ ' Width Width of the base in pixels. Not E angle ||<-------->C' c ...
+ ' the ''LineWidth'' prop. [0] (Wid) |||tipangle' c ...
+ ' Page If provided, non-empty, and not NaN, |||' c ...
+ ' this causes ARROW to use hardcopy |||' c ...
+ ' rather than onscreen proportions. A' c ...
+ ' This is important if screen aspect --> <-- width' c ...
+ ' ratio and hardcopy aspect ratio are ----CrossDir---->' c ...
+ ' vastly different. []' c...
+ ' CrossDir A vector giving the direction towards which the fletches' c ...
+ ' on the arrow should go. [computed such that it is perpen-' c ...
+ ' dicular to both the arrow direction and the view direction' c ...
+ ' (i.e., as if it was pasted on a normal 2-D graph)] (Note' c ...
+ ' that CrossDir is a vector. Also note that if an axis is' c ...
+ ' plotted on a log scale, then the corresponding component' c ...
+ ' of CrossDir must also be set appropriately, i.e., to 1 for' c ...
+ ' no change in that direction, >1 for a positive change, >0' c ...
+ ' and <1 for negative change.)' c ...
+ ' NormalDir A vector normal to the fletch direction (CrossDir is then' c ...
+ ' computed by the vector cross product [Line]x[NormalDir]). []' c ...
+ ' (Note that NormalDir is a vector. Unlike CrossDir,' c ...
+ ' NormalDir is used as is regardless of log-scaled axes.)' c ...
+ ' Ends Set which end has an arrowhead. Valid values are ''none'',' c ...
+ ' ''stop'', ''start'', and ''both''. [''stop''] (End)' c...
+ ' ObjectHandles Vector of handles to previously-created arrows to be' c ...
+ ' updated or line objects to be converted to arrows.' c ...
+ ' [] (Object,Handle)' c ]);
+function out = arrow_demo
+ % demo
+ % create the data
+ [x,y,z] = peaks;
+ [ddd,out.iii]=max(z(:));
+ out.axlim = [min(x(:)) max(x(:)) min(y(:)) max(y(:)) min(z(:)) max(z(:))];
+
+ % modify it by inserting some NaN's
+ [m,n] = size(z);
+ m = floor(m/2);
+ n = floor(n/2);
+ z(1:m,1:n) = NaN*ones(m,n);
+
+ % graph it
+ clf('reset');
+ out.hs=surf(x,y,z);
+ out.x=x; out.y=y; out.z=z;
+ xlabel('x'); ylabel('y');
+
+function h = arrow_demo3(in)
+ % set the view
+ axlim = in.axlim;
+ axis(axlim);
+ zlabel('z');
+ %set(in.hs,'FaceColor','interp');
+ view(viewmtx(-37.5,30,20));
+ title(['Demo of the capabilities of the ARROW function in 3-D']);
+
+ % Normal blue arrow
+ h1 = feval(mfilename,[axlim(1) axlim(4) 4],[-.8 1.2 4], ...
+ 'EdgeColor','b','FaceColor','b');
+
+ % Normal white arrow, clipped by the surface
+ h2 = feval(mfilename,axlim([1 4 6]),[0 2 4]);
+ t=text(-2.4,2.7,7.7,'arrow clipped by surf');
+
+ % Baseangle<90
+ h3 = feval(mfilename,[3 .125 3.5],[1.375 0.125 3.5],30,50);
+ t2=text(3.1,.125,3.5,'local maximum');
+
+ % Baseangle<90, fill and edge colors different
+ h4 = feval(mfilename,axlim(1:2:5)*.5,[0 0 0],36,60,25, ...
+ 'EdgeColor','b','FaceColor','c');
+ t3=text(axlim(1)*.5,axlim(3)*.5,axlim(5)*.5-.75,'origin');
+ set(t3,'HorizontalAlignment','center');
+
+ % Baseangle>90, black fill
+ h5 = feval(mfilename,[-2.9 2.9 3],[-1.3 .4 3.2],30,120,[],6, ...
+ 'EdgeColor','r','FaceColor','k','LineWidth',2);
+
+ % Baseangle>90, no fill
+ h6 = feval(mfilename,[-2.9 2.9 1.3],[-1.3 .4 1.5],30,120,[],6, ...
+ 'EdgeColor','r','FaceColor','none','LineWidth',2);
+
+ % Stick arrow
+ h7 = feval(mfilename,[-1.6 -1.65 -6.5],[0 -1.65 -6.5],[],16,16);
+ t4=text(-1.5,-1.65,-7.25,'global mininum');
+ set(t4,'HorizontalAlignment','center');
+
+ % Normal, black fill
+ h8 = feval(mfilename,[-1.4 0 -7.2],[-1.4 0 -3],'FaceColor','k');
+ t5=text(-1.5,0,-7.75,'local minimum');
+ set(t5,'HorizontalAlignment','center');
+
+ % Gray fill, crossdir specified, 'LineStyle' --
+ h9 = feval(mfilename,[-3 2.2 -6],[-3 2.2 -.05],36,[],27,6,[],[0 -1 0], ...
+ 'EdgeColor','k','FaceColor',.75*[1 1 1],'LineStyle','--');
+
+ % a series of normal arrows, linearly spaced, crossdir specified
+ h10y=(0:4)'/3;
+ h10 = feval(mfilename,[-3*ones(size(h10y)) h10y -6.5*ones(size(h10y))], ...
+ [-3*ones(size(h10y)) h10y -.05*ones(size(h10y))], ...
+ 12,[],[],[],[],[0 -1 0]);
+
+ % a series of normal arrows, linearly spaced
+ h11x=(1:.33:2.8)';
+ h11 = feval(mfilename,[h11x -3*ones(size(h11x)) 6.5*ones(size(h11x))], ...
+ [h11x -3*ones(size(h11x)) -.05*ones(size(h11x))]);
+
+ % series of magenta arrows, radially oriented, crossdir specified
+ h12x=2; h12y=-3; h12z=axlim(5)/2; h12xr=1; h12zr=h12z; ir=.15;or=.81;
+ h12t=(0:11)'/6*pi;
+ h12 = feval(mfilename, ...
+ [h12x+h12xr*cos(h12t)*ir h12y*ones(size(h12t)) ...
+ h12z+h12zr*sin(h12t)*ir],[h12x+h12xr*cos(h12t)*or ...
+ h12y*ones(size(h12t)) h12z+h12zr*sin(h12t)*or], ...
+ 10,[],[],[],[], ...
+ [-h12xr*sin(h12t) zeros(size(h12t)) h12zr*cos(h12t)],...
+ 'FaceColor','none','EdgeColor','m');
+
+ % series of normal arrows, tangentially oriented, crossdir specified
+ or13=.91; h13t=(0:.5:12)'/6*pi;
+ locs = [h12x+h12xr*cos(h13t)*or13 h12y*ones(size(h13t)) h12z+h12zr*sin(h13t)*or13];
+ h13 = feval(mfilename,locs(1:end-1,:),locs(2:end,:),6);
+
+ % arrow with no line ==> oriented downwards
+ h14 = feval(mfilename,[3 3 .100001],[3 3 .1],30);
+ t6=text(3,3,3.6,'no line'); set(t6,'HorizontalAlignment','center');
+
+ % arrow with arrowheads at both ends
+ h15 = feval(mfilename,[-.5 -3 -3],[1 -3 -3],'Ends','both','FaceColor','g', ...
+ 'Length',20,'Width',3,'CrossDir',[0 0 1],'TipAngle',25);
+
+ h=[h1;h2;h3;h4;h5;h6;h7;h8;h9;h10;h11;h12;h13;h14;h15];
+function h = arrow_demo2(in)
+ axlim = in.axlim;
+ dolog = 1;
+ if (dolog), set(in.hs,'YData',10.^get(in.hs,'YData')); end;
+ shading('interp');
+ view(2);
+ title(['Demo of the capabilities of the ARROW function in 2-D']);
+ hold on; [C,H]=contour(in.x,in.y,in.z,20,'-'); hold off;
+ for k=H',
+ set(k,'ZData',(axlim(6)+1)*ones(size(get(k,'XData'))),'Color','k');
+ if (dolog), set(k,'YData',10.^get(k,'YData')); end;
+ end;
+ if (dolog), axis([axlim(1:2) 10.^axlim(3:4)]); set(gca,'YScale','log');
+ else, axis(axlim(1:4)); end;
+
+ % Normal blue arrow
+ start = [axlim(1) axlim(4) axlim(6)+2];
+ stop = [in.x(in.iii) in.y(in.iii) axlim(6)+2];
+ if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end;
+ h1 = feval(mfilename,start,stop,'EdgeColor','b','FaceColor','b');
+
+ % three arrows with varying fill, width, and baseangle
+ start = [-3 -3 10; -3 -1.5 10; -1.5 -3 10];
+ stop = [-.03 -.03 10; -.03 -1.5 10; -1.5 -.03 10];
+ if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end;
+ h2 = feval(mfilename,start,stop,24,[90;60;120],[],[0;0;4],'Ends',str2mat('both','stop','stop'));
+ set(h2(2),'EdgeColor',[0 .35 0],'FaceColor',[0 .85 .85]);
+ set(h2(3),'EdgeColor','r','FaceColor',[1 .5 1]);
+ h=[h1;h2];
+function out = trueornan(x)
+if isempty(x),
+ out=x;
+else,
+ out = isnan(x);
+ out(~out) = x(~out);
+end;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/arrow3.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/arrow3.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,545 @@
+function H=arrow3(p1,p2,s,w,h,ip,alpha,beta)
+% ARROW3
+% ARROW3(P1,P2) will draw vector lines (2D/3D) from P1 to P2 with
+% arrowheads, where P1 and P2 can be either nx2 matrices (for 2D),
+% or nx3 matrices (for 3D).
+%
+% ARROW3(P1,P2,S,W,H,IP,ALPHA,BETA) can be used to specify properties
+% of the line and arrowhead. S is a character string made with one
+% element from any or all of the following 3 columns:
+%
+% Color Switches LineStyle LineWidth
+% ------------------ ------------------- --------------------
+% k black (default) - solid (default) 0.5 points (default)
+% y yellow : dotted 0 no lines
+% m magenta -. dashdot / LineWidthOrder
+% c cyan -- dashed
+% r red * LineStyleOrder
+% g green
+% b blue
+% w white __________ __
+% a apple green ^ |
+% d dark gray / \ |
+% e evergreen / \ |
+% f fuchsia / \ |
+% h honey / \ Height
+% i indigo / \ |
+% j jade / \ |
+% l lilac / \ |
+% n nutbrown /______ ______\ __|__
+% p pink | | | |
+% q kumquat |---- Width ----|
+% s sky blue | | | |
+% t tan | |
+% u umber | |
+% v violet | |
+% z zinc -->| |<--LineWidth
+% x random named color | |
+% o ColorOrder
+%
+% The components of S may be specified in any order. Invalid
+% characters in S will be ignored and replaced by default settings.
+%
+% Prefixing the color code with '_' produces a darker shade, e.g.
+% '_t' is dark tan; prefixing the color code with '^' produces a
+% lighter shade, e.g. '^q' is light kumquat. The relative
+% brightness of light and dark color shades is controled by the
+% scalar parameter BETA. Color code prefixes do not affect the
+% basic colors (kymcrgbw) or the special color switches (xo).
+%
+% ColorOrder may be achieved in two fashions: The user may either
+% set the ColorOrder property (using RGB triples) or define the
+% global variable ColorOrder (using a string of valid color codes).
+% If the color switch is specified with 'o', and the global variable
+% ColorOrder is a string of color codes (color switches less 'x' and
+% 'o', optionally prefixed with '_' or '^'), then the ColorOrder
+% property will be set to the sequence of colors indicated by the
+% ColorOrder variable. If the color switch is specified with 'o',
+% and the global variable ColorOrder is empty or invalid, then the
+% current ColorOrder property will be used. Note that the ColorOrder
+% variable takes precedence over the ColorOrder property.
+%
+% The current LineStyleOrder property will be used if LineStyle is
+% specified with '*'. MATLAB cycles through the line styles defined
+% by the LineStyleOrder property only after using all colors defined
+% by the ColorOrder property. If however, the global variable
+% LineWidthOrder is defined, and LineWidth is specified with '/',
+% then each line will be drawn with sequential color, linestyle, and
+% linewidth.
+%
+% W is a vector of arrowhead widths. For linear plots with equal
+% axes, the units of W (default = 1/72 of the PlotBox diagonal) are
+% the same as those of the coordinate data (P1,P2). For linear plots
+% with unequal axes, the units of W are scaled to fit as if the axes
+% were equal. For log plots, the units of W (default = 1) are 1/72
+% of the PositionRectangle diagonal.
+%
+% H (default = 3W) is a vector of arrowhead heights. If vector IP is
+% neither empty nor negative, initial point markers will be plotted
+% with diameter IP; for default diameter W, use IP = 0. The units of
+% W, H, and IP are absolute for linear plots and relative to the
+% PositionRectangle for log plots.
+%
+% ALPHA (default = 1) is a vector of FaceAlpha (MATLAB 6+) values
+% ranging between 0 (clear) and 1 (opaque). FaceAlpha is a surface
+% (arrowhead and initial point marker) property and does not affect
+% lines. BETA (default = 0.4) is a scalar that controls the relative
+% brightness of light and dark color shades, ranging between 0 (no
+% contrast) and 1 (maximum contrast).
+%
+% Plotting lines with a single color, linestyle, and linewidth is
+% faster than plotting lines with multiple colors and/or linestyles.
+% Plotting lines with multiple linewidths is slower still.
+%
+% H = ARROW3(P1,P2,...) returns a vector of handles to line and
+% surface objects created by ARROW3.
+%
+% ARROW3 COLORS will plot a table of named colors with default
+% brightness. ARROW3('colors',BETA) will plot a table of named
+% colors with brightness BETA.
+%
+% If a particular aspect ratio is required, use DASPECT, PBASPECT,
+% AXIS, or XYZLIM commands before calling ARROW3. Changing aspect
+% ratios or limits after calling ARROW3 may alter the appearance
+% of arrowheads and initial point markers. ARROW3 sets XYZLimMode
+% to manual for all plots, sets DataAspectRatioMode to manual for
+% linear plots, and sets PlotBoxAspectRatioMode to manual for log
+% plots and 3D plots.
+%
+% ARROW3 UPDATE will restore the the appearance of arrowheads and
+% initial point markers that have become corrupted by changes to
+% limits or aspect ratios. ARROW3('update',SF) will redraw initial
+% point markers and arrowheads with scale factor SF. If SF has one
+% one element, SF scales W, H and IP. If SF has two elements, SF(1)
+% scales W and IP, and SF(2) scales H. If SF has three elements,
+% SF(1) scales W, SF(2) scales H, and SF(3) scales IP.
+%
+% Usage Examples:
+%
+% % 2D vectors
+% Arrow3([0 0],[1 3])
+% Arrow3([0 0],[1 2],'-.e')
+% Arrow3([0 0],[10 10],'--x2',1)
+% Arrow3(zeros(10,2),50*rand(10,2),'x',1,3)
+% Arrow3(zeros(10,2),[10*rand(10,1),500*rand(10,1)],'u')
+% Arrow3(10*rand(10,2),50*rand(10,2),'x',1,[],1)
+%
+% % 3D vectors
+% Arrow3([0 0 0],[1 1 1])
+% Arrow3(zeros(20,3),50*rand(20,3),'--x1.5',2)
+% Arrow3(zeros(100,3),50*rand(100,3),'x',1,3)
+% Arrow3(zeros(10,3),[10*rand(10,1),500*rand(10,1),50*rand(10,1)],'a')
+% Arrow3(10*rand(10,3),50*rand(10,3),'x',[],[],0)
+%
+% % Just for fun
+% Arrow3(zeros(100,3),50*rand(100,3),'x',10,3,[],0.95)
+% light('Position',[-10 -10 -10],'Style','local')
+% light('Position',[60,60,60]), lighting gouraud
+%
+% % ColorOrder variable, color code prefixes, and Beta
+% global ColorOrder, ColorOrder='^ui^e_hq^v';
+% theta=[0:pi/22:pi/2]';
+% Arrow3(zeros(12,2),[cos(theta),sin(theta)],'1.5o',0.1,[],[],[],0.5)
+%
+% % ColorOrder property, LineStyleOrder, LineWidthOrder, and Alpha
+% global ColorOrder, ColorOrder=[];
+% set(gca,'ColorOrder',[1,0,0;0,0,1;0.25,0.75,0.25;0,0,0])
+% set(gca,'LineStyleOrder',{'-','--','-.',':'})
+% global LineWidthOrder, LineWidthOrder=[1,2,4,8];
+% w=[5,10,15,20]; h=[20,40,30,40]; alpha=[1,1,0.2,0.2];
+% Arrow3(zeros(4,2),[10*rand(4,1),500*rand(4,1)],'o*/',w,h,10,alpha)
+%
+% % Log plot
+% loglog([1e2,1e8],[1e-2,1e-1],'wo','MarkerSize',eps), hold on
+% p1=repmat([1e3,2e-2],15,1);
+% q1=[1e7,1e6,1e5,1e4,1e3,1e7,1e7,1e7,1e7,1e7,1e7,1e6,1e5,1e4,1e3];
+% q2=1e-2*[9,9,9,9,9,7,5,4,3,2,1,1,1,1,1]; p2=[q1',q2'];
+% global ColorOrder, ColorOrder=[];
+% set(gca,'ColorOrder',rand(15,3))
+% Arrow3(p1,p2,'o'), grid on, hold off
+%
+% % Color tables
+% Arrow3('colors') % default color table
+% Arrow3('colors',0.3) % low contrast color table
+% Arrow3('colors',0.5) % high contrast color table
+%
+% % Update initial point markers and arrowheads
+% Arrow3('update') % redraw same size
+% Arrow3('update',2) % redraw double size
+% Arrow3('update',0.5) % redraw half size
+% Arrow3('update',[0.5,2,1]) % redraw W half size,
+% % H double size, and
+% % IP same size
+
+% Copyright(c)2002,2003 Version 4.54
+% Jeff Chang
+% Tom Davis
+
+% Revision History:
+%
+% 02/01/03 - Added UPDATE scale factor and matlab version
+% checking, replaced call to CROSS (TD)
+% 12/26/02 - Added UserData and UPDATE option (TD)
+% 11/16/02 - Added more named colors, color code prefix,
+% global ColorOrder, ALPHA , and BETA (TD)
+% 10/12/02 - Added global LineWidthOrder,
+% vectorized W, H and IP (TD)
+% 10/05/02 - Changed CLF to CLA for subplot support,
+% added ColorOrder and LineStyleOrder support (TD)
+% 04/27/02 - Minor log plot revisions (TD)
+% 03/26/02 - Added log plot support (TD)
+% 03/24/02 - Adaptive grid spacing control to trade off
+% appearance vs. speed based on size of matrix (JC)
+% 03/16/02 - Added "axis tight" for improved appearance (JC)
+% 03/12/02 - Added initial point marker (TD)
+% 03/03/02 - Added aspect ratio support (TD)
+% 03/02/02 - Enchance program's user friendliness (JC)
+% (lump Color, LineStyle, and LineWidth together)
+% 03/01/02 - Replaced call to ROTATE (TD)
+% 02/28/02 - Modified line plotting,
+% added linewidth and linestyle (TD)
+% 02/27/02 - Minor enhancements on 3D appearance (JC)
+% 02/26/02 - Minor enhancements for speed (TD&JC)
+% 02/26/02 - Optimise PLOT3 and SURF for speed (TD)
+% 02/25/02 - Return handler, error handling, color effect,
+% generalize for 2D/3D vectors (JC)
+% 02/24/02 - Optimise PLOT3 and SURF for speed (TD)
+% 02/23/02 - First release (JC&TD)
+
+%==========================================================================
+% Error Checking
+oldver=0; v=version; if v(1)<'6', oldver=1; end % matlab version
+if nargin<8 | isempty(beta), beta=0.4; end, beta=abs(beta(1));
+if strcmpi(p1,'colors') % plot color table
+ if nargin>1, beta=abs(p2(1)); end
+ LocalColorTable(1,beta); return
+end
+fig=gcf; ax=gca;
+if strcmpi(p1,'update'), ud=get(ax,'UserData'); % update surfaces
+ if size(ud,2)<13, error('Invalid UserData'), end
+ set(ax,'UserData',[]); sf=[1,1,1];
+ if nargin>1, sf=p2(1)*sf; n=length(p2(:));
+ if n>1, sf(2)=p2(2); if n>2, sf(3)=p2(3); end, end
+ end
+ LocalUpdate(fig,ax,ud,sf); return
+end
+InputError=['Invalid input, type HELP ',upper(mfilename),...
+ ' for usage examples'];
+if nargin<2, error(InputError), end
+[r1,c1]=size(p1); [r2,c2]=size(p2); n=r1; Zeros=zeros(n,1);
+if c1<2 | c1>3, error(InputError), end
+if r1~=r2, error('P1 and P2 must have same number of rows'), end
+if c1~=c2, error('P1 and P2 must have same number of columns'), end
+if c1==2, p1=[p1,Zeros]; p2=[p2,Zeros];
+elseif ~any([p1(:,3);p2(:,3)]), c1=2; end
+L=get(ax,'LineStyleOrder'); C=get(ax,'ColorOrder');
+ST=get(ax,'DefaultSurfaceTag'); LT=get(ax,'DefaultLineTag');
+EC=get(ax,'DefaultSurfaceEdgeColor');
+if strcmp(get(ax,'nextplot'),'add') & strcmp(get(fig,'nextplot'),'add')
+ Xr=get(ax,'xlim'); Yr=get(ax,'ylim'); Zr=get(ax,'zlim');
+ set(ax,'XLimMode','auto','YLimMode','auto','ZLimMode','auto');
+ xs=strcmp(get(ax,'xscale'),'log');
+ ys=strcmp(get(ax,'yscale'),'log');
+ zs=strcmp(get(ax,'zscale'),'log');
+ if zs, error('Z log scale not supported'), end
+ xys=xs+ys; restore=1;
+ if xys & any([p1(:,3);p2(:,3)])
+ error('3D log plot not supported')
+ end
+else, restore=0; cla; view(c1); xys=0;
+ set(fig,'nextplot','add'); set(ax,'UserData',[],'nextplot','add');
+end
+
+%==========================================================================
+% Style Control
+[vc,cn]=LocalColorTable(0); prefix=''; OneColor=0;
+if nargin<3, [c,ls,lw]=LocalValidateCLSW; % default Color, LineStyle/Width
+else,
+ [c,ls,lw]=LocalValidateCLSW(s);
+ if length(c)>1, if sum('_^'==c(1)), prefix=c(1); end, c=c(2); end
+ if c=='x', c=cn(randperm(23),:); % random named color (less white)
+ elseif c=='o', global ColorOrder % ColorOrder
+ if length(ColorOrder)
+ [c,failed]=LocalColorMap(lower(ColorOrder),vc,cn,beta);
+ if failed, warning(['Invalid ColorOrder variable, ',...
+ 'current ColorOrder property will be used'])
+ else, C=c; end
+ end, c=C;
+ elseif ~sum(vc==c), c='k'; warning(['Invalid color switch, ',...
+ 'default color (black) will be used'])
+ end
+end
+if length(c)==1 % single color
+ c=LocalColorMap([prefix,c],vc,cn,beta); OneColor=1;
+end
+set(ax,'ColorOrder',c); c=repmat(c,ceil(n/size(c,1)),1);
+if ls~='*', set(ax,'LineStyleOrder',ls); end % LineStyleOrder
+if lw=='/', global LineWidthOrder % LineWidthOrder
+ if length(LineWidthOrder)
+ lw=repmat(LineWidthOrder(:),ceil(n/length(LineWidthOrder)),1);
+ else, lw=0.5; warning(['Undefined LineWidthOrder, ',...
+ 'default width (0.5) will be used'])
+ end
+end
+if nargin<7 | isempty(alpha), alpha=1; end
+a=repmat(alpha(:),ceil(n/length(alpha)),1); % FaceAlpha
+
+%==========================================================================
+% Log Plot
+if xys
+ units=get(ax,'units'); set(ax,'units','points');
+ pos=get(ax,'position'); set(ax,'units',units);
+ if strcmp(get(ax,'PlotBoxAspectRatioMode'),'auto')
+ set(ax,'PlotBoxAspectRatio',[pos(3),pos(4),1]);
+ end
+ par=get(ax,'PlotBoxAspectRatio');
+ set(ax,'DataAspectRatio',[par(2),par(1),par(3)]);
+ % map coordinates onto unit square
+ q=[p1;p2]; xr=Xr; yr=Yr;
+ if xs, xr=log10(xr); q(:,1)=log10(q(:,1)); end
+ if ys, yr=log10(yr); q(:,2)=log10(q(:,2)); end
+ q=q-repmat([xr(1),yr(1),0],2*n,1);
+ dx=xr(2)-xr(1); dy=yr(2)-yr(1);
+ q=q*diag([1/dx,1/dy,1]);
+ q1=q(1:n,:); q2=q(n+1:end,:);
+else, xs=0; ys=0; dx=0; dy=0; xr=0; yr=0; end
+
+%==========================================================================
+% Line
+set(ax,'DefaultLineTag','arrow3');
+if length(lw)==1
+ if lw>0
+ if OneColor & ls~='*' % single color, linestyle, and linewidth
+ P=zeros(3*n,3); i=1:n;
+ P(3*i-2,:)=p1(i,:); P(3*i-1,:)=p2(i,:); P(3*i,1)=NaN;
+ H1=plot3(P(:,1),P(:,2),P(:,3),'LineWidth',lw);
+ else % single linewidth
+ H1=plot3([p1(:,1),p2(:,1)]',[p1(:,2),p2(:,2)]',...
+ [p1(:,3),p2(:,3)]','LineWidth',lw);
+ end
+ else, H1=[]; end
+else % use LineWidthOrder
+ ls=repmat(cellstr(L),ceil(n/size(L,1)),1);
+ H1=Zeros;
+ for i=1:n
+ H1(i)=plot3([p1(i,1),p2(i,1)],[p1(i,2),p2(i,2)],[p1(i,3),p2(i,3)],...
+ ls{i},'Color',c(i,:),'LineWidth',lw(i));
+ end
+end
+
+%==========================================================================
+% Scale
+ar=get(ax,'DataAspectRatio'); ar=sqrt(3)*ar/norm(ar);
+set(ax,'DataAspectRatioMode','manual');
+if nargin<4 | isempty(w) % width
+ if xys, w=1;
+ else, xr=get(ax,'xlim'); yr=get(ax,'ylim'); zr=get(ax,'zlim');
+ w=norm([xr(2)-xr(1),yr(2)-yr(1),zr(2)-zr(1)])/72;
+ end
+end
+w=repmat(w(:),ceil(n/length(w)),1);
+if nargin<5 | isempty(h), h=3*w; end % height
+h=repmat(h(:),ceil(n/length(h)),1);
+if nargin>5 & ~isempty(ip) % ip
+ i=find(ip==0); ip(i)=w(i);
+ ip=repmat(ip(:),ceil(n/length(ip)),1);
+else, ip=-ones(n,1); end
+
+%==========================================================================
+% UserData
+set(ax,'UserData',[get(ax,'UserData');...
+ p1,p2,c(1:n,:),w(1:n),h(1:n),ip(1:n),a]);
+
+%==========================================================================
+% Arrowhead
+if xys, whip=[w,h,ip]*sqrt(2)/72;
+ w=whip(:,1); h=whip(:,2); ip=whip(:,3); p1=q1; p2=q2;
+end
+W=(p1-p2)./repmat(ar,n,1);
+W=W./repmat(sqrt(sum(W.*W,2)),1,3); % new z direction
+U=[-W(:,2),W(:,1),Zeros];
+N=sqrt(sum(U.*U,2)); i=find(N num
+
+set(ax,'DefaultSurfaceTag','arrow3','DefaultSurfaceEdgeColor','none');
+[x,y,z]=cylinder([0,1],m);
+G=surface(x/2,y/2,z); dar=diag(ar);
+X=get(G,'XData'); Y=get(G,'YData'); Z=get(G,'ZData');
+H2=Zeros; [j,k]=size(X);
+for i=1:n % translate, rotate, and scale
+ H2(i)=copyobj(G,ax);
+ xyz=[w(i)*X(:),w(i)*Y(:),h(i)*Z(:)]*[U(i,:);V(i,:);W(i,:)]*dar;
+ x=reshape(xyz(:,1),j,k)+p2(i,1);
+ y=reshape(xyz(:,2),j,k)+p2(i,2);
+ z=reshape(xyz(:,3),j,k)+p2(i,3);
+ LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,...
+ x,y,z,a(i),c(i,:),H2(i),oldver);
+end, delete(G);
+
+%==========================================================================
+% Initial Point Marker
+if any(ip>0)
+ [x,y,z]=sphere(m);
+ G=surface(x*ar(1)/2,y*ar(2)/2,z*ar(3)/2);
+ X=get(G,'XData'); Y=get(G,'YData'); Z=get(G,'ZData');
+ H3=zeros(n,1);
+ for i=1:n % translate
+ if ip(i)>0
+ H3(i)=copyobj(G,ax);
+ x=p1(i,1)+X*ip(i); y=p1(i,2)+Y*ip(i); z=p1(i,3)+Z*ip(i);
+ LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,...
+ x,y,z,a(i),c(i,:),H3(i),oldver);
+ end
+ end, delete(G);
+else, H3=[]; end
+
+%==========================================================================
+% Finish
+if xys, xr=Xr; yr=Yr; zr=Zr;
+ set(ax,'DataAspectRatioMode','auto');
+else, set(fig,'Renderer','OpenGL');
+ w=max(w)*ar/2; ip=max([ip;0])*ar/2;
+ xr=[min([p1(:,1)-ip(1);p2(:,1)-w(1)]),max([p1(:,1)+ip(1);p2(:,1)+w(1)])];
+ yr=[min([p1(:,2)-ip(2);p2(:,2)-w(2)]),max([p1(:,2)+ip(2);p2(:,2)+w(2)])];
+ zr=[min([p1(:,3)-ip(3);p2(:,3)-w(3)]),max([p1(:,3)+ip(3);p2(:,3)+w(3)])];
+ if restore
+ xr=[min(xr(1),Xr(1)),max(xr(2),Xr(2))];
+ yr=[min(yr(1),Yr(1)),max(yr(2),Yr(2))];
+ zr=[min(zr(1),Zr(1)),max(zr(2),Zr(2))];
+ else, set(ax,'nextplot','replace'); end
+end
+set(ax,'LineStyleOrder',L,'ColorOrder',C,'DefaultLineTag',LT,...
+ 'DefaultSurfaceTag',ST,'DefaultSurfaceEdgeColor',EC,...
+ 'xlim',xr,'ylim',yr,'zlim',zr);
+if c1==3, set(ax,'CameraViewAngle',get(ax,'CameraViewAngle'),...
+ 'PlotBoxAspectRatio',get(ax,'PlotBoxAspectRatio'));
+end
+if nargout, H=[H1(:);H2(:);H3(:)]; end
+
+%==========================================================================
+% Update
+function LocalUpdate(fig,ax,ud,sf)
+p1=ud(:,1:3); p2=ud(:,4:6); c=ud(:,7:9); a=ud(:,13);
+w=sf(1)*ud(:,10); h=sf(2)*ud(:,11); ip=sf(3)*ud(:,12);
+H=get(ax,'children'); tag=get(H,'tag'); type=get(H,'type');
+delete(H(strcmp(tag,'arrow3') & strcmp(type,'surface')));
+set(fig,'nextplot','add'); set(ax,'ColorOrder',c,'nextplot','add');
+global ColorOrder, ColorOrder=[]; arrow3(p1,p2,'o0',w,h,ip,a);
+
+%==========================================================================
+% SetSurface
+function LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,x,y,z,a,c,H,oldver)
+if xys
+ x=x*dx+xr(1); y=y*dy+yr(1);
+ if xs, x=10.^x; end
+ if ys, y=10.^y; end
+end
+if oldver
+ set(H,'XData',x,'YData',y,'ZData',z,'FaceColor',c);
+else
+ set(H,'XData',x,'YData',y,'ZData',z,'FaceAlpha',a,'FaceColor',c);
+end
+
+%==========================================================================
+% ColorTable
+function [vc,cn]=LocalColorTable(n,beta)
+vc='kymcrgbadefhijlnpqstuvzw'; % valid color codes
+% k y m c
+cn=[0.00,0.00,0.00; 1.00,1.00,0.00; 1.00,0.00,1.00; 0.00,1.00,1.00;
+% r g b a
+ 1.00,0.00,0.00; 0.00,1.00,0.00; 0.00,0.00,1.00; 0.00,0.70,0.00;
+% d e f h
+ 0.40,0.40,0.40; 0.00,0.40,0.00; 0.90,0.00,0.40; 1.00,0.80,0.00;
+% i j l n
+ 0.00,0.00,0.70; 0.20,0.80,0.50; 0.80,0.40,0.80; 0.50,0.20,0.00;
+% p q s t
+ 1.00,0.40,0.60; 1.00,0.40,0.00; 0.00,0.80,1.00; 0.80,0.40,0.00;
+% u v z w
+ 0.70,0.00,0.00; 0.60,0.00,1.00; 0.60,0.60,0.60; 1.00,1.00,1.00;];
+if n % plot color table
+ name={'black','yellow','magenta','cyan',...
+ 'red','green','blue','apple green',...
+ 'dark gray','evergreen','fuchsia','honey',...
+ 'indigo','jade','lilac','nutbrown',...
+ 'pink','kumquat','sky blue','tan',...
+ 'umber','violet','zinc','white'};
+ c=['yhtn';'gjae';'csbi';'plmv';'frqu';'wzdk'];
+ clf, set(gcf,'DefaultAxesXTick',[],'DefaultAxesYTick',[],...
+ 'DefaultAxesXTickLabel',[],'DefaultAxesYTickLabel',[],...
+ 'DefaultAxesXLim',[0,0.75],'DefaultAxesYLim',[0,0.75],...
+ 'DefaultRectangleEdgeColor','none');
+ for i=1:24
+ subplot(4,6,i); j=find(vc==c(i)); title(name{j});
+ dark=LocalBrighten(cn(j,:),-beta);
+ light=LocalBrighten(cn(j,:),beta);
+ rectangle('Position',[0,0.00,0.75,0.25],'FaceColor',dark);
+ rectangle('Position',[0,0.25,0.75,0.25],'FaceColor',cn(j,:));
+ rectangle('Position',[0,0.50,0.75,0.25],'FaceColor',light);
+ rectangle('Position',[0,0.00,0.75,0.75],'EdgeColor','k');
+ if rem(i,6)==1
+ set(gca,'YTickLabel',{'dark','normal','light'},...
+ 'YTick',[0.125,0.375,0.625]);
+ if i==19
+ text(0,-0.25,['{\bf\itARROW3} Named Color Table ',...
+ '( \beta = ',num2str(beta),' )']);
+ end
+ end
+ end
+end
+
+%==========================================================================
+% ColorMap
+function [C,failed]=LocalColorMap(c,vc,cn,beta)
+n=length(c); failed=0; C=zeros(n,3); i=1; j=1;
+while 1
+ if isempty(find([vc,'_^']==c(i))), failed=1; break, end
+ if sum('_^'==c(i))
+ if i+1>n, failed=1; break, end
+ if ~sum(vc==c(i+1)), failed=1; break, end
+ cc=cn(find(vc==c(i+1)),:); gamma=beta;
+ if c(i)=='_', gamma=-beta; end
+ C(j,:)=LocalBrighten(cc,gamma); i=i+2;
+ else, C(j,:)=cn(find(vc==c(i)),:); i=i+1; end
+ if i>n, break, end, j=j+1;
+end, if n>j, C(j+1:n,:)=[]; end
+
+%==========================================================================
+% Brighten
+function C=LocalBrighten(c,beta)
+C=c.^((1-min(1-sqrt(eps),abs(beta)))^sign(beta));
+
+%==========================================================================
+% Generate valid value for color, linestyle and linewidth
+function [c,ls,lw]=LocalValidateCLSW(s)
+if nargin<1, c='k'; ls='-'; lw=0.5;
+else
+ % identify linestyle
+ if findstr(s,'--'), ls='--'; s=strrep(s,'--','');
+ elseif findstr(s,'-.'), ls='-.'; s=strrep(s,'-.','');
+ elseif findstr(s,'-'), ls='-'; s=strrep(s,'-','');
+ elseif findstr(s,':'), ls=':'; s=strrep(s,':','');
+ elseif findstr(s,'*'), ls='*'; s=strrep(s,'*','');
+ else, ls='-'; end
+
+ % identify linewidth
+ tmp=double(s);
+ tmp=find(tmp>45 & tmp<57);
+ if length(tmp)
+ if any(s(tmp)=='/'), lw='/'; else, lw=str2num(s(tmp)); end
+ s(tmp)='';
+ else, lw=0.5; end
+
+ % identify color
+ if length(s), s=lower(s);
+ if length(s)>1, c=s(1:2);
+ else, c=s(1); end
+ else, c='k'; end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/bin2time.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/bin2time.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% tool
+%
+% 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 res=bin2time(bin,samplerate)
+% gibt die Zeit zurück, bei dem dieses Bin ist
+% Zeit immer in Sekunden
+% Samplerate immer in Bins pro Sekunde (96 kHz)
+
+res=bin/samplerate;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ca.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ca.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,45 @@
+% 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 ca(namearg)
+% function ca('name'): close all open graphic windows that dont contain 'name' in their title
+
+if nargin==0
+ namearg='browser';
+% namearg{2}='aim-mat';
+end
+
+if ~iscell(namearg)
+ if ~ischar(namearg)
+ disp('ca only works with strings as input')
+ else
+ name{1}=namearg;
+ end
+% else
+% name=namearg;
+end
+
+
+
+
+all_windows=get(0,'children'); % is not identic to:
+all_windows=allchild(0);
+for i=1:length(all_windows)
+ if strcmp(get(all_windows(i),'type'),'figure');
+ titl=get(all_windows(i),'name');
+ can_be_cleared=1;
+ for j=1:length(name)
+ if ~isempty(strfind(titl,name{j}))
+ can_be_cleared=0;
+ end
+ end
+ if can_be_cleared
+% set(0,'ShowHiddenHandles','on')
+ close(all_windows(i));
+ end
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/calculate_spectral_profile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/calculate_spectral_profile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,52 @@
+% 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 spectal_profile=calculate_spectral_profile(wave_file)
+% function for Tim Griffith to plot the spectral profile from an simple
+% model
+
+% define the model:
+model_file='simple_model.m'; % this can be exchanged against any model produced with aim-mat by selecting "save standalone parameter file"
+
+% evaluate the model, so that it can passed to aimmat:
+% ( you have to be in the same directory as the model file!)
+[a,b,c]=fileparts(model_file);
+eval(b);
+
+% now there is a variable with the name all_parameters. Tell aimmat to
+% use the given soundfile
+all_options.signal.signal_name=wave_file;
+% tell it to use the full length and the given samplerate (this could be
+% changed here)
+sig=loadwavefile(signal,wave_file);
+all_options.signal.start_time=0;
+all_options.signal.duration=getlength(sig);
+all_options.signal.samplerate=getsr(sig);
+
+% call aimmat with the appropriate model:
+retdata=aim_ng(all_options);
+
+% the nap is now caluclated and available in the returning data structure:
+nap=retdata.data.nap;
+
+% we need the data:
+nap_values=getvalues(nap);
+
+% and calculate the profile:
+spectal_profile=sum(nap_values');
+
+% figure
+% % and plot it
+% plot(spectal_profile);
+
+% an easier (?) way to plot:
+options.frequency_profile_scale=0.7/max(spectal_profile);
+options.maximum_time_interval=getlength(sig);
+options.turn_axis_vertically=0;
+figure
+plotfrequencyprofile(nap,options);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/cell2double.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/cell2double.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% 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 doubles=cell2double(cell,name)
+% usage: doubles=cell2double(cell,name)
+% returns a array of doubles, if the cell is a string of numbers
+% the cell must have the filds name
+
+nr=length(cell);
+doubles=zeros(nr,1);
+
+for i=1:nr
+ eval(sprintf('doubles(i)=cell{i}.%s;',name));
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/cent2fre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/cent2fre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,13 @@
+% 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 hz=cent2fre(f0,cent)
+% usage: hz=cent2fre(sp,cent,oct)
+% returns the frequency of a cent-note, or this frequency in another octave
+% base is "A" at 27.5 Hz
+
+hz=f0*power(2,((cent)/1200));
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/combfrePtiP.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/combfrePtiP.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,181 @@
+% tool
+%
+% 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 combfrePtiP(framestruct_a);
+% combined graphic of frequency axis and time interval axis
+% on one axis
+% plots one graphic that consists of two parts:
+% the frequency profile and the interval profile on one axis
+
+graphix=1; % for debugging
+
+
+if ~isstruct(framestruct_a)
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+
+if ~isfield(framestruct,'show_time');
+ show_time=1;
+else
+ show_time=framestruct.show_time;
+end
+
+% scaling of the two individual profiles:
+if isfield(framestruct,'frequency_profile_scale');
+ frequency_profile_scale=framestruct.frequency_profile_scale;
+else
+ frequency_profile_scale=1;
+end
+if isfield(framestruct,'time_profile_scale');
+ time_profile_scale=framestruct.time_profile_scale;
+else
+ time_profile_scale=1;
+end
+
+current_frame=framestruct.current_frame;
+
+pitch_current_frame=current_frame;
+% schmeisse die physikalisch nicht sinnvollen Bereiche raus!
+% current_frame=extractpitchregion(current_frame);
+
+% berechne die pitches vom Orginal
+% pitch=calcresidualprobability(pitch_current_frame,graphix);
+
+% calculate the sum of the frequencies
+fresumme=getfrequencysum(current_frame);
+
+nrchannels=getnrchannels(current_frame);
+% smoothwidth=128/nrchannels;
+% smooth the sum with a smoothwidth of 1
+% fresumme=smooth(fresumme,smoothwidth);
+
+% calculate the sum from interval profile
+intsumme=getsum(current_frame);
+
+% bastel zwei lineare Funktionen zusammen: eine aus dem zeitlichen Verlauf,
+% und eine aus dem spektralen.
+minimum_time_interval=1;
+maximum_time_interval=32;
+
+% if the intervals are plotted positiv to the right, turn around the signal
+if getminimumtime(intsumme) >= 0
+ intsumme=reverse(intsumme);
+ intsumme=setstarttime(intsumme,-0.035);
+end
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Die Intervallsumme muss von linear auf logarithmisch umgestellt werden
+nr_points=getnrpoints(intsumme);
+intervalsum=logsigx(intsumme,-maximum_time_interval/1000,-minimum_time_interval/1000,nr_points);
+intervalsum=setstarttime(intervalsum,0);
+% ab nun haben wir eine lineare Zeitachse mit logarithmischen Werten
+
+global fnull;global stepsperoctave; % brauch ich unten in den Unterfunktionen
+% fnull=1000/32.389; % per Definition die niedrigste Frequenz
+fnull=1000/maximum_time_interval; % per Definition die niedrigste Frequenz = Anfangsfrequenz der gesamten Achse
+
+% soviel "cent" hat die Zeitachse.
+stepsperoctave=log2(maximum_time_interval/minimum_time_interval)/getnrpoints(intervalsum); % soviel octaven/Pixel
+intervalsum=setsr(intervalsum,1/stepsperoctave);
+% intervalsum now goes from -32 to -1 ms in the interval profile
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Die Frequenzsumme
+% plot the frequency profile in the same Graphic
+cfs=getcf(current_frame);
+minimum_fre=cfs(1); % the lowest frequency
+maximum_fre=cfs(end); % the lowest frequency
+srate=getsr(current_frame);
+
+% Die Frequenzsumme muss von erb (oder cfs) auf logarithmisch umgestellt werden
+fresumme=erb2log(fresumme,cfs);
+
+
+total_length=f2p(maximum_fre); % gesamte Länge des Plots
+start_fre_profile=f2p(minimum_fre); % Startpunkt der Frequenzachse
+stop_int_profile=f2p(1000/minimum_time_interval); % Ende des Überlapps
+
+nr_addpoints=total_length-stop_int_profile; % soviel Punkte müssen hinten an die Intervallachse
+tsig=signal(zeros(floor(nr_addpoints),1),getsr(intervalsum)); % Ein Nullensignal mit den richtigen Daten
+intervalsum=append(intervalsum,tsig); % hänge es an die Intervallsumme hinten an
+% glätte die Frequenzachse noch:
+% intervalsum=smooth(intervalsum,smoothwidth);
+
+
+nr_addpoints=start_fre_profile; % soviel Punkte müssen vor die Frequenzsumme gehängt werden
+
+% wieviel Punkte pro Octave in der Frequenzachse
+freoctrelation=log2(maximum_fre/minimum_fre)/getnrpoints(fresumme); % soviel octaven/Pixel
+fresumme=setsr(fresumme,1/freoctrelation); % anpassen der Zahl der Punkte auf die Intervalachse
+fresumme=changesr(fresumme,getsr(intervalsum));
+
+tsig=fresumme;
+tsig=setlength(tsig,bin2time(fresumme,nr_addpoints));
+tsig=mute(tsig);
+% tsig=signal(zeros(floor(nr_addpoints),1),getsr(fresumme)); %
+fresumme=append(tsig,fresumme);
+fresumme=setstarttime(fresumme,0);
+
+% scale both signals to the specified scaling values
+% scaling value, if in a movie
+scale_summe=getscalesumme(current_frame);
+fre_scale=getscalefrequency(current_frame);
+fresumme=scale(fresumme,1/fre_scale*frequency_profile_scale);
+intervalsum=scale(intervalsum,1/scale_summe*time_profile_scale);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% plot it both
+plot(intervalsum,'b');
+[intermaxpos,interminpos,intermax,intermin]=getminmax(intervalsum);
+intermaxpos=time2bin(intervalsum,intermaxpos);
+interminpos=time2bin(intervalsum,interminpos);
+hold on
+plot(fresumme,'r');
+[fremaxpos,freminpos,fremax,fremin]=getminmax(fresumme);
+fremaxpos=time2bin(fresumme,fremaxpos);
+freminpos=time2bin(fresumme,freminpos);
+axis([1 getnrpoints(fresumme) 0 1])
+% make x-Ticks
+nr_labels=8;ti=50*power(2,[0:7]);tix=f2p(ti);ti=round(ti*10)/10;
+set(gca,'XTick',tix);set(gca,'XTickLabel',ti);
+xlabel('Frequency [Hz]');ylabel('PitchStrength');title('');
+
+if show_time
+ srate=getsr(current_frame);
+ text_x=0.8*getnrpoints(fresumme);
+ text_y=0.9;
+ frame_number=getcurrentframenumber(current_frame);
+ frame_time=getcurrentframestarttime(current_frame);
+ text(text_x,text_y,sprintf('%3d : %4.0fms',frame_number,frame_time*1000),'FontSize',8);
+end
+
+return
+
+% Pixel 2 frequency
+function f=p2f(pix)
+global fnull;
+global stepsperoctave;
+f=fnull*power(2,(pix-1)*stepsperoctave);
+return
+
+function p=f2p(fre)
+global fnull;
+global stepsperoctave;
+p=1/stepsperoctave*log2(fre/fnull)+1;
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/combfrePtiPdots.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/combfrePtiPdots.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,255 @@
+% tool
+%
+% 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 pitch=combfrePtiPdots(framestruct_a);
+% combined graphic of frequency axis and time interval axis
+% on one axis
+% plots one graphic that consists of two parts:
+% the frequency profile and the interval profile on one axis
+
+if nargin < 2
+ grafix=0; % for debugging
+end
+dot_scaler=200; % wie gross Punkte dargestellt werden sollen in Punkt
+
+% wie weit die Intervallsumme runterskaliert werden muss, damit die Zahlen vernünftigt werden
+norm_intervalhight=100;
+% wie weit die spektrale Summe runterskaliert werden muss, damit die Zahlen vernünftigt werden
+norm_spektralhight=10;
+
+% how big must the contrast of the envelope be to be recognised as one pitch
+envcontrast_threshold=0.15;
+
+% A single factor, that can vary between
+% 0 = complete attention to temporal structure
+% 1 = complete attention to spectral structure
+spectral_attention_factor=0.5;
+
+if ~isstruct(framestruct_a)
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+
+if isfield(framestruct_a,'plot_only_highest') % if only one dot per line shell be plotted
+ plot_only_highest=framestruct_a.plot_only_highest;
+else
+ plot_only_highest=0;
+end
+
+if isfield(framestruct_a,'plot_bw') % on paper work with different colors
+ plot_bw=framestruct_a.plot_bw;
+else
+ plot_bw=0;
+end
+
+if isfield(framestruct_a,'normalise') % normalize the frame to a fixed value to get rid of effects of loudness and strobing points
+ normalise=framestruct_a.normalise;
+else
+ normalise=0;
+end
+
+% ob vorher die Region unten rechts rausgeworfen werden soll
+if ~isfield(framestruct_a,'extract_pitch_region');
+ extract_pitch_region=0;
+else
+ extract_pitch_region=framestruct_a.extract_pitch_region;
+end
+
+current_frame=framestruct.current_frame;
+
+% Wheh normalized, it is assumed that the overall energy in the stimulus is
+% always the same
+if normalise
+ current_frame=normaliseto(current_frame,1);
+end
+
+pitch_current_frame=current_frame;
+if extract_pitch_region
+ % schmeisse die physikalisch nicht sinnvollen Bereiche raus!
+ current_frame=extractpitchregion(current_frame);
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% % hier werden die Quellen berechnet:
+parameters=framestruct;
+pitch=calcresidualprobability(pitch_current_frame,parameters);
+
+% calculate the sum of the frequencies
+fresumme=getfrequencysum(current_frame);
+
+nrchannels=getnrchannels(current_frame);
+smoothwidth=128/nrchannels;
+% smooth the sum with a smoothwidth of 1
+fresumme=smooth(fresumme,smoothwidth);
+
+% calculate the sum from interval profile
+intsumme=getsum(current_frame);
+
+% scaling value, if in a movie
+scale_summe=getsumscale(current_frame);
+
+% start plotting:
+% clf;
+
+% bastel zwei lineare Funktionen zusammen: eine aus dem zeitlichen Verlauf,
+% und eine aus dem spektralen.
+minimum_time_interval=1;
+maximum_time_interval=32;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Die Intervallsumme muss von linear auf logarithmisch umgestellt werden
+nr_points=getnrpoints(intsumme);
+intervalsum=logsigx(intsumme,-maximum_time_interval/1000,-minimum_time_interval/1000,nr_points);
+intervalsum=setstarttime(intervalsum,0);
+% ab nun haben wir eine lineare Zeitachse mit logarithmischen Werten
+
+global fnull;global stepsperoctave; % brauch ich unten in den Unterfunktionen
+fnull=1000/maximum_time_interval; % per Definition die niedrigste Frequenz = Anfangsfrequenz der gesamten Achse
+
+% soviel "cent" hat die Zeitachse.
+stepsperoctave=log2(maximum_time_interval/minimum_time_interval)/getnrpoints(intervalsum); % soviel octaven/Pixel
+intervalsum=setsr(intervalsum,1/stepsperoctave);
+% intervalsum now goes from -32 to -1 ms in the interval profile
+% empirische Werte zum Skalieren auf einen einheitlichen Wert (1)
+intervalsum=scale(intervalsum,norm_intervalhight);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Die Frequenzsumme
+% plot the frequency profile in the same Graphic
+cfs=getcf(current_frame);
+minimum_fre=cfs(1); % the lowest frequency
+maximum_fre=cfs(end); % the lowest frequency
+
+total_length=f2p(maximum_fre); % gesamte Länge des Plots
+start_fre_profile=f2p(minimum_fre); % Startpunkt der Frequenzachse
+stop_int_profile=f2p(1000/minimum_time_interval); % Ende des Überlapps
+
+nr_addpoints=total_length-stop_int_profile; % soviel Punkte müssen hinten an die Intervallachse
+tsig=signal(zeros(floor(nr_addpoints),1),getsr(intervalsum)); % Ein Nullensignal mit den richtigen Daten
+intervalsum=append(intervalsum,tsig); % hänge es an die Intervallsumme hinten an
+% empirische Werte zum Skalieren auf einen einheitlichen Wert (1)
+
+% glätte die Frequenzachse:
+% intervalsum=smooth(intervalsum,smoothwidth);
+
+% Die Frequenzsumme muss von erb (oder cfs) auf logarithmisch umgestellt werden
+fresumme=erb2log(fresumme,cfs);
+
+nr_addpoints=start_fre_profile; % soviel Punkte müssen vor die Frequenzsumme gehängt werden
+
+% wieviel Punkte pro Octave in der Frequenzachse
+freoctrelation=log2(maximum_fre/minimum_fre)/getnrpoints(fresumme); % soviel octaven/Pixel
+fresumme=setsr(fresumme,1/freoctrelation); % anpassen der Zahl der Punkte auf die Intervalachse
+fresumme=changesr(fresumme,getsr(intervalsum));
+
+tsig=signal(zeros(floor(nr_addpoints),1),getsr(fresumme)); %
+fresumme=scale(fresumme,norm_spektralhight);
+
+fresumme=append(tsig,fresumme);
+fresumme=setstarttime(fresumme,0);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% plot it both
+if plot_bw
+ han=plot(intervalsum,'k--');
+ set(han,'linewidth',1);
+else
+ plot(intervalsum,'b');
+end
+[intermaxpos,interminpos,intermax,intermin]=getminmax(intervalsum);
+intermaxpos=time2bin(intervalsum,intermaxpos);
+interminpos=time2bin(intervalsum,interminpos);
+hold on
+if plot_bw
+ plot(fresumme,'k');
+else
+ plot(fresumme,'r');
+end
+[fremaxpos,freminpos,fremax,fremin]=getminmax(fresumme);
+fremaxpos=time2bin(fresumme,fremaxpos);
+freminpos=time2bin(fresumme,freminpos);
+axis([1 getnrpoints(fresumme) 0 1])
+% make x-Ticks
+nr_labels=8;ti=50*power(2,[0:7]);tix=f2p(ti);ti=round(ti*10)/10;
+set(gca,'XTick',tix);set(gca,'XTickLabel',ti);
+xlabel('Frequency [Hz]');ylabel('PitchStrength');title('');
+
+
+
+if plot_only_highest
+ n=1;
+else
+ n=length(pitch):-1:1;
+end
+
+% if ~isempty(pitch) % only, when temporal pitches occure
+frequencydots=sortstruct(pitch,'spektral_profile.activity');
+for i=n
+ % Plotte die blauen Punkte (Intervalle)
+ pfre=pitch{i}.interval_profile.fre;
+ xx=f2p(pfre); %das liegt wegen Rundungsfehlern zu weit links??
+ xx=getmaximumrightof(xx-1,intermaxpos,interminpos,intermax,intermin);
+ hei=getbinvalue(intervalsum,xx);
+ if i==1
+ radius=max(2,dot_scaler*pitch{i}.residuumpitchstrength);
+ if plot_bw
+ plot(xx,hei,'k.','MarkerSize',radius/2,'Marker','^','MarkerFaceColor','k');
+ else
+ plot(xx,hei,'b.','MarkerSize',radius);
+ end
+% text(xx+30,texthei*1.1,sprintf('%3.0f Hz %5.3f',pitch{i}.fre,pitch{i}.residuumpitchstrength)); % this is at a nice position
+% if pitch{i}.envcontrast > envcontrast_threshold
+ a=text(xx+30,hei*1.2,sprintf('%3.0f Hz',pfre)); % this is at a nice position
+ set(a,'Color','b');
+ % end
+ else
+ radius=max(2,dot_scaler*pitch{i}.residuumpitchstrength);
+ plot(xx,hei,'b.','MarkerSize',radius);
+ end
+
+ % Plotte die roten Punkte (Frequenzen)
+ pfre=chan2fre(current_frame,frequencydots{i}.spektral_profile.position);
+ xx=f2p(pfre); % suche den Punkt auf dem nächsten Maximum um Rundungsfehler zu vermeiden
+ xx2=getmaximumrightof(xx-1,fremaxpos,freminpos,fremax,fremin);
+ if xx2/xx < 1.015 % wenn das nächste Maximum nah dran ist, dann wars ein Fehler
+ xx=xx2;
+ end
+ hei=getbinvalue(fresumme,xx);
+ radius=max(2,dot_scaler*frequencydots{i}.spektral_profile.hight);
+ if plot_bw
+ plot(xx,hei,'k.','MarkerSize',radius);
+ else
+ plot(xx,hei,'r.','MarkerSize',radius);
+ end
+ a=text(xx+30,hei*1.2,sprintf('%4.2f kHz',pfre/1000)); % this is at a nice position
+ set(a,'Color','r');
+
+end
+
+return
+
+
+
+function f=p2f(pix)
+global fnull;
+global stepsperoctave;
+f=fnull*power(2,(pix-1)*stepsperoctave);
+return
+
+function p=f2p(fre)
+global fnull;
+global stepsperoctave;
+p=1/stepsperoctave*log2(fre/fnull)+1;
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/cool_frame_plot_colors.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/cool_frame_plot_colors.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,81 @@
+% 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 cool_frame_plot_colors(fr,handle,options)
+% changes the plot colors of a frame plot
+
+
+
+if isfield(options,'select_channel_center_frequency')
+ color_center_frequency=options.select_channel_center_frequency;
+ select_channel_frequency_above=options.select_channel_frequency_range_above;
+ select_channel_frequency_below=options.select_channel_frequency_range_below;
+% color_width_frequency=options.select_channel_frequency_range;
+ stress_color='r';
+ % calculate, which channels are wanted, and wich are not
+ min_selected_frequency=color_center_frequency/power(2,select_channel_frequency_below);
+ max_selected_frequency=color_center_frequency*power(2,select_channel_frequency_above);
+else
+ min_selected_frequency=0;
+ max_selected_frequency=inf;
+end
+
+% do we have resolved harmonics additionally? If so, new color!
+if isfield(options,'resolved_harmonic_minimum')
+ has_resolved_harmonics=1;
+ resolved_harmonics=options.resolved_harmonic_minimum;
+% resolved_harmonics=20;;
+else
+ has_resolved_harmonics=0;
+end
+
+
+if has_resolved_harmonics==0 && min_selected_frequency==0 && max_selected_frequency==0
+ return
+end
+if has_resolved_harmonics==0 && min_selected_frequency==0 && max_selected_frequency==inf
+ return
+end
+
+cfs=getcf(fr);
+sr=getsr(fr);
+
+
+% Special Effect: Make Region cool!
+cdat=get(handle,'cdata');
+cdat=zeros(size(cdat));
+nr_points=size(cdat,1);
+nr_chan=getnrchannels(fr);
+for channr=1:nr_chan
+ current_cf=cfs(channr);
+ if current_cf >min_selected_frequency && current_cf < max_selected_frequency
+ cdat(:,channr)=1;
+ else
+ cdat(:,channr)=0;
+ end
+ if has_resolved_harmonics
+ resolved_time=1/(current_cf/resolved_harmonics);
+ resolved_bin=floor(resolved_time*sr);
+ resolved_bin=min(resolved_bin,nr_points);
+ % resolved_bin=200;
+ cdat(1:resolved_bin,channr)=0.5;
+ end
+end
+
+colm=prism;
+colm(1,:)=0; % black for zero
+
+colormap(colm);
+
+% Trick, den ich nicht verstehe, wenn ich das nicht mache, werden
+% unten Linien eingeblendet
+cd=get(handle,'cdata');
+nans=find(isnan(cd));
+cdat(nans)=nan; %????????
+set(handle,'cdata',cdat);
+% set(handle,'CDataMapping','scaled');
+% set(handle,'edgecolor','flat')
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/coolregion.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/coolregion.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,79 @@
+% tool
+%
+% 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 cdat=coolregion(current_frame,cdat,peak)
+
+% Ich geh von einer Colormap aus, die Farben pro Wert zwischen 0 und 1
+% unterschiedlich darstellt. 0=schwarz, und dann z.B zirkeln wie in prism
+
+
+
+fre_val=peak.spektral_profile.position;
+int_val=peak.interval_profile.position;
+
+% current_frame_handle=peak.current_frame_handle;
+
+vals=getvalues(current_frame);
+% cdat=get(current_frame_handle,'cdata');
+% erst mal alle erhaltenen Werte auf Null setzen
+ca=cdat;
+
+% wie weit die spektrale Summe runterskaliert werden muss, damit die Zahlen vernünftigt werden
+norm_spektralhight=1.5/1e5;
+fresumme=getfrequencysum(current_frame);
+fresumme=fresumme*norm_spektralhight;
+gauss=signal(fresumme);
+maxmaxpos=fre_val;
+maxmaxhight=1;
+sigma=peak.spektral_profile.sigma;
+gauss=generategauss(gauss,maxmaxpos,maxmaxhight,sigma);
+
+
+from_fre=fre_val-sigma;
+to_fre=fre_val+sigma;
+maxbin=length(cdat);
+minbin=1;
+maxchan=getnrchannels(current_frame);
+minchan=1;
+
+from_fre=min(from_fre,maxchan);
+from_fre=max(from_fre,minchan);
+to_fre=max(to_fre,minchan);
+to_fre=min(to_fre,maxchan);
+sr=getsr(current_frame);
+
+for i=from_fre:to_fre
+ sig=getsinglechannel(current_frame,i);
+ [maxpos,minpos,maxs,mins]=getminmax(sig);
+
+ % Die Intervalle zwischen den Minima links und rechts vom Maximum werden eingefärbt
+ from_int=getminimumleftof(int_val,maxpos,minpos,maxs,mins);
+ to_int=getminimumrightof(int_val,maxpos,minpos,maxs,mins);
+% frombin=displaytime2bin(current_frame,from_int);
+% tobin=displaytime2bin(current_frame,to_int);
+ frombin=time2bin(from_int,sr);
+ tobin=time2bin(to_int,sr);
+ frombin=min(frombin,maxbin);
+ frombin=max(frombin,minbin);
+ tobin=max(tobin,minbin);
+ tobin=min(tobin,maxbin);
+
+ tob=floor(maxbin-frombin);
+ fromb=floor(maxbin-tobin+1);
+
+% ca(fromb:tob,i)=getbinvalue(gauss,i)*peak.spektralhight;
+ ca(fromb:tob,i)=peak.source_color;
+% ca(fromb:tob,i)=floor(rand(1)*10);
+end
+
+cdat=ca;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/dB.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/dB.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,19 @@
+% 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 x=dB(y,method)
+% convert to dB representation
+
+if nargin<2
+ method='power';
+end
+
+if strcmp(method,'power')
+ x=10*log(y)./log(10);
+else
+ x=20*log(y)./log(10);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/dBpower.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/dBpower.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+% 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 x=dBpower(y)
+% convert power to dB representation
+
+x=10*log(y)./log(10);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/data_gui.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/data_gui.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,741 @@
+% 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 varargout = data_gui(varargin)
+% allow some nice action with a gui.
+% Example: try:
+% function plot_psth(data,options)
+% options.startms=0;
+% options.duration=data.expparams.spike_window_end_ms;
+% options.binwidth=1;
+% options.info.buttontext={'plot psth','save as ascii'};
+% options.info.data=data;
+% options.info.title='psth parameter';
+% options.info.callback={'plot_psth(data,options,''plot'')','plot_psth(data,options,''save_as_ascii'')'};
+% out.handle=data_gui(options);
+%
+
+% Begin initialization code - DO NOT EDIT
+
+% find out, if we want a new window or the old one:
+if length(varargin)==1
+ gui_Singleton = 0; % normally we want a new window
+ all_childs=get(0,'children');
+ this_name=varargin{1}.info.title;
+ for i=1:length(all_childs)
+ name=get(all_childs(i),'name');
+ if strcmp(name,this_name)
+ gui_Singleton = 1; % but if there is a copy already, take that window instead
+ % and bring it to the front
+ figure(all_childs(i));
+ end
+ end
+else
+ gui_Singleton = 1; % but if there is a copy already, take that window instead
+end
+
+gui_State = struct('gui_Name', mfilename, ...
+ 'gui_Singleton', gui_Singleton, ...
+ 'gui_OpeningFcn', @data_gui_OpeningFcn, ...
+ 'gui_OutputFcn', @data_gui_OutputFcn, ...
+ 'gui_LayoutFcn', @data_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 data_gui is made visible.
+function data_gui_OpeningFcn(hObject, eventdata, handles, varargin)
+% This function has no output args, see OutputFcn.
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+% varargin command line arguments to data_gui (see VARARGIN)
+
+% Choose default command line output for data_gui
+handles.output = hObject;
+
+
+% copy the options in place
+options=varargin{1};
+handles.options=options;
+
+% Update handles structure
+guidata(hObject, handles);
+
+global result;
+% UIWAIT makes data_gui wait for user response (see UIRESUME)
+
+if ~isfield(options.info,'default_value')
+ result=''; % not determined yet
+else
+ result=options.info.default_value;
+end
+
+if isfield(options.info,'mode') && strcmp(options.info.mode,'modal')
+ uiwait(handles.figure1);
+end
+
+
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = data_gui_OutputFcn(hObject, eventdata, handles)
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+global result;
+varargout{1} = result;
+
+
+% --- Executes on button press in pushbutton1.
+function pushbuttons_Callback(hObject, eventdata, handles)
+% hObject handle to pushbutton1 (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see GUIDATA)
+options=handles.options;
+
+
+if iscell(handles.options.info.buttontext)
+ nr_buttons=length(handles.options.info.buttontext);
+else
+ nr_buttons=1;
+end
+for ii=1:nr_buttons
+ pushtag=sprintf('pushbutton%d',ii);
+ handstr=sprintf('hand=handles.%s;',pushtag);
+ eval(handstr);
+ if hObject==hand;
+ buttonnumber=ii;
+ break;
+ end
+end
+% dispatch all data values to the options structure
+
+options=handles.options;
+% radiobuttons=options.toggleradiobuttons;
+% nr_but=length(radiobuttons);
+nr_hands=length(fields(handles));
+all_fields=fields(handles);
+% set all to 0
+linecount=1;
+params=fields(options);
+nr_params=length(params);
+
+params=fields(options);
+nr_params=length(params);
+linecount=1;
+
+for i=1:nr_params % look through all parameter and find the assoziated handle for it
+ if ~strcmp(params(i),'info')
+ for j=1:nr_hands % go through all handles. One must be it
+ curhand=getfield(handles,all_fields{j});
+ if ishandle(curhand)
+ fieldname=all_fields{j};
+ allfi=get(curhand);
+ if isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'edit')
+ fieldvalue=get(curhand,'String');
+ val=str2num(fieldvalue{1});
+ stuctname=get(curhand,'userdata');
+ if isnumeric(val) && ~isempty(val)
+ options=setfield(options,stuctname,val);
+ else
+ options=setfield(options,stuctname,fieldvalue{1});
+ end
+ linecount=linecount+1;
+ elseif isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'radiobutton')
+ val=get(curhand,'value');
+ nr=get(curhand,'Userdata');
+ options.toggleradiobuttons{nr}.value=val;
+ elseif isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'checkbox')
+ val=get(curhand,'value');
+ nr=get(curhand,'Userdata');
+ options.checkboxes{nr}.value=val;
+ end
+ end
+ end
+ end
+end
+
+
+data=options.info.data;
+if nr_buttons==1
+ callline=sprintf('%s;',options.info.callback);
+else
+ callline=sprintf('%s;',options.info.callback{buttonnumber});
+end
+eval(callline);
+
+% does the function give back a value?
+gleichwo=strfind(callline,'=');
+if ~isempty(gleichwo)
+ retvar=callline(1:gleichwo-1);
+ global result;
+ resstr=sprintf('result=%s;',retvar);
+ eval(resstr);
+end
+
+
+function togglebuttons_Callback(hObject, eventdata, handles)
+if get(hObject,'value')==0
+ return
+end
+options=handles.options;
+radiobuttons=options.toggleradiobuttons;
+nr_but=length(radiobuttons);
+nr_hands=length(fields(handles));
+all_fields=fields(handles);
+% set all to 0
+for i=1:nr_hands
+ curhand=getfield(handles,all_fields{i});
+ if ishandle(curhand)
+ name1=get(curhand,'tag');
+ for j=1:nr_but
+ name2=sprintf('togglebutton%d',j);
+ if strcmp(name1,name2) && hObject~=curhand
+ set(curhand,'value',0);
+ end
+ end
+ end
+end
+
+% --- Creates and returns a handle to the GUI figure.
+function h1 = data_gui_LayoutFcn(policy)
+% policy - create a new figure or use a singleton. 'new' or 'reuse'.
+
+persistent hsingleton;
+if strcmpi(policy, 'reuse') & ishandle(hsingleton)
+ h1 = hsingleton;
+ return;
+end
+% collect my own options to generate parmeters on the fly
+global options
+
+% now build from bottom to top a line of text and an edit box for each
+% parameter
+params=fields(options);
+nr_params=length(params);
+linecount=1;
+% first find out, what the longest name is
+maxxlen=0; % the longest text in width
+maxylen=0; % essentially the number of lines
+rowheight=2; % how high every row is
+elementhigth=1.5; % how high every element is
+edit_width=20; % how wide an edit box is
+spacebetweentextandedit=5; % space between text and edit box
+leftoffset=2; % offset of text to the left boundary (and right as well)
+
+for i=1:nr_params
+ if ~strcmp(params(i),'info')
+ string_text=params{i};
+ textlen=length(string_text)+3;
+ maxxlen=max(maxxlen,textlen);
+ maxylen=maxylen+rowheight; % the distance between lines
+ end
+ if strcmp(params(i),'toggleradiobuttons')
+ radiobuttons=options.toggleradiobuttons;
+ nr_but=length(radiobuttons);
+ maxylen=maxylen+nr_but*rowheight; % the distance between lines
+ end
+
+end
+
+% the total size of the window is now:
+window_width=maxxlen+spacebetweentextandedit+edit_width+2*leftoffset;
+window_height=maxylen+3*leftoffset;
+% get the size of the screen in chars
+set(0,'units','char');
+siz=get(0,'screensize');
+screeen_height=siz(4);
+screeen_width=siz(3);
+set(0,'units','pixels'); % back to normal
+
+% the figure
+windoff=2; % offset from the top right corner
+h1 = figure(...
+ 'Units','characters',...
+ 'PaperUnits',get(0,'defaultfigurePaperUnits'),...
+ 'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
+ 'IntegerHandle','off',...
+ 'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
+ 'MenuBar','none',...
+ 'Name',options.info.title,...
+ 'NumberTitle','off',...
+ 'PaperPosition',get(0,'defaultfigurePaperPosition'),...
+ 'PaperSize',[20.98404194812 29.67743169791],...
+ 'PaperType',get(0,'defaultfigurePaperType'),...
+ 'Position',[screeen_width-window_width-windoff screeen_height-window_height-windoff window_width window_height],...
+ 'Renderer',get(0,'defaultfigureRenderer'),...
+ 'RendererMode','manual',...
+ 'Resize','on',...
+ 'HandleVisibility','callback',...
+ 'Tag','figure1',...
+ 'UserData',zeros(1,0));
+
+% application data
+setappdata(h1, 'GUIDEOptions', struct(...
+ 'active_h', 1.020033e+002, ...
+ 'taginfo', struct(...
+ 'figure', 2, ...
+ 'pushbutton', 2), ...
+ 'override', 0, ...
+ 'release', 13, ...
+ 'resize', 'simple', ...
+ 'accessibility', 'callback', ...
+ 'mfile', 1, ...
+ 'callbacks', 1, ...
+ 'singleton', 1, ...
+ 'syscolorfig', 1, ...
+ 'lastSavedFile', 'c:\bla bla bla'));
+
+% buttons
+if iscell(options.info.buttontext)
+ nr_buttons=length(options.info.buttontext);
+else
+ nr_buttons=1;
+end
+gesbtextlen=0;
+boffset=2;
+% for ii=1:nr_buttons
+% if nr_buttons==1
+% btext=options.info.buttontext;
+% textlen=length(btext)+4;
+% textx=(window_width-textlen)/2;
+% fbtext{1}=btext;
+% buttonposx(1)=textx-textlen/2;
+% buttonwidth(1)=textlen+boffset;
+% else
+% btext=options.info.buttontext{ii};
+% fbtext{ii}=btext;
+% textlen=length(btext)+4;
+%
+% buttonposx(ii)=gesbtextlen+boffset;
+% gesbtextlen=gesbtextlen+textlen+boffset;
+%
+% buttonwidth(ii)=textlen;
+%
+% end
+% end
+%
+% for ii=1:nr_buttons
+% callbackstr='data_gui(''pushbuttons_Callback'',gcbo,[],guidata(gcbo))';
+% pushtag=sprintf('pushbutton%d',ii);
+% h2 = uicontrol(...
+% 'Parent',h1,...
+% 'Units','characters',...
+% 'Callback',callbackstr,...
+% 'ListboxTop',0,...
+% 'Position',[buttonposx(ii) 1 buttonwidth(ii) 1.5],...
+% 'String',fbtext{ii},...
+% 'Tag',pushtag);
+% options.buttonhandles(ii)=h2;
+% end
+
+for ii=1:nr_buttons
+ if nr_buttons==1
+ btext=options.info.buttontext;
+ textlen=length(btext)+4;
+ textx=(window_width-textlen)/2;
+ fbtext{1}=btext;
+ buttonposx(1)=textx-textlen/2;
+ buttonwidth(1)=textlen+boffset;
+ else
+ btext=options.info.buttontext{ii};
+ fbtext{ii}=btext;
+ textlen=length(btext)+4;
+
+ buttonposx(ii)=gesbtextlen+boffset;
+ gesbtextlen=gesbtextlen+textlen+boffset;
+
+ buttonwidth(ii)=textlen;
+
+ end
+end
+
+for ii=1:nr_buttons
+ callbackstr='data_gui(''pushbuttons_Callback'',gcbo,[],guidata(gcbo))';
+ pushtag=sprintf('pushbutton%d',ii);
+ h2 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'Callback',callbackstr,...
+ 'ListboxTop',0,...
+ 'Position',[buttonposx(ii) 1 buttonwidth(ii) 1.5],...
+ 'String',fbtext{ii},...
+ 'Tag',pushtag);
+ options.buttonhandles(ii)=h2;
+end
+
+% make the window wider if necessary
+
+% the total size of the window is now:
+new_window_width=window_width;
+if buttonposx(end)+buttonwidth(end)+boffset >new_window_width
+ new_window_width=buttonposx(end)+buttonwidth(end)+boffset;
+end
+
+set(h1,'Position',[screeen_width-new_window_width-windoff screeen_height-window_height-windoff new_window_width window_height]);
+
+
+% now put a text and an edit field on every line
+% tagcount=1;
+togglecount=1;
+checkcount=1;
+for i=nr_params:-1:1
+ if ~strcmp(params(i),'info') && ~strcmp(params(i),'toggleradiobuttons') && ~strcmp(params(i),'checkboxes')
+ string_text=params{i};
+ plot_text=[string_text ' '];
+% plot_text=string_text;
+ tag=sprintf('text%d',linecount);
+ text_len=length(string_text);
+ pos_x=maxxlen-text_len+leftoffset;
+ pos_y=(linecount+1)*rowheight;
+ h2 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'ListboxTop',0,...
+ 'Position',[pos_x pos_y text_len+5 elementhigth],...
+ 'String',plot_text,...
+ 'Style','text',...
+ 'Tag',tag);
+
+ edittag=sprintf('edit%d',linecount);
+ pos_x=window_width-edit_width-leftoffset;
+ pos_y=(linecount+1)*rowheight;
+ value=getfield(options,string_text);
+ if isnumeric(value)
+ valuestr=num2str(value);
+ if length(value)>1 % a field instead a single number
+ valuestr='[';
+ for j=1:length(value)
+ valuestr=[valuestr ' ' num2str(value(j))];
+ end
+ valuestr=[valuestr ']'];
+ end
+ else % a string
+ valuestr=value;
+ end
+ h3 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'ListboxTop',0,...
+ 'Position',[pos_x pos_y edit_width elementhigth],...
+ 'String',{ valuestr },...
+ 'userdata',plot_text,...
+ 'Style','edit',...
+ 'Tag',edittag);
+ % 'Callback','data_gui(''edit1_Callback'',gcbo,[],guidata(gcbo))',...
+
+ linecount=linecount+1;
+ elseif strcmp(params(i),'toggleradiobuttons')
+ radiobuttons=options.toggleradiobuttons;
+ nr_but=length(radiobuttons);
+ for jj=1:nr_but
+ string_text=radiobuttons{jj}.name;
+ plot_text=[string_text ' '];
+ % plot_text=string_text;
+ tag=sprintf('text%d',linecount);
+ text_len=length(string_text);
+ pos_x=maxxlen-text_len+leftoffset;
+ pos_y=(linecount+1)*rowheight;
+ h2 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'ListboxTop',0,...
+ 'Position',[pos_x pos_y text_len+5 elementhigth],...
+ 'String',plot_text,...
+ 'Style','text',...
+ 'Tag',tag);
+
+ toggletag=sprintf('togglebutton%d',togglecount);
+ togglecount=togglecount+1;
+ pos_x=window_width-edit_width-leftoffset;
+ pos_y=(linecount+1)*rowheight;
+ value=radiobuttons{jj}.value;
+ h3 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'ListboxTop',0,...
+ 'Position',[pos_x+2 pos_y 4 elementhigth],...
+ 'Value',value,...
+ 'Style','radiobutton',...
+ 'backgroundcolor',[0.925 0.914 0.847],...
+ 'userdata',jj,...
+ 'Callback','data_gui(''togglebuttons_Callback'',gcbo,[],guidata(gcbo))',...
+ 'Tag',toggletag);
+
+ linecount=linecount+1;
+ end
+ elseif strcmp(params(i),'checkboxes')
+ checkboxes=options.checkboxes;
+ nr_but=length(checkboxes);
+ for jj=1:nr_but
+ string_text=checkboxes{jj}.name;
+ plot_text=[string_text ' '];
+ % plot_text=string_text;
+ tag=sprintf('text%d',linecount);
+ text_len=length(string_text);
+ pos_x=maxxlen-text_len+leftoffset;
+ pos_y=(linecount+1)*rowheight;
+ h2 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'ListboxTop',0,...
+ 'Position',[pos_x pos_y text_len+5 elementhigth],...
+ 'String',plot_text,...
+ 'Style','text',...
+ 'Tag',tag);
+
+ checktag=sprintf('checkbox%d',checkcount);
+ checkcount=checkcount+1;
+ pos_x=window_width-edit_width-leftoffset;
+ pos_y=(linecount+1)*rowheight;
+ value=checkboxes{jj}.value;
+ h3 = uicontrol(...
+ 'Parent',h1,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'ListboxTop',0,...
+ 'Position',[pos_x+2 pos_y 4 elementhigth],...
+ 'Value',value,...
+ 'Style','checkbox',...
+ 'backgroundcolor',[0.925 0.914 0.847],...
+ 'userdata',jj,...
+ 'Tag',checktag);
+
+ linecount=linecount+1;
+ end
+ end
+end
+
+
+hsingleton = h1;
+
+
+% --- Handles default GUIDE GUI creation and callback dispatch
+function varargout = gui_mainfcn(gui_State, varargin)
+
+
+% GUI_MAINFCN provides these command line APIs for dealing with GUIs
+%
+% data_gui, by itself, creates a new data_gui or raises the existing
+% singleton*.
+%
+% H = data_gui returns the handle to a new data_gui or the handle to
+% the existing singleton*.
+%
+% data_gui('CALLBACK',hObject,eventData,handles,...) calls the local
+% function named CALLBACK in data_gui.M with the given input arguments.
+%
+% data_gui('Property','Value',...) creates a new data_gui or raises the
+% existing singleton*. Starting from the left, property value pairs are
+% applied to the GUI before untitled_OpeningFunction gets called. An
+% unrecognized property name or invalid value makes property application
+% stop. All inputs are passed to untitled_OpeningFcn via varargin.
+%
+% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
+% instance to run (singleton)".
+
+% Copyright 1984-2002 The MathWorks, Inc.
+% $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+gui_StateFields = {'gui_Name'
+ 'gui_Singleton'
+ 'gui_OpeningFcn'
+ 'gui_OutputFcn'
+ 'gui_LayoutFcn'
+ 'gui_Callback'};
+gui_Mfile = '';
+for i=1:length(gui_StateFields)
+ if ~isfield(gui_State, gui_StateFields{i})
+ error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);
+ elseif isequal(gui_StateFields{i}, 'gui_Name')
+ gui_Mfile = [getfield(gui_State, gui_StateFields{i}), '.m'];
+ end
+end
+
+numargin = length(varargin);
+
+if numargin == 0
+ % data_gui
+ % create the GUI
+ gui_Create = 1;
+elseif numargin > 3 & ischar(varargin{1}) & ishandle(varargin{2})
+ % data_gui('CALLBACK',hObject,eventData,handles,...)
+ gui_Create = 0;
+else
+ % data_gui(...)
+ % create the GUI and hand varargin to the openingfcn
+ gui_Create = 1;
+end
+
+if gui_Create == 0
+ varargin{1} = gui_State.gui_Callback;
+ if nargout
+ [varargout{1:nargout}] = feval(varargin{:});
+ else
+ feval(varargin{:});
+ end
+else
+ if gui_State.gui_Singleton
+ gui_SingletonOpt = 'reuse';
+ else
+ gui_SingletonOpt = 'new';
+ end
+
+ % Open fig file with stored settings. Note: This executes all component
+ % specific CreateFunctions with an empty HANDLES structure.
+ % make options global, so that I can access them in the generation
+ % function
+ global options
+ options=varargin{1};
+
+ % Do feval on layout code in m-file if it exists
+ if ~isempty(gui_State.gui_LayoutFcn)
+ gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
+ % SB: this one finds the wrong one, possible because it just looks
+ % for the first one with the m-file. We can do better:
+
+ all_childs=get(0,'children');
+ this_name=options.info.title;
+ for i=1:length(all_childs)
+ name=get(all_childs(i),'name');
+ if strcmp(name,this_name)
+ gui_hFigure=all_childs(i);
+ end
+ end
+
+
+ else
+ gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);
+ % If the figure has InGUIInitialization it was not completely created
+ % on the last pass. Delete this handle and try again.
+ if isappdata(gui_hFigure, 'InGUIInitialization')
+ delete(gui_hFigure);
+ gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);
+ end
+ end
+
+ % Set flag to indicate starting GUI initialization
+ setappdata(gui_hFigure,'InGUIInitialization',1);
+
+ % Fetch GUIDE Application options
+ gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
+
+ if ~isappdata(gui_hFigure,'GUIOnScreen')
+ % Adjust background color
+ if gui_Options.syscolorfig
+ set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
+ end
+
+ % Generate HANDLES structure and store with GUIDATA
+ guidata(gui_hFigure, guihandles(gui_hFigure));
+ end
+
+ % If user specified 'Visible','off' in p/v pairs, don't make the figure
+ % visible.
+ gui_MakeVisible = 1;
+ for ind=1:2:length(varargin)
+ if length(varargin) == ind
+ break;
+ end
+ len1 = min(length('visible'),length(varargin{ind}));
+ len2 = min(length('off'),length(varargin{ind+1}));
+ if ischar(varargin{ind}) & ischar(varargin{ind+1}) & ...
+ strncmpi(varargin{ind},'visible',len1) & len2 > 1
+ if strncmpi(varargin{ind+1},'off',len2)
+ gui_MakeVisible = 0;
+ elseif strncmpi(varargin{ind+1},'on',len2)
+ gui_MakeVisible = 1;
+ end
+ end
+ end
+
+ % Check for figure param value pairs
+ for index=1:2:length(varargin)
+ if length(varargin) == index
+ break;
+ end
+ try, set(gui_hFigure, varargin{index}, varargin{index+1}), catch, break, end
+ end
+
+ % If handle visibility is set to 'callback', turn it on until finished
+ % with OpeningFcn
+ gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
+ if strcmp(gui_HandleVisibility, 'callback')
+ set(gui_hFigure,'HandleVisibility', 'on');
+ end
+
+ feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
+
+ if ishandle(gui_hFigure)
+ % Update handle visibility
+ set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
+
+ % Make figure visible
+ if gui_MakeVisible
+ set(gui_hFigure, 'Visible', 'on')
+ if gui_Options.singleton
+ setappdata(gui_hFigure,'GUIOnScreen', 1);
+ end
+ end
+
+ % Done with GUI initialization
+ rmappdata(gui_hFigure,'InGUIInitialization');
+ end
+
+ % If handle visibility is set to 'callback', turn it on until finished with
+ % OutputFcn
+ if ishandle(gui_hFigure)
+ gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
+ if strcmp(gui_HandleVisibility, 'callback')
+ set(gui_hFigure,'HandleVisibility', 'on');
+ end
+ gui_Handles = guidata(gui_hFigure);
+ else
+ gui_Handles = [];
+ end
+
+ if nargout
+ [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
+ else
+ feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
+ end
+
+ if ishandle(gui_hFigure)
+ set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
+ end
+end
+
+
+function gui_hFigure = local_openfig(name, singleton)
+if nargin('openfig') == 3
+ gui_hFigure = openfig(name, singleton, 'auto');
+else
+ % OPENFIG did not accept 3rd input argument until R13,
+ % toggle default figure visible to prevent the figure
+ % from showing up too soon.
+ gui_OldDefaultVisible = get(0,'defaultFigureVisible');
+ set(0,'defaultFigureVisible','off');
+ gui_hFigure = openfig(name, singleton);
+ set(0,'defaultFigureVisible',gui_OldDefaultVisible);
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/distributelogarithmic.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/distributelogarithmic.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% tool
+%
+% 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 [res,scaleinfo]=distributelogarithmic(from,to,steps)
+% usage: [res,scaleinfo]=distributelogarithmic(from,to,steps)
+% gives back values that start from "from" and go to "to" in
+% "steps" steps, so that the stepwidth is logarithmic
+
+% returnvalues to keep track (needed in some cases)
+scaleinfo.from=from;
+scaleinfo.to=to;
+scaleinfo.steps=steps;
+
+
+res=0:steps-1;
+res=lin2log(res,scaleinfo);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/dots2sig.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/dots2sig.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% tool
+%
+% 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=dots2sig(dots,nr_bins)
+% usage: sig=dots2sig(dots)
+% makes a signal from the dots by adding them to bins according to their octave shift
+% the dots must have pitchstrength in the region from 0 to 1
+% the outsignal has nr_bins points and a length of 1
+
+
+if nargin < 2
+ nr_bins=100;
+end
+
+sig=signal(1,nr_bins);
+
+nr=max(size(dots));
+for i=1:nr
+ shift=dots{i}.octave_shift;
+ old_val=gettimevalue(sig,shift);
+ new_val=dots{i}.pitchstrength;
+ sig=settimevalue(sig,shift,old_val+new_val);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/ellipse.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/ellipse.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,149 @@
+function h=ellipse(ra,rb,ang,x0,y0,C,Nb)
+% Ellipse adds ellipses to the current plot
+%
+% ELLIPSE(ra,rb,ang,x0,y0) adds an ellipse with semimajor axis of ra,
+% a semimajor axis of radius rb, a semimajor axis of ang, centered at
+% the point x0,y0.
+%
+% The length of ra, rb, and ang should be the same.
+% If ra is a vector of length L and x0,y0 scalars, L ellipses
+% are added at point x0,y0.
+% If ra is a scalar and x0,y0 vectors of length M, M ellipse are with the same
+% radii are added at the points x0,y0.
+% If ra, x0, y0 are vectors of the same length L=M, M ellipses are added.
+% If ra is a vector of length L and x0, y0 are vectors of length
+% M~=L, L*M ellipses are added, at each point x0,y0, L ellipses of radius ra.
+%
+% ELLIPSE(ra,rb,ang,x0,y0,C)
+% adds ellipses of color C. C may be a string ('r','b',...) or the RGB value.
+% If no color is specified, it makes automatic use of the colors specified by
+% the axes ColorOrder property. For several circles C may be a vector.
+%
+% ELLIPSE(ra,rb,ang,x0,y0,C,Nb), Nb specifies the number of points
+% used to draw the ellipse. The default value is 300. Nb may be used
+% for each ellipse individually.
+%
+% h=ELLIPSE(...) returns the handles to the ellipses.
+%
+% as a sample of how ellipse works, the following produces a red ellipse
+% tipped up at a 45 deg axis from the x axis
+% ellipse(1,2,pi/8,1,1,'r')
+%
+% note that if ra=rb, ELLIPSE plots a circle
+%
+
+% written by D.G. Long, Brigham Young University, based on the
+% CIRCLES.m original
+% written by Peter Blattner, Institute of Microtechnology, University of
+% Neuchatel, Switzerland, blattner@imt.unine.ch
+
+
+% Check the number of input arguments
+
+if nargin<1,
+ ra=[];
+end;
+if nargin<2,
+ rb=[];
+end;
+if nargin<3,
+ ang=[];
+end;
+
+%if nargin==1,
+% error('Not enough arguments');
+%end;
+
+if nargin<5,
+ x0=[];
+ y0=[];
+end;
+
+if nargin<6,
+ C=[];
+end
+
+if nargin<7,
+ Nb=[];
+end
+
+% set up the default values
+
+if isempty(ra),ra=1;end;
+if isempty(rb),rb=1;end;
+if isempty(ang),ang=0;end;
+if isempty(x0),x0=0;end;
+if isempty(y0),y0=0;end;
+if isempty(Nb),Nb=300;end;
+if isempty(C),C=get(gca,'colororder');end;
+
+% work on the variable sizes
+
+x0=x0(:);
+y0=y0(:);
+ra=ra(:);
+rb=rb(:);
+ang=ang(:);
+Nb=Nb(:);
+
+if isstr(C),C=C(:);end;
+
+if length(ra)~=length(rb),
+ error('length(ra)~=length(rb)');
+end;
+if length(x0)~=length(y0),
+ error('length(x0)~=length(y0)');
+end;
+
+% how many inscribed elllipses are plotted
+
+if length(ra)~=length(x0)
+ maxk=length(ra)*length(x0);
+else
+ maxk=length(ra);
+end;
+
+% drawing loop
+
+for k=1:maxk
+
+ if length(x0)==1
+ xpos=x0;
+ ypos=y0;
+ radm=ra(k);
+ radn=rb(k);
+ if length(ang)==1
+ an=ang;
+ else
+ an=ang(k);
+ end;
+ elseif length(ra)==1
+ xpos=x0(k);
+ ypos=y0(k);
+ radm=ra;
+ radn=rb;
+ an=ang;
+ elseif length(x0)==length(ra)
+ xpos=x0(k);
+ ypos=y0(k);
+ radm=ra(k);
+ radn=rb(k);
+ an=ang(k)
+ else
+ rada=ra(fix((k-1)/size(x0,1))+1);
+ radb=rb(fix((k-1)/size(x0,1))+1);
+ an=ang(fix((k-1)/size(x0,1))+1);
+ xpos=x0(rem(k-1,size(x0,1))+1);
+ ypos=y0(rem(k-1,size(y0,1))+1);
+ end;
+
+ co=cos(an);
+ si=sin(an);
+ the=linspace(0,2*pi,Nb(rem(k-1,size(Nb,1))+1,:)+1);
+% x=radm*cos(the)*co-si*radn*sin(the)+xpos;
+% y=radm*cos(the)*si+co*radn*sin(the)+ypos;
+ h(k)=line(radm*cos(the)*co-si*radn*sin(the)+xpos,radm*cos(the)*si+co*radn*sin(the)+ypos);
+ set(h(k),'color',C(rem(k-1,size(C,1))+1,:));
+
+end;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/extracttolist.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/extracttolist.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% tool
+%
+% 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 ret=extracttolist(list,delimiter)
+%usage: ret=extracttolist(list,delimiter)
+% returns a list of strings that are in 'list' and deliminited by delimiter
+
+nrwhere=findstr(list,delimiter); % 9 is tab!
+start=1;
+for i=1:length(nrwhere)
+ stop=nrwhere(i)-1;
+ ret{i}=list(start:stop);
+ start=nrwhere(i);
+end
+
+% and the last one before the end of the line
+ret{i+1}=list(start:end);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/fexist.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/fexist.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,63 @@
+% tool
+%
+% 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 is_there=fexist(datei)
+%usage: is_there=fexist(datei)
+% returns a boolean (1 or 0) whether the requested datei exist or not
+
+is_there=0;
+
+
+try
+ nr=exist(datei);
+catch
+ is_there=0;
+ return;
+end
+
+% is a normal file:
+if nr==2
+ is_there=1;
+ return;
+end
+
+% is a directory:
+if nr==7
+ is_there=1;
+ return;
+end
+
+
+%
+%
+% FID = -1;
+% FID = fopen(datei,'r');
+% if FID ~=-1
+% is_there=1;
+% fclose(FID);
+% return
+% end
+%
+% % if still here, it can be a directory
+% % try to find the name in the list
+% dir_struct = dir;
+% [sorted_names,sorted_index] = sortrows({dir_struct.name}');
+%
+% for i=1:length(sorted_index)
+% if strcmp(sorted_names(i),datei)
+% is_there=1;
+% return
+% end
+% end
+% is_there=0;
+%
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/filterbandamp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/filterbandamp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,38 @@
+% tool
+%
+% 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 ampscale=filterbandamp(fre,amp,fc,df1,bw,df2)
+% usage: ampscale=filterbandamp(fre,amp,fc,df1,bw,df2)
+% given a frequency and its associated amplitude, and the defining properties of
+% a bandpass filter (cf. Krumbholz et al (2000), JASA 108, 1170-1180, Fig.3)
+% this function returns the amplitude of the frequency component after it has
+% passed through the filter. The reurned amplitude should be used to SCALE the
+% amplitude of the given frequency component.
+% fre frequency in Hz
+% amp amplitude
+% fc lower cutoff frequency
+% df1 lower spectral ramp width
+% bw bandwidth (of plateau)
+% df2 upper spectral ramp
+%
+% David Smith (16/05/02)
+
+if (fre<(fc-df1)) | (fre>(fc+bw+df2))
+ ampscale=0; %ignore everything outside passband
+elseif fre<=fc %lower spectral ramp
+ ampscale=max(cos((fc-fre)*pi/(2*df1)),0); %quarter-cycle of cosine function
+elseif fre<=fc+bw %flat part of filter
+ ampscale=1;
+else %upper spectral ramp
+ ampscale=max(cos((fre-(fc+bw))*pi/(2*df2)),0);
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/findstrobes.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/findstrobes.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,593 @@
+% tool for aim
+%
+% 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: 2009-11-10 10:53:21 +0000 (Tue, 10 Nov 2009) $
+% $Revision: 705 $
+
+function [strobe_points,threshold]=adaptivthreshold(sig,options)
+
+
+sr=getsr(sig);
+newsig=sig;
+newsig=setname(newsig,sprintf('adaptive threshold of %s',getname(sig)));
+threshold=sig;
+tresval=getvalues(sig);
+
+% for speed reasons (matlab cant accelerate classes) all signals are
+% passed as their values
+sigvals=getvalues(sig);
+options.sr=sr;
+
+switch options.strobe_criterion
+ case 'parabola'
+ [strobe_points,tresval]=do_parabola(sigvals,options);
+ case 'threshold'
+ case 'peak'
+ [strobe_points,tresval]=do_peak(sigvals,options);
+ case 'temporal_shadow_plus'
+ [strobe_points,tresval]=do_peakshadowplus(sigvals,options);
+ case 'local_maximum'
+ [strobe_points,tresval]=do_local_maximum(sigvals,options);
+ case 'constrained_local_maximum'
+ [strobe_points,tresval]=do_constrained_local_maximum(sigvals,options);
+ case 'temporal_shadow'
+ [strobe_points,tresval]=do_peakshadow(sigvals,options);
+ case 'delta_gamma'
+ case 'adaptive'
+ [strobe_points,tresval]=do_adaptive(sigvals,options);
+ case 'bunt'
+ [strobe_points,tresval]=do_bunt(sigvals,options);
+ otherwise
+ error(sprintf('findstrobes: Sorry, I dont know the strobe criterium %s',options.strobe_criterion));
+
+end
+
+strobe_points=bin2time(sig,strobe_points);
+
+threshold=setvalues(threshold,tresval);
+
+return
+
+
+
+function [strobe_points,tresval]=do_parabola(sigvals,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
+
+current_threshold=0;
+sr=options.sr;
+last_strobe=-inf;
+
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1); % makes things faster
+
+%when the last strobe occured
+last_strobe_time=-inf;
+last_threshold_value=0;
+last_val=sigvals(1);
+
+% copy options to save time
+h=options.parabel_heigth;
+wnull=options.parabel_width_in_cycles*1/options.current_cf;
+w_variabel=wnull;
+
+strobe_decay_time=options.strobe_decay_time;
+
+counter=1;
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+ next_val=sigvals(ii+1);
+
+ if current_val>=current_threshold % above threshold -> criterium for strobe
+ current_threshold=current_val;
+ if current_val > last_val && current_val > next_val % only strobe on local maxima
+ % take this one as a new one
+ strobe_points(counter)=ii;
+ strobe_time(counter)=ii/sr;
+ counter=counter+1; % strobecounter
+
+ last_strobe_time=ii/sr; % anyhow, its a candidate
+ last_threshold_value=current_threshold;
+ a=4*(1-h)/(wnull*wnull);
+ b=-wnull/2;
+ w_variabel=wnull-(current_threshold-2*a*b)/(2*a);
+ end
+ end
+ tresval(ii)=current_threshold;
+
+ time_since_last_strobe=current_time-last_strobe_time;
+ if time_since_last_strobe > w_variabel % linear falling threshold
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ else % parabel for the first time y=a(x+b)^2+c
+ a=4*(1-h)/(wnull*wnull);
+ b=-wnull/2;
+ c=h;
+ factor=a*(time_since_last_strobe + b) ^2+c;
+ current_threshold=last_threshold_value*factor;
+ end
+
+ current_threshold=max(0,current_threshold); % cant be smaller then 0
+ last_val=current_val;
+end
+% give back only the strobes, that really occured:
+if counter>1
+ strobe_points=strobe_points(1:counter-1);
+else
+ strobe_points=[];
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval]=do_peak(sigvals,options)
+% finds every single local maximum
+sr=options.sr;
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+sig=signal(sigvals);
+sig=setsr(sig,sr);
+[t,h]=getlocalmaxima(sig);
+strobe_points=t*sr;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval]=do_peakshadow(sigvals,options)
+% finds every single peak and starts from that an falling threshold
+
+current_threshold=0;last_threshold_value=0;last_strobe=-inf;counter=1;
+sr=options.sr;
+tresval=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1);
+strobe_decay_time=options.strobe_decay_time;
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+ if current_val>current_threshold
+ if sigvals(ii) > sigvals(ii-1) && sigvals(ii) > sigvals(ii+1)
+ new_val=current_val-current_threshold;
+ current_threshold=current_val;
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ last_strobe=ii;
+ last_threshold_value=current_threshold;
+ end
+ end
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ tresval(ii)=current_threshold;
+end
+% give back only the strobes, that really occured:
+strobe_points=strobe_points(1:counter);
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval]=do_peakshadowplus(sigvals,options)
+% finds each local maximum. The next peak must be further away then
+% strobe_lag. But after timeout a strobe must occure
+
+strobe_lag=options.strobe_lag;
+timeout=options.timeout;
+
+current_threshold=0;
+sr=options.sr;
+tresval=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1);
+strobe_decay_time=options.strobe_decay_time;
+last_strobe=-inf;last_strobe_time=-inf;
+counter=1;
+last_threshold_value=0;
+
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+
+ if current_val>current_threshold
+ if sigvals(ii) > sigvals(ii-1) && sigvals(ii) > sigvals(ii+1)
+ if current_time > last_strobe_time+strobe_lag || ... % not in these 5 ms
+ current_time > last_strobe_time + timeout % but after 10 ms again
+ new_val=current_val-current_threshold;
+ current_threshold=current_val;
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ last_strobe_time=ii/sr;
+ last_strobe=ii;
+ last_threshold_value=current_threshold;
+ end
+ end
+ end
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ tresval(ii)=current_threshold;
+end
+% give back only the strobes, that really occured:
+strobe_points=strobe_points(1:counter);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval]=do_constrained_local_maximum(sigvals,options)
+% finds each local maximum. The next peak must be further away then
+% strobe_lag. But after timeout a strobe must occur. This version has
+% the added constraint that the timeout and decay constant are calculated
+% on a per-channel basis.
+
+
+% set strobe_lag to the rise time of the filter in this channel
+% For now, this assumes a gammatone filterbank with standard parameters.
+% Todo: update this.
+n=4; b=1.019; %! hard-coded - fix!!
+fc=options.current_cf;
+strobe_lag=(n-1)./(2.*pi.*b.*(24.7+0.108.*fc));% value in seconds
+
+% The decay time is set according to the channel's centre frequency
+strobe_decay_time=1/options.current_cf; % value in seconds
+
+current_threshold=0;
+sr=options.sr;
+tresval=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1);
+
+% last_strobe=-inf;
+last_strobe_time=-inf;
+counter=1;
+last_threshold_value=0;
+
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+ if current_val>current_threshold
+ if sigvals(ii) > sigvals(ii-1) && sigvals(ii) > sigvals(ii+1)
+ current_threshold=current_val;
+ if current_time > last_strobe_time+strobe_lag || ... % not in these 5 ms
+ current_time > last_strobe_time + timeout % but after 10 ms again
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ last_strobe_time=ii/sr;
+% last_strobe=ii;
+ end
+ end
+ last_threshold_value=current_threshold;
+ end
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ tresval(ii)=current_threshold;
+end
+% give back only the strobes, that really occured:
+strobe_points=strobe_points(1:counter);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval]=do_local_maximum(sigvals,options)
+% finds each local maximum. The next peak must be further away then
+% strobe_lag. But after timeout a strobe must occure
+
+unit=options.unit;
+
+if strcmp(unit,'cycles')
+ strobe_lag=1/options.current_cf*options.strobe_lag;
+ timeout=1/options.current_cf*options.timeout;
+elseif strcmp(unit,'sec')
+ strobe_lag=options.strobe_lag;
+ timeout=options.timeout;
+elseif strcmp(unit,'ms')
+ strobe_lag=options.strobe_lag/1000;
+ timeout=options.timeout/1000;
+else
+ error(sprintf('findstobes: dont know unit %s',unit));
+end
+
+current_threshold=0;
+sr=options.sr;
+tresval=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1);
+strobe_decay_time=options.strobe_decay_time;
+% last_strobe=-inf;
+last_strobe_time=-inf;
+counter=1;
+last_threshold_value=0;
+
+if options.current_cf>300
+ a=0;
+end
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+ if current_val>current_threshold
+ if sigvals(ii) > sigvals(ii-1) && sigvals(ii) > sigvals(ii+1)
+ current_threshold=current_val;
+ if current_time > last_strobe_time+strobe_lag || ... % not in these 5 ms
+ current_time > last_strobe_time + timeout % but after 10 ms again
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ last_strobe_time=ii/sr;
+% last_strobe=ii;
+ end
+ end
+ last_threshold_value=current_threshold;
+ end
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+ current_threshold=max(0,current_threshold);
+ tresval(ii)=current_threshold;
+end
+% give back only the strobes, that really occured:
+strobe_points=strobe_points(1:counter);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [strobe_points,tresval]=do_adaptive(sigvals,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
+
+current_threshold=0;
+sr=options.sr;
+last_strobe=-inf;
+
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1);
+
+%when the last strobe occured
+% last_strobe=-inf;
+last_threshold_value=0;
+
+% copy options to save time
+strobe_decay_time=options.strobe_decay_time;
+
+bunt=0.5;
+
+% decay_time=options.strobe_decay_time;
+% threshold_decay_constant=power(0.5,1./(options.strobe_decay_time*sr));
+
+slope_coefficient=options.slope_coefficient;
+slope_coefficient=0.0005;
+minoffset=0.2;
+
+threshold_decay_offset=-1/(options.strobe_decay_time*sr);
+default_threshold_decay_offset=threshold_decay_offset;
+
+counter=1;
+for ii=1:nr
+ current_val=sigvals(ii);
+ current_time=ii/sr;
+
+ if current_val>current_threshold
+ new_val=current_val-current_threshold;
+ current_threshold=current_val;
+ strobe_points(counter)=ii;
+ counter=counter+1;
+ time_offset=ii-last_strobe; % time since last strobe
+ last_strobe=ii;
+
+ amplitude_offset=current_threshold-last_threshold_value;
+
+ last_threshold_value=current_threshold;
+
+ current_bunt=0;
+ % if amplitude_offset>0
+ % current_bunt=amplitude_offset/1;
+ % else
+ % current_bunt=0;
+ % end
+ current_threshold=current_threshold+current_bunt+minoffset;
+
+ offset=amplitude_offset/time_offset*slope_coefficient;
+
+ threshold_decay_offset=threshold_decay_offset+offset;
+ % threshold_decay_constant=power(0.5,1./(decay_time*sr));
+ else
+ new_val=0;
+ end
+ tresval(ii)=current_threshold;
+ time_since_last_strobe=(ii-last_strobe)/sr;
+
+
+ % current_threshold=current_threshold*threshold_decay_constant;
+ current_threshold=current_threshold+threshold_decay_offset;
+ current_threshold=max(current_threshold,0);
+
+ if time_since_last_strobe>0.035
+ current_threshold=0;
+ threshold_decay_offset=default_threshold_decay_offset;
+ end
+
+ newvals(ii)=new_val;
+end
+% give back only the strobes, that really occured:
+strobe_points=strobe_points(1:counter);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% BUNT
+function [strobe_points,tresval]=do_bunt(sigvals,options)
+% the bunt is relative to the last peak hight
+
+current_threshold=0;
+sr=options.sr;
+last_strobe=-inf;
+
+tresval=zeros(size(sigvals));
+newvals=zeros(size(sigvals));
+nr=length(sigvals);
+strobe_points=zeros(1000,1);
+
+%when the last strobe occured
+last_strobe_time=-inf;
+last_threshold_value=0;
+% last_was_depressed_time=-inf; % time, when last strobe was thown out
+
+% copy options to save time
+strobe_decay_time=options.strobe_decay_time;
+
+% wait that many cycles to confirm a strobe
+wait_time=options.wait_cycles/options.current_cf;
+
+% if waited for too long, then strobe anyhow after some passed candidates:
+wait_timeout=options.wait_timeout_ms/1000;
+
+
+bunt_height=options.bunt;
+
+strobe_decay_time=options.strobe_decay_time;
+last_val=sigvals(1);
+
+counter=1;
+for ii=2:nr-1
+ current_val=sigvals(ii);
+ next_val=sigvals(ii+1);
+ current_time=ii/sr;
+ if current_val>=current_threshold % above threshold -> criterium for strobe
+ current_threshold=current_val;
+ if current_val > last_val && current_val > next_val % only strobe on local maxima
+
+ % so far its a candidate, but is it a real strobe?
+ % look if there was a strobe in the past, that is deleted
+ if (current_time-last_strobe_time1 )
+ % if its too long in the past, fire anyway
+ timediff=current_time-last_strobe_time;
+ prob=f2f(timediff,0,wait_timeout,0,1);
+
+% if timediff>wait_timeout %&& current_time-last_was_depressed_timerand(1);
+ is_valid=1;
+ else % this one was not a good one,
+ counter=counter-1; % delete the last one
+% last_was_depressed_time=current_time;
+ is_valid=0;
+ end
+ else
+ is_valid=1;
+ end
+
+ % take this one as a new one
+ strobe_points(counter)=ii;
+ strobe_time(counter)=ii/sr;
+ counter=counter+1; % strobecounter
+
+ % increase the threshold by an amount
+ current_threshold=current_threshold*bunt_height; %increase threshold
+ last_threshold_value=current_threshold;
+% if is_valid==1
+ last_strobe_time=ii/sr; % anyhow, its a candidate
+% end
+
+
+ end
+ end
+ tresval(ii)=current_threshold;
+
+ const_decay=last_threshold_value/sr/strobe_decay_time;
+ current_threshold=current_threshold-const_decay;
+
+ current_threshold=max(current_threshold,0);
+ last_val=current_val;
+end
+% give back only the strobes, that really occured:
+strobe_points=strobe_points(1:counter);
+
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %%%% BUNT
+% function [strobe_points,tresval]=do_bunt(sigvals,options)
+% % the bunt is relative to the last peak hight
+%
+% current_threshold=0;
+% sr=options.sr;
+% last_strobe=-inf;
+%
+% tresval=zeros(size(sigvals));
+% newvals=zeros(size(sigvals));
+% nr=length(sigvals);
+% strobe_points=zeros(100,1);
+%
+% %when the last strobe occured
+% last_strobe_time=-inf;
+% last_threshold_value=0;
+%
+% % copy options to save time
+% strobe_decay_time=options.strobe_decay_time;
+%
+% % wait that many cycles to confirm a strobe
+% wait_time=options.wait_cycles/options.current_cf;
+%
+% % if waited for too long, then strobe anyhow after some passed candidates:
+% wait_candidate_max=options.nr_strobe_candidates;
+% current_jumped_candidates=1;
+%
+%
+% bunt=options.bunt;
+%
+% strobe_decay_time=options.strobe_decay_time;
+% last_val=sigvals(1);
+%
+% counter=1;
+% for ii=2:nr-1
+% current_val=sigvals(ii);
+% next_val=sigvals(ii+1);
+% current_time=ii/sr;
+% if current_val>=current_threshold % above threshold -> criterium for strobe
+% current_threshold=current_val;
+% if current_val > last_val && current_val > next_val % only strobe on local maxima
+%
+% % so far its a candidate, but is it a real strobe?
+% % look if there was a strobe in the past, that is deleted
+% if (counter>1 && current_time-strobe_time(counter-1)last_threshold_value
+% % if its too long in the past, fire anyway
+% if current_jumped_candidates > wait_candidate_max
+% current_jumped_candidates=1; % reset counter
+% else
+% current_jumped_candidates=current_jumped_candidates+1;
+% counter=counter-1; % delete the last one
+% end
+% else
+% current_jumped_candidates=1;
+% end
+%
+%
+% % take this one as a new one
+% strobe_points(counter)=ii;
+% strobe_time(counter)=ii/sr;
+% counter=counter+1; % strobecounter
+% current_threshold=current_threshold*options.bunt; %increase threshold
+%
+% last_strobe_time=ii/sr; % anyhow, its a candidate
+% last_threshold_value=current_threshold;
+%
+% end
+% end
+% tresval(ii)=current_threshold;
+%
+% const_decay=last_threshold_value/sr/strobe_decay_time;
+% current_threshold=current_threshold-const_decay;
+%
+% current_threshold=max(current_threshold,0);
+% last_val=current_val;
+% end
+%
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/frand.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/frand.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,12 @@
+% 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 r=frand(from,to)
+% returns a random number in that range
+
+range=to-from;
+r=from+rand*range;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/fre2cent.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/fre2cent.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,11 @@
+% 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 cent=fre2cent(f0,hz)
+% usage: cent=fre2cent(f0,cent)
+
+cent=1200*log2(hz/f0);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/fre2note.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/fre2note.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,63 @@
+% 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 [str,oct,nr_note]=fre2note(fre)
+
+% translates the fre to the nearest real note in a-g
+
+if fre==0
+ str='no';
+ oct=0;
+ nr_note=-1;
+ return
+end
+
+note_names=['A ';'A#';'B ';'C ';'C#';'D ';'D#';'E ';'F ';'F#';'G ';'G#'];
+lowest_note=27.5; % Hz =A1 440 Hz= a4
+
+for i=1:length(fre)
+ if fre(i)>0
+ cent(i)=fre2cent(lowest_note,fre(i));
+ % how many octaves?
+ nr_octs(i)=round(cent(i)/1200)-1;
+ oct(i)=nr_octs(i)+1;
+
+ % how many tones?
+ cento(i)=mod(cent(i),1200)/100;
+ nr_note(i)=round(cento(i)+1);
+ if nr_note(i)>12
+ nr_note(i)=1;
+ end
+ % nr_note(find(nr_note>12))=1;
+ else
+ nr_note(i)=0;
+ end
+end
+% compansate for that the octave changes at C
+for i=1:length(fre)
+ if nr_note(i) > 3 && nr_note(i) < 7
+ nr_octs(i)=nr_octs(i)+1;
+ end
+end
+
+for i=1:length(fre)
+ if nr_note(i)==0
+ str{i}=['00'];
+ elseif strcmp(note_names(nr_note(i),2),' ')
+ if nr_octs(i)<0
+ str{i}=[note_names(nr_note(i)) '0'];
+ else
+ str{i}=[note_names(nr_note(i)) num2str(nr_octs(i))+1];
+ end
+ else
+ if nr_octs(i)<0
+ str{i}=[note_names(nr_note(i),1:2) '0'];
+ else
+ str{i}=[note_names(nr_note(i),1:2) num2str(nr_octs(i))+1];
+ end
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/gen_ms_mc_ch.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/gen_ms_mc_ch.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,90 @@
+%
+% function sig = gen_ms_mc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq)
+%
+% generates a multi segment, multi carrier, changing half-life, damped or ramped sound
+%
+% The size of the matrices corresponds to the number of segments
+% All vectors must have the same size or must be a scalar instead
+% If a scalar is used, this value is the same for each segment
+%
+% Matrix convention:
+% ----> column: each column contains the parameter for one segment
+% |
+% v 1st row contains the parameter for the 1st carrier etc.
+%
+%
+%
+% INPUT VALUES:
+% segment_len length of each segment in s (vector/scalar)
+% carrier_fq carrier frequence (matrix/vector)
+% envelope_fq envelope frequence = modulator fq (vector/scalar)
+% halflife Half life (matrix/vector) in seconds !!!
+% d_r 0 = damped,
+% 1 = ramped (vector, scalar)
+% sample_fq the sample frequence
+%%
+% RETURN VALUE:
+% sig the signal (object of class signal)
+%
+% REMARK: Sample frequence should be a multiple of both, the
+% carrier frequence as well as the envelope frequence
+%
+%
+% (c) 2003-2008, University of Cambridge, Medical Research Council
+% Christoph Lindner
+% 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 = gen_ms_mc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq)
+
+% sample_fq should be a multiple of carrier and envelope_fq
+if (mod(sample_fq, carrier_fq) ~= 0)
+ warning('Sample frequence should be a multiple of carrier frequence for a smooth transition between the segemnts');
+end
+if (mod(sample_fq, envelope_fq) ~= 0)
+ warning('Sample frequence should be a multiple of envelope frequence for a smooth transition between the segemnts');
+end
+% find out the number of segments
+nos = max([length(segment_len) size(carrier_fq,2) length(envelope_fq) size(halflife,2) length(d_r)]);
+
+sig = signal(0, sample_fq);
+% loop the segments
+for i =1:nos
+ % vector vs scalar
+ if length(segment_len) > 1
+ sl = segment_len(i);
+ else
+ sl = segment_len;
+ end
+ if size(carrier_fq, 2) > 1
+ cf = carrier_fq(:, i);
+ else
+ cf = carrier_fq;
+ end
+ if length(envelope_fq) > 1
+ ef = envelope_fq(i);
+ else
+ ef = envelope_fq;
+ end
+ if size(halflife, 2) > 1
+ hl = halflife(:, i);
+ else
+ hl = halflife;
+ end
+ if length(d_r) > 1
+ dr = d_r(i);
+ else
+ dr = d_r;
+ end
+
+ % generate signal
+ if dr == 1
+ sig_tmp = gen_multiramp(cf, hl, ef, sl, sample_fq);
+ else
+ sig_tmp = gen_multidamp(cf, hl, ef, sl, sample_fq);
+ end
+ % add the segement to the main signal vector
+ sig = append(sig, sig_tmp);
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/gen_ms_sc_ch.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/gen_ms_sc_ch.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,92 @@
+%
+% sig = function gen_ms_sc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq)
+%
+% The size of the vectors corresponds to the number of segments
+% All vectors must have the same size or must be a scalar instead
+% If a scalar is used, this value is the same for each segment
+%
+% INPUT VALUES:
+% segment_len length of each segment in s (vector/scalar)
+% carrier_fq carrier frequence (vector/scalar)
+% envelope_fq envelope frequence = modulator fq (vector/ scalar)
+% halflife Half life (vector/ scalar) in seconds !!!
+% d_r 0 = damped,
+% 1 = ramped (vector/scalar)
+% sample_fq the sample frequence
+%
+% RETURN VALUE:
+% sig the signal (object of class signal)
+%
+% REMARK: Sample frequence should be a multiple of both, the
+% carrier frequence as well as the envelope frequence
+%
+% (c) 2003-2008, University of Cambridge, Medical Research Council
+% Christoph Lindner
+% 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 = gen_ms_sc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq)
+
+% sample_fq should be a multiple of carrier and envelope_fq
+if (mod(sample_fq, carrier_fq) ~= 0)
+ warning('Sample frequence should be a multiple of carrier frequence for a smooth transition between the segemnts');
+end
+if (mod(sample_fq, envelope_fq) ~= 0)
+ warning('Sample frequence should be a multiple of envelope frequence for a smooth transition between the segemnts');
+end
+
+% find out the number of segments
+nos = max([length(segment_len) length(carrier_fq) length(envelope_fq) length(halflife) length(d_r)]);
+
+sig = signal(0, sample_fq);
+% loop the segments
+for i =1:nos
+ % vector vs scalar
+ if length(segment_len) > 1
+ sl = segment_len(i);
+ else
+ sl = segment_len;
+ end
+ % Special workaround to avoid aliases at the trasition (one
+ % point will be deleted)
+ if length(carrier_fq) > 1
+ cf = carrier_fq(i);
+ else
+ cf = carrier_fq;
+ end
+ if length(envelope_fq) > 1
+ ef = envelope_fq(i);
+ else
+ ef = envelope_fq;
+ end
+ if length(halflife) > 1
+ hl = halflife(i);
+ else
+ hl = halflife;
+ end
+ if length(d_r) > 1
+ dr = d_r(i);
+ else
+ dr = d_r;
+ end
+
+ % generate object
+ sig_obj = signal(sl, sample_fq);
+
+ % generate signal
+ if dr == 1
+ sig_tmp = generaterampsinus(sig_obj, cf, ef, 1, hl);
+ else
+ sig_tmp = generatedampsinus(sig_obj, cf, ef, 1, hl);
+ end
+ % add the segement to the main signal vector
+ % Special workaround to avoid aliases at the trasition (one
+ % point will be deleted)
+
+ sig = append(sig, sig_tmp);
+end
+
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/gen_multidamp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/gen_multidamp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,77 @@
+%
+% function sig=gen_multidamp(carriers,halflifes,reprate,signal_length, sample_fq)
+%
+% Generates a superposition of damped sinusiod signals
+%
+% INPUT VALUES:
+% carriers carrier frequences (vector)
+% halflifes (vector, same length as carriers)
+% reprate frequence of envelope
+% signal_length in seconds !!!
+% sample_fq sample frequence
+%
+% RETURN VALUE:
+% sig object signal
+%
+% (c) 2003-2008, University of Cambridge, Medical Research Council
+% Christoph Lindner
+% 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) $
+% $Version$
+
+function sig=gen_multidamp(carriers,halflifes,reprate,signal_length, sample_fq)
+
+if nargin < 5
+ sample_fq=16000;
+end
+if nargin < 4
+ signal_length=0.1;
+end
+if nargin < 3
+ reprate=100;
+end
+if nargin < 2
+ hlsteps=1;
+ halflifes=distributelogarithmic(0.064,0.0005,hlsteps);
+ halflifes=0.005;
+else
+ hlsteps=length(halflifes);
+end
+if nargin < 1
+ carsteps=5;
+ carriers=distributelogarithmic(250,4000,carsteps);
+else
+ carsteps=length(carriers);
+end
+
+sr = sample_fq;
+% sr=2^14;
+% sr=16000;
+% signal_length=0.264-1/sr;
+sig=signal(signal_length,sr);
+
+for i=1:hlsteps
+ for j=1:carsteps
+ current_carrier=carriers(j);
+ halflife=halflifes(i);
+ sig=generatedampsinus(sig,current_carrier,reprate,1,halflife);
+
+ if j==1
+ gsig=sig;
+ else
+ gsig=gsig+sig;
+ end
+ end
+
+ if i==1
+ tsig=gsig;
+ else
+ tsig=append(tsig,gsig);
+ end
+
+end
+% savewave(tsig,'tsig');
+
+
+sig=tsig;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/gen_multiramp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/gen_multiramp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,72 @@
+%
+% function sig=gen_multiramp(carriers,halflifes,reprate,signal_length, sample_fq)
+%
+% Generates a superposition of ramped sinusiod signals
+%
+% INPUT VALUES:
+% carriers carrier frequences (vector)
+% halflifes (vector, same length as carriers)
+% reprate frequence of envelope
+% signal_length in seconds !!!
+% sample_fq sample frequence
+%
+% RETURN VALUE:
+% sig object signal
+%
+%
+% (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) $
+% $Version$
+
+function sig=gen_multiramp(carriers,halflifes,reprate,signal_length, sample_fq)
+if nargin < 4
+ signal_length=0.128;
+end
+if nargin < 3
+ reprate=62.5;
+end
+if nargin < 2
+ hlsteps=8;
+ halflives=distributelogarithmic(0.064,0.0005,hlsteps);
+else
+ hlsteps=length(halflifes);
+end
+if nargin < 1
+ carsteps=5;
+ carriers=distributelogarithmic(250,4000,carsteps);
+else
+ carsteps=length(carriers);
+end
+
+
+sr = sample_fq;
+% sr=16000;
+% signal_length=0.264-1/sr;
+sig=signal(signal_length,sr);
+
+for i=1:hlsteps
+ for j=1:carsteps
+ current_carrier=carriers(j);
+ halflife=halflifes(i);
+ sig=generaterampsinus(sig,current_carrier,reprate,1,halflife);
+
+ if j==1
+ gsig=sig;
+ else
+ gsig=gsig+sig;
+ end
+ end
+
+ if i==1
+ tsig=gsig;
+ else
+ tsig=append(tsig,gsig);
+ end
+
+end
+% savewave(tsig,'tsig');
+
+
+sig=tsig;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/genam.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/genam.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,18 @@
+% tool
+%
+% 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=genam(sig,car,mod)
+
+nr_harm=3;
+sig=genharmton(sig,nr_harm,car-mod,mod);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/generate_clicktrain_normal.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/generate_clicktrain_normal.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,112 @@
+% support file for 'aim-mat'
+%
+% This 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 res=generate_clicktrain_normal
+% generate the "standart clicktrain response, that is subtracted from
+% the sai
+% generate a clicktrain, send it through an aim-model and average the
+% clicktrain response from 50-200 ms. Save the result in a file called
+% "click_frame"
+
+
+clear all_options
+ct=clicktrain(0.2,25000,25); % the clicktrain is below the width of the image
+
+% generate the model parameters:
+
+%%%%%%%%%%%%%
+% Signaloptions
+all_options.signal.signal_filename='temp.wav';
+all_options.signal.start_time=0;
+all_options.signal.duration=0.5;
+all_options.signal.samplerate=getsr(ct);
+
+%%%%%%%%%%%%%
+% outer/middle ear filter function
+all_options.pcp.none.generatingfunction='gennopcp';
+all_options.pcp.none.displayname='no correction by outer/middle ear';
+all_options.pcp.none.revision='$Revision: 585 $';
+
+
+%%%%%%%%%%%%%
+% bmm
+all_options.bmm.gtfb.generatingfunction='gen_gtfb';
+all_options.bmm.gtfb.displayname='Gamma tone filter bank';
+all_options.bmm.gtfb.revision='$Revision: 585 $';
+all_options.bmm.gtfb.nr_channels=50;
+all_options.bmm.gtfb.lowest_frequency=100;
+all_options.bmm.gtfb.highest_frequency=6400;
+all_options.bmm.gtfb.do_phase_alignment='off';
+all_options.bmm.gtfb.phase_alignment_nr_cycles=3;
+all_options.bmm.gtfb.b=1.019;
+
+
+%%%%%%%%%%%%%
+% nap
+all_options.nap.hcl.generatingfunction='gen_hcl';
+all_options.nap.hcl.displayname='halfwave rectification, compression and lowpass filtering';
+all_options.nap.hcl.revision='$Revision: 585 $';
+all_options.nap.hcl.compression='log';
+all_options.nap.hcl.do_lowpassfiltering=1;
+all_options.nap.hcl.lowpass_cutoff_frequency=1200;
+all_options.nap.hcl.lowpass_order=2;
+
+
+%%%%%%%%%%%%%
+% strobes
+all_options.strobes.sf2003.generatingfunction='gen_sf2003';
+all_options.strobes.sf2003.displayname='strobe finding';
+all_options.strobes.sf2003.revision='$Revision: 585 $';
+all_options.strobes.sf2003.strobe_criterion='interparabola';
+all_options.strobes.sf2003.strobe_decay_time=0.02;
+all_options.strobes.sf2003.parabel_heigth=1.2;
+all_options.strobes.sf2003.parabel_width_in_cycles=1.5;
+all_options.strobes.sf2003.bunt=1.02;
+all_options.strobes.sf2003.wait_cycles=1.5;
+all_options.strobes.sf2003.wait_timeout_ms=20;
+all_options.strobes.sf2003.slope_coefficient=1;
+
+
+%%%%%%%%%%%%%
+% sai
+all_options.sai.ti2003.generatingfunction='gen_ti2003';
+all_options.sai.ti2003.displayname='time integration stabilized auditory image';
+all_options.sai.ti2003.revision='$Revision: 585 $';
+all_options.sai.ti2003.criterion='change_weights';
+all_options.sai.ti2003.start_time=0;
+all_options.sai.ti2003.maxdelay=0.035;
+all_options.sai.ti2003.buffer_memory_decay=0.03;
+all_options.sai.ti2003.frames_per_second=300;
+all_options.sai.ti2003.weight_threshold=0;
+all_options.sai.ti2003.do_normalize=1;
+all_options.sai.ti2003.do_times_nap_height=0;
+all_options.sai.ti2003.do_adjust_weights=1;
+all_options.sai.ti2003.strobe_weight_alpha=0.5;
+all_options.sai.ti2003.delay_weight_change=0.5;
+all_options.sai.ti2003.erb_frequency_integration=0;
+
+
+
+% set the signal to the appropriate one
+savewave(ct,'temp.wav');
+
+
+
+res=aim(all_options);
+
+resu=res.result;
+len=length(resu);
+click_frame=resu{1}; % its an empty one anyhow
+for i=10:len
+ fr=resu{i}/1000;
+ click_frame=click_frame+fr;
+end
+
+save click_frame click_frame
+
+
+res=click_frame;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/generatemultidamp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/generatemultidamp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,64 @@
+% tool
+%
+% 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=generatemultidamp(carriers,halflifes,reprate,signal_length)
+
+if nargin < 4
+ signal_length=0.128;
+end
+if nargin < 3
+ reprate=62.5;
+end
+if nargin < 2
+ hlsteps=8;
+ halflives=distributelogarithmic(0.064,0.0005,hlsteps);
+else
+ hlsteps=length(halflifes);
+end
+if nargin < 1
+ carsteps=5;
+ carriers=distributelogarithmic(250,4000,carsteps);
+else
+ carsteps=length(carriers);
+end
+
+
+sr=2^14;
+% sr=16000;
+% signal_length=0.264-1/sr;
+sig=signal(signal_length,sr);
+
+for i=1:hlsteps
+ for j=1:carsteps
+ current_carrier=carriers(j);
+ halflife=halflifes(i);
+ sig=generatedampsinus(sig,current_carrier,reprate,1,halflife);
+
+ if j==1
+ gsig=sig;
+ else
+ gsig=gsig+sig;
+ end
+ end
+
+ if i==1
+ tsig=gsig;
+ else
+ tsig=append(tsig,gsig);
+ end
+
+end
+% savewave(tsig,'tsig');
+
+
+sig=tsig;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/generatemultiramp.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/generatemultiramp.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,63 @@
+% tool
+%
+% 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=generatemultiramp(carriers,halflifes,reprate,signal_length)
+
+if nargin < 4
+ signal_length=0.128;
+end
+if nargin < 3
+ reprate=62.5;
+end
+if nargin < 2
+ hlsteps=8;
+ halflives=distributelogarithmic(0.064,0.0005,hlsteps);
+else
+ hlsteps=length(halflifes);
+end
+if nargin < 1
+ carsteps=5;
+ carriers=distributelogarithmic(250,4000,carsteps);
+else
+ carsteps=length(carriers);
+end
+
+
+sr=16000;
+% signal_length=0.264-1/sr;
+sig=signal(signal_length,sr);
+
+for i=1:hlsteps
+ for j=1:carsteps
+ current_carrier=carriers(j);
+ halflife=halflifes(i);
+ sig=generaterampsinus(sig,current_carrier,reprate,1,halflife);
+
+ if j==1
+ gsig=sig;
+ else
+ gsig=gsig+sig;
+ end
+ end
+
+ if i==1
+ tsig=gsig;
+ else
+ tsig=append(tsig,gsig);
+ end
+
+end
+% savewave(tsig,'tsig');
+
+
+sig=tsig;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/generateparameterfile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/generateparameterfile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,54 @@
+% tool
+%
+% 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 generateparameterfile(makefilename,varargin)
+% usage:generateparameterfile(makefilename,varargin)
+% produces the "makefilename" from the parameters in varargin
+
+
+nr_pairs=size(varargin{1},2)/2;
+
+if mod(size(varargin{1},2),2)==1
+ disp('odd number of parameters - please input a full set of parameters and arguments');
+ return;
+end
+
+count=1;
+for i=1:nr_pairs
+ a=varargin{1}{count};
+ b=varargin{1}{count+1};
+ if isnumeric(b)
+ te='[';
+ for j=1:size(b,2)
+ sss=sprintf('%f',b(j));
+ te=[te sss ' '];
+ end
+ te=[te ']'];
+ str{i}=sprintf('%s\t%s',varargin{1}{count},te);
+ else
+ if iscell(b)
+ te='[';
+ for j=1:size(b,2)
+ te=[te b{j} ' '];
+ end
+ te=[te ']'];
+ str{i}=sprintf('%s\t%s',varargin{1}{count},te);
+ else
+ str{i}=sprintf('%s\t%s',a,b);
+ end
+ end
+ count=count+2;
+end
+
+
+savetofile(str,makefilename);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/genrow.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/genrow.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,64 @@
+% tool
+%
+% 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 res=genrow
+
+
+s1=signal(0.3,16000); %erster Ton
+s2=signal(0.3,16000); % zweiter Ton
+s3=signal(0.3,16000); %
+s4=signal(0.3,16000); %
+s5=signal(0.3,16000); %
+s6=signal(0.3,16000); %
+
+
+s1=genharmonics(s1,'fundamental','100','min_fre','500','max_fre','3000');
+s2=genharmonics(s1,'fundamental','100','min_fre','500','max_fre','3000','type','decreaseoddamplitude','changeby','-2');
+s3=genharmonics(s1,'fundamental','100','min_fre','500','max_fre','3000','type','decreaseoddamplitude','changeby','-4');
+s4=genharmonics(s1,'fundamental','100','min_fre','500','max_fre','3000','type','decreaseoddamplitude','changeby','-6');
+s5=genharmonics(s1,'fundamental','100','min_fre','500','max_fre','3000','type','decreaseoddamplitude','changeby','-8');
+s6=genharmonics(s1,'fundamental','100','min_fre','500','max_fre','3000','type','decreaseoddamplitude','changeby','-10');
+
+rms1=rms(s1);
+rms2=rms(s2);
+rms3=rms(s3);
+rms4=rms(s4);
+rms5=rms(s5);
+rms6=rms(s6);
+
+rmsmax=max([rms1 rms2 rms3 rms4 rms5 rms6]);
+
+s1=RampAmplitude(s1,0.05); % baue eine Rampe
+s2=RampAmplitude(s2,0.05); % baue eine Rampe
+s3=RampAmplitude(s3,0.05); % baue eine Rampe
+s4=RampAmplitude(s4,0.05); % baue eine Rampe
+s5=RampAmplitude(s5,0.05); % baue eine Rampe
+s6=RampAmplitude(s6,0.05); % baue eine Rampe
+
+s1=s1*(rmsmax/rms1);
+s2=s2*(rmsmax/rms2);
+s3=s3*(rmsmax/rms3);
+s4=s4*(rmsmax/rms4);
+s5=s5*(rmsmax/rms5);
+s6=s6*(rmsmax/rms6);
+
+signal res;
+res=s1;
+res=append(res,s2);
+res=append(res,s3);
+res=append(res,s4);
+res=append(res,s5);
+res=append(res,s6);
+res=setname(res,'five sounds');
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/genton.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/genton.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% tool
+%
+% 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 res=genton(nr_comps,nr_harm,f0,len)
+
+if nargin < 4
+ len=0.3;
+end
+
+s1=signal(len,16000); %erster Ton
+
+fundamental=f0;
+fcs=nr_harm*f0;
+bandwidth=(nr_comps-1)*f0;
+s=sprintf('sig=genharmonics(s1,''fundamental'',''%f'',''filterprop'',[%f 1 %f 1]);',fundamental,fcs,bandwidth);
+eval(s);
+
+sig=scaletomaxvalue(sig,1);
+sig=RampAmplitude(sig,0.01); % baue eine Rampe
+
+sig=setname(sig,sprintf('Fundamental:%dHz',round(f0)));
+res=sig;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getAIFFinfo.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getAIFFinfo.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,121 @@
+% tool
+%
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: GetAIFFinfo.m
+% by stefan@bleeck.de
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function ret = GetAIFFinfo(fname)
+
+[fid, msg] = fopen(fname);
+if fid == -1
+ error('File open error. Please check that the file name is correctly spelled.')
+end
+littleEndian = 0;
+aiff_form = ReadBytes(fid, 4, littleEndian);
+if aiff_form' == double('FORM')
+% disp('big-endian');
+else
+% disp('little-endian');
+ littleEndian = 1;
+end;
+
+chunkSize = Read32Bits(fid, littleEndian);
+
+aiff_aiff = ReadBytes(fid, 4, littleEndian);
+if aiff_aiff' ~= double('AIFF')
+ aiff_aiff
+ disp('Not a valid AIFF file.');
+ return
+end;
+chunkSize = chunkSize - 16;
+
+while chunkSize - 4 > 0;
+ chunkName = ReadBytes(fid, 4, littleEndian);
+ chunkSize = chunkSize - 4;
+ if chunkName' == double('COMM');
+% disp('step COMM');
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize-subSize;
+ numChannels = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ numSampleFrames = Read32Bits(fid, littleEndian);
+ subSize = subSize - 4;
+ sampleSize = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ sampleRate = ReadIEEE2(fid, littleEndian);
+ subSize = subSize - 10;
+ fread(fid, subSize, 'char');
+ elseif chunkName' == double('SSND');
+% disp('step SSND');
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize - subSize;
+ offset = Read32Bits(fid, littleEndian);
+ subSize = subSize - 4;
+ blockSize = Read32Bits(fid, littleEndian);
+ subSize = subSize - 4;
+ soundPosition = ftell(fid) + offset;
+ fread(fid, subSize, 'char');
+ elseif chunkName' == double('LUT2');
+% disp('step LUT2');
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize - subSize;
+ interleaveLevel = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ numWindowFrames = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ staticTimeFlag = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ outputTimeOffset = ReadIEEE2(fid, littleEndian);
+ subSize = subSize - 10;
+ absoluteNormalise = ReadIEEE2(fid, littleEndian);
+
+ subSize = subSize - 10;
+ fread(fid, subSize, 'char');
+
+ else;
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize - subSize;
+ fread(fid, subSize, 'char');
+
+ end;
+end;
+fclose(fid);
+
+wordSize = floor((sampleSize + 7 ) / 8);
+normalise = (2^16 - 1) / 2^(17 - wordSize * 8) / absoluteNormalise;
+switch wordSize
+ case 1, scale = normalise / 127.0;
+ case 2, scale = normalise / 32768.0;
+ case 4, scale = normalise / 32768.0 / 65536;
+end
+frameLength = numSampleFrames / numWindowFrames;
+
+ret.totalframetime=frameLength/sampleRate;
+ret.numWindowFrames=numWindowFrames;
+ret.scale=scale;
+ret.wordSize=wordSize;
+ret.soundPosition=soundPosition;
+ret.littleEndian=littleEndian;
+ret.frameLength=frameLength;
+ret.numChannels=numChannels;
+ret.numSampleFrames=numSampleFrames;
+ret.sampleSize=sampleSize;
+ret.sampleRate=sampleRate;
+ret.interleaveLevel=interleaveLevel;
+ret.numWindowFrames=numWindowFrames;
+ret.staticTimeFlag=staticTimeFlag;
+ret.outputTimeOffset=outputTimeOffset;
+ret.absoluteNormalise=absoluteNormalise;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/get_new_filename.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/get_new_filename.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,36 @@
+% support file for 'aim-mat'
+%
+% This 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 filename=get_new_filename(prefix,extension);
+% gives back the a name of a file that does not exist yet that has a number
+% one higher then the highest number that exist with that name
+% example: newfile('new','mat') gives back new1.mat
+% again: newfile('new','mat') gives back new2.mat new3.mat etc
+
+if nargin<2 || strcmp(extension,'');
+ extension='*';
+else
+ if isempty(strfind(extension,'.'))
+ extension=['.' extension];
+ end
+end
+searchstr=sprintf('allfiles=dir(''%s*%s'');',prefix,extension);
+eval(searchstr);
+
+if length(allfiles)==0
+ filename=[prefix '1' extension];
+ return
+end
+
+lastfileinfo=allfiles(end);
+lastfile=lastfileinfo.name;
+nr1=strfind(lastfile,prefix)+length(prefix);
+nr2=strfind(lastfile,extension);
+nr=str2num(lastfile(nr1:nr2));
+
+newnumber=nr+1;
+filename=sprintf('%s%d%s',prefix,newnumber,extension);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getaiffs.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getaiffs.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,378 @@
+% tool
+%
+% 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 aiffs=getaiffs(varargin)
+%usage: aiffs=getaiff(varargin)
+%
+% otherwise parameter must come in pairs: 'param','value'
+% allowed parameters are:
+% modelfile - the spf file that specifies the version of AMS/AIM (required)
+% soundcommand - a wave or raw file with the sound in (required)
+% framespersecond (default: 12)
+% output_normalization - the norm_mode parameter in out_file very useful for automatic scaling
+% sound_sample_rate - the sample rate of the sound file
+% sound_endian - endian of the sound file (l or b)(PC's are little endian Suns are big endian)
+% writeaiffile - optional: a file to which the output aif file will be written
+% echo - on (default) or off - if output is written on the screen
+%
+% returns an array of the class "frame" for each frame read
+
+defined_input_gain=70;
+temp_sound_file_name='temp_sound.wav';
+temp_aiff_file_name='temp_aiff.aif';
+
+if nargin<2 % only one parameter -> read file
+ if size(varargin)==1
+ makefilename=varargin{1};
+ else
+ makefilename='lastrun.genmovie';
+ end
+ % fprintf('movie is produced from file %s from aifffile "makemovie_temp.aif"\n!',makefilename);
+% fprintf('aiff-file is produced according to file ''%s''\n',makefilename);
+else
+ makefilename='lastrun.genmovie';
+ generateparameterfile(makefilename,varargin);
+end
+
+arguments=readparameterfile(makefilename);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% make a string from each parameter
+str_model=getargument(arguments,'modelfile');
+str_soundcommand=getargument(arguments,'soundfile');
+str_framespersecond=getargument(arguments,'framespersecond');
+str_output_normalization=getargument(arguments,'output_normalization');
+str_sound_sample_rate=getargument(arguments,'sound_sample_rate');
+str_sound_endian=getargument(arguments,'sound_endian');
+str_writeaiffile=getargument (arguments,'writeaiffile');
+str_echo=getargument(arguments,'echo');
+str_setvalue=getargument(arguments,'setvalue');
+str_setvalueto=getargument(arguments,'setvalueto');
+str_movie_duration=getargument(arguments,'movie_duration');
+str_movie_start_time=getargument(arguments,'movie_start_time');
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% default values for all parameters
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% sound-file. can be a command or a file
+if isempty(str_soundcommand) %
+ error('soundcommand must be given');
+else
+ soundcommand=str_soundcommand;
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% spf-file.
+if isempty(str_model) %
+ error('modelfile must be given');
+else
+ % check for extension
+ [dumy_path,dummy_name,ext,versn] = fileparts(str_model);
+ if strcmp(ext,'')
+ model=sprintf('%s.spf',str_model);
+ else
+ model=str_model;
+ end
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% output normalization cares for the correct scaling in the aiff-files
+% to prevent negativ numbers
+if ~isempty(str_output_normalization) % how much the spf file should be normalized by setting the norm_mode parameter in out_file
+ eval(sprintf('scale_factor_output=%s;',str_output_normalization));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% frames per second
+if isempty(str_framespersecond) % default frames per second
+ framespersecond=12;
+else
+ eval(sprintf('framespersecond=%s;',str_framespersecond));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% echo on screen
+if isempty(str_echo) % default frames per second
+ echo=1;
+else
+ if strcmp(str_echo,'off')
+ echo=0;
+ else
+ echo=1;
+ end
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% read the sound command and transfere the data to the buffer
+if ~isempty(str_movie_duration) % default frames per second
+ eval(sprintf('movie_start_time=%s;',str_movie_start_time));
+ eval(sprintf('movie_duration=%s;',str_movie_duration));
+% [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian,movie_start_time,movie_duration);
+ [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian);
+else
+ movie_start_time=0;
+ [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian);
+ movie_duration=length(sounddata)/samplerate;
+end
+
+disp(sprintf('producing sound from command: %s',soundcommand));
+videolength=size(sounddata,1)/samplerate;
+
+% so long is one picture:
+duration=1/framespersecond;
+if duration > movie_duration
+ duration = movie_duration;
+end
+
+% so many frames is the video size in the end:
+nr_frames=round(videolength*framespersecond);
+starttime=0;
+
+% open Modelfile for read in some parameters like cfs etc
+id=fopen(model,'rt');
+if id<=0
+ error(sprintf('Model-file %s not found',model));
+end
+fclose(id);
+% open the soundfile to find out about sr and length
+id=fopen(soundcommand,'rt');
+if id<=0
+ error(sprintf('Sound-file %s not found',soundcommand));
+end
+fclose(id);
+
+% put everything important in the options to be called with ams_ng
+options=[];
+somuchruns=sprintf('%2.0f',nr_frames);
+options=[options ' NUM_RUNS.ams ' somuchruns];
+options=[options ' SEGMENT_MODE.ams ' 'ON'];
+options=[options ' FILELOCKING_MODE.ams ' 'ON'];
+options=[options ' CHANNELS.DataFile_In ' '1'];
+
+%% user defined changes to values in the spf-file (eg for setting random seed)
+if ~isempty(str_setvalue) %
+ options=[options ' ' str_setvalue ' ' str_setvalueto ' '];
+end
+
+% build the correct dsam-output my-input aif-file:
+options=[options ' FILENAME.DataFile_Out ' temp_aiff_file_name];
+
+% make the correct soundcommand
+
+if strfind(str_soundcommand,'wav')
+ options=[options ' FILENAME.DataFile_In ' str_soundcommand];% always the same name: makemovie_temp.wav
+else
+ options=[options ' FILENAME.DataFile_In ' temp_sound_file_name];% always the same name: makemovie_temp.wav
+end
+
+% bring it to a format, that dsam understands:
+wordsize=bits/8;
+words=sprintf('%d',wordsize);
+options=[options ' WORDSIZE.DataFile_In ' words];
+srat=sprintf('%f',samplerate);
+options=[options ' SAMPLERATE.DataFile_In ' srat];
+dur=sprintf('%f',duration);
+options=[options ' DURATION.DataFile_In ' dur];
+star=sprintf('%f',starttime);
+options=[options ' STARTTIME.DataFile_In ' star];
+gain=sprintf('%f',defined_input_gain);
+options=[options ' GAIN.DataFile_In ' gain];
+
+
+% scaling must be performed in the input file to prevent too high numbers in the output
+% !!!
+% % the user has to set the correct scale value in the original spf-file
+% this is best done by watching a whole film in ams and searching for the biggest
+% value. Set this value as parameter 'NORM_MODE.DataFile_Out'
+% it is NOT A GOOD IDEA to set this value to -1 (auto) because, this value is calculated
+% from the first frame and this ist not the highest. As result, strange negative values occur!
+if ~isempty(str_output_normalization) % how much the spf file should be normalized by setting the norm_mode parameter in out_file
+ options=[options ' NORM_MODE.DataFile_Out ' str_output_normalization];
+end
+
+% find out abput the times used in ms to display numbers
+content_spfmodel=loadtextfile(model);
+t_minusstr=DSAMFindParameter(content_spfmodel,'NWIDTH.Ana_SAI');
+t_minus=sscanf(t_minusstr,'%f')*1000;
+t_plusstr=DSAMFindParameter(content_spfmodel,'PWIDTH.Ana_SAI');
+t_plus=sscanf(t_plusstr,'%f')*1000;
+
+% do I need later:
+str_scale_factor_output=DSAMFindParameter(content_spfmodel,'NORM_MODE.DataFile_Out');
+scale_factor_output=sscanf(str_scale_factor_output,'%f');
+
+% find out about the frequency axis and make it nice
+cf=DSAMGetCFs(content_spfmodel);
+nr_freq=length(cf);
+
+
+% delete the remains from last run
+if fexist(temp_aiff_file_name)
+ try
+ delete(temp_aiff_file_name);
+ catch
+ error(sprintf('ReadAiff: Error: Could not delete existing file %s',temp_aiff_file_name));
+ end
+end
+
+% the command line, that starts the process:
+% ams must be in Path or this line must point to its directory:
+%cd('C:\Program Files\DSAM\AMS');
+% mas_ng starts a single ams process without grafik (very fast)
+% -d turns off the debug messages
+% -s calls the file makemovie_temp.spf
+% -r gives the number of runs (somuchruns)
+% segment on tells dsam to run in segmented mode
+if ispc
+% str=sprintf('! ams_ng.exe -doff -smakemovie_temp.spf -r%s segment on',somuchruns);
+ str=sprintf('! ams_ng.exe -doff -s%s -r%s segment on %s',model,somuchruns,options);
+else
+% str=sprintf('!/cbu/cnbh/dsam/bin/ams_ng -doff -smakemovie_temp.spf -r%s segment on',somuchruns);
+ str=sprintf('! /cbu/cnbh/dsam/bin/ams_ng -doff -s%s -r%s segment on %s',model,somuchruns,options);
+end
+
+% this one works with a window.
+% str=sprintf('! AMS.exe -S -s makemovie_temp.spf -r %s &',somuchruns);
+
+% delete the remains of some buggy run:
+if fexist('.ams_LCK')
+ try
+ delete('.ams_LCK');
+ catch
+ error('Could not delete existing file .ams_LCK. Please restart matlab');
+ end
+end
+
+if echo disp('Ams simulation started...');end
+eval([str]); % do ams!
+
+t0 = clock;
+while etime(clock,t0)<0.1 %wait a little while
+end
+
+% and look for the lock file
+while fexist('.ams_LCK')
+end % continue, when its _not_ there
+
+
+
+FID = fopen(temp_aiff_file_name,'r');
+if FID==-1
+ error('error in simulation: aif-file was not generated!');
+end
+fclose(FID);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% all finished :) now read in the aiff-file
+allframes=SBReadAiff(temp_aiff_file_name,echo); % returns all info in a struct
+
+if ~isempty(str_writeaiffile)
+ % for jen: make a copy of the aiff file to something else
+ copyfile(temp_aiff_file_name, str_writeaiffile);
+end
+
+% find out about the structure
+sample_frame=allframes(1);
+nr_channels=getnrchannels(sample_frame);
+nr_points=getnrpoints(sample_frame);
+nr_frames=size(allframes,2);
+
+% put the information about the center frequencies in the frames
+if ~is_current_var('cf',who) % if read from aif-file, no such info exist
+ for i=1:nr_channels
+ cf(i)=i*1000;
+ end
+ t_plus=getmaximumtime(sample_frame)*1000;
+ t_minus=getminimumtime(sample_frame)*1000;
+end
+% set the frequency information in each frame
+for i=1:nr_frames
+ allframes(i)=setcf(allframes(i),cf);
+end
+% and make a nice name for it:
+for i=1:nr_frames
+ allframes(i)=setname(allframes(i),sprintf('Frame #%d of %d from sound %s',i,nr_frames,str_soundcommand));
+ start_times=(i-1)*duration+movie_start_time;
+ allframes(i)=setcurrentframestarttime(allframes(i),start_times);
+end
+
+% values for scaling the actual sum of all channels
+scale_summe=0;% this value is used to scale the picture of the sum later
+for i=1:nr_frames
+ vals=getvalues(allframes(i));
+ maxsc=getamplitudemaxvalue(sample_frame);
+ if maxsc~=0
+ vals=vals/getamplitudemaxvalue(sample_frame);
+ end
+ su=sum(vals);
+ ma=max(su);
+ if ma > scale_summe scale_summe=ma; end
+end
+
+
+low=getamplitudeminvalue(sample_frame);
+
+
+if low < 0
+ disp('Achtung: Negative values in the AIFF-File! ');
+ disp('This probably means, that the value in ');
+ disp('NORM_MODE in DataFile_Out was not high enough!');
+ disp(sprintf('current value: %5.1f',scale_factor_output));
+ fprintf('\n[a] double it to %5.1f, or \n(b) continue anyway \nor type in the new value\n',scale_factor_output*2);
+
+ reply = input(': ','s');
+
+ if isempty(reply) % default
+ reply ='a';
+ end
+
+ valgiven=0;
+ if reply~='a' & reply~='b'
+ eval(sprintf('val=%s;',reply));
+ else
+ if reply=='a'
+ val=2 * scale_factor_output; % double it!
+ end
+ if reply=='b'
+ val=scale_factor_output; % no change
+ end
+ end
+ if isnan(val) | val<=0
+ error('sorry, no valid input');
+ end
+
+ if val~=scale_factor_output % only, if there is a change!
+ scale_factor_output=val;
+ % try it again!
+ aiffs=getaiffs(...
+ 'modelfile',str_model,...
+ 'soundcommand',str_soundcommand,...
+ 'framespersecond',str_framespersecond,...
+ 'output_normalization',scale_factor_output,... %thats the new one
+ 'sound_sample_rate',str_sound_sample_rate,...
+ 'writeaiffile',str_writeaiffile,...
+ 'echo',str_echo,...
+ 'sound_endian',str_sound_endian,...
+ 'setvalue',str_setvalue,...
+ 'setvalueto',str_setvalueto...
+ );
+ return;
+
+ end
+end
+
+aiffs=allframes;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getargument.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getargument.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% tool
+%
+% 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 str=getargument(source,search)
+% usage: str=getargument(source,search)
+% searchs in the pairs of parameters 'param','value' for the argument and returns the value as string
+% source must be a even number of input parameters
+
+% for compatibility with old version
+if ~isfield(source,'name')
+ nr=size(source,2); % so many pairs
+ for i=1:nr
+ param=source(i);
+ if strcmp(param,search)
+ str= source(i+1);
+ return
+ end
+ end
+ str{1}='';
+ return
+
+else
+
+ % new version is much more elegant
+ nr=size(source.name,2); % so many pairs
+ for i=1:nr
+ param=source.name{i};
+ if strcmp(param,search)
+ str=source.argument{i};
+
+ % if the argument is put into "[]" then remove them
+ return
+ end
+ end
+end
+str='';
+return
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getfiltervaluehighpass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getfiltervaluehighpass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% tool
+%
+% 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 scaler=getfiltervaluehighpass(cur_fre,cutoff,dbperoctave)
+
+
+%feststellen, wieviel octaven ich unter dem cutoff bin:
+octs=log2(cutoff/cur_fre);
+
+% wieviel dB sind das?
+nrdB=octs*dbperoctave;
+
+scaler=power(10,(-nrdB/20));
+
+% gib nur die Werte > Cutoff zurück
+scaler=min(1,scaler);
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getfiltervaluelowpass.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getfiltervaluelowpass.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% tool
+%
+% 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 scaler=getfiltervaluehighpass(cur_fre,cutoff,dbperoctave)
+
+
+%feststellen, wieviel octaven ich über dem cutoff bin:
+octs=log2(cur_fre/cutoff);
+
+% wieviel dB sind das?
+nrdB=octs*dbperoctave;
+
+scaler=power(10,(-nrdB/20));
+
+% gib nur die Werte > Cutoff zurück
+scaler=min(1,scaler);
+
+
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getmaxcontrast.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getmaxcontrast.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,46 @@
+% tool
+%
+% 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 contrast=getmaxcontrast(wo,maxpos,minpos,maxs,mins)
+% usage: getmaxcontrast(wo,maxs,mins)
+% returns the contrast of the maximum at wo
+% this is calculated by taking the left and the right minimum of the max
+
+[leftminwo,leftmin]=getminimumleftof(wo,maxpos,minpos,maxs,mins);
+if isempty(leftminwo)
+ % wenns keinen linkes minimum gibt, versuche, obs ein rechtes gibt
+ [rightminwo,rightmin]=getminimumrightof(wo,maxpos,minpos,maxs,mins);
+ if ~isempty(rightminwo)
+ leftmin=rightmin;
+ else
+ leftmin=0;
+ end
+end
+
+[rightminwo,rightmin]=getminimumrightof(wo,maxpos,minpos,maxs,mins);
+if isempty(rightminwo)
+ rightmin=leftmin;
+end
+
+maxval=maxs(find(maxpos==wo));
+
+% Wenn der Punkt kein Maximum der Einhüllenden ist
+if isempty(maxval)
+ p=0;
+% error('getmaxcontrast:maximum not in list');
+end
+
+minval=(rightmin+leftmin)/2;
+
+contrast=(maxval-minval)/(maxval+minval);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getmaximacharacteristics.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getmaximacharacteristics.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,66 @@
+% tool
+%
+% 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 ret=getmaximacharacteristics(where,maxpos,minpos,maxs,mins)
+% gibt die wesentlichen Eigenschaften der Maxima zurück:
+% absoulte_height
+% position = position of the maximum
+% distance = mean distance to neighbour mins
+% contrast = peak to trough ration of max to neighbour mins
+% supheight = height above the neighbour peaks
+
+nr=length(where);
+for i=1:nr
+ [minleft,minleftwo]=getminimumleftof(where(i),maxpos,minpos,maxs,mins);
+ [minright,minrightwo]=getminimumrightof(where(i),maxpos,minpos,maxs,mins);
+ [maxleft,maxleftwo]=getmaximumleftof(where(i),maxpos,minpos,maxs,mins);
+ [maxright,maxrightwo]=getmaximumrightof(where(i),maxpos,minpos,maxs,mins);
+
+ current_val=maxs(find(maxpos==where(i)));
+ ret{i}.absheight=current_val;
+
+ ret{i}.position=where(i);
+
+ ret{i}.contrast=getmaxcontrast(where(i),maxpos,minpos,maxs,mins);
+ ret{i}.width=getmaxwidth(where(i),maxpos,minpos,maxs,mins);
+
+ if ~isempty(minleft) & ~isempty(minright)
+ ret{i}.distance=(abs(minrightwo) - abs(minleftwo))/2; % Mittelwert der Abstände zu den nächsten beiden peaks
+ end
+ if isempty(minleft)
+ ret{i}.distance=abs(minrightwo);
+ end
+ if isempty(minright)
+ ret{i}.distance=abs(minleftwo);
+ end
+
+ if ~isempty(maxleft) & ~isempty(maxright)
+ ret{i}.supheight=current_val/(maxleft+maxright)/2;
+ end
+
+ if isempty(maxleft)
+ if isempty(maxright)
+ ret{i}.supheight=0;
+ else
+ ret{i}.supheight=current_val/maxright;
+ end
+ end
+
+ if isempty(maxleft)
+ if isempty(maxright)
+ ret{i}.supheight=0;
+ else
+ ret{i}.supheight=current_val/maxright;
+ end
+ end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getmaximumleftof.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getmaximumleftof.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,54 @@
+% tool
+%
+% 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 [pos_max,maxval]=getmaximumleftof(where,maxpos,minpos,maxs,mins)
+% usage: [pos_max,maxval]=getmaximumleftof(where,womins,minvals,womaxs,maxvals)
+% returns the maximum that is left of point "where"
+% mins and maxs must be complete sets of minimums and maximums
+% interwoven
+
+pos_max=[];
+maxval=[];
+
+if isempty(maxpos)
+ return;
+end
+
+if where < maxpos(1)
+ return;
+ error('getminimumleftof:: no maximum left of point');
+end
+
+
+nr =length(where);
+for j=1:nr
+ cwhere=fround(where(j),5);
+ nr_maxs=length(maxpos);
+ for i=nr_maxs:-1:1
+ if fround(maxpos(i),5) < cwhere
+ pos_max(j)=maxpos(i);
+ maxval(j)=maxs(i);
+ break;
+ end
+ end
+end
+%
+% nr_maxs=length(womaxs);
+% for i=nr_maxs:-1:1
+% if womaxs(i) < where
+% pos_max=womaxs(i);
+% maxval=maxvals(i);
+% return;
+% end
+% end
+%
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getmaximumrightof.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getmaximumrightof.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,52 @@
+% tool
+%
+% 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 [pos_max,maxval,index]=getmaximumrightof(where,maxpos,minpos,maxs,mins)
+% usage: [pos_max,maxval]=getmaximumrightof(where,womins,minvals,womaxs,maxvals)
+% returns the maximum that is right of point "where"
+% mins and maxs must be complete sets of minimums and maximums
+% interwoven
+
+pos_max=[];
+maxval=[];
+index=-1;
+
+if where > maxpos(end)
+ return;
+ error('getmaximumrightof:: no maximum right of point');
+end
+
+
+nr =length(where);
+for j=1:nr
+ cwhere=where(j);
+ nr_maxs=length(maxpos);
+ for i=1:nr_maxs
+ if fround(maxpos(i),5) > fround(cwhere,5)
+ pos_max(j)=maxpos(i);
+ maxval(j)=maxs(i);
+ index=j;
+ break;
+ end
+ end
+end
+
+% nr_maxs=length(womaxs);
+% for i=nr_maxs:-1:1
+% if womaxs(i) < where
+% pos_max=womaxs(i);
+% maxval=maxvals(i);
+% return;
+% end
+% end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getmaxwidth.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getmaxwidth.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,36 @@
+% tool
+%
+% 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 width=getmaxwidth(wo,maxpos,minpos,maxs,mins)
+% usage: width=getmaxwidth(wo,frewomax,fremaxs,frewomin,fremins)
+% returns the width of the maximum
+% this is calculated by taking the left and the right minimum of the max
+
+[leftminwo,val]=getminimumleftof(wo,maxpos,minpos,maxs,mins);
+if isempty(leftminwo)
+ % wenns keinen linkes minimum gibt, versuche, obs ein rechtes gibt
+ [rightminwo,rightmin]=getminimumrightof(wo,maxpos,minpos,maxs,mins);
+ if ~isempty(rightminwo)
+ leftminwo=rightminwo;
+ else
+ leftminwo=0;
+ end
+end
+
+[rightminwo,val]=getminimumrightof(wo,maxpos,minpos,maxs,mins);
+if isempty(rightminwo)
+ rightminwo=leftminwo;
+end
+
+width=abs((leftminwo+rightminwo)/2);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getminimumleftof.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getminimumleftof.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% tool
+%
+% 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 [pos_min,minval,index]=getminimumleftof(where,maxpos,minpos,maxs,mins)
+% usage: [pos_min,minval]=getminimumleftof(where,womins,minvals,womaxs,maxvals)
+% returns the minimum that is left of point "where"
+% mins and maxs must be complete sets of minimums and maximums
+% interwoven
+
+pos_min=[];
+minval=[];
+index=-1;
+
+if isempty(maxpos)
+ return;
+end
+if where < minpos(1)
+ return;
+ error('getminimumleftof:: no minimum left of point');
+end
+
+nr =length(where);
+for j=1:nr
+ cwhere=where(j);
+ nr_mins=length(minpos);
+ for i=nr_mins:-1:1
+% if fround(minpos(i),5) < fround(cwhere,5)
+% pos_min(j)=minpos(i);
+% minval(j)=mins(i);
+% break;
+% end
+ if minpos(i) < cwhere
+ pos_min(j)=minpos(i);
+ minval(j)=mins(i);
+ index=i;
+ break;
+ end
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getminimumrightof.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getminimumrightof.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% tool
+%
+% 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 [pos_min,minval,index]=getminimumrightof(where,maxpos,minpos,maxs,mins)
+% returns the minimum that is right of point "where"
+% mins and maxs must be complete sets of minimums and maximums
+% interwoven
+
+
+pos_min=[];
+minval=[];
+index=-1;
+
+if isempty(maxpos)
+ return;
+end
+if where > minpos(end)
+ return;
+ error('getminimumrightof:: no minimum right of point');
+end
+
+nr =length(where);
+for j=1:nr
+ cwhere=where(j);
+ nr_mins=length(minpos);
+ for i=1:nr_mins
+ if fround(minpos(i),5) > fround(cwhere,5)
+ pos_min(j)=minpos(i);
+ minval(j)=mins(i);
+ index(j)=i;
+ break;
+ end
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getmusicaltone.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getmusicaltone.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,28 @@
+% tool
+%
+% 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 [cent,oct,relcent]=getmusicaltone(fre)
+% usage: [cent,oct]=getmusicaltone(fre)
+% gives back the cent of this tone and in which octave above 27.5 Hz it is
+% and the relative cent above the last octave - redundant, but useful
+
+min_fre=27.5; % the frequency, that defines the smallest frequency (A2)
+
+oct=floor(log2(fre/min_fre));
+
+% one octave is 1200 cent:
+% f= f_min*power(2,oct)*power(2,cent/1200)
+
+cent=1200*log2(fre/min_fre);
+
+relcent=cent-oct*1200;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getrandommelody.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getrandommelody.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,37 @@
+% tool
+%
+% 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 fres=getrandommelody(nr,from,to)
+
+if nargin < 3
+ to=1000;
+end
+if nargin < 2
+ from=100;
+end
+if nargin < 1
+ nr=5;
+end
+
+
+notearray1=note2fre(1:83);
+notearray2=find(notearray1 > from & notearray1 < to);
+notearray=notearray1(notearray2);
+
+fres=[];
+for i=1:nr
+ randnr=ceil(rand(1)*size(notearray,2));
+ note=notearray(randnr);
+ fres(i)=note;
+end
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getsingleaif.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getsingleaif.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,84 @@
+% tool
+%
+% 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 fr=getsingleaif(varargin)
+% usage: fr=getsingleaif(varargin)
+% produces only one frame from the (static) sound "soundfile"
+% This frame is taken as with the makeaimmovie with the framesperseconds-parameter
+% set to longer than the stimulus. Therefore the frame at the end of the signal duration is taken
+
+temp_sound_file_name='temp.wav';
+
+if nargin<2 % only one parameter -> read file
+ if size(varargin)==1
+ makefilename=varargin{1};
+ else
+ makefilename='lastrun.genmovie';
+ end
+ % fprintf('movie is produced from file %s from aifffile "makemovie_temp.aif"\n!',makefilename);
+ fprintf('aiff-file is produced according to file ''%s''\n',makefilename);
+else
+ makefilename='lastrun.genmovie';
+ generateparameterfile(makefilename,varargin);
+end
+
+arguments=readparameterfile(makefilename);
+
+str_model=getargument(arguments,'modelfile');
+str_soundcommand=getargument(arguments,'soundfile');
+str_movie_duration=getargument(arguments,'movie_duration');
+str_movie_start_time=getargument(arguments,'movie_start_time');
+str_output_normalization=getargument(arguments,'output_normalization');
+str_sound_sample_rate=getargument(arguments,'sound_sample_rate');
+str_sound_endian=getargument(arguments,'sound_endian');
+str_echo=getargument(arguments,'echo');
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% read the sound command and transfere the data to the buffer
+if ~isempty(str_movie_duration) % default frames per second
+ eval(sprintf('movie_duration=%s;',str_movie_duration));
+ eval(sprintf('movie_start_time=%s;',str_movie_start_time));
+ [sounddata,samplerate,bits,endian]=producesounddata(str_soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian,movie_start_time,movie_duration);
+else
+ movie_start_time=0;
+ [sounddata,samplerate,bits,endian]=producesounddata(str_soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian);
+ movie_duration=length(sounddata)/samplerate;
+end
+
+videolength=size(sounddata,1)/samplerate;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% frames per second
+framespersecond=1/videolength; %
+framespersecond=framespersecond*1.001;
+
+aiffs=getaiffs('modelfile',str_model,...
+ 'soundfile',str_soundcommand,...
+ 'framespersecond',sprintf('%f',framespersecond),...
+ 'output_normalization',str_output_normalization,...
+ 'movie_duration',movie_duration,...
+ 'movie_start_time',movie_start_time,...
+ 'echo',str_echo);
+% aiffs=getaiffs('modelfile',str_model,...
+% 'soundfile',temp_sound_file_name,...
+% 'framespersecond',sprintf('%f',framespersecond),...
+% 'output_normalization',str_output_normalization,...
+% 'movie_duration',movie_duration,...
+% 'movie_start_time',movie_start_time,...
+% 'echo',str_echo);
+
+fr=aiffs(1); % this is the one and only
+
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getstimulusparameter.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getstimulusparameter.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,15 @@
+% tool
+%
+% 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 ret=getstimulusparameter()
+ret=tame_get_stimulus_parameter;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/getupdownmelody.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/getupdownmelody.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,48 @@
+% tool
+%
+% 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 fres=getupdownmelody(nr,aroundfre,upordown)
+
+if nargin < 3
+ upordown='down';
+end
+if nargin < 2
+ aroundfre='A4';
+end
+if nargin < 1
+ nr=5;
+end
+
+
+% notearray1=note2fre(1:83);
+% notearray2=find(notearray1 > aroundfre & notearray1 < to);
+% notearray=notearray1(notearray2);
+
+fres=[];
+df=power(2,1/12);
+if strfind(upordown,'up')
+ fre1=note2fre(aroundfre);
+ fre2=fre1*power(df,2);
+else
+ fre1=note2fre(aroundfre);
+ fre2=fre1/power(df,2);
+end
+
+for i=1:nr
+ if mod(i,2)
+ fres(i)=fre1;
+ else
+ fres(i)=fre2;
+ end
+end
+
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/is_current_var.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/is_current_var.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,26 @@
+% tool
+%
+% 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 wheter=is_current_var(varname,in)
+% usage: is_current_var(varname,)
+% returns a bool whether this variable is a defined variable or not
+
+n=size(in,1);
+for i=1:n
+ if strcmp(in(i),varname)
+ wheter=1;
+ return
+ end
+end
+wheter=0;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/lin2log.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/lin2log.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,43 @@
+% tool
+%
+% 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 logmeasure=lin2log(value,scaleinfo)
+% usage: function logmeasure=lin2log(value,scaleinfo)
+% wandelt einen Wert entsprechend den Angaben in scaleinfo
+% von einem linearen in einen logarithmischen Wert um
+% scaleinfo.from;
+% scaleinfo.to;
+% scaleinfo.steps;
+%
+
+
+from=scaleinfo.from;
+to=scaleinfo.to;
+steps=scaleinfo.steps;
+
+
+if steps==1
+ logmeasure=(from+to)/2;
+ logmeasure=from;
+ return
+end
+
+a1=log(from);
+a2=log(to);
+st=(a2-a1)/(steps-1);
+
+res=st*value;
+res=exp(res);
+
+logmeasure=res*from;
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/loadstimulus.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/loadstimulus.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,48 @@
+% 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 [stim,wavefilename,stimdir]=loadstimulus(handles,annum,unnum,exnum,sweepnum)
+
+
+
+if nargin==5 % its single electrode
+ [extypetotal,experiment_type,ana_tpye]=get_experiment_type(handles,annum,unnum,exnum);
+ if strcmp(experiment_type,'aseca')
+ stimdir=get_aseca_wave_dir(handles,annum,unnum,exnum);
+ idstr=['0000' num2str(sweepnum)];
+ idstr=idstr(end-4:end);
+ wavefilename=sprintf('stimid%s.CAP.wav',idstr);
+ fullname=fullfile(stimdir,wavefilename);
+ else
+ exdir=get_experiment_dir(handles,annum,unnum,exnum);
+ stimdir=fullfile(exdir,'Saved Stimuli');
+ anstr=num2str(annum);
+ unstr=['00' num2str(unnum)];
+ unstr=unstr(end-2:end);
+ exstr=['00' num2str(exnum)];
+ exstr=exstr(end-2:end);
+ swstr=['000' num2str(sweepnum)];
+ swstr=swstr(end-3:end);
+ wavefilename=sprintf('an%sun%sex%sstim%s.wav',anstr,unstr,exstr,swstr);
+ fullname=fullfile(stimdir,wavefilename);
+ end
+ stim=loadwavefile(signal,fullname);
+elseif nargin==4 % its multielectrode
+ sweepnum=exnum;
+ exnum=unnum;
+ exdir=get_meex_dir(handles,annum,exnum);
+ stimdir=fullfile(exdir,'Saved Stimuli');
+ anstr=num2str(annum);
+ exstr=['000' num2str(exnum)];
+ exstr=exstr(end-3:end);
+ swstr=['000' num2str(sweepnum)];
+ swstr=swstr(end-3:end);
+ stimname=sprintf('an%sex%sstim%s.wav',anstr,exstr,swstr);
+ fullname=fullfile(stimdir,stimname);
+ stim=loadwavefile(signal,fullname);
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/loadtextfile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/loadtextfile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% tool
+%
+% 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 str=loadtextfile(name)
+% usage: str=loadtextfile(pfad,name)
+% loads the pfad,name in a structure of strings. one per line
+
+id=fopen(name,'rt');
+%titel=fgetl(id); % in der ersten Zeile stehen die Namen der PArameter drin
+if id<=0
+ disp('File not found');
+end
+
+ret=sprintf('\n');
+str=[];
+i=1;
+while ~feof(id)
+ zeile=fgetl(id);
+ str{i}=zeile;
+ i=i+1;
+end
+fclose(id);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/log2lin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/log2lin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% tool
+%
+% 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 linmeasure=log2lin(value,scaleinfo)
+
+% wandelt einen Wert entsprechend den Angaben in scaleinfo wieder
+% in den ursprünglichen linearen Wert zurück
+
+from=scaleinfo.from;
+to=scaleinfo.to;
+steps=scaleinfo.steps;
+
+a1=log(from);
+a2=log(to);
+st=(a2-a1)/(steps-1);
+
+linmeasure=log(value/from)/st+1;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/makeaimmovie.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/makeaimmovie.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,423 @@
+% tool
+%
+% 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 makeaimmovie(varargin)
+%usage: function makemovie(arguments)
+%
+% produces a quicktime-video from an AMS/AIM spf file and a sound file
+% inputs:
+% if no or only one parameter is given, than a make file is read instead
+% that should contain all parameters and their values
+% this file is generated automatically as "lastrun.genmovie"
+%
+% otherwise parameter must come in pairs: 'param','value'
+%
+% parameters for generating the SAI:
+% modelfile - the spf file that specifies the version of AMS/AIM (required)
+% output_normalization - the norm_mode parameter in out_file very useful for automatic scaling
+% soundfile - a wave or raw file with the sound in (required)
+% sound_sample_rate - the sample rate of the sound file
+% sound_endian - endian of the sound file (l or b)(PC's are little endian Suns are big endian)
+% framespersecond (default: 12)
+% moviefile - the name of the output file (default: "name of model plus name of sound")
+% echo - if off, than no output is created on screen
+% aifffile - optional instead of model. When aifffile is given, the aif file is read in directly from it
+%
+% Parameter for generating the graphic
+% AuditoryImageFormat: "AI", "AIpitch", "AIsum", "AIsum2", "sumai", or "AIsurface" (default: AIsum) or any user-defined-function
+% the user-defined-function is called with the current frame and must produce a picture
+% currently supported: show_pitch_spiral
+% AIFrePtiPStress (Auditory Image with Frequency profile and time interval profile with the colors in the image where the information was derived from
+%
+% TimeIntervalUnits "log" or "linear" (default: log)
+% colormap (default: black)
+% input_scale - scaling factor, that is directly applied to the input values - to prevent too loud sounds (default 1 can be set to auto)
+% minimum_time_interval - the minimal time that should be displayed in logarithmic form (in ms)
+% maximum_time_interval - the maximal time that should be displayed in logarithmic form
+% linewidth - Width of all plotted lines (default 1)
+% showtime - plot the time and the number of each frame (default on)
+% text - show a text in each frame in the upper right corner. The text must be given in a struct with .time and .label
+% plot_scale - scales the whole frame up or down
+% profile_scale - increases the amplitude of the profiles
+
+% the length of the final movie is the length of the soundfile plus the length of one picture in the beginning
+
+% valid calls:
+% the shortest valid call:
+% makemovie('modelfile''aim.spf','soundfile','cegc_br.raw')
+% produces the video "aim.mov" from the soundfile "cegc_br.wav" and the model file aim.spf
+% example
+%makemovie( 'modelfile','AIMghs.spf',...
+% 'soundfile','f128h8j0-2.wav',...
+% 'framespersecond','12',...
+% 'moviefile', 'impressing_movie',... %(".mov" is added)
+% 'TimeIntervalUnits','log',... % (or linear)
+% 'input_scale','default',... % ( or any number >0)
+% 'output_normalization','1000',... % (this number overwrites the NORM_MODE.DataFile_Out)
+% 'AuditoryImageFormat','sum',... % ( or AI,AIsurface,AIsum)
+% 'sound_sample_rate','20000',... % ( if the soundfile is not a wavfile - this must be togehter with the next one)
+% 'minimum_time_interval','2',... % ( in ms the smalles time, that is displayed)
+% 'sound_endian','l') % ( if the soundfile is not a wavfile - this must be togehter with the previous one)
+
+
+% you can choose between several types without changing the spf-file! If you want all channels with the waterfal than
+% the according reduce_channels are commented out automatically
+
+% the full movie will consist of so many pictures as the length of the soundfile divided by the frames per seconds.
+% To avoid clicks (due to quicktime) at the onset of the sound one frame and
+% an pause of one frame is inserted at the beginning of the movie.
+% To avoid a black picture at the end, one more frame is inserted at the end of the movie, so that the final movie
+% is slighly longer than the sound and the last picture is shown twice
+
+% the principle of the generation is to load the spf file and crucial variables are overwwitten:
+% the file_in is overwritten by the calling "soundfile" and the sound-out is overwritten by some temp-aiff file
+% the modified spf-file is stored under makemovie_temp.spf and this file is called via ams
+
+temp_sound_file_name='temp_sound.wav'; % must be the same as in getaiffs!!!
+
+if nargin<2 % only one parameter -> read file
+ if size(varargin)==1
+ makefilename=varargin{1};
+ else
+ makefilename='lastrun.genmovie';
+ end
+ % fprintf('movie is produced from file %s from aifffile "makemovie_temp.aif"\n!',makefilename);
+% fprintf('movie is produced from file ''%s''\n',makefilename);
+else
+ makefilename='lastrun.genmovie';
+ generateparameterfile(makefilename,varargin);
+end
+arguments=readparameterfile(makefilename);
+
+
+str_moviefile=getargument(arguments,'moviefile');
+str_aifffile=getargument(arguments,'aifffile');
+str_movie_duration=getargument(arguments,'movie_duration');
+str_movie_start_time=getargument(arguments,'movie_start_time');
+str_AuditoryImageFormat=getargument(arguments,'AuditoryImageFormat');
+str_TimeIntervalUnits=getargument(arguments,'TimeIntervalUnits');
+str_colormap=getargument(arguments,'colormap');
+str_minimum_time_interval=getargument(arguments,'minimum_time_interval');
+str_maximum_time_interval=getargument(arguments,'maximum_time_interval');
+str_sound_sample_rate=getargument(arguments,'sound_sample_rate');
+str_sound_endian=getargument(arguments,'sound_endian');
+str_linewidth=getargument(arguments,'linewidth');
+str_echo=getargument(arguments,'echo');
+str_showtime=getargument(arguments,'showtime');
+str_showtextname=getargument(arguments,'showtextname');
+str_showtexttime=getargument(arguments,'showtexttime');
+str_plotscale=getargument(arguments,'plotscale');
+str_profile_scale=getargument(arguments,'profile_scale');
+
+% data originally used in readaiff, but needed here also:
+str_framespersecond=getargument(arguments,'framespersecond');
+str_model=getargument(arguments,'modelfile');
+str_soundcommand=getargument(arguments,'soundfile');
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% set some default values, if the values are not explecitly given:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% scale the amplitude of the whole picture up
+if isempty(str_plotscale) % default frames per second
+ plot_scale=1;
+else
+ eval(sprintf('plot_scale=%s;',str_plotscale));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% scale the amplitude of the profiles (only when profiles are plotted of course)
+if isempty(str_profile_scale) % default frames per second
+ profile_scale=1;
+else
+ eval(sprintf('profile_scale=%s;',str_profile_scale));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% show time and number of frame
+if isempty(str_showtime) % default frames per second
+ showtime=1;
+else
+ if strcmp(str_showtime,'off')
+ showtime=0;
+ else
+ showtime=1;
+ end
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% frames per second
+if isempty(str_framespersecond) % default frames per second
+ framespersecond=12;
+else
+ eval(sprintf('framespersecond=%s;',str_framespersecond));
+end
+
+
+if isempty(str_linewidth) % how much the spf file should be normalized by setting the norm_mode parameter in out_file
+ line_width=1;
+else
+ eval(sprintf('line_width=%s;',str_linewidth));
+end
+
+if isempty(str_TimeIntervalUnits) % output is linear or logarithmic
+ TimeIntervalUnits='log';
+else
+ TimeIntervalUnits=str_TimeIntervalUnits;
+end
+
+if isempty(str_moviefile) % default name of the movie
+ [dumy_path,tempmodelname,ext,versn] = fileparts(str_model);
+ [dumy_path,tempsoundname,ext,versn] = fileparts(str_soundcommand);
+ moviefile=sprintf('soundfile_%s_model_%s.mov',tempsoundname,tempmodelname);
+else
+ [dumy_path,tempmodelname,ext,versn] = fileparts(str_moviefile);
+ if strcmp(ext,'')
+ moviefile=sprintf('%s.mov',str_moviefile);
+ else
+ moviefile=str_moviefile;
+ end
+end
+
+if isempty(str_AuditoryImageFormat) % which AuditoryImageFormat should be used
+ AuditoryImageFormat='AIsum';
+else
+ AuditoryImageFormat=str_AuditoryImageFormat;
+end
+
+if isempty(str_colormap) % an aifffile that is read instead
+ if strcmp(AuditoryImageFormat,'AI') | strcmp(AuditoryImageFormat,'AIsum') | strcmp(AuditoryImageFormat,'sum')| strcmp(AuditoryImageFormat,'singlegraphic')
+ clrmap=zeros(64,3); % all black
+ end
+ if strcmp(AuditoryImageFormat,'AIsurface')
+ clrmap=1-gray; % invertes grayscale: 0 is white and 1 is black
+ end
+else % colormap was given
+ eval(sprintf('clrmap=%s;',str_colormap));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% sound-file. can be a command or a file
+if isempty(str_soundcommand) %
+ error('soundcommand must be given');
+else
+ soundcommand=str_soundcommand;
+end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% echo on screen
+if isempty(str_echo) % default frames per second
+ echo=1;
+else
+ if strcmp(str_echo,'off')
+ echo=0;
+ else
+ echo=1;
+ end
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% construct the aiff-file with a call to the dsam-routine:
+
+% if aifffile is given from a previous run, than simply load it:
+if ~isempty(str_aifffile)
+ allframes=SBReadAiff(str_aifffile,echo); % returns all info in a struct
+else
+ allframes=getaiffs(makefilename);
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% read the sound command and transfere the data to the buffer
+if ~isempty(str_movie_duration) % default frames per second
+ eval(sprintf('movie_duration=%s;',str_movie_duration));
+ eval(sprintf('movie_start_time=%s;',str_movie_start_time));
+ [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian,movie_start_time,movie_duration);
+else
+ movie_start_time=0;
+ [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian);
+ movie_duration=length(sounddata)/samplerate;
+end
+
+
+% the duration of the whole video
+videolength=size(sounddata,1)/samplerate;
+% so long is one picture:
+duration=1/framespersecond;
+
+% so many frames is the video size in the end:
+nr_frames=videolength*framespersecond;
+
+% find out about the general structure of all frames by taking the first as a sample (they are all identical)
+sample_frame=allframes(1);
+nr_channels=getnrchannels(sample_frame);
+nr_points=getnrpoints(sample_frame);
+nr_frames=size(allframes,2);
+t_plus=getmaximumtime(sample_frame); % usually 5 ms
+t_minus=getminimumtime(sample_frame); % usually -35 ms
+
+% set a variable for the current starting time of each frame for plotting
+for i=1:nr_frames
+ allframes(i)=setcurrentframestarttime(allframes(i),(i-1)*duration);
+end
+
+% start producing the movie!
+MakeQTMovie('start',moviefile);
+MakeQTMovie('size', [640 400]);
+MakeQTMovie('quality', 0.8); % reduces the size
+
+if echo fprintf('start produce pictures:\n'); end
+
+% We start the time at zero:
+current_time=0;
+
+for i=0:nr_frames
+ if echo
+ % plot a start for each frame, so that we see, how long it takes
+ fprintf('*');
+ if(mod(i+1,30)==0)
+ fprintf('\n');
+ end
+ end
+
+ if i==0 % trick: the first picture is the same as the second to prevent quick time from producing a click sound, that it otherwise does
+ c_frame=allframes(1);
+ current_time=0;
+ else
+ c_frame=allframes(i);
+ end
+
+ % set some default values that depend on the frames
+ if strcmp(TimeIntervalUnits,'log')>0
+ framestruct.is_log=1;
+ else
+ framestruct.is_log=0;
+ end
+
+ if showtime
+ framestruct.show_time=1;
+ else
+ framestruct.show_time=0;
+ end
+
+ if ~isempty(str_showtextname)
+ texts=str2cell(str_showtextname);
+ times=str2cell(str_showtexttime);
+ nr_times=size(times,1);
+ if nr_times<=1 % every picture
+ c_frame=settext(c_frame,texts(1));
+ else
+ for i=1:nr_times
+ tt=str2num(times{i});
+ if tt>current_time
+ c_frame=settext(c_frame,texts(i));
+ break;
+ end
+ end
+ end
+ end
+
+ if isempty(str_minimum_time_interval) % how much the spf file should be normalized by setting the norm_mode parameter in out_file
+ if framestruct.is_log
+ minimum_time_interval=2; % ms = default value for the minimum time
+ else
+ minimum_time_interval=-t_plus*1000; % ms = default value for the minimum time
+ end
+ else
+ eval(sprintf('minimum_time_interval=%s;',str_minimum_time_interval));
+ if framestruct.is_log
+ if minimum_time_interval < 0
+ disp('minimum time interval must be >0 for log plots');
+ minimum_time_interval=2;
+ end
+ end
+ end
+
+ if isempty(str_maximum_time_interval) % default value for maximum time
+ maximum_time_interval=-t_minus*1000; % in ms! % to the end of the stimulus
+ else
+ eval(sprintf('maximum_time_interval=%s;',str_maximum_time_interval));
+ end
+
+ % construct the framestructure for calling the plotting-routine
+ framestruct.current_frame = c_frame;
+ framestruct.maximum_time_interval=maximum_time_interval;
+ framestruct.minimum_time_interval=minimum_time_interval;
+ framestruct.plot_scale=plot_scale;
+ framestruct.profile_scale=profile_scale;
+
+
+ % call the plotting routine
+ eval(sprintf('%s(framestruct);',AuditoryImageFormat));
+
+ % bring the figure to front
+ figure(gcf);
+
+ % and add it to the movie
+ MakeQTMovie('addframe');
+
+ current_time=current_time+duration;
+
+end % End of current_frame - loop
+
+% add one, to fill the last picture (the sound is longer than n*nr_frames)
+MakeQTMovie('addframe');
+MakeQTMovie('framerate', framespersecond);
+
+% soundgap=zeros(floor(samplerate/framespersecond),1);
+% stemp=[soundgap' sounddata'];
+% sounddata=stemp';
+MakeQTMovie('addsound',sounddata,samplerate);
+
+MakeQTMovie('finish');
+MakeQTMovie('cleanup');
+
+% fprintf('\n\nFinished successfully! :-)\n');
+if echo
+ disp(sprintf('\n\nWrote QuickTime movie %s\\%s',pwd,moviefile));
+end
+
+return
+
+
+% clean up
+ans=input('start with QuickTime? y/[n]','s')
+if ans=='y'
+ !C:\Program Files\QuickTime\QuickTimePlayer
+end
+
+
+% not cleaning up: (for test purpose)
+return
+% clean up temporary files
+try
+ delete('makemovie_temp.spf');
+end
+try
+ delete('makemovie_temp.aif');
+end
+if rememberdeletesoundfile
+ try
+ delete(soundfile);
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/makeall.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/makeall.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,78 @@
+% tool
+%
+% 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 $
+
+
+fundamental=125;
+fc=[500 1000 2000];
+
+% bandwidthtype='linear';
+bandwidthtype='linear';
+bandwidth_first=2000;
+bandwidth_scale=2.2;
+
+
+phase=[50 80];
+amplitude=[-4 -10];
+
+
+nr_amps=size(amplitude,2);
+nr_fre=size(fc,2);
+nr_phase=size(phase,2);
+
+bandwidth=bandwidth_first;
+
+for i=1:nr_fre
+ fcs=fc(i);
+
+% name=sprintf('sound(cf=%4.0f,bw=%4.0f)',fcs,bandwidth);
+ name=sprintf('PAsdgsdgsound(cf=%4.0f,bw=%4.0f)',fcs,bandwidth);
+ s=sprintf('genharmonics(signal(0.5,16000),''fundamental'',''%f'',''filterprop'',[%f 256 %f 512]);',fundamental,fcs,bandwidth);
+ ss=sprintf('%s=%s','tsig',s);
+ eval(ss);
+ tsig=scaletorms(tsig,0.1);
+ tsig=rampamplitude(tsig,0.05);
+ writetowavefile(tsig,name);
+ return
+
+ str_amp='decreaseoddamplitude';
+ for j=1:nr_amps
+ changeby=amplitude(j);
+ name=sprintf('sound(cf=%4.0f,amp=%3.0f,bw=%4.0f)',fcs,changeby,bandwidth);
+ s=sprintf('genharmonics(signal(0.5,16000),''fundamental'',''%f'',''type'',''%s'',''changeby'',''%f'',''filterprop'',[%f 256 %f 512]);',fundamental,str_amp,changeby,fcs,bandwidth);
+ ss=sprintf('%s=%s','tsig',s);
+ eval(ss);
+ tsig=scaletorms(tsig,0.1);
+ tsig=rampamplitude(tsig,0.05);
+ writetowavefile(tsig,name);
+ end
+
+ str_amp='decreaseoddphase';
+ for j=1:nr_phase
+ changeby=phase(j);
+ name=sprintf('sound(cf=%4.0f,phase=%3.0f,bw=%4.0f)',fcs,changeby,bandwidth);
+ s=sprintf('genharmonics(signal(0.5,16000),''fundamental'',''%f'',''type'',''%s'',''changeby'',''%f'',''filterprop'',[%f 256 %f 512]);',fundamental,str_amp,changeby,fcs,bandwidth);
+ ss=sprintf('%s=%s','tsig',s);
+ eval(ss);
+ tsig=scaletorms(tsig,0.1);
+ tsig=rampamplitude(tsig,0.05);
+ writetowavefile(tsig,name);
+ end
+
+ if strcmp(bandwidthtype,'linear')
+ bandwidth=bandwidth_first;
+ else
+ bandwidth=bandwidth*bandwidth_scale;
+ end
+
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/maxstruct.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/maxstruct.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,34 @@
+% tool
+%
+% 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 [ret,womax]=maxstruct(str,topic,nr_second_dimension)
+% gets back the structitem with the highest value in "topic"
+% if topic is twodimensional, then "nr_second_dimension" gives the chosen
+% number
+
+
+if nargin < 3
+ nr=size(str,2);
+ for i=1:nr
+ sortcount(i)=eval(sprintf('str{%d}.%s',i,topic));
+ end
+ [ismax,womax]=max(sortcount);
+ ret=str{womax};
+else
+ nr=size(str,2);
+ for i=1:nr
+ sortcount(i)=eval(sprintf('str(%d).%s(%d)',i,topic,nr_second_dimension));
+ end
+ [ismax,womax]=max(sortcount);
+ ret=str{womax};
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/mixstruct.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/mixstruct.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,123 @@
+% 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 new_struct=mixstruct(old_struct,add_struct)
+% old_struct is the original structure
+% add_struct is the new struct
+% entries that are double are overwritten by the entry in add_struct
+% works only for the first recursion level
+
+
+newstructs=fieldnames(add_struct);
+% copy all old stuff
+new_struct=old_struct;
+
+for i=1:length(newstructs)
+ curr_str=newstructs{i};
+ % if ~strcmp(curr_col,'signal')
+% if ~isfield(old_struct,curr_str) % add whole new fields from the new struct
+ est=sprintf('new_struct.%s=add_struct.%s;',curr_str,curr_str);
+ 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);
+% end
+end
+
+
+
+% 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);
+% end
+% end
+%
+%
+% 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,ver12]=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,ver22]=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 ver211
+ resp=input('Achtung: Clipping in the input signal due to too high input_scale. Correct it? [y]/n','s');
+ if ~strcmp(resp,'n')
+ readsounddata=readsounddata*0.999/fmax;
+ end
+ end
+
+ % and then write it back again to the temp-name:
+ cd(old_path);
+ wavwrite(readsounddata,samplerate,'findpitch_temp.wav');
+ str_soundfile{1}='findpitch_temp.wav';
+ else
+ disp('Format not implemented yet!');
+ return;
+ end
+else
+ % a user defined function
+ if strcmp(calculation_type,'normal') % nur, wenn das Signal nötig ist
+ eval(sprintf('datasig=%s;',str_soundfile{1}));
+ datasig=ScaleToMaxValue(datasig,0.999);
+ readsounddata=getdata(datasig);
+ cd(old_path);
+ samplerate=getsr(datasig);
+ bits=16;
+ writetowavefile(datasig,'findpitch_temp.wav');
+ str_soundfile{1}='findpitch_temp.wav';
+ soundfile='findpitch_temp.wav';
+ end
+end
+
+
+% if the wav file has two channels, (stereo) only the left channel is used for calculation
+if strcmp(calculation_type,'normal') % nur, wenn das Signal nötig ist
+ nr_chan=size(readsounddata,2);
+ if nr_chan>1
+ sounddata=readsounddata(:,1); % only the first channel
+ else
+ sounddata=readsounddata;
+ end
+ videolength=size(sounddata,1)/samplerate;
+end
+
+% so long is one picture:
+duration=1/framespersecond;
+% so many frames is the video size in the end:
+nr_frames=videolength*framespersecond;
+starttime=0;
+
+if strcmp(calculation_type,'normal')
+
+ disp('Start generating sounds and modify spf-file...');
+ % if which=1 then a new aif file is constructed with simulation (the final mode)
+ % to test things, its useful to have a test mode in which a already made findpitch_temp.aif is loaded
+ id=fopen(model,'rt');
+ if id<=0
+ disp(sprintf('Model-file %s not found',model));
+ return;
+ end
+ fclose(id);
+ id=fopen(soundfile,'rt');
+ if id<=0
+ disp(sprintf('Sound-file %s not found',soundfile));
+ return;
+ end
+ fclose(id);
+
+ % fit the spf file to our needs. The line command-line options are not powerful enough (and not working correctly in <2.6.3)
+ l=loadtextfile(model);
+ somuchruns=sprintf('%2.0f',nr_frames);
+ l=DSAMSubstituteParameter(l,'NUM_RUNS.ams.0',somuchruns);
+ % actually, this one is not working in version 2.6.3, so we have to define it by command line. I let it in here, because Id prefere it this way
+ l=DSAMSubstituteParameter(l,'SEGMENT_MODE.ams.0','ON'); % just to be sure...
+ l=DSAMSubstituteParameter(l,'FILELOCKING_MODE.ams.0','ON'); % just to be sure...
+
+ % check, if there is an output, otherwise create one
+ dummy='nothing';
+ dummy=DSAMFindParameter(l,'DataFile_Out');
+ if strcmp(dummy,'<') %yes, the parameter is there, but is it commented?
+ bool=DSAMtParameterIsCommented(l,'DataFile_Out',1);
+ if bool % disp('DataFile_Out file commented in spf ');
+ l=DSAMCommentParameter(l,'DataFile_Out',0,1);% remove the comment
+ else % everything ok! :-) OutFile is there and not commented
+ end
+ else
+ disp('no DataFile_Out file specified in spf - building one... ');
+ l=DSAMAddOutputFile(l,aifffile,'l',samplerate);
+ % return;
+ end
+
+ % if the user wants all channels, than comment out the channel reducing line
+ % if strcmp(str_graphictype,'waterfall') | strcmp(str_graphictype,'waterfallsum')| strcmp(str_graphictype,'surf')
+ % l=DSAMCommentParameter(l,'Util_ReduceChannels',1);
+ % end
+
+ % turn off the displays:
+ finished=0;
+ nr_display=1;
+ while ~finished
+ new=DSAMCommentParameter(l,'Display_Signal',1,nr_display); % comment this line
+
+ if isnumeric(new) & new==-1
+ break; % finished :-)
+ else
+ l=new;
+ nr_display=nr_display+1;
+ end
+ end
+
+ % build the correct dsam-output my-input aif-file:
+ stra=sprintf('"%s"',aifffile);
+
+ l=DSAMSubstituteParameter(l,'FILENAME.DataFile_Out',stra);
+
+
+ % l=DSAMSubstituteParameter(l,'FILENAME.DataFile_In',sfile);
+ l=DSAMSubstituteParameter(l,'FILENAME.DataFile_In','findpitch_temp.wav');
+
+ % bring it to a format, that dsam understands:
+ wordsize=bits/8;
+ words=sprintf('%d',wordsize);
+ l=DSAMSubstituteParameter(l,'WORDSIZE.DataFile_In',words);
+ srat=sprintf('%f',samplerate);
+ l=DSAMSubstituteParameter(l,'SAMPLERATE.DataFile_In',srat);
+ dur=sprintf('%f',duration);
+ l=DSAMSubstituteParameter(l,'DURATION.DataFile_In',dur);
+ star=sprintf('%f',starttime);
+ l=DSAMSubstituteParameter(l,'STARTTIME.DataFile_In',star);
+
+ if strcmp(str_input_scale,'default') % scale to a fixed number in the input
+ gain=sprintf('%f',defined_input_gain);
+ l=DSAMSubstituteParameter(l,'GAIN.DataFile_In',gain);
+ end
+
+
+ % scaling must be performed in the input file to prevent too high numbers in the output
+
+ % !!!
+ % % the user has to set the correct scale value in the original spf-file
+ % this is best done by watching a whole film in ams and searching for the biggest
+ % value. Set this value as parameter 'NORM_MODE.DataFile_Out'
+ % it is NO GOOD IDEA to set this value to -1 (auto) because, this value is calculated
+ % from the first frame and this ist not the highest. As result, strange negative values occure!
+
+ % therefore we set the gain in the input file to a very small value:
+ % gain=sprintf('%f',70);
+ % l=DSAMSubstituteParameter(l,'GAIN.DataFile_In',gain);
+ % the version with scaling in the output file (below) didnt work:
+
+ if ~strcmp(str_output_normalization,'') % how much the spf file should be normalized by setting the norm_mode parameter in out_file
+ l=DSAMSubstituteParameter(l,'NORM_MODE.DataFile_Out',str_output_normalization{1});
+ end
+
+
+ % save the modified file to disk
+ savetofile(l,'findpitch_temp.spf');
+
+ % find out abput the times used in ms to display numbers
+ t_minusstr=DSAMFindParameter(l,'NWIDTH.Ana_SAI');
+ t_minus=sscanf(t_minusstr,'%f')*1000;
+ t_plusstr=DSAMFindParameter(l,'PWIDTH.Ana_SAI');
+ t_plus=sscanf(t_plusstr,'%f')*1000;
+
+ % do I need later:
+ str_scale_factor_output=DSAMFindParameter(l,'NORM_MODE.DataFile_Out');
+ scale_factor_output=sscanf(str_scale_factor_output,'%f');
+
+
+ % find out about the frequency axis and make it nice
+ nrfreqstr=DSAMFindParameter(l,'CHANNELS.BM_GammaT');
+ nr_freq=sscanf(nrfreqstr,'%d'); % so many frequencies on y-axis
+
+ for i=1:nr_freq
+ cfstr=DSAMFindParameter(l,'CENTRE_FREQ.BM_GammaT',i); % so many frequencies on y-axis
+ cfb=sscanf(cfstr,'%f:%f'); % so many frequencies on y-axis
+ cf(i)=cfb(2);
+ end
+
+ % ams must be in Path or this line must point to its directory:
+ %cd('C:\Program Files\DSAM\AMS');
+
+ % delete the remains from last run
+ if fexist('findpitch_temp.aif')
+ eval('! del findpitch_temp.aif');
+ end
+
+
+ % the command line, that starts the process:
+ % mas_ng starts a single ams process without grafik (very fast)
+ % -d turns off the debug messages
+ % -s calls the file findpitch_temp.spf
+ % -r gives the number of runs (somuchruns)
+ % segment on tells dsam to run in segmented mode
+ str=sprintf('! AMS_ng.exe -doff -sfindpitch_temp.spf -r%s segment on',somuchruns);
+
+ % this one works with a window.
+ % str=sprintf('! AMS.exe -S -s findpitch_temp.spf -r %s &',somuchruns);
+
+ % delete the remains of some buggy run:
+ if fexist('.ams_LCK')
+ try
+ delete('.ams_LCK');
+ catch
+ disp('Could not delete existing file .ams_LCK. Please restart matlab');
+ end
+ end
+
+ disp('Ams simulation started...')
+ eval([str]); % do ams!
+
+ t0 = clock;
+ while etime(clock,t0)<0.5 %wait a little while
+ end
+
+ % and look for the lock file
+ while fexist('.ams_LCK')
+ end % continue, when its _not_ there
+
+
+ % if strcmp(calculation_type,'no_dsam')
+ FID = fopen(aifffile,'r');
+ if FID==-1
+ disp('error in simulation: aif-file was not generated!');
+ return;
+ end
+ fclose(FID);
+ % end
+ % now we know for shure, that it was successfull!
+
+end
+
+
+allframes=SBReadAiff(aifffile); % returns all info in a struct
+
+% find out about the structure
+sample_frame=allframes(1);
+nr_channels=getnrchannels(sample_frame);
+nr_points=getnrpoints(sample_frame);
+nr_frames=size(allframes,2);
+
+for i=1:nr_frames allframes(i)=setcf(allframes(i),cf); end
+
+% values for scaling the actual sum of all channels
+scale_summe=0;% this value is used to scale the picture of the sum later
+for i=1:nr_frames
+ su=getsum(allframes(i));
+ ma=max(su);
+ if ma > scale_summe scale_summe=ma; end
+end
+
+low=getamplitudeminvalue(sample_frame);
+
+if low < 0
+ disp('Achtung: Negative values in the AIFF-File! ');
+ disp('This probably means, that the value in ');
+ disp('NORM_MODE in DataFile_Out was not high enough!');
+ disp(sprintf('current value: %f',scale_factor_output));
+ fprintf('\n[a] double it, (b) stop, (c) continue anyway \nor type in the new value\n');
+ reply = input(': ','s');
+ if isempty(reply) % default
+ reply ='a';
+ end
+ if reply == 'b'
+ return;
+ end
+ valgiven=0;
+ if reply~='a' & reply~='c'
+ eval(sprintf('val=%s;',reply));
+ else
+ if reply=='a'
+ val=2 * scale_factor_output; % double it!
+ end
+ if reply=='c'
+ val=scale_factor_output; % no change
+ end
+ end
+ if isnan(val) | val<=0
+ disp('sorry, no valid input');
+ return;
+ end
+ if val~=scale_factor_output % only, if there is a change!
+ scale_factor_output=val;
+ strscale=sprintf('%f',scale_factor_output); % run again with higher output normalization
+ ret=model_findpitch('modelfile',str_model{1},'soundfile',str_soundfile{1}, ...
+ 'output_normalization',strscale,'input_scale',str_input_scale{1}, ...
+ 'framespersecond',str_framespersecond{1});
+ return;
+ end
+end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% finished with calculating, now the pitch extraction can begin:
+reduced_channel_mode=0; % erstmal...
+
+t_minus=getminimumtime(sample_frame);
+t_plus=getmaximumtime(sample_frame);
+
+minimum_time_interval=0.5; % highest frequency
+maximum_time_interval=-t_minus; % in ms! % to the end of the stimulus
+
+% setsumscale(sample_frame(framestruct.scale_summe = scale_summe;
+
+% wenn gar keine verschiedenen pitches berechnet werden sollen
+if no_pitch_frame_instead_modus
+ time=frame_instead_at;
+ nr_fr=floor(time*framespersecond);
+ if nr_fr>nr_frames
+ disp('single frame time not in range of audio signal');
+ return;
+ end
+ ret=allframes(nr_fr);
+
+ return;
+end
+
+disp('calculate pitches');
+
+if single_frame_modus
+ time=single_frame;
+ nr_fr=floor(time*framespersecond);
+ if nr_fr>nr_frames
+ disp('single frame time not in range of audio signal');
+ return;
+ end
+ current_frame=allframes(nr_fr);
+ ret=findsummaxima(current_frame);
+
+else % calculate pitch for all frames
+ for i=1:nr_frames
+ fprintf('*');
+ if(mod(i+1,30)==0)
+ fprintf('\n');
+ end
+ current_frame=allframes(nr_fr);
+ ret(i)=findsummaxima(current_frame);
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/moviescript.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/moviescript.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,54 @@
+% tool
+%
+% 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 moviescript()
+% makes movies for all sound files in this directory
+
+modelfile='aim.spf';
+framespersecond='12';
+graphicstyle='log';
+graphictype='sumonly';
+sound_sample_rate='20000';
+sound_endian='l';
+minimum_time_interval='2.0';
+% input_scale='default'; % that makes problems!!
+input_scale='1.0';
+output_normalization='1.0';
+
+dircont=dir;
+nr_files=size(dircont);
+
+fileid=fopen('movie_log.txt','w');
+
+for i=1:nr_files
+ fullname=dircont(i).name;
+ [path,name,ext,versn] = fileparts(fullname);
+
+
+ if strcmp(ext,'') & exist(fullname)~=7 % not directorys
+ fprintf('\n\nMaking Movie from soundfile %s\n',fullname);
+
+ outname=sprintf('%s.mov',fullname);
+ dostring=sprintf('makemovie(''modelfile'',''%s'',''soundfile'',''%s'',''outfile'',''%s'',''framespersecond'',''%s'',''graphicstyle'',''%s'',''graphictype'',''%s'',''sound_sample_rate'',''%s'',''sound_endian'',''%s'',''minimum_time_interval'',''%s'',''input_scale'',''%s'',''output_normalization'',''%s'')',...
+ modelfile,fullname,outname,framespersecond,graphicstyle,graphictype,sound_sample_rate,...
+ sound_endian,minimum_time_interval,input_scale,output_normalization);
+
+ fprintf('%s\n',dostring);
+ fprintf(fileid,'%s\n',dostring);
+ eval(dostring);
+
+ end
+end
+
+fclose(fileid);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/myReadAIFF.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/myReadAIFF.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,116 @@
+% 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 $
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% File: ReadAIFF.m
+% Purpose: Reads an AIFF format file.
+% Comments: The default binary format is big-endian, if this does not
+% work, then little-endian format is tried.
+% Author: L. P. O'Mard
+% Revised by: M.Tsuzaki
+% Created:
+% Updated: 31,Oct.2001
+% Copyright: (c) 2000, University of Essex
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function signal = myReadAIFF(fname,frameId)
+if nargin < 2
+ frameId=1:10000; %default: read to end
+end
+absoluteNormalise = 1.0;
+[fid, msg] = fopen(fname);
+if fid == -1
+ error('File open error. Please check that the file name is correctly spelled.')
+end
+littleEndian = 0;
+aiff_form = ReadBytes(fid, 4, littleEndian);
+if aiff_form' == double('FORM')
+% disp('big-endian');
+else
+% disp('little-endian');
+ littleEndian = 1;
+end;
+chunkSize = Read32Bits(fid, littleEndian);
+aiff_aiff = ReadBytes(fid, 4, littleEndian);
+if aiff_aiff' ~= double('AIFF')
+ aiff_aiff
+ disp('Not a valid AIFF file.');
+ return
+end;
+chunkSize = chunkSize - 16;
+while chunkSize - 4 > 0;
+ chunkName = ReadBytes(fid, 4, littleEndian);
+ chunkSize = chunkSize - 4;
+ if chunkName' == double('COMM');
+% disp('step COMM');
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize-subSize;
+ numChannels = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ numSampleFrames = Read32Bits(fid, littleEndian);
+ subSize = subSize - 4;
+ sampleSize = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ sampleRate = ReadIEEE(fid, littleEndian);
+ subSize = subSize - 10;
+ fread(fid, subSize, 'char');
+ elseif chunkName' == double('SSND');
+% disp('step SSND');
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize - subSize;
+ offset = Read32Bits(fid, littleEndian);
+ subSize = subSize - 4;
+ blockSize = Read32Bits(fid, littleEndian);
+ subSize = subSize - 4;
+ soundPosition = ftell(fid) + offset;
+ fread(fid, subSize, 'char');
+ elseif chunkName' == double('LUT2');
+% disp('step LUT2');
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize - subSize;
+ interleaveLevel = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ numWindowFrames = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ staticTimeFlag = Read16Bits(fid, littleEndian);
+ subSize = subSize - 2;
+ outputTimeOffset = ReadIEEE(fid, littleEndian);
+ subSize = subSize - 10;
+ absoluteNormalise = ReadIEEE(fid, littleEndian);
+ subSize = subSize - 10;
+ fread(fid, subSize, 'char');
+
+ else;
+ subSize = Read32Bits(fid, littleEndian);
+ chunkSize = chunkSize - subSize;
+ fread(fid, subSize, 'char');
+
+ end;
+end;
+wordSize = floor((sampleSize + 7 ) / 8);
+normalise = (2^16 - 1) / 2^(17 - wordSize * 8) / absoluteNormalise;
+switch wordSize
+ case 1, scale = normalise / 127.0;
+ case 2, scale = normalise / 32768.0;
+ case 4, scale = normalise / 32768.0 / 65536;
+end
+frameLength = numSampleFrames / numWindowFrames;
+% signal = zeros(numChannels,frameLength, numWindowFrames);
+fclose(fid);
+if littleEndian
+ fopen(fname,'r','l');
+% disp('open as little endian')
+else
+ fopen(fname,'r','b');
+% disp('open as big endian')
+end
+status = fseek(fid, soundPosition, 'bof');
+% disp( [frameId numWindowFrames numChannels frameLength wordSize])
+signal = ReadWinFrame2(fid, frameId, numWindowFrames, numChannels,frameLength, wordSize);
+signal = signal .* scale;
+status = fclose(fid);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/myplotfft.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/myplotfft.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,40 @@
+% tool
+%
+% 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 plotfft(name)
+% usage: plotfft('ghfgghfh.wav')
+
+[y,Fs,bits]=wavread(name);
+
+Fn=Fs/2; % Nyquist frequency
+t=0:1/Fs:length(y)/Fs; % time vector sampled at Fs Hz,
+
+% Next highest power of 2 greater than or equal to length(y)
+NFFT=2.^(ceil(log(length(y))/log(2)));
+% Take fft, padding with zeros, length(FFTX)==NFFT
+FFTX=fft(y,NFFT);
+NumUniquePts = ceil((NFFT+1)/2);
+% fft is symmetric, throw away second half
+FFTX=FFTX(1:NumUniquePts);
+MX=abs(FFTX); % Take magnitude of X
+% Multiply by 2 to take into account the fact that we threw out
+% second half of FFTX above
+MX=MX*2;
+MX(1)=MX(1)/2; % Account for endpoint uniqueness
+MX(length(MX))=MX(length(MX))/2; % We know NFFT is even
+% Scale the FFT so that it is not a function of the length of y.
+MX=MX/length(y); %
+f=(0:NumUniquePts-1)*2*Fn/NFFT;plot(f,MX);
+plot(f,MX);
+xlabel('Frequency [Hz]');
+ylabel('Magnitude');
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/mysubplot.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/mysubplot.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,84 @@
+% tool
+%
+% 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 back=mysubplot(nr_y,nr_x,nr,rect, hint)
+% usage: mysubplot(nr_y,nr_x,nr,rect, hint))
+% exact like subplot, but can draw into arbitrary figures
+% the rect in which the new axis are plottet are given by rect.
+% if rect is not given, 0 0 1 1 is taken
+% rect is (x_min,y_min,x_width,y_width)
+% hint gives additionally information about spaces in the graphic
+% hint=0: normal with spaces everywere (every figure has its own axis)
+% hint=1: Space only at the bottom and on the left. of the outer pictures. There are the titles
+
+spacing=0.05;
+
+if nargin < 4
+ rect=[0 0 1 1];
+end
+
+if nargin < 5
+ hint=0;
+end
+
+rectleft=rect(1);
+rectbottom=rect(2);
+rectwidth=rect(3);
+rectheight=rect(4);
+
+
+if hint==0
+ distleft=rectwidth*spacing; % der Abstand, der vom Rand eingehalten werden soll
+ distright=rectwidth*spacing;
+ disthochzwischen=rectheight*spacing; % Abstand zwischen zwei vertikalen Bildern
+ distbreitzwischen=rectwidth*spacing; % Abstand zwischen zwei vertikalen Bildern
+ distunten=rectwidth*spacing; % Abstand nach unten
+end
+if hint==1
+ distleft=rectwidth*spacing; % der Abstand, der vom Rand eingehalten werden soll
+ distright=0;
+ disthochzwischen=rectheight*0.01; % Abstand zwischen zwei vertikalen Bildern
+ distbreitzwischen=0; % Abstand zwischen zwei vertikalen Bildern
+ distunten=rectwidth*spacing; % Abstand nach unten
+end
+
+if hint==0
+ x=rectwidth/nr_x;
+ y=rectheight/nr_y;
+
+ nnx=mod(nr-1,nr_x);
+ ges=nr_x*nr_y;
+ nny=ges/nr_x - round((nr-1)/nr_x+0.5);
+
+ left=distleft+x*nnx;
+ bottom=distunten+y*nny;
+ width=x-distleft-distright;
+ height=y-distunten-disthochzwischen;
+end
+if hint==1
+ x=(rectwidth-distleft)/nr_x;
+ y=(rectheight-distunten)/nr_y;
+
+ nnx=mod(nr-1,nr_x);
+ ges=nr_x*nr_y;
+ nny=ges/nr_x - round((nr-1)/nr_x+0.5);
+
+ left=distleft+x*nnx;
+ bottom=distunten+y*nny;
+ width=x-distbreitzwischen;
+ height=y-disthochzwischen;
+end
+
+back=[rectleft+left rectbottom+bottom width height];
+
+axes('position',back);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/note2fre.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/note2fre.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,74 @@
+% 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 [fre,oct,nr_note]=note2fre(note)
+
+% translates the note to the frequency
+
+note_names=['A ';'B ';'C ';'C#';'D ';'D#';'E ';'F ';'F#';'G ';'G#';'H '];
+lowest_note=27.5; % Hz =A1 440 Hz= a5
+
+
+rnote=note(1);
+if strcmp(rnote(1),' ') || double(rnote(1))==9
+ note=note(2:end);
+ rnote=note(1);
+end
+if strcmp(note(2),'#')
+ rnote=[rnote '#'];
+ octnum=note(3);
+elseif strcmp(note(2),'b')
+ rnote=[rnote 'b'];
+ octnum=note(3);
+else
+ octnum=note(2);
+end
+
+
+% http://www.jita.com.cn/Seiten/Theorie/musik_theorie_1.htm
+switch rnote
+ case {'A','a'}
+ nr_note=1;
+ case {'A#','a#','Bb','bb'}
+ nr_note=2;
+ case {'H','h','B','b'}
+ nr_note=3;
+ case {'C','c'}
+ nr_note=4;
+ case {'C#','c#','Db','db'}
+ nr_note=5;
+ case {'D','d'}
+ nr_note=6;
+ case {'D#','d#','Eb','eb'}
+ nr_note=7;
+ case {'E','e'}
+ nr_note=8;
+ case {'F','f'}
+ nr_note=9;
+ case {'F#','f#','Gb','gb'}
+ nr_note=10;
+ case {'G','g'}
+ nr_note=11;
+ case {'G#','g#','Ab','ab'}
+ nr_note=12;
+ otherwise
+ fre=0;
+ return
+end
+
+oct=str2num(octnum);
+
+% compansate for that the octave changes at C
+if nr_note > 3
+ calcoct=oct-1;
+else
+ calcoct=oct;
+end
+gescent=calcoct*1200+100*(nr_note-1);
+fre=cent2fre(lowest_note,gescent);
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/parametergui.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/parametergui.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,1267 @@
+%
+%
+% (c) 2003-2008, University of Cambridge
+% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
+% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
+% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+function varargout = parametergui(varargin)
+% all action from a parametergui.
+%
+% parametergui_MAINFCN provides these command line APIs for dealing with parameterguis
+%
+% parametergui, by itself, creates a new parametergui or raises the existing
+% singleton*.
+%
+% H = parametergui returns the handle to a new parametergui or the handle to
+% the existing singleton*.
+%
+% parametergui(parameter_structure) creates a new window with the guis
+% for each parameter
+%
+% parametergui('CALLBACK',hObject,eventData,handles,...) calls the local
+% function named CALLBACK in parametergui.M with the given input arguments.
+%
+% parametergui('Property','Value',...) creates a new parametergui or raises the
+% existing singleton*. Starting from the left, property value pairs are
+% applied to the parametergui before untitled_OpeningFunction gets called. An
+% unrecognized property name or invalid value makes property application
+% stop. All inputs are passed to untitled_OpeningFcn via varargin.
+%
+% Copyright 1984-2002 The MathWorks, Inc.
+% $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+%
+% Copyright 2004 Stefan Bleeck
+% $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
+
+
+
+% find out, if we want a new window or the old one:
+if length(varargin)==1 && ~isempty(varargin{1})
+ parametergui_Singleton = 0; % normally we want a new window
+ all_childs=get(0,'children');
+ this_name=getname(varargin{1});
+ for i=1:length(all_childs)
+ name=get(all_childs(i),'name');
+ if strcmp(name,this_name)
+ parametergui_Singleton = 1; % but if there is a copy already, take that window instead
+ % and bring it to the front
+ figure(all_childs(i));
+ break
+ end
+ end
+else
+ parametergui_Singleton = 1; % but if there is a copy already, take that window instead
+end
+
+parametergui_State = struct('parametergui_Name', mfilename, ...
+ 'parametergui_Singleton', parametergui_Singleton, ...
+ 'parametergui_OpeningFcn', @parametergui_OpeningFcn, ...
+ 'parametergui_OutputFcn', @parametergui_OutputFcn, ...
+ 'parametergui_LayoutFcn', @parametergui_LayoutFcn, ...
+ 'parametergui_Callback', []);
+if nargin && ischar(varargin{1})
+ parametergui_State.parametergui_Callback = str2func(varargin{1});
+end
+
+if nargout
+ [varargout{1:nargout}] = parametergui_mainfcn(parametergui_State, varargin{:});
+else
+ parametergui_mainfcn(parametergui_State, varargin{:});
+end
+
+
+% --- Executes just before parametergui is made visible.
+function parametergui_OpeningFcn(hObject, eventdata, handles, varargin) %#ok
+% This function has no output args, see OutputFcn.
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see guidata)
+% varargin command line arguments to parametergui (see VARARGIN)
+
+% Choose default command line output for parametergui
+handles.output = hObject;
+
+
+% copy the params in place
+% params=varargin{1};
+% handles.params=params;
+
+% Update handles structure
+guidata(hObject, handles);
+
+global result;
+% UIWAIT makes parametergui wait for user response (see UIRESUME)
+
+% result=getdefaultvalue(handles.params);
+
+
+if strcmp(getmode(handles.params),'modal')
+ % set the first focus
+ focus=getfirstfocus(handles.params);
+ if ~isempty(focus)
+ hand=gethandle(handles.params,focus);
+ if ishandle(hand)
+ uicontrol(hand);
+ end
+ end
+
+ uiwait(handles.figure1);
+end
+
+% % set the userdata to the parameters so that they can be accessed from other programs
+% set(handles.figure1,'userdata',handles.params);
+% w=get(handles.figure1,'userdata');
+%%%% that doesnt work because of an obvious bug in matlab. The set routine
+%%%% calls the params set not the windows set
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = parametergui_OutputFcn(hObject, eventdata, handles) %#ok
+% varargout cell array for returning output args (see VARARGOUT);
+% hObject handle to figure
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles structure with handles and user data (see guidata)
+
+
+% Get default command line output from handles structure
+global result;
+% if isfield(result,'handles')
+% % matlab doesnt call the callback routine when closed, so update all values
+% % first:
+% generic_Callback([], 'onlyupdate', result.handles);
+% end
+
+
+varargout{1} = result;
+
+
+% --- Executes on button press in pushbutton1.
+function generic_Callback(hObject, eventdata, handles)
+global result;
+if ischar(eventdata) && strcmp(eventdata,'default')
+ p=getdefaultbutton(handles.params); % its as if the button was pressed
+ hObject=p.handle{1};
+end
+if ischar(eventdata) && strcmp(eventdata,'onlyupdate')
+ p=get(handles.params);
+ hObject=p{1}.handle{1};
+end
+centry=getentrybyhandle(handles.params,hObject);
+if isempty(centry)
+ disp('clicked on something outside')
+ return
+end
+
+params=handles.params;
+entryparams=get(params);
+data=getuserdata(params);
+callback=centry.callback;
+nr_params=length(entryparams);
+
+% second go through all fields and update the value. This is neccessary to
+% make sure to update the values in the params-structure when altered from
+% outside
+for iii=1:nr_params
+% param=entryparams{iii};
+ type=entryparams{iii}.type;
+ handleb=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel);
+ switch type
+ case {'pop-up menu'}
+ vals=get(handleb,'string');
+ nrval=get(handleb,'value');
+ value=vals{nrval};
+ params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel); % set the string value
+ case {'bool','radiobutton'}
+ value=get(handleb,'value');
+ params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel);
+
+ % bool items can enable or disable other items:
+ for i=1:length(entryparams{iii}.enables)
+ params=enable(params,entryparams{iii}.enables{i},value,entryparams{iii}.enables_inbox{i});
+ end
+ for i=1:length(entryparams{iii}.disables)
+ params=enable(params,entryparams{iii}.disables{i},1-value,entryparams{iii}.disables_inbox{i});
+ end
+ case {'filename','string','directoryname'}
+ stringvalue=get(handleb,'string');
+ params=set(params,entryparams{iii}.text,stringvalue,entryparams{iii}.panel);
+ case {'slider'}
+ % user could have clicked on the slider or on the edit
+ secombi=entryparams{iii}.slidereditcombi;
+ hand1=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel,1);
+ hand2=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel,3);
+ if hObject==hand1
+ strval=get(hand1,'string');
+ val=str2num(strval);
+ secombi=slidereditcontrol_set_raweditvalue(secombi,val);
+ else
+ val=get(hand2,'value');
+ secombi=slidereditcontrol_set_rawslidervalue(secombi,val);
+ end
+ val=slidereditcontrol_get_value(secombi);
+ selectedunit=getcurrentunit(params,entryparams{iii}.text);
+ toval=val*secombi.editscaler;
+ params=setas(params,entryparams{iii}.text,toval,selectedunit,entryparams{iii}.panel); % set the real value
+ case {'float'}
+ set(handleb,'backgroundcolor','w');
+ set(handleb,'foregroundcolor','k');
+ strvalue=get(handleb,'string'); % value is a string, lets see what we make of it
+ if ~strcmp(strvalue,'auto')
+ selectedunit=getcurrentunit(params,entryparams{iii}.text);
+ units=entryparams{iii}.unittype;
+ if isa(units,'unit_none')
+ testvalue=str2num(strvalue); % its a float, it must have a value
+ realvalue=testvalue;
+ selectedunit='';
+ else
+ params=setas(params,entryparams{iii}.text,strvalue,selectedunit,entryparams{iii}.panel); % set the real value
+ testvalue=getas(params,entryparams{iii}.text,entryparams{iii}.orgunit);
+ realvalue=str2num(strvalue);
+ end
+ if isempty(testvalue)
+ set(handleb,'backgroundcolor','g');
+ set(handleb,'foregroundcolor','r');
+ uicontrol(handleb);
+ errordlg(sprintf('no valid value for ''%s''',entryparams{iii}.text));
+ return
+ end
+ if min(testvalue)entryparams{iii}.maxvalue
+ set(handleb,'backgroundcolor','g');
+ set(handleb,'foregroundcolor','r');
+ uicontrol(handleb);
+ if testvalueentryparams{iii}.maxvalue
+ set(handleb,'foregroundcolor','g');
+ set(handleb,'backgroundcolor','r');
+ uicontrol(handleb);
+ if testvaluemaxtextlen
+ maxtextlen=text_len;
+ end
+
+ if strcmp(param.type,'filename')
+ maxeditwidth=filenamelength+10;
+ end
+ if strcmp(param.type,'directoryname')
+ maxeditwidth=filenamelength+10;
+ end
+ if strcmp(param.type,'string')
+ maxeditwidth=max(maxeditwidth,param.width);
+ maxeditwidth=max(maxeditwidth,mineditwidth);
+ end
+ if strcmp(param.type,'float') || strcmp(param.type,'int')
+ maxeditwidth=max(maxeditwidth,25);
+ end
+ if strcmp(param.type,'pop-up menu')
+ maxeditwidth=max(maxeditwidth,20);
+ end
+ if strcmp(param.type,'slider')
+ thirdpaneladd=30;
+ maxeditwidth=max(maxeditwidth,45);
+ end
+end
+
+% the total size of the window is now:
+maxwidth=max(maxeditwidth,edit_width);
+window_width=maxtextlen+spacebetweentextandedit+maxwidth+3*leftoffset+rightoffset+thirdpaneladd;
+window_height=(nr_params+1)*rowheight;
+% get the size of the screen in chars
+set(0,'units','char');
+siz=get(0,'screensize');
+screeen_height=siz(4);
+screeen_width=siz(3);
+set(0,'units','pixels'); % back to normal
+
+% the figure
+% windoff=1.3; % offset from the top right corner
+windoff=0;
+guihandle = figure(...
+ 'Units','characters',...
+ 'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
+ 'IntegerHandle','off',...
+ 'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
+ 'MenuBar','none',...
+ 'Name',getname(params),...
+ 'NumberTitle','off',...
+ 'Position',[screeen_width-window_width+windoff screeen_height-window_height-windoff window_width window_height],...
+ 'Renderer',get(0,'defaultfigureRenderer'),...
+ 'RendererMode','manual',...
+ 'Resize','off',...
+ 'HandleVisibility','callback',...
+ 'visible','off',...
+ 'KeyPressFcn' ,@doFigureKeyPress , ...
+ 'Tag','figure1');
+
+pos=getposition(params);
+movegui(guihandle,pos);
+
+% make sure we are on screen
+movegui(guihandle)
+
+% error in V7... correct for small offset
+if strcmp(pos,'northeast')
+ wp=get(guihandle,'pos');
+ wp(1)=wp(1)+5;
+ wp(2)=wp(2)+5;
+ set(guihandle,'pos',wp);
+end
+set(guihandle,'visible','on')
+
+% application data
+setappdata(guihandle, 'parameterguiDEOptions', struct(...
+ 'active_h', 1.020033e+002, ...
+ 'taginfo', struct(...
+ 'figure', 2, ...
+ 'pushbutton', 2), ...
+ 'override', 0, ...
+ 'release', 13, ...
+ 'resize', 'simple', ...
+ 'accessibility', 'callback', ...
+ 'mfile', 1, ...
+ 'callbacks', 1, ...
+ 'singleton', 1, ...
+ 'syscolorfig', 1, ...
+ 'lastSavedFile', 'c:\bla bla bla'));
+
+% generate a huge panel that resides in that figure
+
+set(guihandle,'Units','characters');
+winsize=get(guihandle,'position');
+winsize(1)=0;
+winsize(2)=0;
+bigpanel=uipanel(...
+ 'Parent',guihandle,...
+ 'Units','characters',...
+ 'Position',winsize,...
+ 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'Title','',...
+ 'BorderType','none',...
+ 'visible','on',...
+ 'Tag','parameterpanel');
+
+
+
+
+% first plot all panels so that they are in the background
+linecount=1;
+panelcount=1;
+for iii=nr_params:-1:1
+ param=entryparams{iii};
+ type=param.type;
+ if strcmp(type,'panel') % draw a panel around the next ones
+ pos_x=leftoffset;
+ width=window_width-2*leftoffset+rightoffset/2;
+ height=(param.nr_elements+0.99)*rowheight;
+ pos_y=(linecount+0.82)*rowheight-height-all_y_offset;
+ % panelhand(panelcount) = uipanel(... % panel
+ callbackstr='parametergui(''generic_Callback'',gcbo,[],guidata(gcbo))';
+ panelhand(panelcount) = uibuttongroup(... % panel
+ 'Parent',bigpanel,...
+ 'Units','characters',...
+ 'Position',[pos_x pos_y width height],...
+ 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'TitlePosition','lefttop',...
+ 'Title',param.text,...
+ 'BorderType','etchedin',...
+ 'FontWeight','bold',...
+ 'Fontsize',11,...
+ 'Tag',sprintf('panel%d',panelcount),...
+ 'SelectionChangeFcn',callbackstr,...
+ 'Userdata',param.text);
+ panelcount=panelcount+1;
+ params=sethandle(params,param.text,panelhand,param.panel); % save the handle
+ end
+ linecount=linecount+1;
+ param_y(iii)=linecount;
+end
+% then make a line for each parameter
+linecount=ones(panelcount,1); % one linecounter for each panel
+general_line_count=1;
+for iii=nr_params:-1:1
+ param=entryparams{iii};
+ type=param.type;
+ callbackstr='parametergui(''generic_Callback'',gcbo,[],guidata(gcbo))';
+ tooltiptext=param.tooltiptext;
+ % find out to which panel we belong and set the parent appropriate
+ parentpanel=bigpanel; % by default the ui is in the big panel without subp
+ current_panel_count=1; % by default in the big panel
+ for jjj=1:panelcount-1
+ if strcmp(param.panel,get(panelhand(jjj),'title'))
+ parentpanel=panelhand(jjj);
+ current_panel_count=jjj+1; % the current panel +1 to avoid confusion with the big one
+ end
+ end
+ if ~strcmp(type,'button') && ~strcmp(type,'panel')
+ text_len=length(param.text);
+ if current_panel_count==1
+ pos_x=maxtextlen-(text_len+2*spacearoundtext)+3*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen-(text_len+2*spacearoundtext)+3*leftoffset-2;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ h2 = uicontrol(... % text
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'Position',[pos_x pos_y-yoffset text_len+2*spacearoundtext elementhigth],...
+ 'String',param.text,...
+ 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'HorizontalAlignment','right',...
+ 'Tag',sprintf('text%d',general_line_count),...
+ 'Style','text');
+ if strcmp(type,'text')
+ set(h2,'FontSize',12);
+ set(h2,'Fontweight','bold');
+ ext=get(h2,'extent');
+ pos=get(h2,'position');
+ pos(1)=buttonoffset;
+ pos(3)=ext(3);
+ pos(4)=ext(4);
+ set(h2,'position',pos);
+ end
+ end
+ switch param.enable
+ case 0
+ enableval='off';
+ case 1
+ enableval='on';
+ end
+
+ switch type
+ case {'int'}
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ val=getraw(params,param.text);
+ hand = uicontrol(... % float edit box
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y edit_width elementhigth],...
+ 'Callback',callbackstr,...
+ 'String',val,...
+ 'enable',enableval,...
+ 'Style','edit',...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+ set(hand,'HorizontalAlignment','right');
+ params=sethandle(params,param.text,hand,param.panel);
+ case {'float'}
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ % val=getas(params,param.text,param.orgunit);
+ strval=param.stringvalue;
+ hand = uicontrol(... % float edit box
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y edit_width elementhigth],...
+ 'Callback',callbackstr,...
+ 'String',strval,...
+ 'Style','edit',...
+ 'enable',enableval,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+
+ set(hand,'HorizontalAlignment','left');
+ params=sethandle(params,param.text,hand,param.panel);
+
+ % make the unit poupbox
+ unit=param.unittype;
+ % make a tooltip for it
+ unittype=getname(unit);
+ if ~isa(unit,'unit_none')
+ pos_x=pos_x+edit_width+2;
+ possible_units=getunitstrings(unit);
+ possible_units_full=getunitfullstrings(unit);
+ select_nr=findunit(unit,param.orgunit);
+ unitname=possible_units{select_nr};
+ fullunitname=possible_units_full{select_nr};
+ tooltips=sprintf('%s measured in %s (%s)',unittype,unitname,fullunitname);
+ hand2 = uicontrol(... % bool: radiobutton
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y unit_width elementhigth],...
+ 'string',possible_units,...
+ 'enable',enableval,...
+ 'value',select_nr,...
+ 'Style','popupmenu',...
+ 'Callback',callbackstr,...
+ 'tooltip',tooltips,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
+ params=sethandle(params,param.text,hand2,param.panel,2);
+ end
+ case {'slider'}
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ % val=getas(params,param.text,param.orgunit);
+ strval=param.stringvalue;
+ hand = uicontrol(... % float edit box
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y edit_width elementhigth],...
+ 'Callback',callbackstr,...
+ 'String',strval,...
+ 'Style','edit',...
+ 'enable',enableval,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+
+ set(hand,'HorizontalAlignment','left');
+ params=sethandle(params,param.text,hand,param.panel);
+
+ % make the unit poupbox
+ unit=param.unittype;
+ % make a tooltip for it
+ unittype=getname(unit);
+ if ~isa(unit,'unit_none')
+ pos_x=pos_x+edit_width+2;
+ possible_units=getunitstrings(unit);
+ possible_units_full=getunitfullstrings(unit);
+ select_nr=findunit(unit,param.orgunit);
+ unitname=possible_units{select_nr};
+ fullunitname=possible_units_full{select_nr};
+ tooltips=sprintf('%s measured in %s (%s)',unittype,unitname,fullunitname);
+ hand2 = uicontrol(... % bool: radiobutton
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y unit_width elementhigth],...
+ 'string',possible_units,...
+ 'enable',enableval,...
+ 'value',select_nr,...
+ 'Style','popupmenu',...
+ 'Callback',callbackstr,...
+ 'tooltip',tooltips,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
+ params=sethandle(params,param.text,hand2,param.panel,2);
+ else
+ pos_x=pos_x+edit_width+2;
+ params=sethandle(params,param.text,0,param.panel,2);
+ end
+
+ % make the slider
+ pos_x=pos_x+unit_width+2;
+ hand3 = uicontrol(... % bool: radiobutton
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'Position',[pos_x pos_y thirdpaneladd+15 elementhigth],...
+ 'enable',enableval,...
+ 'value',1,...
+ 'Style','slider',...
+ 'Callback',callbackstr,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
+ params=sethandle(params,param.text,hand3,param.panel,3);
+
+ % set up the slidereditcontrol
+ secombi=slidereditcontrol_setup(hand3,hand,param.minvalue,param.maxvalue,param.rawvalue,param.islog,param.editscaler,param.nreditdigits);
+ secombi=slidereditcontrol_set_value(secombi,param.rawvalue);
+ params=setslidereditcontrol(params,param.text,secombi,param.panel);
+
+ case 'string'
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ width=max(stringedit_width,param.width)-2;
+ hand = uicontrol(... % string edit box
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'enable',enableval,...
+ 'Position',[pos_x pos_y width elementhigth],...
+ 'Callback',callbackstr,...
+ 'String',param.value,...
+ 'Style','edit',...
+ 'HorizontalAlignment','left',...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+ params=sethandle(params,param.text,hand,param.panel);
+ case 'bool'
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ hand = uicontrol(... % bool: checkbox
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'Position',[pos_x pos_y edit_width elementhigth],...
+ 'enable',enableval,...
+ 'value',param.value,...
+ 'Style','checkbox',...
+ 'Callback',callbackstr,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+ params=sethandle(params,param.text,hand,param.panel);
+ case 'radiobutton'
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+ hand = uicontrol(... % bool: radiobutton
+ 'Parent',parentpanel,...
+ 'TooltipString',tooltiptext,...
+ 'Units','characters',...
+ 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
+ 'Position',[pos_x pos_y 3 elementhigth],...
+ 'value',param.value,...
+ 'Style','radiobutton',...
+ 'enable',enableval,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+ params=sethandle(params,param.text,hand,param.panel);
+ if strcmp(param.text,'other...')
+ pos_x=pos_x+4;
+% width=max(window_width-pos_x-5,10);
+ width=maxeditwidth-1;
+ if isfield(param,'userdata')
+ userstr=param.userdata;
+ else
+ userstr='';
+ end
+ hand2 = uicontrol(... % string edit box
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y width elementhigth],...
+ 'Callback',callbackstr,...
+ 'String',userstr,...
+ 'Style','edit',...
+ 'enable',enableval,...
+ 'HorizontalAlignment','left',...
+ 'Tag',sprintf('other_entry%d',general_line_count),...
+ 'Userdata',param.text);
+ params=sethandle(params,param.text,hand2,param.panel,2);
+ % params=sethandle(params,param.text,param.panel,hand2,2);
+ end
+ case {'filename','directoryname'}
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+
+ hand = uicontrol(... % bool: radiobutton
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y filenamelength elementhigth],...
+ 'enable',enableval,...
+ 'string',param.value,...
+ 'Style','edit',...
+ 'Callback',callbackstr,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
+ params=sethandle(params,param.text,hand,param.panel);
+ % and a button
+ pos_x=pos_x+filenamelength+2;
+ str=' select...';
+ width=length(str);
+ hand2 = uicontrol(... % string edit box
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'Position',[pos_x pos_y width elementhigth+0.2],...
+ 'Callback',callbackstr,...
+ 'String',str,...
+ 'Style','pushbutton',...
+ 'HorizontalAlignment','left',...
+ 'enable',enableval,...
+ 'Tag',sprintf('other_entry%d',general_line_count),...
+ 'Userdata',param.text);
+ params=sethandle(params,param.text,hand2,param.panel,2);
+ % params=sethandle(params,param.text,param.panel,hand2,2);
+
+ case 'button'
+ textlen=length(param.text)+4;
+ buttonwidth=2*spacearoundtext+textlen;
+ if current_panel_count==1
+ buttonposy=rowheight*linecount(current_panel_count)-yoffset-all_y_offset-extrabuttondown+0.5;
+ else
+ buttonposy=rowheight*linecount(current_panel_count)-yoffset-all_y_offset-extrabuttondown-3+0.5;
+ end
+
+ hand = uicontrol(... % button
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'Callback',callbackstr,...
+ 'Position',[buttonoffset+2*leftoffset buttonposy+0.1 buttonwidth 1.8],...
+ 'String',param.text,...
+ 'Style','pushbutton',...
+ 'enable',enableval,...
+ 'KeyPressFcn',@doFigureKeyPress , ...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.text);
+ % 'backgroundcolor',[0.5 1 1],...
+ % 'foregroundcolor',[0.5 1 1],...
+ params=sethandle(params,param.text,hand,param.panel);
+
+ if param.isdefaultbutton==1
+ setappdata(guihandle, 'DefaultValid', true);
+ h = uicontrol(...
+ 'Units','characters',...
+ 'BackgroundColor', 'k', ...
+ 'Style','frame',...
+ 'Position',[buttonoffset+2*leftoffset-0.5 buttonposy-0.05 buttonwidth+0.9 1.9],...
+ 'Parent',parentpanel...
+ );
+ uistack(h,'bottom')
+ end
+
+ case 'pop-up menu'
+ if current_panel_count==1
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
+ pos_y=general_line_count*rowheight-all_y_offset;
+ else
+ pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
+ pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
+ end
+
+ hand = uicontrol(... % bool: radiobutton
+ 'Parent',parentpanel,...
+ 'Units','characters',...
+ 'BackgroundColor',[1 1 1],...
+ 'Position',[pos_x pos_y filenamelength elementhigth],...
+ 'string',param.possible_values,...
+ 'Style','popupmenu',...
+ 'enable',enableval,...
+ 'Callback',callbackstr,...
+ 'Tag',sprintf('entry%d',general_line_count),...
+ 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
+ params=sethandle(params,param.text,hand,param.panel);
+ end
+
+ linecount(current_panel_count)=linecount(current_panel_count)+1;
+ general_line_count=general_line_count+1;
+end
+
+hsingleton = guihandle;
+
+
+% --- Handles default parameterguiDE parametergui creation and callback dispatch
+function varargout = parametergui_mainfcn(parametergui_State, varargin)
+
+parametergui_StateFields = {'parametergui_Name'
+ 'parametergui_Singleton'
+ 'parametergui_OpeningFcn'
+ 'parametergui_OutputFcn'
+ 'parametergui_LayoutFcn'
+ 'parametergui_Callback'};
+parametergui_Mfile = '';
+for i=1:length(parametergui_StateFields)
+ if ~isfield(parametergui_State, parametergui_StateFields{i})
+ error('Could not find field %s in the parametergui_State struct in parametergui M-file %s', parametergui_StateFields{i}, parametergui_Mfile);
+ elseif isequal(parametergui_StateFields{i}, 'parametergui_Name')
+ parametergui_Mfile = [getfield(parametergui_State, parametergui_StateFields{i}), '.m'];
+ end
+end
+
+numargin = length(varargin);
+
+if numargin == 0
+ % parametergui
+ % create the parametergui
+ parametergui_Create = 1;
+elseif numargin > 3 && ischar(varargin{1}) && ishandle(varargin{2})
+ % parametergui('CALLBACK',hObject,eventData,handles,...)
+ parametergui_Create = 0;
+else
+ % parametergui(...)
+ % create the parametergui and hand varargin to the openingfcn
+ parametergui_Create = 1;
+end
+
+%SB: return values
+global params
+
+if parametergui_Create == 0
+ varargin{1} = parametergui_State.parametergui_Callback;
+ if nargout
+ [varargout{1:nargout}] = feval(varargin{:});
+ else
+ feval(varargin{:});
+ end
+else
+ if parametergui_State.parametergui_Singleton
+ parametergui_SingletonOpt = 'reuse';
+ else
+ parametergui_SingletonOpt = 'new';
+ end
+
+ % Open fig file with stored settings. Note: This executes all component
+ % specific CreateFunctions with an empty HANDLES structure.
+ % make params global, so that I can access them in the generation
+ % function
+ params=varargin{1};
+
+ % Do feval on layout code in m-file if it exists
+ if ~isempty(parametergui_State.parametergui_LayoutFcn)
+ gui_hFigure = feval(parametergui_State.parametergui_LayoutFcn, parametergui_SingletonOpt);
+ % SB: the original one finds the wrong one, possible because it just looks
+ % for the first one with the m-file. We can do better:
+
+ all_childs=get(0,'children');
+ this_name=getname(params);
+ for i=1:length(all_childs)
+ name=get(all_childs(i),'name');
+ if strcmp(name,this_name)
+ gui_hFigure=all_childs(i);
+ break
+ end
+ end
+
+ else
+ gui_hFigure = local_openfig(parametergui_State.parametergui_Name, parametergui_SingletonOpt);
+ % If the figure has InparameterguiInitialization it was not completely created
+ % on the last pass. Delete this handle and try again.
+ if isappdata(gui_hFigure, 'InparameterguiInitialization')
+ delete(gui_hFigure);
+ gui_hFigure = local_openfig(parametergui_State.parametergui_Name, parametergui_SingletonOpt);
+ end
+ end
+
+ % Set flag to indicate starting parametergui initialization
+ setappdata(gui_hFigure,'InparameterguiInitialization',1);
+
+ % Fetch parameterguiDE Application params
+ parametergui_Options = getappdata(gui_hFigure,'parameterguiDEOptions');
+
+ if ~isappdata(gui_hFigure,'parameterguiOnScreen')
+ % Adjust background color
+ if parametergui_Options.syscolorfig
+ set(gui_hFigure,'Color', [0.831372549019608 0.815686274509804 0.784313725490196]);
+ end
+
+ % Generate HANDLES structure and store with guidata
+ guidata(gui_hFigure, guihandles(gui_hFigure));
+ end
+
+
+
+ % If user specified 'Visible','off' in p/v pairs, don't make the figure
+ % visible.
+ parametergui_MakeVisible = 1;
+ for ind=1:2:length(varargin)
+ if length(varargin) == ind
+ break;
+ end
+ len1 = min(length('visible'),length(varargin{ind}));
+ len2 = min(length('off'),length(varargin{ind+1}));
+ if ischar(varargin{ind}) && ischar(varargin{ind+1}) && ...
+ strncmpi(varargin{ind},'visible',len1) && len2 > 1
+ if strncmpi(varargin{ind+1},'off',len2)
+ parametergui_MakeVisible = 0;
+ elseif strncmpi(varargin{ind+1},'on',len2)
+ parametergui_MakeVisible = 1;
+ end
+ end
+ end
+
+ % Check for figure param value pairs
+ for index=1:2:length(varargin)
+ if length(varargin) == index
+ break;
+ end
+ try
+ set(gui_hFigure, varargin{index},vargin{index+1});
+ catch
+ break
+ end
+ end
+
+ % If handle visibility is set to 'callback', turn it on until finished
+ % with OpeningFcn
+ parametergui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
+ if strcmp(parametergui_HandleVisibility, 'callback')
+ set(gui_hFigure,'HandleVisibility', 'on');
+ end
+
+ % SB: save the user structure to the handle struct
+ handles=guidata(gui_hFigure);
+ handles.params=params;
+ guidata(gui_hFigure, handles);
+ feval(parametergui_State.parametergui_OpeningFcn, gui_hFigure, [], handles, varargin{:});
+
+
+
+
+ if ishandle(gui_hFigure)
+ % Update handle visibility
+ set(gui_hFigure,'HandleVisibility', parametergui_HandleVisibility);
+
+ % Make figure visible
+ if parametergui_MakeVisible
+ set(gui_hFigure, 'Visible', 'on')
+ if parametergui_Options.singleton
+ setappdata(gui_hFigure,'parameterguiOnScreen', 1);
+ end
+ end
+
+ % Done with parametergui initialization
+ rmappdata(gui_hFigure,'InparameterguiInitialization');
+ end
+
+ % If handle visibility is set to 'callback', turn it on until finished with
+ % OutputFcn
+ if ishandle(gui_hFigure)
+ parametergui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
+ if strcmp(parametergui_HandleVisibility, 'callback')
+ set(gui_hFigure,'HandleVisibility', 'on');
+ end
+ parametergui_Handles = guidata(gui_hFigure);
+ else
+ parametergui_Handles = [];
+ end
+
+
+ % SB: if the window was reused then update the handles in the params, so
+ % that they can be recalculated.
+ % this only works when the number and type of variables have not
+ % changed in between
+ if strcmp(parametergui_SingletonOpt,'reuse')
+ dsnew=get(handles.params); % the new parameter without handles
+ nr_ds=length(dsnew);
+ fields=fieldnames(handles);
+ for i=1:nr_ds % we have to find the uicontrol with these two features:
+ searchtext=dsnew{i}.text;
+ searchpanel=dsnew{i}.panel;
+ searchtype=dsnew{i}.type;
+ nr_h=length(fields);
+ for j=1:nr_h % search through all
+ fh=getfield(handles,fields{j});
+ if ishandle(fh)
+ type=get(fh,'type');
+ [nr_enty,len]=size(type);
+ if nr_enty>1
+ type=type(1);
+ secondh=fh(1);
+ fh=fh(2);
+ end
+ if strcmp(type,'uipanel') && strcmp(searchtype,'panel')
+ panelname=get(fh,'title');
+ if strcmp(searchpanel,panelname)
+ params=sethandle(params,searchtext,fh,searchpanel); % set the handle
+ break
+ end
+ end
+ % if its not a panel then its an uicontrol
+ if strcmp(type,'uicontrol')
+ parent=get(fh,'parent');
+ panelname=get(parent,'title'); % this is the panel
+ if strcmp(panelname,'')
+ panelname='all';
+ end
+ uiname=get(fh,'UserData');
+
+ if strcmp(searchpanel,panelname) && strcmp(searchtext,uiname)
+ params=sethandle(params,searchtext,fh,searchpanel); % set the handle
+ if nr_enty>1
+ params=sethandle(params,searchtext,secondh,searchpanel,2); % set the handle
+ end
+ break
+ end
+
+ % newstyle=get(fh,'style');
+ % if strcmp(orgstyle,newstyle)
+ % str2=get(fh,'UserData');
+ % if strcmp(str1,str2)
+ % params=sethandle(params,str1,fh); % set the handle
+ % style=get(fh,'style');
+ % switch style
+ % case 'edit'
+ % params=set(params,str1,get(fh,'string'));
+ % case {'checkbox','radiobox','int','float'}
+ % params=set(params,str1,get(fh,'value'));
+ % params=set(params,str1,get(fh,'value'));
+ % end
+ % break
+ % end
+ % end
+ end
+ end
+ % h=gethandle(params,searchtext,searchpanel);
+ end
+ end
+ handles.params=params;
+ guidata(gui_hFigure, handles);
+ end
+
+
+
+ if nargout
+ global result
+ parametergui_Handles=result;
+ if strcmp(getmode(handles.params),'nonmodal')
+ result=params;
+ end
+ [varargout{1:nargout}] = feval(parametergui_State.parametergui_OutputFcn, gui_hFigure, [], parametergui_Handles);
+ else
+ feval(parametergui_State.parametergui_OutputFcn, gui_hFigure, [], parametergui_Handles);
+ end
+
+ if ishandle(gui_hFigure)
+ set(gui_hFigure,'HandleVisibility', parametergui_HandleVisibility);
+ end
+
+
+end
+
+
+function gui_hFigure = local_openfig(name, singleton)
+if nargin('openfig') == 3
+ gui_hFigure = openfig(name, singleton, 'auto');
+else
+ % OPENFIG did not accept 3rd input argument until R13,
+ % toggle default figure visible to prevent the figure
+ % from showing up too soon.
+ parametergui_OldDefaultVisible = get(0,'defaultFigureVisible');
+ set(0,'defaultFigureVisible','off');
+ gui_hFigure = openfig(name, singleton);
+ set(0,'defaultFigureVisible',parametergui_OldDefaultVisible);
+end
+
+function doFigureKeyPress(obj, evd)
+switch(evd.Key)
+ case {'return','space'}
+ if getappdata(gcbf,'DefaultValid')
+ handles=guidata(gcbf);
+ generic_Callback([],'default',handles)
+ end
+ case 'escape'
+ close(gcbf)
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/playstereo.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/playstereo.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% tool
+%
+% 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 playstereo(sig1,sig2)
+
+sig1=rampamplitude(sig1,0.005);
+sig1=scaletomaxvalue(sig1,0.999);
+sig2=rampamplitude(sig2,0.005);
+sig2=scaletomaxvalue(sig2,0.999);
+
+values1=getvalues(sig1);
+values2=getvalues(sig2);
+
+finvals=[values1 values2];
+sr=getsr(sig1);
+
+wavwrite(finvals,sr,'last stereo');
+
+sound(finvals,sr);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/plotfft.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/plotfft.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,40 @@
+% tool
+%
+% 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 plotfft(name)
+% usage: plotfft('ghfgghfh.wav')
+
+[y,Fs,bits]=wavread(name);
+
+Fn=Fs/2; % Nyquist frequency
+t=0:1/Fs:length(y)/Fs; % time vector sampled at Fs Hz,
+
+% Next highest power of 2 greater than or equal to length(y)
+NFFT=2.^(ceil(log(length(y))/log(2)));
+% Take fft, padding with zeros, length(FFTX)==NFFT
+FFTX=fft(y,NFFT);
+NumUniquePts = ceil((NFFT+1)/2);
+% fft is symmetric, throw away second half
+FFTX=FFTX(1:NumUniquePts);
+MX=abs(FFTX); % Take magnitude of X
+% Multiply by 2 to take into account the fact that we threw out
+% second half of FFTX above
+MX=MX*2;
+MX(1)=MX(1)/2; % Account for endpoint uniqueness
+MX(length(MX))=MX(length(MX))/2; % We know NFFT is even
+% Scale the FFT so that it is not a function of the length of y.
+MX=MX/length(y); %
+f=(0:NumUniquePts-1)*2*Fn/NFFT;plot(f,MX);
+plot(f,MX);
+xlabel('Frequency [Hz]');
+ylabel('Magnitude');
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/producesounddata.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/producesounddata.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,158 @@
+% tool
+%
+% 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 [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian,start_time,duration)
+% usage: [sounddata,samplerate,endian]=producesounddata(soundcommand)
+% returns important data about the sound.
+% The sound can be a file (wav or raw) or a function or a global signal-object
+% parameters:
+% soundcommand - the file or the command
+% temp_sound_file_name - a filename to which the wave is written
+% str_sound_sample_rate - the sample rate
+% str_sound_endian - the sound endian
+% start_time - the starting time when not zero
+% duration - how long shell the signal be
+
+if nargin < 4 str_sound_endian=1;end
+if nargin < 3 str_sound_sample_rate=20000;end
+if nargin < 2 temp_sound_file_name='temp_sound.wav';end
+if nargin < 1
+ error('producesounddata: Sound command must be given');
+end
+
+
+old_path=pwd;
+endian=0;
+bits=16;
+
+[soundpathstr,soundname,ext,versn] = fileparts(soundcommand);
+if fexist(soundcommand) % if it is a file. It could be a function
+ with_sound=1;
+ [soundpathstr,soundname,ext,versn] = fileparts(soundcommand);
+ if ~strcmp(soundpathstr,'')
+ cd(soundpathstr);
+ end
+ if fexist(soundcommand)
+ if strcmp(ext,'.raw') | strcmp(ext,'') % or no ending
+ if isempty(str_sound_sample_rate) & isempty(str_sound_endian)
+ [data,sr,endi]=rawfile2wavfile(soundcommand);
+ else
+ if isempty(str_sound_sample_rate) | isempty(str_sound_endian)
+ error('makemovie: error: both samplerate and endian must be given!');
+ else
+ eval(sprintf('samplerate=%s;',str_sound_sample_rate));
+ endian=str_sound_endian;
+ rawfile2wavfile(soundcommand,samplerate,endian);
+ end
+ end
+
+ [path,name,ext,versn] = fileparts(soundcommand);
+ newfilename=sprintf('%s.wav',name);
+ % newname=fullfile(old_path,newfilename);
+ newname=fullfile(path,newfilename);
+ soundcommand=newname;
+ end
+ [soundpathstr,soundname,ext,versn] = fileparts(soundcommand);
+ if strcmp(ext,'.wav')
+
+ % first read in data
+ [readsounddata,samplerate,bits] = wavread(soundcommand);
+% [readsounddata,samplerate,bits] = wavread([soundname ext]);
+
+ fmax=max(readsounddata);
+ if fmax>1
+ resp=input('Achtung: Clipping in the input signal due to too high input_scale. Correct it? [y]/n','s');
+ if ~strcmp(resp,'n')
+ readsounddata=readsounddata*0.999/fmax;
+ end
+ end
+
+ % dsam doesnt like samplerates of 44100. It explodes
+ if samplerate==44100
+ disp('dsam doesnt like samplerates of 44100. It explodes. Changing SR to 16000');
+ samplerate=16000;
+ sig=signal(readsounddata);
+ sig=setsr(samplerate);
+ sig=changesr(sig,samplerate);
+ readsounddata=getvalues(sig);
+ end
+
+ % and then write it back again to the temp-name:
+ cd(old_path);
+ wavwrite(readsounddata,samplerate,bits,temp_sound_file_name);
+ else
+ error('Format not implemented yet!');
+ end
+ else
+ error('Sound-file not found');
+ end
+
+ % if the wav file has two channels, (stereo) only the left channel is used for calculation
+ nr_chan=size(readsounddata,2);
+ if nr_chan>1
+ sounddata=readsounddata(:,1); % only the first channel
+ else
+ sounddata=readsounddata;
+ end
+ videolength=size(sounddata,1)/samplerate;
+else %if exist soundcommand
+
+ % a user defined function or an object
+ try % to simple make the thing. If its a script, that works
+ eval(sprintf('datasig=%s;',soundcommand));
+% disp(sprintf('producing sound from function: %s',soundcommand));
+ catch
+ try % to assume, that its an global object
+ eval(sprintf('global %s;',soundcommand));
+ eval(sprintf('datasig=%s;',soundcommand));
+% disp(sprintf('producing sound from signal-object: %s',soundcommand));
+ catch
+ if strfind(soundcommand,'wav') | strfind(soundcommand,'raw')
+ error(sprintf('could not open soundfile: %s',soundcommand));
+ else
+ disp('getaiffs: error: something wrong with the creation of the signal!');
+ error(sprintf('if %s is a signal-object, than make it global!',soundcommand));
+ end
+ end
+ end
+ datasig=scaletomaxvalue(datasig,0.999);
+ readsounddata=getdata(datasig);
+ cd(old_path);
+ samplerate=getsr(datasig);
+ bits=16;
+ writetowavefile(datasig,temp_sound_file_name);
+ soundcommand=temp_sound_file_name;
+end
+
+
+nr_chan=size(readsounddata,2);
+if nr_chan>1
+ sounddata=readsounddata(:,1); % only the first channel
+else
+ sounddata=readsounddata;
+end
+
+
+% simple way to define the length of the singal: read it back in again :-)
+% this is simple, because I know, that it is there!
+
+if nargin > 5 % only, when start time is there
+ sig=loadwavefile(signal,temp_sound_file_name);
+ if start_time+duration < getlength(sig)
+ sig=getpart(sig,start_time,start_time+duration);
+ else
+ sig=getpart(sig,start_time,getmaximumtime(sig));
+ end
+ writetowavefile(sig,temp_sound_file_name);
+ [sounddata,samplerate,bits] = wavread(temp_sound_file_name);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/publishtoword.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/publishtoword.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,218 @@
+% 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 $
+
+% publishtoword
+
+% publish the figures on the screen
+% this is a script, not a function
+
+
+% exclude the windows with the following names:
+exclude{1}='browser';
+
+global publish_parameters;
+% if publish_parameters==1
+exclude{2}='parameter';
+% end
+
+global extra_publish
+
+% first search through all windows for the parameter ones
+% all_windows=get(0,'children');
+all_windows=allchild(0);
+for i=1:length(all_windows)
+ if strcmp(get(all_windows(i),'type'),'figure');
+ titl=get(all_windows(i),'name');
+ if strcmp(titl,'browser')
+ browserwindow=all_windows(i);
+ end
+ % for j=1:length(exclude) TODO
+ if ~isempty(strfind(lower(titl),exclude{2})) && publish_parameters==1
+
+ hand=all_windows(i);
+ dat=guidata(hand);
+ params=dat.params;
+ disp(params);
+ end
+ % end
+ end
+end
+
+clear createdfigs
+global createdfigs
+global was_unit_info
+createdfigs=[];
+createtits=[];
+count=0;
+for i=1:length(all_windows)
+ if strcmp(get(all_windows(i),'type'),'figure');
+ titl=get(all_windows(i),'name');
+
+ % special
+ if strfind(titl,'unitinfo')==1
+ handles=guidata(browserwindow);
+ cur_un=handles.info.current_unit;
+ cur_an=handles.info.current_animal;
+ unitinfo=getunitinfo(handles,cur_an,cur_un);
+ nr_coms=length(unitinfo.comment);
+ for ii=1:nr_coms
+ alcoms=unitinfo.comment{ii};
+ nr_comm=length(alcoms);
+ disp(sprintf('\n'));
+ thres=unitinfo.thresh;
+ atten=unitinfo.stimulus_parameter{unitinfo.ex_number(i)}.attenuation_db_power_atten.values;
+ abovethres=thres-atten;
+ disp(sprintf('Automatic classification of Unit %d of Animal %d Experiment %d (%2.0f dB above threshold)',cur_un,cur_un,unitinfo.ex_number(i),abovethres));
+ for iii=1:nr_comm
+ disp(alcoms{iii});
+ end
+ disp(sprintf('--> Unit was classified automatically as %s',unitinfo.found_type{ii}));
+ disp(sprintf('\n'));
+ end
+
+ was_unit_info=1;
+ else
+ was_unit_info=0;
+ end
+ can_be_published=1;
+ for j=1:length(exclude)
+ if ~isempty(strfind(titl,exclude{j}))
+ can_be_published=0;
+ break
+ end
+ end
+ if can_be_published
+ % disp(titl)
+ fig=all_windows(i);
+
+ nfignam=sprintf('c:\\temp\\tempfig%d.fig',count);
+ saveas(fig,nfignam)
+ % open('c:\temp\tempfig.fig');
+ % refresh
+ count=count+1;
+ creatednames{count}=nfignam;
+ createtits{count}=titl;
+ end
+ end
+end
+
+%%
+if length(createtits)>0
+ [nr_x,nr_y]=size(extra_publish);
+ if nr_y0
+ if nr_y>0
+ disp(extra_publish{1,1});
+ end
+ if nr_y>1
+ disp(extra_publish{1,2});
+ end
+ if nr_y>2
+ disp(extra_publish{1,3});
+ end
+ if nr_y>3
+ disp(extra_publish{1,4});
+ end
+ if nr_y>4
+ disp(extra_publish{1,5});
+ end
+ if nr_y>5
+ disp(extra_publish{1,6});
+ end
+ if nr_y>6
+ disp(extra_publish{1,7});
+ end
+ if nr_y>7
+ disp(extra_publish{1,8});
+ end
+ if nr_y>8
+ disp(extra_publish{1,9});
+ end
+ if nr_y>9
+ disp(extra_publish{1,10});
+ end
+ end
+ disp(createtits{1})
+ open(creatednames{1});
+ createdfigs(1)=gcf;
+end
+
+%%
+if length(createtits)>1
+ [nr_x,nr_y]=size(extra_publish);
+ if nr_y1
+ if nr_y>0
+ disp(extra_publish{2,1});
+ end
+ if nr_y>1
+ disp(extra_publish{2,2});
+ end
+ if nr_y>2
+ disp(extra_publish{2,3});
+ end
+ end
+ disp(createtits(2))
+ open(creatednames{2});
+ createdfigs(2)=gcf;
+end
+
+%%
+if length(createtits)>2
+ [nr_x,nr_y]=size(extra_publish);
+ if nr_y2
+ if nr_y>0
+ disp(extra_publish{3,1});
+ end
+ if nr_y>1
+ disp(extra_publish{3,2});
+ end
+ if nr_y>2
+ disp(extra_publish{3,3});
+ end
+ end
+ disp(createtits(3))
+ open(creatednames{3});
+ createdfigs(3)=gcf;
+end
+
+%%
+if length(createtits)>3
+ [nr_x,nr_y]=size(extra_publish);
+ if nr_y3
+ if nr_y>1
+ disp(extra_publish{4,1});
+ end
+ if nr_y>1
+ disp(extra_publish{4,2});
+ end
+ if nr_y>2
+ disp(extra_publish{4,3});
+ end
+ end
+
+ disp(createtits(4))
+ open(creatednames{4});
+ createdfigs(4)=gcf;
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/randint.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/randint.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% tool
+%
+% 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 int=randint(von,bis)
+% produces an int between von and bis or from 1 to von
+
+if nargin < 2
+ bis=von;
+ von=1;
+end
+
+v=rand(1)*(bis-von);
+v=v+von;
+int=round(v);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/rawfile2wavfile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/rawfile2wavfile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,62 @@
+% tool
+%
+% 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 [data,samplerate,endian]=rawfile2wavfile(datafile,samplerate,endian)
+% usage: wavdata=rawfile2wavfile(datafile,samplerate,endian)
+% input: the name of a datafile and the samplerate
+% endian is little or big endian to indicate byte order
+% output: the vector of the data
+% and the file "datafile" with the extension "wav"
+
+if nargin< 2
+ valid=0;
+ while ~valid
+ strsamplerate=input('please input samplerate (default: 20000) ','s');
+ if isempty(strsamplerate)
+ strsamplerate = '20000';
+ end
+ samplerate=sscanf(strsamplerate,'%f');
+ valid=(samplerate>0);
+ end
+end
+
+if nargin< 3
+ valid=0;
+ while ~valid
+ endian=input('please input endian: (l)ittle or (b)ig (default: l) ','s');
+ if isempty(endian)
+ endian = 'l';
+ end
+ valid=(size(endian,2)==1) & ((endian=='l') | (endian=='b'));
+ end
+end
+
+try
+ fid=fopen(datafile,'r',endian);
+catch
+ disp('rawfile2wavfile: could not open file');
+ disp(datafile);
+ return;
+end
+
+data=fread(fid,'integer*2');
+
+% data=data/max(data)*0.9999;
+data=data/32768;
+
+[path,name,ext,versn] = fileparts(datafile);
+newfilename=sprintf('%s.wav',name);
+newname=fullfile(path,newfilename);
+
+wavwrite(data,samplerate,newname);
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/readparameterfile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/readparameterfile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,37 @@
+% tool
+%
+% 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 str=readparameterfile(filename)
+
+lines=loadtextfile(filename);
+nr_lines=size(lines,2);
+
+varcounter=1;
+for i=1:nr_lines % tranlsate each line in a parameter and a value
+ line=lines{i};
+ count=1;tab=sprintf('\t');ret=sprintf('\n');
+ maxline=size(line,2);
+ while ~strcmp(line(count),' ') & ~strcmp(line(count),tab) & count < maxline & count <1000 % run till the first space
+ count=count+1;
+ end
+ str1=line(1:count-1);
+ str2=line(count+1:end);
+ if strcmp(str2,'') str2=' '; end
+
+ str.name{varcounter}=str1;
+ str.argument{varcounter}=str2;
+ varcounter=varcounter+1;
+end
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/replacestr.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/replacestr.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,24 @@
+% tool
+%
+% 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 ret=replacestr(orginal,org,sub)
+% usage: ret=replacestr(orginal,org,sub)
+% replaces org with sub without any error checking
+
+a=findstr(orginal,org);
+while ~isempty(a)
+ orginal(a)=sub;
+ a=findstr(orginal,org);
+end
+
+ret=orginal;
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/resrictstructtohighest.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/resrictstructtohighest.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% tool
+%
+% 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 res=resrictstructtohighest(str,topic,maxrange)
+
+
+nr=length(str);
+
+for i=1:nr
+ sortcount(i)=eval(sprintf('str{%d}.%s',i,topic));
+end
+
+maxheight=max(sortcount);
+
+count=1;
+for i=1:nr
+ if sortcount(i) > maxheight*(1-maxrange)
+ res{count}=str{i};
+ end
+end
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/reversecorrelate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/reversecorrelate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,51 @@
+% 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 sig=reversecorrelate(a,st,von,bis)
+% signal muss ein Signal sein
+% st muss ein Spiketrain sein
+% das Ergebnissignal hat die Länge bis-von
+
+if ~isobject(a)
+ disp('error: Signal must be an Object signal')
+end
+
+if nargin < 4
+ bis=0.01; %standart: 10 ms nach 0
+end
+
+if nargin < 3
+ von=-0.05; %standart: 50 ms vor 0
+end
+
+
+duration=bis-von; % so lang ist das ErgebnisSignal
+sr=getsr(a);
+sig=signal(duration,sr); %mache ein neues Signal
+nrpoints=getnrpoints(sig);
+
+nr_spikes=length(st);
+orglen=GetLength(a);
+
+for i=1:nr_spikes
+ spiketime=st(i);
+ start=spiketime+von;
+ stop=spiketime+bis;
+ off=0;
+ if start<0
+ off=-start;
+ start=0;
+ end
+ if stop>orglen-1/sr
+ stop=orglen-1/sr;
+ end
+ temp=getpart(a,start,stop);
+ sig=add(sig,temp,off);
+end
+
+sig=getpart(sig,0,duration);
+sig=setstarttime(sig,von);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/saimovie.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/saimovie.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,509 @@
+% tool
+%
+% 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 saimakeaimmovie(varargin)
+
+temp_sound_file_name='temp_sound.wav'; % must be the same as in getaiffs!!!
+
+if nargin<2 % only one parameter -> read file
+ if size(varargin)==1
+ makefilename=varargin{1};
+ else
+ makefilename='lastrun.genmovie';
+ end
+ % fprintf('movie is produced from file %s from aifffile "makemovie_temp.aif"\n!',makefilename);
+ % fprintf('movie is produced from file ''%s''\n',makefilename);
+else
+ makefilename='lastrun.genmovie';
+ generateparameterfile(makefilename,varargin);
+end
+arguments=readparameterfile(makefilename);
+
+
+str_moviefile=getargument(arguments,'moviefile');
+str_aifffile=getargument(arguments,'aifffile');
+str_movie_duration=getargument(arguments,'movie_duration');
+str_movie_start_time=getargument(arguments,'movie_start_time');
+str_AuditoryImageFormat=getargument(arguments,'AuditoryImageFormat');
+str_TimeIntervalUnits=getargument(arguments,'TimeIntervalUnits');
+str_colormap=getargument(arguments,'colormap');
+str_minimum_time_interval=getargument(arguments,'minimum_time_interval');
+str_maximum_time_interval=getargument(arguments,'maximum_time_interval');
+str_sound_sample_rate=getargument(arguments,'sound_sample_rate');
+str_sound_endian=getargument(arguments,'sound_endian');
+str_linewidth=getargument(arguments,'linewidth');
+str_echo=getargument(arguments,'echo');
+str_showtime=getargument(arguments,'showtime');
+str_showtextname=getargument(arguments,'showtextname');
+str_showtexttime=getargument(arguments,'showtexttime');
+str_plotscale=getargument(arguments,'plotscale');
+str_profile_scale=getargument(arguments,'profile_scale');
+str_producemovie=getargument(arguments,'producemovie');
+
+% data originally used in readaiff, but needed here also:
+str_framespersecond=getargument(arguments,'framespersecond');
+str_sai_picturespersecond=getargument(arguments,'sai_picturespersecond');
+str_nap_picturespersecond=getargument(arguments,'nap_picturespersecond');
+str_model=getargument(arguments,'modelfile');
+str_soundcommand=getargument(arguments,'soundfile');
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% if a movie is produced at all, or just the sais
+if isempty(str_producemovie) %
+ producemovie='sai_and_nap';
+else
+ producemovie=str_producemovie;
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% scale the amplitude of the whole picture up
+if isempty(str_plotscale) % default frames per second
+ plot_scale=1;
+else
+ eval(sprintf('plot_scale=%s;',str_plotscale));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% scale the amplitude of the profiles (only when profiles are plotted of course)
+if isempty(str_profile_scale) % default frames per second
+ profile_scale=1;
+else
+ eval(sprintf('profile_scale=%s;',str_profile_scale));
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% show time and number of frame
+if isempty(str_showtime) % default frames per second
+ showtime=1;
+else
+ if strcmp(str_showtime,'off')
+ showtime=0;
+ else
+ showtime=1;
+ end
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% frames per second
+if isempty(str_framespersecond) % default frames per second
+ framespersecond=12;
+else
+ eval(sprintf('framespersecond=%s;',str_framespersecond));
+end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% pictures per second
+if isempty(str_sai_picturespersecond) % default every ms
+ sai_picturespersecond=1000;
+else
+ eval(sprintf('sai_picturespersecond=%s;',str_sai_picturespersecond));
+end
+if isempty(str_nap_picturespersecond) % default every ms
+ nap_picturespersecond=1000;
+else
+ eval(sprintf('nap_picturespersecond=%s;',str_nap_picturespersecond));
+end
+
+if isempty(str_moviefile) % default name of the movie
+ [dumy_path,tempmodelname,ext,versn] = fileparts(str_model);
+ [dumy_path,tempsoundname,ext,versn] = fileparts(str_soundcommand);
+ moviefile=sprintf('soundfile_%s_model_%s.mov',tempsoundname,tempmodelname);
+else
+ [dumy_path,tempmodelname,ext,versn] = fileparts(str_moviefile);
+ if strcmp(ext,'')
+ moviefile=sprintf('%s.mov',str_moviefile);
+ else
+ moviefile=str_moviefile;
+ end
+end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% sound-file. can be a command or a file
+if isempty(str_soundcommand) %
+ error('soundcommand must be given');
+else
+ soundcommand=str_soundcommand;
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% construct the aiff-file with a call to the dsam-routine:
+
+% if aifffile is given from a previous run, than simply load it:
+if ~isempty(str_aifffile)
+ allframes=SBReadAiff(str_aifffile); % returns all info in a struct
+else
+ allframes=getaiffs(makefilename);
+end
+complete_nap=allframes(1);
+nr_channels=getnrchannels(complete_nap);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+% grafix=1;
+select_channels=1:nr_channels;
+select_single_channels=3;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% read the sound command and transfere the data to the buffer
+if ~isempty(str_movie_duration) % default frames per second
+ eval(sprintf('movie_duration=%s;',str_movie_duration));
+ eval(sprintf('movie_start_time=%s;',str_movie_start_time));
+ [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian,movie_start_time,movie_duration);
+else
+ movie_start_time=0;
+ [sounddata,samplerate,bits,endian]=producesounddata(soundcommand,temp_sound_file_name,str_sound_sample_rate,str_sound_endian);
+ movie_duration=length(sounddata)/samplerate;
+end
+sampletime=1/samplerate;
+% the duration of the whole video
+videolength=size(sounddata,1)/samplerate;
+% so long is one picture:
+
+if ~strcmp(producemovie,'sai_only')
+ sai_pictureduration=1/sai_picturespersecond;
+else
+ sai_pictureduration=1/framespersecond;
+end
+% so many frames is the video size in the end:
+nr_sai_pictures=floor(videolength/sai_pictureduration);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% start processing the data
+% first: 2DAT on the nap:
+clear napoptions;
+napoptions.time_constant_factor=6; %makes the time constant for the time adaption longer
+% napoptions.frequency_constant_factor=0.8; % the influence of the neighboring channels
+napoptions.frequency_constant_factor=0.0; % the influence of the neighboring channels
+
+disp('calculating 2D adaptive threshold...');
+sharpnap=twoDat(complete_nap,napoptions); % two dimensional adaptive thresholding
+
+% strobeoptions
+strobeoptions.strobe_decay_time=0.02; % in this time the strobe threshold decreases to 0
+strobeoptions.parabel_heigth=1.2; % times the nap height at that point
+% strobeoptions.parabel_width=0.01; % ms
+strobeoptions.parabel_width_in_cycles=1.5; % cycles
+strobeoptions.influence_nap_heigth=0; % influcence of the height of the nap at the point, where the strobe was elicited
+strobeoptions.nr_cyclyes_to_wait=1.5; % wait a little longer then once cycle for the real strobe
+strobeoptions.select_channels=select_channels;
+
+disp('calculating strobes...');
+[allstrobeprocesses,allthresholds]=findstrobes(sharpnap,strobeoptions);
+
+
+% figure(1);clf
+% plotwithstrobes(sharpnap,allstrobeprocesses);
+%
+% return
+if strcmp(producemovie,'sai_and_nap')
+ step=1/nap_picturespersecond;
+ graphic_times=movie_start_time:step:movie_start_time+movie_duration;
+ maxheight=5;
+ maxnap=max(sharpnap);
+ next_nap_picture=step;
+ current_graphic=1;
+ f1=figure(1);clf;
+ set(f1,'position',[ 640 1 640 400])
+else
+ next_nap_picture=inf; % never this graphic
+end
+
+
+
+% set a variable for the current starting time of each frame for plotting
+for i=1:nr_sai_pictures
+ start_times(i)=(i-1)*sai_pictureduration+movie_start_time;
+ sai_graphic_times(i)=start_times(i)+sai_pictureduration-sampletime;
+end
+
+next_sai_graphic=sai_graphic_times(1);
+current_sai_graphic=1;
+
+fprintf('producing stobed image:\n');
+% We start the time at zero:
+current_time=movie_start_time;
+nr_dots=getnrpoints(sharpnap);
+clear saioptions;
+saioptions.start_time=start_times(i);
+saioptions.maxdelay=0.035;
+saioptions.strobe_weight_alpha=1; % alpha parameter in the weightening of the single strobes
+saioptions.phase_adjustment=1.5; % after so many cycles the change of weight takes effect
+saioptions.mindelay_in_cycles=1.5; % so many cycles are not filled in the sai-buffer
+saioptions.buffer_memory_decay=0.04; % time for the buffer to go from 100% to 0
+saioptions.weightthreshold=0.001; % only thresholds bigger than 1%
+if ~strcmp(producemovie,'no')
+ saioptions.grafix=1; % no graphical outout during processing
+end
+saioptions.select_channels=select_channels;
+saioptions.const_memory_decay=power(0.5,1/(saioptions.buffer_memory_decay*samplerate)); % the amount per sampletime
+saioptions.signal_start_time=movie_start_time;
+
+% construct the starting SAI with zeros
+nrdots_insai=round(saioptions.maxdelay*samplerate);
+svals=zeros(getnrchannels(sharpnap),nrdots_insai);
+fstruct.outputTimeOffset=0;
+fstruct.totalframetime=saioptions.maxdelay;
+current_sai=frame(svals,fstruct,getcf(sharpnap));
+current_sai_struct.data=current_sai;
+for i=select_channels
+ if length(allstrobeprocesses{i}.strobes) > 0
+ info.next_strobe=allstrobeprocesses{i}.strobes(1); % the next strobe in line
+ else
+ info.next_strobe=inf; % no strobe
+ end
+ info.current_strobe_nr=0; % the current number of the strobe which is processed
+ info.strobeprocesses=[]; % no active strobes in queue
+ info.strobe_adjust_phase=inf; % the next update of weights
+ info.was_adjusted=0;
+ current_sai_struct.info{i}=info;
+end
+
+
+if ~strcmp(producemovie,'no')
+ MakeQTMovie('start',moviefile);
+ MakeQTMovie('size', [640 400]);
+ MakeQTMovie('quality', 0.9); % reduces the size
+ % only, to know, how many channels we have:
+ for i=1:nr_sai_pictures
+ fprintf('*');
+ end
+ fprintf('\n');
+end
+
+for i=1:nr_dots
+% fprintf('*');
+ current_time=current_time+sampletime;
+ current_sai_struct=updatesai2(sharpnap,current_sai_struct,allstrobeprocesses,saioptions,current_time);
+
+ if ~strcmp(producemovie,'no')
+ if current_time>=next_nap_picture
+ if current_graphic maxtime
+ disp_start_time = maxtime-disp_duration;
+ end
+
+ plotoptions.sharpnap=sharpnap;
+ plotoptions.allthresholds=allthresholds;
+ plotoptions.current_sai_struct=current_sai_struct;
+ plotoptions.allstrobeprocesses=allstrobeprocesses;
+ plotoptions.maxnap=maxnap;
+ plotoptions.maxheight=maxheight;
+ plotoptions.current_time=current_time;
+ plotoptions.saioptions=saioptions;
+ plotoptions.select_channels=select_single_channels;
+ plotoptions.disp_start_time=disp_start_time;
+ plotoptions.disp_duration=disp_duration;
+
+ plotoptions=doplot(plotoptions);
+ end
+ if current_time > next_sai_graphic
+ fprintf('*');
+ current_sai_struct.data=setcurrentframestarttime(current_sai_struct.data,current_time);
+ all_finished_frames(current_sai_graphic)=current_sai_struct.data;
+ if current_sai_graphicmaxheight
+ maxheight=maxheight*1.1;
+ end
+ axis([1 getnrpoints(saibuffer),0,maxheight]);
+ % text(300,maxheight/1.5,sprintf('sum: %3.2f',sum(saibuffer)));
+ text(300,maxheight/2,sprintf('#time: %dms',floor(current_time*1000)));
+ text(300,maxheight/2.8,sprintf('#Strobes: %d',nr_active_strobes));
+
+ mysubplot(1,1,1,[0.65 0.5 0.35 0.3]);
+ if options.oldhandle2~=0
+ delete(options.oldhandle2);
+ end
+ options.oldhandle2=gca;
+ set(gca,'Xtick',[]);
+ set(gca,'Ytick',[]);
+ plot(threshold,'g');
+ hold on
+ plot(single_channel,'-');
+ ylabel('');
+ if max(single_channel)>maxnap
+ maxnap=maxnap*1.1;
+ end
+ if max(threshold)>maxnap
+ maxnap=maxnap*1.1;
+ end
+ axis([1 getnrpoints(single_channel),0,maxnap]);
+ for k=1:length(strobe_process)
+ gc=plot(time2bin(single_channel,strobe_process(k).time),strobe_process(k).nap_value,'.r');
+ suze=log(200*strobe_process(k).weight)*5;
+ suze=max(suze,5);
+ set(gc,'MarkerSize',suze);
+ end
+ drawnow;
+else % end only one channel
+ % from here: more then one channel
+ % figure(1);clf;
+ % partthres=getpart(allthresholds,disp_start_time,current_time);
+ % str.plotcolor='g';
+ % plot(partthres,str); hold on
+ % partnap=getpart(sharpnap,disp_start_time,disp_start_time+disp_duration);
+ % plot(partnap); hold on
+ %
+ % % for k=1:length(strobe_process)
+ % % gc=plot(time2bin(single_channel,strobe_process(k).time),strobe_process(k).nap_value,'.r');
+ % % suze=log(200*strobe_process(k).weight)*5;
+ % % suze=max(suze,5);
+ % % set(gc,'MarkerSize',suze);
+ % % end
+ %
+ %
+ %
+ % sai=current_sai_struct.data;
+ % % figure(2);clf;
+ % plot(sai);
+ %
+ % drawnow;
+end
+return
+
+
+
+function options=plotsai(current_sai_struct,current_time,options)
+mysubplot(1,1,1,[-0.05 0 0.7 0.9]);
+gopt.current_frame = current_sai_struct.data;
+gopt.maximum_time_interval = 35;
+gopt.minimum_time_interval= 0;
+gopt.is_log=0;
+gopt.plot_scale=1/5;
+gopt.show_time=1;
+gopt.time_reversed=1;
+gopt.frequency_profile_scale=400;
+gopt.time_profile_scale=0.03;
+gopt.options=options;
+options=AIFrePtiP(gopt);
+drawnow;
+return
+
+function plotsaionly(current_sai_struct,current_time)
+gopt.current_frame = current_sai_struct.data;
+gopt.maximum_time_interval = 35;
+gopt.minimum_time_interval= 0;
+gopt.is_log=0;
+gopt.plot_scale=1/5;
+gopt.show_time=1;
+gopt.time_reversed=1;
+gopt.frequency_profile_scale=400;
+gopt.time_profile_scale=0.03;
+clf
+AIFrePtiP(gopt);
+drawnow;
+return
+
+function plotsaiprofiles(current_sai_struct,current_time)
+gopt.current_frame = current_sai_struct.data;
+gopt.frequency_profile_scale=0.002;
+gopt.time_profile_scale=0.01;clf
+combFrePtiP(gopt);
+drawnow;
+return
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/savetofile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/savetofile.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,23 @@
+% tool
+%
+% 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 savetofile(in,file)
+
+id=fopen(file,'wt');
+
+nr=length(in);
+for i=1:nr
+ fprintf(id,'%s\n',in{i});
+end
+
+fclose(id);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/scalefigure.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/scalefigure.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,61 @@
+% 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 scalefigure(hand,x,y)
+% change the size of the window in hand by the factors in x and y without
+% changing the top left corner
+% checks that the graphic does not become bigger then the screen
+
+screensize=get(0,'ScreenSize');
+sw=screensize(3);
+sh=screensize(4);
+
+np=get(hand,'pos');
+% np comes as x,y,width,height
+newheigh=np(4)*y;
+newwidth=np(3)*x;
+heightdiff=np(4)-newheigh;
+widthdiff=np(3)-newwidth;
+% np(2)=np(2)-np(4)/1.5;
+% np(4)=np(4)*1.5;
+% np(2)=0;
+% nullp=get(0,'ScreenSize');
+% np(4)=nullp(4);
+
+
+x=np(1);
+y=np(2)+heightdiff;
+w=newwidth;
+h=newheigh;
+% check for the screensize. If its too high then push it upwards. If its
+% still too high then make it smaller
+if y<0
+% y=-62; % bug in version 7. Zero sits not at the bottom
+ y=0; % bug in version 7. Zero sits not at the bottom
+ if h>sh
+% h=sh-10;
+ h=sh-62;
+ end
+end
+
+if x+w>sw
+ x=sw-w;
+ if x<0
+ x=0;
+ w=sw;
+ end
+end
+
+newnp(1)=x;
+newnp(2)=y;
+newnp(3)=w;
+newnp(4)=h;
+
+set(hand,'pos',newnp);
+
+%and bring to front
+figure(gcf)
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/show_pitch_spiral.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/show_pitch_spiral.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,50 @@
+% tool
+%
+% 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 show_pitch_spiral(frame)
+
+cls;
+s=getallnotes;
+
+min_fre=abs(1000/frame.time_minus);
+max_fre=abs(1000/frame.time_plus);
+max_fre=2000;
+
+sp=spiral(min_fre,max_fre);
+sp=adddots(sp,s);
+
+frame.search_type='best_n';
+frame.nr_search_maxima=50;
+
+[pitches,s]=findpitch(frame);
+
+sp=adddots(pitches,s);
+plot(sp);
+set(gca,'Position',[0 0.2 1 0.8]);
+%
+% % and the sum
+rect=[-0.04 0 1 0.2];
+mysubplot(1,1,1,rect,1);
+
+nr_bins=24;
+tones=pitch_radar(sp,nr_bins); % here it is calculated
+h=plot(tones,'.-');
+set(gca,'yticklabel','')
+axis([0.5 nr_bins+0.5 0 3]);
+tix=1:nr_bins/12:nr_bins;
+ti=['a ';'a#';'h ';'c ';'c#';'d ';'d#';'e ';'f ';'f#';'g ';'g#'];
+set(gca,'XTick',tix);
+set(gca,'XTickLabel',ti);
+
+
+return;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/slidercontrols/slidereditcontrol_get_value.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/slidercontrols/slidereditcontrol_get_value.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% tool
+%
+% 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/01/17 16:57:45 $
+% $Revision: 1.3 $
+
+function value=slidereditcontrol_get_value(combi)
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+value=combi.current_value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/slidercontrols/slidereditcontrol_set_range.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/slidercontrols/slidereditcontrol_set_range.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% tool
+%
+% 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/03 19:50:26 $
+% $Revision: 1.6 $
+
+function combi=slidereditcontrol_set_range(combi,duration)
+% sets the range and the step size, so that the width of the slider is OK
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% works only for linear sliders (yet)
+if combi.is_log==1
+ set(combi.sliderhandle,'SliderStep',[0.01 0.1]);
+else
+ dur=combi.maxvalue-combi.minvalue; % so long is it indeed
+ if abs(dur-duration)>0
+ step1=duration/abs(dur-duration);
+ % step1=duration/dur;
+ if abs(dur) > 0
+ step2=duration/dur/10;
+ step1=max(0,step1);
+ step1=min(1,step1);
+ step2=max(0,step2);
+ step2=min(1,step2);
+ set(combi.sliderhandle,'SliderStep',[step2 step1]);
+ return
+ end
+ end
+ step1=1;
+ step2=1;
+ set(combi.sliderhandle,'SliderStep',[step2 step1]);
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/slidercontrols/slidereditcontrol_set_raweditvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/slidercontrols/slidereditcontrol_set_raweditvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,55 @@
+% tool
+%
+% 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/02/21 20:00:38 $
+% $Revision: 1.6 $
+
+function combi=slidereditcontrol_set_raweditvalue(combi,value)
+% set the edit value eg. by typing a text in the edit control
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% the slider gets the raw value back:
+if ~isempty(value)
+ set(combi.edithandle,'String',num2str(value));
+else % set back to old value
+ set(combi.edithandle,'String',num2str(combi.current_value*combi.editscaler));
+ return
+end
+
+% the real value must be translated
+realval=value/combi.editscaler;
+realval=max(realval,combi.minvalue);
+realval=min(realval,combi.maxvalue);
+
+if combi.is_log==1
+ sliderval=f2f(realval,combi.minvalue,combi.maxvalue,0,1,'loglin');
+else
+ sliderval=f2f(realval,combi.minvalue,combi.maxvalue,0,1,'linlin');
+end
+
+sliderval=min(1,sliderval);
+sliderval=max(0,sliderval);
+
+set(combi.sliderhandle,'Value',sliderval);
+val=realval*combi.editscaler;
+editval=fround(val,combi.nreditdigits);
+set(combi.edithandle,'String',num2str(editval));
+
+combi.current_value=realval;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/slidercontrols/slidereditcontrol_set_rawslidervalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/slidercontrols/slidereditcontrol_set_rawslidervalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% tool
+%
+% 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/01/17 16:57:45 $
+% $Revision: 1.3 $
+
+function combi=slidereditcontrol_set_rawslidervalue(combi,value)
+% set the slider value e.g. by using the slider
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% the slider gets the raw value back:
+set(combi.sliderhandle,'Value',value);
+
+% the real value must be translated
+if combi.is_log==1
+ realval=f2f(value,0,1,combi.minvalue,combi.maxvalue,'linlog');
+else
+ realval=f2f(value,0,1,combi.minvalue,combi.maxvalue,'linlin');
+end
+realval=max(realval,combi.minvalue);
+realval=min(realval,combi.maxvalue);
+
+editval=realval*combi.editscaler;
+editval=fround(editval,combi.nreditdigits);
+set(combi.edithandle,'String',num2str(editval));
+
+combi.current_value=realval;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/slidercontrols/slidereditcontrol_set_value.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/slidercontrols/slidereditcontrol_set_value.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% tool
+%
+% 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/02/14 14:39:32 $
+% $Revision: 1.5 $
+
+function combi=slidereditcontrol_set_value(combi,value)
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% translate the value to the value, the slider wants to see
+if combi.is_log==1
+ sliderval=f2f(value,combi.minvalue,combi.maxvalue,0,1,'loglin');
+else
+ sliderval=f2f(value,combi.minvalue,combi.maxvalue,0,1,'linlin');
+end
+sliderval=max(sliderval,0);
+sliderval=min(sliderval,1);
+set(combi.sliderhandle,'Value',sliderval);
+
+editval=value*combi.editscaler;
+editval=max(editval,combi.minvalue*combi.editscaler);
+editval=min(editval,combi.maxvalue*combi.editscaler);
+
+editval=fround(editval,combi.nreditdigits);
+set(combi.edithandle,'String',num2str(editval));
+
+combi.current_value=value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/slidercontrols/slidereditcontrol_setup.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/slidercontrols/slidereditcontrol_setup.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% tool
+%
+% 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/02/13 18:16:07 $
+% $Revision: 1.4 $
+
+function combi=slidereditcontrol_setup(sliderhandle,edithandle,minvalue,maxvalue,current_value,is_log,editscaler,nreditdigits)
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+combi.sliderhandle=sliderhandle;
+combi.edithandle=edithandle;
+combi.minvalue=minvalue;
+combi.maxvalue=maxvalue;
+combi.current_value=current_value;
+combi.is_log=is_log;
+combi.editscaler=editscaler;
+combi.nreditdigits=nreditdigits;
+
+
+combi=slidereditcontrol_set_range(combi,maxvalue/10);
+
+% set(sliderhandle,'SliderStep',[0.01 0.1]);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/solve.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/solve.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+function x=solve(p,y)
+% solves the polynom p for the value at y
+%
+% INPUT VALUES:
+% input: a polynom
+%
+% RETURN VALUE:
+% return value(s) are the values, where the polynom is equal the
+% y-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 $
+
+
+p(end)=p(end)-y;
+x=roots(p);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/sortstruct.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/sortstruct.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,40 @@
+% tool
+%
+% 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 ret=sortstruct(str,topic,nr_second_dimension)
+% sorts the structure str by the values in "topic"
+% if topic is twodimensional, then "nr_second_dimension" gives the chosen
+% number
+
+
+if nargin < 3
+ nr=size(str,2);
+ for i=1:nr
+ sortcount(i)=eval(sprintf('str{%d}.%s',i,topic));
+ end
+ for i=1:nr
+ [ismax,womax]=max(sortcount);
+ ret{i}=str{womax};
+ sortcount(womax)=-inf; % den möchte ich nicht mehr sehen!
+ end
+else
+ nr=size(str,2);
+ for i=1:nr
+ sortcount(i)=eval(sprintf('str(%d).%s(%d)',i,topic,nr_second_dimension));
+ end
+ for i=1:nr
+ [ismax,womax]=max(sortcount);
+ ret(i)=str(womax);
+ sortcount(womax)=-inf; % den möchte ich nicht mehr sehen!
+ end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/spectrogram.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/spectrogram.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,115 @@
+% 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 f=spectrogram(sig,nr_f,maxfre)
+
+nsig=changesr(sig,maxfre*2);
+sr=getsr(nsig);
+vals=getvalues(nsig);
+
+% sig_len=getlength(sig);
+% time_step=sig_len/nr_t;
+% window=[0:time_step:sig_len];
+% win_len=getnrpoints(nsig)/nr_t;
+% window = hann(round(win_len));
+% noverlap=round(win_len/2);
+noverlap=nr_f*2-2;
+[Bb,freqs,ts]=specgram(vals,nr_f*2,sr*2,[],noverlap);
+
+B=Bb(2:nr_f+1,:);
+
+nr_t=size(B,2);
+nr_f=size(B,1);
+
+srf=nr_t/getlength(sig);
+f=field(nr_t,nr_f,srf);
+f=setvalues(f,abs(B));
+f=setmaxfre(f,maxfre);
+
+return
+
+
+
+
+% function f=spectrogram(sig,tstart,tstop,nr_t,nr_f,maxfre)
+% alle Zeiten in Sekunden
+% macht ein Sektrogramm aus dem Signal sig, das zu nr_t Zeiten gesampelt
+% wird und nr_f Frequenzen hat
+% das Signal wird aus sig in der Zeit von start bis stop genommen
+% das Signal sig wird erst so auf eine Samplerate gebracht, dass
+% das Resultat der FFT eine Auflösung bis maxfre hat.
+
+if nargin<6
+ maxfre=GetSR(sig)/2;
+end
+
+% die alte (orginale) Samplerate
+sr_old=GetSR(sig);
+
+%wenn die maxfre anders ist als die, die das Signal mitbringt, dann muss das Signal heruntergesamplet werden:
+if sr_old~=maxfre*2
+ sr_neu=maxfre*2;
+ sig=changesr(sig,sr_neu); % änder das ganze Signal zu der neuen SR
+else
+ sr_neu=sr_old;
+end
+
+% Punkte, die die FFT benötigt, damit nr_f punkte hinten raus kommen
+nr_fft=nr_f*2;
+% und das ist ein Signal von dieser Länge: (auch mit neuer Samplerate)
+stime=bin2time(nr_fft,sr_neu);
+% Dauer des zu untersuchenden Signals
+duration=tstop-tstart;
+% wenn die gewünschte Samplingrate nicht hoch genug ist, weil zuviel Punkte erforderlich sind
+if duration < stime
+ error('spectrogram: desired Samplingrate too low: take less points or higher freqeuncy!');
+ return;
+end
+
+
+% meine Notation ist anders als Matlab: Bei mir ist x die Zeit
+% und y die Frequenz
+sr_field=nr_t/duration; % die "SampleRate" des Feldes (sehr klein, da nur wenig Punkte)
+f=field(nr_t,nr_f,sr_field);
+f=setmaxfre(f,maxfre); % Für die Grafik: Wie hoch die Frequenzen geben
+
+% damit die fft immer von einem richtigen vollen Signal gemacht werden kann, werden die
+% FFTs an Stellen berechenet, die immer ein volles signal haben
+time_step=(tstop-tstart-stime)/nr_t;
+
+count=0;
+w = hann(nr_fft); % for later: the window
+% for t=56*time_step:time_step:tstop-stime-time_step
+
+sig=setstarttime(sig,0);
+for t=tstart:time_step:tstop-stime-time_step
+ count=count+1;
+ s1=t;
+ s2=t+stime;
+ if s2strip it
+ ps=strippowerspectrum(ps); % cut the leading zero
+% figure(1)
+% plot(s,'.-');
+% figure(2)
+% plot(ps,'.-');
+ % normiere das Spektrum auf die maximale Amplitude des Signals
+ ms=max(s);
+ ps=ps*ms;
+ f=setcolumn(f,count,ps);
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/spikeautocorrelate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/spikeautocorrelate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,32 @@
+% 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 cor=spikeautocorrelate(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/tools/spikecrosscorrelate.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/spikecrosscorrelate.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% 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 cor=spikecrosscorrelate(data1,data2,sr,window_start,window_stop)
+% 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_dat1=length(data1);
+nr_dat2=length(data2);
+
+if nr_dat1<2 || nr_dat2<2
+ cor=[];
+ return
+end
+
+cor=zeros(1,round((window_stop-window_start)*sr));
+zeroindx=window_stop*sr;
+for ii=1:nr_dat1
+ dat1=data1(ii);
+ for jj=1:nr_dat2
+ dat2=data2(jj);
+ len=(dat2-dat1)*sr;
+ indx=round(len);
+ if indx < window_stop*sr && indx > window_start*sr
+ cor(indx+zeroindx)=cor(indx+zeroindx)+1;
+ end
+ end
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/str2cell.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/str2cell.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,140 @@
+% tool
+%
+% 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 c = str2cell(varargin)
+%STR2CELL Convert a string to a cell array of lines.
+%
+% C = STR2CELL(STR) creates a cell array C where each cell contains a line
+% of the string STR.
+%
+% C = STR2CELL(STR, OPTS), where OPTS is 'L', 'T' or both, removes leading
+% and/or trailing blank lines from the string before converting to a cell
+% array.
+%
+% If the string contains LFs (linefeed characters, decimal 10), the input
+% string is split at their position after all CRs (carriage return
+% characters, decimal 13) have been removed. If there are no LFs, the
+% string is split at the position of the CRs. This should ensure that the
+% string is split correctly with both UNIX (LF), DOS (CR+LF) and MAC (CR)
+% definitions of a newline.
+
+% Author: Peter J. Acklam
+% Time-stamp: 2002-03-03 13:44:44 +0100
+% E-mail: pjacklam@online.no
+% URL: http://home.online.no/~pjacklam
+
+ error(nargchk(1, 3, nargin));
+
+ %
+ % Assign default values to parameters that can be changed by command line
+ % options.
+ %
+ strip_lead = 0;
+ strip_trail = 0;
+
+ %
+ % Process command line options.
+ %
+% while length(varargin) > 1
+% opt = varargin{2};
+% if ~ischar(opt)
+% error('Options must be strings.');
+% end
+% switch opt
+% case { 'l', 'L' }
+% strip_lead = 1;
+% case { 'u', 'U' }
+% strip_trail = 1;
+% otherwise
+% error([ 'Unknown option: ' opt ]);
+% end
+% varargin(2) = [];
+% end
+ str = varargin{1};
+
+ %
+ % Strip leading blank lines.
+ %
+ if strip_lead
+ k = find(~isspace(str));
+ if ~isempty(k)
+ k = min(k);
+ str = str(k:end);
+ end
+ end
+
+ %
+ % Strip trailing blank lines.
+ %
+ if strip_trail
+ k = find(~isspace(str));
+ if ~isempty(k)
+ k = max(k);
+ str = str(1:k);
+ end
+ end
+
+ %
+ % Quick exit if string is empty.
+ %
+ if isempty(str)
+ c = { '' };
+ return
+ end
+
+ %
+ % Find the characters that separate the lines.
+ %
+
+ % just a hack from me... sorry... no time
+
+ % strip []
+ if str(1)=='['
+ str=str(2:end-1);
+ end
+ k = find(str == 10); % find all LF chars
+ l = find(str == 13); % find all CR chars
+ m=find(str==' ');
+ if isempty(m)
+ m=length(str)+1;
+ end
+ if isempty(k) % if no LF chars were found
+ k = l; % split at CR chars
+ else % or else
+ if ~isempty(l) % if there are CR chars
+ str(l) = []; % remove them
+ k = find(str == 10); % find all LF chars
+ end
+ end
+
+ %
+ % Avoid empty last string in output list when string ends in a newline.
+ %
+ if ~isempty(k) & k(end) == length(str)
+ k = [ 0 k ]; % add beginning
+ else
+ k = [ 0 k length(str)+1 ]; % add beginning and end
+ end
+
+ %
+ % Now split the string into lines.
+ %
+ n = length(m); % number of lines
+ c = cell(n,1); % initialize output
+ m=[0 m];
+ for i = 1:n
+ c{i} = str(m(i)+1 : m(i+1)-1); % extract line
+ end
+
+
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/strf.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/strf.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,106 @@
+% 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 retfld=strf(sig,spikes,start,stop,nrfre,maxfre)
+% sig muss ein Signal sein
+% st muss ein Spiketrain sein
+% das Ergebnissignal hat die Länge bis-von
+% das Ergebnis ist ein Feld mit der Länge stop-start und der Breite nrfre
+
+if ~isobject(sig)
+ disp('error: Signal must be an Object signal')
+end
+
+if nargin < 6
+ maxfre=GetSR(sig)/2;
+end
+if nargin < 5
+ nrfre=512;
+end
+if nargin < 4
+ stop=0.01; %standart: 10 ms nach 0
+end
+if nargin < 3
+ start=-0.05; %standart: 50 ms vor 0
+end
+
+
+% make one big spectrogram of the whole signal and then split the important
+% parts:
+bigspectrum=spectrogram(sig,nrfre,maxfre);
+
+avera=mean(mean(getvalues(bigspectrum)));
+nr_t=getnrt(bigspectrum);
+nr_f=getnrf(bigspectrum);
+
+
+duration= stop-start; % so long is the signal that we want to analyse
+nr_spikes=length(spikes);
+orglen=GetLength(sig);
+
+
+srf=getsr(bigspectrum);
+res_nr_t=round(duration*srf);
+all_vals=getvalues(bigspectrum);
+fld=zeros(nr_f,res_nr_t);
+
+for i=1:nr_spikes
+ spiketime=spikes(i);
+ t_start=spiketime+start;
+% t_stop=spiketime+stop;
+
+ binstart=time2bin(srf,t_start);
+ binstop=binstart+res_nr_t-1;
+
+% tempfeld=zeros(nr_f,res_nr_t);
+ % fill the rest of the signal with the average value so that its not going
+ % down im amplitude
+ tempfeld=ones(nr_f,res_nr_t).*avera;
+
+ if t_start >= orglen
+ break; % no more relevant spikes in this spiketrain
+ end
+
+ if binstart>0 & binstop <= res_nr_t % der "Normalfall" (full signal is in window)
+ tempfeld=all_vals(:,binstart:binstop);
+ else % either start or stop are out of signal window
+ if binstart<0 %wenn das Signal nicht so lang ist, müssen wir nullen vornedranhängen
+ tempfeld(:,-binstart+1:end)=all_vals(:,1:binstop+1);
+ end
+ if binstop>res_nr_t %wenn das Signal länger sein sollte hängen wir Nullen hintenan
+ nr_v=binstop-nr_t;
+ tempfeld(:,1:(res_nr_t-nr_v))=all_vals(:,binstart:binstart+(res_nr_t-nr_v)-1);
+ end
+ end
+% if size(tempfeld,2)>res_nr_t
+% o=0;
+% end
+ tempfeld=tempfeld(:,1:res_nr_t);
+ fld=fld+tempfeld;
+
+% if mod(i,1)==0
+% figure(234)
+% testfld=field(res_nr_t,nr_f,srf);
+% testfld=setmaxfre(testfld,maxfre);
+% testfld=setoffset(testfld,start);
+% testfld=setvalues(testfld,fld);
+% plot(testfld,'log')
+% % plot(fld)
+% drawnow
+% end
+end
+
+retfld=field(res_nr_t,nr_f,srf);
+retfld=setmaxfre(retfld,maxfre);
+retfld=setoffset(retfld,start);
+retfld=setvalues(retfld,fld);
+
+
+
+% figure(23423)
+% plot(fld,'log');
+% drawnow
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/struct2double.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/struct2double.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,33 @@
+% tool
+%
+% 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 ret=struct2double(str,field,mmm)
+% returns a field of the values in str.fild
+% like: ret=str(1:12).value
+
+nr=length(str);
+if nargin < 3
+ % ret=zeros(nr,1);
+ for i=1:nr
+ eval(sprintf('dim=length(str(1).%s);',field));
+ if dim==1
+ eval(sprintf('ret(%d)=str(%d).%s;',i,i,field));
+ else
+ eval(sprintf('ret(%d,:)=str(%d).%s;',i,i,field));
+ end
+ end
+else
+ for i=1:nr
+ eval(sprintf('ret(%d,:)=str(%d).%s(%d);',i,i,field,mmm));
+ end
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/struct2stringarray.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/struct2stringarray.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,110 @@
+% tool
+%
+% 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 lines=struct2stringarray(str,strname)
+% goes recursevly through the struct and appends a line for each
+% structthing
+
+lines=[];
+
+counter=1;
+if isstruct(str)
+ names=fieldnames(str);
+ conts=struct2cell(str);
+ for i=1:length(names);
+ cstr=names{i};
+
+ nr_cont=length(str);
+ for kkk=1:nr_cont
+ if nr_cont==1
+ strstr=sprintf('%s.%s',strname,cstr);
+ else
+ strstr=sprintf('%s(%d).%s',strname,kkk,cstr);
+ end
+ % eval(sprintf('vari=str.%s;',cstr));
+ eval(sprintf('vari=str(%d).%s;',kkk,cstr));
+
+ newlinestr='';
+ if isstruct(vari)
+ newlinestr=struct2stringarray(vari,strstr);
+ nrlines=length(newlinestr);
+ for j=1:nrlines
+ lines{counter}=newlinestr{j};counter=counter+1;
+ end
+ else
+ if isnumeric(vari)
+ nrlines=size(vari,1);
+ nrcolumns=size(vari,2);
+ res='';
+ for jj=1:nrcolumns
+ for ii=1:nrlines
+ res=sprintf('%s %s',res,num2str(vari(ii,jj)));
+ end
+ if nrlines>1 && jj< nrlines
+ res=[res ';'];
+ end
+ end
+
+ if length(vari)>1
+ newlinestr=sprintf('%s=[%s]',strstr,res);
+ else
+ newlinestr=sprintf('%s=%s',strstr,num2str(vari));
+ end
+ else
+ if iscell(vari)
+ res='';
+ for jj=1:length(vari)
+ subvari=vari{jj};
+ if iscell(subvari)
+ res2='';
+ for kk=1:length(subvari)
+ res2=sprintf('%s {''%s''}',res2,subvari{kk});
+ end
+ newlinestr{jj}=sprintf('%s{%d}=[%s]',strstr,jj,res2);
+ elseif isstruct(subvari)
+ strstrh=sprintf('%s{%d}',strstr,jj);
+ newlinestr{jj}=struct2stringarray(subvari,strstrh);
+ elseif isstr(vari{jj})
+ res=sprintf('%s {''%s''}',res,vari{jj});
+ newlinestr=sprintf('%s=[%s]',strstr,res);
+ end
+ end
+ else
+ newlinestr=sprintf('%s=''%s''',strstr,vari);
+ end
+ end
+ % try
+ if iscell(newlinestr)
+ for oo=1:length(newlinestr)
+ newstrcell=newlinestr{oo};
+ if iscell(newstrcell)
+ for iii=1:length(newstrcell)
+ lines{counter}=newstrcell{iii};counter=counter+1;
+ end
+ else
+ lines{counter}=newstrcell;counter=counter+1;
+ end
+ % lines=[lines newlinestr{oo}];counter=counter+1;
+ end
+ else
+ lines{counter}=newlinestr;counter=counter+1;
+ end
+ % catch
+ % p=0
+ % end
+ end
+ end
+ end
+else % not a struct,
+
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/structisequal.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/structisequal.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,41 @@
+% tool
+%
+% 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 ret=structisequal(str1,str2)
+
+s1=struct2stringarray(str1,'test');
+s2=struct2stringarray(str2,'test');
+
+strings1=sort(s1);
+strings2=sort(s2);
+
+nr1=length(strings1);
+nr2=length(strings2);
+if nr1~=nr2
+ ret=0;
+ return
+end
+
+for i=1:nr1
+ s1=strings1(i);s1=s1{1};
+ s2=strings2(i);s2=s2{1};
+ if length(s1)~=length(s2)
+ ret=0;
+ return
+ end
+ if ~isempty(find(s1~=s2))
+ ret=0;
+ return
+ end
+end
+ret=1;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/suptitle.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/suptitle.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,116 @@
+function hout=suptitle(str)
+%SUPTITLE Puts a title above all subplots.
+% SUPTITLE('text') adds text to the top of the figure
+% above all subplots (a "super title"). Use this function
+% after all subplot commands.
+
+% Drea Thomas 6/15/95 drea@mathworks.com
+% John Cristion 12/13/00 modified
+% Mark Histed 03/13/04 histed@mit.edu: fix disappearing legend on last plot
+%
+% $Id: suptitle.m 3 2006-01-10 14:50:30Z Tom $
+
+% Warning: If the figure or axis units are non-default, this
+% will break.
+
+
+
+% Parameters used to position the supertitle.
+
+% Amount of the figure window devoted to subplots
+plotregion = .92;
+
+% Y position of title in normalized coordinates
+titleypos = .95;
+
+% Fontsize for supertitle
+%fs = get(gcf,'defaultaxesfontsize')+4;
+
+fs = get(gcf,'defaultaxesfontsize');
+
+% Fudge factor to adjust y spacing between subplots
+fudge=1;
+
+haold = gca;
+figunits = get(gcf,'units');
+
+% Get the (approximate) difference between full height (plot + title
+% + xlabel) and bounding rectangle.
+
+ if (~strcmp(figunits,'pixels')),
+ set(gcf,'units','pixels');
+ pos = get(gcf,'position');
+ set(gcf,'units',figunits);
+ else,
+ pos = get(gcf,'position');
+ end
+ ff = (fs-4)*1.27*5/pos(4)*fudge;
+
+ % The 5 here reflects about 3 characters of height below
+ % an axis and 2 above. 1.27 is pixels per point.
+
+% Determine the bounding rectange for all the plots
+
+% h = findobj('Type','axes');
+
+% findobj is a 4.2 thing.. if you don't have 4.2 comment out
+% the next line and uncomment the following block.
+
+h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
+
+% If you don't have 4.2, use this code instead
+%ch = get(gcf,'children');
+%h=[];
+%for i=1:length(ch),
+% if strcmp(get(ch(i),'type'),'axes'),
+% h=[h,ch(i)];
+% end
+%end
+
+
+
+
+max_y=0;
+min_y=1;
+
+oldtitle =0;
+for i=1:length(h),
+ if (~strcmp(get(h(i),'Tag'),'suptitle')),
+ pos=get(h(i),'pos');
+ if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
+ if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
+ else,
+ oldtitle = h(i);
+ end
+end
+
+if max_y > plotregion,
+ scale = (plotregion-min_y)/(max_y-min_y);
+ for i=1:length(h),
+ pos = get(h(i),'position');
+ pos(2) = (pos(2)-min_y)*scale+min_y;
+ pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
+ set(h(i),'position',pos);
+ end
+end
+
+np = get(gcf,'nextplot');
+set(gcf,'nextplot','add');
+if (oldtitle),
+ delete(oldtitle);
+end
+ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
+ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
+set(gcf,'nextplot',np);
+axes(haold);
+
+% fix legend if one exists
+legH = legend;
+if ~isempty(legH)
+ axes(legH);
+end
+
+if nargout,
+ hout=ht;
+end
+
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tentsurface.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tentsurface.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,30 @@
+% tool
+%
+% 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 tentsurface(framestruct_a);
+% plots the current frame (cframe)
+% all relevant data must be in the frame-object
+% same as aisurface, only of the tent
+
+
+if ~isstruct(framestruct_a)
+% error('AIsum must be called with a structure');
+ framestruct.current_frame=framestruct_a;
+else
+ framestruct=framestruct_a;
+end
+current_frame=framestruct.current_frame;
+current_frame=buildtent(current_frame);
+framestruct.current_frame=current_frame;
+
+aisurface(framestruct);
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/time2bin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/time2bin.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% tool
+%
+% 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 res=time2bin(time,samplerate)
+% gibt das Bin zurück, bei dem diese Zeit wäre
+% Zeit immer in Sekunden
+% Samplerate immer in Bins pro Sekunde (96 kHz)
+
+res=time*samplerate;
+
+res=round(res); % rundungsfehler!!!
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/extra_path.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/extra_path.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,21 @@
+% 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 extra_path
+udir = 'units';
+if exist(udir,'dir')
+ udir = [pwd '\units'];
+ A = dir('units');
+ for i=3:length(A)
+ if (A(i).isdir)
+ addpath(fullfile(udir,A(i).name),'-end')
+ end
+ end
+ addpath('tools','-end')
+else
+ disp('Change to ''mfiles'' folder and try again')
+end
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/f2f.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/f2f.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,46 @@
+% tool
+%
+% 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 res=f2f(value,from1,to1,from2,to2,logstate)
+% usage:res=f2f(from1,to1,value1,from2,to2,is_log)
+% translates the value from the system from1 to1 to the system from2 to2
+% either logarithmic or not
+
+if nargin < 6
+ logstate='linlin';
+end
+
+
+if to1==from1
+ res=from1;
+ return;
+end
+
+
+switch logstate
+ case 'loglin'
+ m=(to2-from2)/(log(to1)-log(from1));
+ c= from2-log(from1)*m;
+ res= m*log(value)+c;
+ case 'linlog'
+ m=(log(to2)-log(from2))/(to1-from1);
+ c= log(from2)-m*from1;
+ res=exp(m*value+c);
+
+% b=log(min)+gene_val*(log(max)-log(min));
+% res=exp(b);
+ case 'linlin'
+ m=(to2-from2)/(to1-from1);
+ c= from2-m*from1;
+ res=m*value+c;
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/fround.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/fround.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,20 @@
+% tool
+%
+% 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 num=fround(num,nr)
+% usage: num=round(num,nr)
+% rounds the number num to nr relevant decimal places
+
+ex=10^nr;
+
+num=round(num*ex)/ex;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/slidereditcontrol_get_value.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/slidereditcontrol_get_value.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,27 @@
+% tool
+%
+% 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 value=slidereditcontrol_get_value(combi)
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+value=combi.current_value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/slidereditcontrol_set_range.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/slidereditcontrol_set_range.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,49 @@
+% tool
+%
+% 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 combi=slidereditcontrol_set_range(combi,duration)
+% sets the range and the step size, so that the width of the slider is OK
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% works only for linear sliders (yet)
+if combi.is_log==1
+ set(combi.sliderhandle,'SliderStep',[0.01 0.1]);
+else
+ dur=combi.maxvalue-combi.minvalue; % so long is it indeed
+ if abs(dur-duration)>0
+ step1=duration/abs(dur-duration);
+ % step1=duration/dur;
+ if abs(dur) > 0
+ step2=duration/dur/10;
+ step1=max(0,step1);
+ step1=min(1,step1);
+ step2=max(0,step2);
+ step2=min(1,step2);
+ set(combi.sliderhandle,'SliderStep',[step2 step1]);
+ return
+ end
+ end
+ step1=1;
+ step2=1;
+ set(combi.sliderhandle,'SliderStep',[step2 step1]);
+end
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/slidereditcontrol_set_raweditvalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/slidereditcontrol_set_raweditvalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,55 @@
+% tool
+%
+% 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 combi=slidereditcontrol_set_raweditvalue(combi,value)
+% set the edit value eg. by typing a text in the edit control
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% the slider gets the raw value back:
+if ~isempty(value)
+ set(combi.edithandle,'String',num2str(value));
+else % set back to old value
+ set(combi.edithandle,'String',num2str(combi.current_value*combi.editscaler));
+ return
+end
+
+% the real value must be translated
+realval=value/combi.editscaler;
+realval=max(realval,combi.minvalue);
+realval=min(realval,combi.maxvalue);
+
+if combi.is_log==1
+ sliderval=f2f(realval,combi.minvalue,combi.maxvalue,0,1,'loglin');
+else
+ sliderval=f2f(realval,combi.minvalue,combi.maxvalue,0,1,'linlin');
+end
+
+sliderval=min(1,sliderval);
+sliderval=max(0,sliderval);
+
+set(combi.sliderhandle,'Value',sliderval);
+val=realval*combi.editscaler;
+editval=fround(val,combi.nreditdigits);
+set(combi.edithandle,'String',num2str(editval));
+
+combi.current_value=realval;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/slidereditcontrol_set_rawslidervalue.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/slidereditcontrol_set_rawslidervalue.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% tool
+%
+% 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 combi=slidereditcontrol_set_rawslidervalue(combi,value)
+% set the slider value e.g. by using the slider
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% the slider gets the raw value back:
+set(combi.sliderhandle,'Value',value);
+
+% the real value must be translated
+if combi.is_log==1
+ realval=f2f(value,0,1,combi.minvalue,combi.maxvalue,'linlog');
+else
+ realval=f2f(value,0,1,combi.minvalue,combi.maxvalue,'linlin');
+end
+realval=max(realval,combi.minvalue);
+realval=min(realval,combi.maxvalue);
+
+editval=realval*combi.editscaler;
+editval=fround(editval,combi.nreditdigits);
+set(combi.edithandle,'String',num2str(editval));
+
+combi.current_value=realval;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/slidereditcontrol_set_value.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/slidereditcontrol_set_value.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,44 @@
+% tool
+%
+% 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 combi=slidereditcontrol_set_value(combi,value)
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+% translate the value to the value, the slider wants to see
+if combi.is_log==1
+ sliderval=f2f(value,combi.minvalue,combi.maxvalue,0,1,'loglin');
+else
+ sliderval=f2f(value,combi.minvalue,combi.maxvalue,0,1,'linlin');
+end
+sliderval=max(sliderval,0);
+sliderval=min(sliderval,1);
+set(combi.sliderhandle,'Value',sliderval);
+
+editval=value*combi.editscaler;
+editval=max(editval,combi.minvalue*combi.editscaler);
+editval=min(editval,combi.maxvalue*combi.editscaler);
+
+editval=fround(editval,combi.nreditdigits);
+set(combi.edithandle,'String',num2str(editval));
+
+combi.current_value=value;
\ No newline at end of file
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/tools/slidereditcontrol_setup.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/tools/slidereditcontrol_setup.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,39 @@
+% tool
+%
+% 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 combi=slidereditcontrol_setup(sliderhandle,edithandle,minvalue,maxvalue,current_value,is_log,editscaler,nreditdigits)
+% a slidereditcontrol consists of a slider and an edit object, that are
+% related. When one value changes, the other also changes.
+% The combination has the following variables:
+% sliderhandle - the handle of the slider control
+% edithandle - the handle of the edit control
+% minvalue - the minimum value allowed
+% maxvalue - the maximum allowed value
+% (current_value - the current value)
+% is_log - whether the slider reponds logarithmically
+% editscaler - a number, that is multiplied to the edit control (to make ms of secs)
+% nreditdigits - the number of digits in the edit control
+
+combi.sliderhandle=sliderhandle;
+combi.edithandle=edithandle;
+combi.minvalue=minvalue;
+combi.maxvalue=maxvalue;
+combi.current_value=current_value;
+combi.is_log=is_log;
+combi.editscaler=editscaler;
+combi.nreditdigits=nreditdigits;
+
+
+combi=slidereditcontrol_set_range(combi,maxvalue/10);
+
+% set(sliderhandle,'SliderStep',[0.01 0.1]);
diff -r 000000000000 -r 74dedb26614d aim-mat/tools/transferetotune.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aim-mat/tools/transferetotune.m Fri May 20 12:32:31 2011 +0100
@@ -0,0 +1,132 @@
+% tool
+%
+% 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=transferetotune(tune,art)
+
+% Tonlength:
+% a=0.25
+% b=0.5
+% c=1
+if nargin < 1
+ % tunes:
+ % Yankee Doodle
+ tune='aC5aC5aD5aE5aC5aE5aD5aG4aC5aC5aD5aE5aC5aC5aB4aG4aC5aC5aD5aE5aF5aE5aD5aC5aB4aG4aA4aB4aC5aC5aC5aC5';
+ % Frere Jackes
+ tune='aC5aD5aE5aC5aC5aD5aE5aC5aE5aF5aG5aE5aF5aG5');
+end
+
+if nargin<2
+% art='decreaseoddamplitude';
+ art='decreaseoddphase';
+% art='sinus';
+% art='harmonic';
+% art='clicktrain';
+end
+
+nr=size(tune,2);
+duration=0.25;
+sr=16000;
+sig=signal(0,sr);
+
+count=1;
+notecount=0;
+while count < nr-2
+ cur=tune(count);
+ if cur~='a' & cur~='b' & cur~='c'
+ error('Error in tune');
+ else
+ if cur=='a' duration=0.25;end
+ if cur=='b' duration=0.5;end
+ if cur=='c' duration=1;end
+ end
+ cur1=tune(count+1);
+ if cur1=='P';
+ fre=0;
+ count=count+2;
+ else
+ cur2=tune(count+2);
+ if countstart_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 & time