annotate aim-mat/tools/@frame/createscaleprofile.asv @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 74dedb26614d
children
rev   line source
tomwalters@0 1 function ret_field=createscaleprofile(current_frame,options)
tomwalters@0 2 % creates a profile with an angle to the auditory image. The angle is
tomwalters@0 3 % ususally 45° and therefore the result is the collapsed Mellin image
tomwalters@0 4 %
tomwalters@0 5
tomwalters@0 6 % do we want debugging graphic? (very nice!!)
tomwalters@0 7 grafix=0;
tomwalters@0 8
tomwalters@0 9 % the angle of the profile
tomwalters@0 10 if isfield(options,'angle')
tomwalters@0 11 angle=options.angle;
tomwalters@0 12 else
tomwalters@0 13 angle=45; % in degrees
tomwalters@0 14 end
tomwalters@0 15
tomwalters@0 16 % the borders of the profiles are given by the minimum and the maximum
tomwalters@0 17 % harmonic relationship:
tomwalters@0 18 if isfield(options,'min_harmonic_relationship')
tomwalters@0 19 min_harmonic_relationship=options.min_harmonic_relationship;
tomwalters@0 20 else
tomwalters@0 21 min_harmonic_relationship=0.5;
tomwalters@0 22 end
tomwalters@0 23 if isfield(options,'max_harmonic_relationship')
tomwalters@0 24 max_harmonic_relationship=options.max_harmonic_relationship;
tomwalters@0 25 else
tomwalters@0 26 max_harmonic_relationship=20;
tomwalters@0 27 end
tomwalters@0 28 % how many points do we want to have on our profile?
tomwalters@0 29 if isfield(options,'nr_points')
tomwalters@0 30 nr_points=options.nr_points;
tomwalters@0 31 else
tomwalters@0 32 nr_points=200;
tomwalters@0 33 end
tomwalters@0 34
tomwalters@0 35
tomwalters@0 36 % if we know about the periodicity, we can restrict ourself to the
tomwalters@0 37 % interesting region
tomwalters@0 38 if isfield(options,'periodicity')
tomwalters@0 39 periodicity=options.periodicity;
tomwalters@0 40 else
tomwalters@0 41 periodicity=0.035; % in seconds
tomwalters@0 42 end
tomwalters@0 43
tomwalters@0 44 % translate to radian
tomwalters@0 45 angle=angle*2*pi/360;
tomwalters@0 46 tanangle=tan(angle); % accelerate
tomwalters@0 47
tomwalters@0 48 cfs=getcf(current_frame);
tomwalters@0 49
tomwalters@0 50 vals=getvalues(current_frame);
tomwalters@0 51 nr_channels=getnrchannels(current_frame);
tomwalters@0 52
tomwalters@0 53
tomwalters@0 54
tomwalters@0 55
tomwalters@0 56 t_min=getminimumtime(current_frame);
tomwalters@0 57 t_max=getmaximumtime(current_frame);
tomwalters@0 58
tomwalters@0 59 if periodicity < t_max
tomwalters@0 60 t_max=periodicity;
tomwalters@0 61 end
tomwalters@0 62
tomwalters@0 63 if t_min==0
tomwalters@0 64 t_min=0.0001;
tomwalters@0 65 end
tomwalters@0 66
tomwalters@0 67
tomwalters@0 68 fre_min=1/t_max;
tomwalters@0 69 if t_min>0
tomwalters@0 70 fre_max=1/t_min;
tomwalters@0 71 else
tomwalters@0 72 fre_max=1000;
tomwalters@0 73 end
tomwalters@0 74
tomwalters@0 75 % das ist die niedrigste Frequenz, die auf der Basilarmembran zu finden ist
tomwalters@0 76 min_fre_current_frame=cfs(1);
tomwalters@0 77 % das bedeutet, dass wir über die harmonischen Grenzen rausfinden können,
tomwalters@0 78 % wie groß der Bereich ist, den wir gehen müssen:
tomwalters@0 79 % die untere harmonische Zahl gibt uns den oberen Wert:
tomwalters@0 80 smallest_interval_value=min_harmonic_relationship/min_fre_current_frame;
tomwalters@0 81 biggest_interval_value=max_harmonic_relationship/min_fre_current_frame;
tomwalters@0 82
tomwalters@0 83 % wieviel cent wollen wir tatsächlich untersuchen lassen:
tomwalters@0 84 % nr_cent=fre2cent(1/biggest_interval_value,1/smallest_interval_value); % so viele cent sind insgesamt im interval profile
tomwalters@0 85 % wir starten von links nach rechts und gehen in Schrittweite
tomwalters@0 86 % start_cent=fre2cent(fre_min,1/biggest_interval_value);
tomwalters@0 87
tomwalters@0 88 % Die Schrittweite berechnet sich aus den Extremen:
tomwalters@0 89 % delta_cent=nr_cent/(nr_points-1);
tomwalters@0 90
tomwalters@0 91 res_vals=zeros(1,nr_points);
tomwalters@0 92 for jj=1:nr_channels
tomwalters@0 93 current_channel(jj)=getsinglechannel(current_frame,jj);
tomwalters@0 94 end
tomwalters@0 95 if grafix
tomwalters@0 96 colors=['b','r','g','c','m','k','y'];
tomwalters@0 97 figure(2);
tomwalters@0 98 clf
tomwalters@0 99 hold on
tomwalters@0 100 str.is_log=1;
tomwalters@0 101 str.time_reversed=1;
tomwalters@0 102 str.minimum_time=t_min;
tomwalters@0 103 str.maximum_time=t_max;
tomwalters@0 104 plot(current_frame/1,str);
tomwalters@0 105 end
tomwalters@0 106
tomwalters@0 107 % start_harmonic_relations=linspace(min_harmonic_relationship,max_harmonic_relationship,nr_points);
tomwalters@0 108 start_harmonic_relations=distributelogarithmic(min_harmonic_relationship,max_harmonic_relationship,nr_points);
tomwalters@0 109
tomwalters@0 110
tomwalters@0 111 channel_step=1; % skip maybe some channels
tomwalters@0 112 nr_y_dots=floor(length(cfs)/channel_step);
tomwalters@0 113 % the result is a twoDfield with x=harmonic number and y=whateverthisis
tomwalters@0 114 % the number of field entries is given by the given number and the number
tomwalters@0 115 % of channels
tomwalters@0 116 result_field=zeros(nr_points,nr_y_dots);
tomwalters@0 117
tomwalters@0 118
tomwalters@0 119 for ii=1:nr_points
tomwalters@0 120 current_start_cent=fre2cent(fre_min,cfs(1)/start_harmonic_relations(ii));
tomwalters@0 121 y_count=1;
tomwalters@0 122 for jj=1:channel_step:nr_channels
tomwalters@0 123 % soviel cent ist dieser Kanal über dem ersten
tomwalters@0 124 channel_diff_cent=fre2cent(cfs(1),cfs(jj));
tomwalters@0 125 % soviel cent gehen wir nach rechts im Intervall
tomwalters@0 126 cur_cent_x=channel_diff_cent/tanangle+current_start_cent;
tomwalters@0 127 % das bedeutet diese Frequenz auf der Intervallachse:
tomwalters@0 128 cur_fre=cent2fre(fre_min,cur_cent_x);
tomwalters@0 129 cur_time=1/cur_fre;
tomwalters@0 130 if cur_time> t_min && cur_time < t_max
tomwalters@0 131 cur_val=gettimevalue(current_channel(jj),cur_time);
tomwalters@0 132 if grafix
tomwalters@0 133 col=colors(mod(ii,7)+1);
tomwalters@0 134 plot3(time2bin(current_frame,cur_time),jj,cur_val/30,'.','color',col);
tomwalters@0 135 end
tomwalters@0 136 else
tomwalters@0 137 cur_val=0;
tomwalters@0 138 end
tomwalters@0 139 result_field(ii,y_count)=cur_val;
tomwalters@0 140 y_count=y_count+1;
tomwalters@0 141 end
tomwalters@0 142 end
tomwalters@0 143
tomwalters@0 144 % ret_field=frame(result_field');
tomwalters@0 145 % ret_field=setstarttime(ret_field,min_harmonic_relationship);
tomwalters@0 146 % newsr=nr_points/(max_harmonic_relationship-min_harmonic_relationship);
tomwalters@0 147 % ret_field=setsr(ret_field,newsr);
tomwalters@0 148 % ret_field=setxaxisname(ret_field,'harmonic ratio');
tomwalters@0 149 % return
tomwalters@0 150
tomwalters@0 151 % next step: calculate the autocorrelation function in each channel:
tomwalters@0 152
tomwalters@0 153 % grafix=1;
tomwalters@0 154 % res_field2=result_field;
tomwalters@0 155 % for ii=1:nr_points;
tomwalters@0 156 % spalte=result_field(ii,:);
tomwalters@0 157 % sig=signal(spalte,1);
tomwalters@0 158 % acsig=autocorrelate(sig,1,getnrpoints(sig));
tomwalters@0 159 % acsigvals=getvalues(acsig);
tomwalters@0 160 % res_field2(ii,:)=acsigvals';
tomwalters@0 161 %
tomwalters@0 162 % % fftsig=powerspectrum(sig);
tomwalters@0 163 % % nrs=linspace(1,getnrpoints(fftsig),getnrpoints(sig));
tomwalters@0 164 % % ftsigvals=getvalues(fftsig);
tomwalters@0 165 % % ftsigvals=ftsigvals(round(nrs));
tomwalters@0 166 % % res_field2(ii,:)=-ftsigvals';
tomwalters@0 167 %
tomwalters@0 168 %
tomwalters@0 169 % % if grafix
tomwalters@0 170 % % figure(23423)
tomwalters@0 171 % % clf
tomwalters@0 172 % % hold on
tomwalters@0 173 % % plot(acsig/max(acsig),'r');
tomwalters@0 174 % % plot(ftsigvals/min(ftsigvals),'r');
tomwalters@0 175 % % plot(sig/max(sig));
tomwalters@0 176 % % end
tomwalters@0 177 % p=0;
tomwalters@0 178 % end
tomwalters@0 179
tomwalters@0 180 % result_field=result_field';
tomwalters@0 181 % result_field=result_field(end:-1:1,:);
tomwalters@0 182 % result_field=result_field(:,end:-1:1);
tomwalters@0 183 ret_field=frame(result_field');
tomwalters@0 184
tomwalters@0 185 ret_field=setstarttime(ret_field,min_harmonic_relationship);
tomwalters@0 186 newsr=nr_points/(max_harmonic_relationship-min_harmonic_relationship);
tomwalters@0 187 ret_field=setsr(ret_field,newsr);
tomwalters@0 188 ret_field=setxaxisname(ret_field,'harmonic ratio');
tomwalters@0 189 % ret_field=setyaxisname(ret_field,'erb distance');
tomwalters@0 190
tomwalters@0 191
tomwalters@0 192 % try to extract everything that is "suprising" (e.g. not click response)
tomwalters@0 193
tomwalters@0 194
tomwalters@0 195 return
tomwalters@0 196
tomwalters@0 197 % one dimensional profile
tomwalters@0 198 profile=signal(res_vals);
tomwalters@0 199 % profile=setunit_x(profile,'scaling-frequency dimension');
tomwalters@0 200
tomwalters@0 201
tomwalters@0 202 % scaliere die x-achse auf das wachsende harmonische Verhältnis:
tomwalters@0 203 % chr=current_harmonic_relation(end:-1:1);
tomwalters@0 204 % rprof=res_vals(end:-1:1);
tomwalters@0 205 % rprof=signal(rprof);
tomwalters@0 206 % nr_dots=length(chr);
tomwalters@0 207 % for i=1:length(chr)
tomwalters@0 208 % n_y=f2f(i,1,nr_dots,min_harmonic_relationship,max_harmonic_relationship);
tomwalters@0 209 % rx=interp1(chr,1:nr_dots,n_y);
tomwalters@0 210 % nprof(i)=getbinvalue(rprof,rx);
tomwalters@0 211 % end
tomwalters@0 212 %
tomwalters@0 213 % profile=signal(nprof);
tomwalters@0 214 profile=setstarttime(profile,min_harmonic_relationship);
tomwalters@0 215 newsr=getnrpoints(profile)/(max_harmonic_relationship-min_harmonic_relationship);
tomwalters@0 216 profile=setsr(profile,newsr);
tomwalters@0 217 profile=setunit_x(profile,'harmonic ratio');