annotate aim-mat/tools/AIFrePtiPStress.m @ 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 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % tool
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
tomwalters@0 7 %
bleeck@3 8 % (c) 2011, University of Southampton
bleeck@3 9 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 10 % download of current version is on the soundsoftware site:
bleeck@3 11 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 12 % documentation and everything is on http://www.acousticscale.org
bleeck@3 13
tomwalters@0 14
tomwalters@0 15 function pitch=AIFrePtiPStress2(framestruct_a);
tomwalters@0 16 % plots the current frame (cframe) together with its sum of intervals
tomwalters@0 17 % and the sum of frequencies
tomwalters@0 18 % all relevant data must be in the frame-object
tomwalters@0 19 % the return value "pitch" is the result from the call to "calcresidualprobability"
tomwalters@0 20
tomwalters@0 21 if ~isstruct(framestruct_a)
tomwalters@0 22 % error('AIsum must be called with a structure');
tomwalters@0 23 framestruct.current_frame=framestruct_a;
tomwalters@0 24 current_frame_number=1;
tomwalters@0 25 else
tomwalters@0 26 framestruct=framestruct_a;
tomwalters@0 27 end
tomwalters@0 28
tomwalters@0 29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tomwalters@0 30 % Different Parameters
tomwalters@0 31 % if the label of the time should be shown in the upper left corner
tomwalters@0 32 if ~isfield(framestruct,'show_time');
tomwalters@0 33 show_time=1;
tomwalters@0 34 else
tomwalters@0 35 show_time=framestruct.show_time;
tomwalters@0 36 end
tomwalters@0 37
tomwalters@0 38 % if any grafic should be displayed. Otherwise only the value is returned
tomwalters@0 39 if ~isfield(framestruct,'show_graphic');
tomwalters@0 40 show_graphic=1;
tomwalters@0 41 else
tomwalters@0 42 show_graphic=framestruct.show_graphic;
tomwalters@0 43 end
tomwalters@0 44
tomwalters@0 45 % both profiles can be scaled to a higher value
tomwalters@0 46 if ~isfield(framestruct,'profile_scale');
tomwalters@0 47 profile_scale=1;
tomwalters@0 48 else
tomwalters@0 49 profile_scale=framestruct.profile_scale;
tomwalters@0 50 end
tomwalters@0 51
tomwalters@0 52 % the picture can be scaled overall to a higher value
tomwalters@0 53 if ~isfield(framestruct,'plot_scale');
tomwalters@0 54 plot_scale=1;
tomwalters@0 55 else
tomwalters@0 56 plot_scale=framestruct.plot_scale;
tomwalters@0 57 end
tomwalters@0 58
tomwalters@0 59 % the minimum time interval (usually 1 ms) on the right
tomwalters@0 60 if ~isfield(framestruct,'minimum_time_interval');
tomwalters@0 61 minimum_time_interval=1;
tomwalters@0 62 else
tomwalters@0 63 minimum_time_interval=framestruct.minimum_time_interval;
tomwalters@0 64 end
tomwalters@0 65
tomwalters@0 66 % the maximum time interval (usually 35 ms) on the left
tomwalters@0 67 if ~isfield(framestruct,'maximum_time_interval');
tomwalters@0 68 maximum_time_interval=35;
tomwalters@0 69 else
tomwalters@0 70 maximum_time_interval=framestruct.maximum_time_interval;
tomwalters@0 71 end
tomwalters@0 72
tomwalters@0 73 % linear or logarithmic structure
tomwalters@0 74 if ~isfield(framestruct,'is_log');
tomwalters@0 75 is_log=1;
tomwalters@0 76 else
tomwalters@0 77 is_log=framestruct.is_log;;
tomwalters@0 78 end
tomwalters@0 79 current_frame=framestruct.current_frame;
tomwalters@0 80
tomwalters@0 81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tomwalters@0 82 % Parameter für die PitchBerechnung
tomwalters@0 83 dot_scaler=200; % wie gross Punkte dargestellt werden sollen in Punkt
tomwalters@0 84 grafix=0;
tomwalters@0 85 % wie weit die Intervallsumme runterskaliert werden muss, damit die Zahlen vernünftigt werden
tomwalters@0 86 norm_intervalhight=1/1e4;
tomwalters@0 87 % wie weit die spektrale Summe runterskaliert werden muss, damit die Zahlen vernünftigt werden
tomwalters@0 88 norm_spektralhight=1.5/1e5;
tomwalters@0 89
tomwalters@0 90 % how big must the contrast of the envelope be to be recognised as one pitch
tomwalters@0 91 envcontrast_threshold=0.15;
tomwalters@0 92
tomwalters@0 93 % A single factor, that can vary between
tomwalters@0 94 % 0 = complete attention to temporal structure
tomwalters@0 95 % 1 = complete attention to spectral structure
tomwalters@0 96 spectral_attention_factor=0.5;
tomwalters@0 97
tomwalters@0 98 pitch_current_frame=current_frame;
tomwalters@0 99 % schmeisse die physikalisch nicht sinnvollen Bereiche raus!
tomwalters@0 100 current_frame=extractpitchregion(current_frame);
tomwalters@0 101
tomwalters@0 102 % berechne die pitches vom Orginal
tomwalters@0 103 parameters.norm_intervalhight=norm_intervalhight;
tomwalters@0 104 parameters.norm_spektralhight=norm_spektralhight;
tomwalters@0 105 parameters.graphix=grafix;
tomwalters@0 106 parameters.dot_scaler=dot_scaler;
tomwalters@0 107 parameters.spectral_attention_factor=spectral_attention_factor;
tomwalters@0 108 parameters.extract_pitch_region=1; % schmeiss die Ecke unten rechts raus
tomwalters@0 109 parameters.use_whole_spektral_profile=1; % nimm das gesamte Profil zum mitteln!
tomwalters@0 110
tomwalters@0 111
tomwalters@0 112 % Berechnet den Pitch
tomwalters@0 113 pitch=calcresidualprobability(pitch_current_frame,parameters);
tomwalters@0 114 % if we dont need any graphic, than return here
tomwalters@0 115 if ~show_graphic
tomwalters@0 116 return;
tomwalters@0 117 end
tomwalters@0 118
tomwalters@0 119 % start plotting:
tomwalters@0 120 clf;
tomwalters@0 121 rect=[-0.04 0.15 0.9 0.85];
tomwalters@0 122 hint=1; % this indicate that we dont want a title
tomwalters@0 123 mysubplot(1,1,1,rect, hint);
tomwalters@0 124 plot_struct.t_min=minimum_time_interval/1000;
tomwalters@0 125 plot_struct.t_max=maximum_time_interval/1000;
tomwalters@0 126 % current_frame=setdisplayminimumtime(current_frame,minimum_time_interval);
tomwalters@0 127 % current_frame=setdisplaymaximumtime(current_frame,maximum_time_interval);
tomwalters@0 128
tomwalters@0 129 plot_struct.has_axis=0;
tomwalters@0 130 plot_struct.is_log=is_log;
tomwalters@0 131 plot_struct.has_y_axis=0;
tomwalters@0 132
tomwalters@0 133 rethand=plot(current_frame,plot_struct);
tomwalters@0 134 set(gca,'zlim',[0 1/plot_scale]);
tomwalters@0 135
tomwalters@0 136 % if show_time
tomwalters@0 137 % srate=getsr(current_frame);
tomwalters@0 138 % text_x=0.9*maximum_time_interval*srate/1000;
tomwalters@0 139 % text_y=getnrchannels(current_frame)+5;
tomwalters@0 140 % str=getstructure(current_frame);
tomwalters@0 141 % if ~isfield(str,'current_frame_start_time')
tomwalters@0 142 % str.current_frame_start_time=0.0;
tomwalters@0 143 % end
tomwalters@0 144 % frame_number=str.current_frame_number;
tomwalters@0 145 % frame_time=str.current_frame_start_time*1000;
tomwalters@0 146 % text(text_x,text_y,sprintf('%d : %4.0fms',frame_number,frame_time),'FontSize',8);
tomwalters@0 147 % % text(text_x,text_y,sprintf('%d',frame_number),'FontSize',8);
tomwalters@0 148 % end
tomwalters@0 149
tomwalters@0 150 % and the sum
tomwalters@0 151 rect=[-0.04 0 0.9 0.2];
tomwalters@0 152 mysubplot(1,1,1,rect, hint);
tomwalters@0 153 summe=getsum(current_frame); % here it is calculated
tomwalters@0 154
tomwalters@0 155 srate=getsr(current_frame);
tomwalters@0 156 if is_log
tomwalters@0 157
tomwalters@0 158 t=minimum_time_interval;
tomwalters@0 159 ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
tomwalters@0 160 tix=(ti)/1000*srate; % there shell be the tix
tomwalters@0 161
tomwalters@0 162 ti=(ti);
tomwalters@0 163 ti=round(ti*100)/100;
tomwalters@0 164
tomwalters@0 165 psumme=getpart(summe,getminimumtime(summe),getmaximumtime(summe));
tomwalters@0 166 rsumme=reverse(psumme);
tomwalters@0 167 sumvalues=getvalues(rsumme);
tomwalters@0 168
tomwalters@0 169 min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
tomwalters@0 170 max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
tomwalters@0 171
tomwalters@0 172 else % its not logarithmic!
tomwalters@0 173 summe=getpart(summe,-maximum_time_interval/1000,-minimum_time_interval/1000);
tomwalters@0 174
tomwalters@0 175 nr_labels=8;
tomwalters@0 176 xbis=getnrpoints(summe);
tomwalters@0 177 tix=0:xbis/nr_labels:xbis;
tomwalters@0 178 xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
tomwalters@0 179 xstep=round(xstep);
tomwalters@0 180 ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000])/1000;
tomwalters@0 181 ti=round(ti*10)/10;
tomwalters@0 182 sumvalues=getvalues(reverse(summe));
tomwalters@0 183
tomwalters@0 184 min_x_screen=0;
tomwalters@0 185 max_x_screen=(maximum_time_interval-minimum_time_interval)/1000*srate; % thats the first point we want to see on the screen
tomwalters@0 186
tomwalters@0 187 end
tomwalters@0 188
tomwalters@0 189 % alle Werte sind auf empirische Werte genormt, so dass sie immer gleich hoch sind
tomwalters@0 190 sumvalues=sumvalues*norm_intervalhight;
tomwalters@0 191 % alle Werte auf die Benutzerscalierung scalen
tomwalters@0 192 sumvalues=sumvalues*profile_scale;
tomwalters@0 193
tomwalters@0 194 summe=setvalues(summe,sumvalues,floor(min_x_screen));
tomwalters@0 195 h=plot(sumvalues); hold on
tomwalters@0 196
tomwalters@0 197 axis([min_x_screen max_x_screen 0 1]);
tomwalters@0 198 sr=getsr(current_frame);
tomwalters@0 199
tomwalters@0 200 % % Ein roter Punkt dort, wo der pitch vermutet wird
tomwalters@0 201 n=length(pitch);
tomwalters@0 202 for i=n:-1:1
tomwalters@0 203 peak=pitch{i};
tomwalters@0 204 timex=peak.interval_profile.time;
tomwalters@0 205
tomwalters@0 206 % binx=displaytime2bin(current_frame,timex)-2;
tomwalters@0 207 binx=time2bin(timex,sr)-2;
tomwalters@0 208 hei=getbinvalue(summe,max_x_screen-binx+min_x_screen);
tomwalters@0 209 % hei=gettimevalue(summe,getminimumtime(summe)-timex);
tomwalters@0 210 % bin=time2bin(summe,timex);
tomwalters@0 211 if i==1
tomwalters@0 212 radius=max(5,dot_scaler*peak.residuumpitchstrength);
tomwalters@0 213 plot(max_x_screen-binx,hei,'r.','MarkerSize',radius);
tomwalters@0 214 texthei=hei*1.2;
tomwalters@0 215 if texthei>max(summe)/1.4
tomwalters@0 216 texthei=max(summe)/1.4;
tomwalters@0 217 end
tomwalters@0 218 if peak.interval_profile.envcontrast > envcontrast_threshold
tomwalters@0 219 % text(binx/1.06,texthei*1.2,sprintf('%3.0f Hz %5.3f',peak.fre,peak.pitchstrength)); % this is at a nice position
tomwalters@0 220 text((max_x_screen-binx)/1.06,texthei*1.2,sprintf('%3.0f Hz',peak.interval_profile.fre)); % this is at a nice position
tomwalters@0 221 end
tomwalters@0 222 else
tomwalters@0 223 radius=max(5,dot_scaler*peak.residuumpitchstrength);
tomwalters@0 224 plot(max_x_screen-binx,hei,'b.','MarkerSize',radius);
tomwalters@0 225 end
tomwalters@0 226 end
tomwalters@0 227 %
tomwalters@0 228 set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
tomwalters@0 229 if is_log
tomwalters@0 230 set(gca,'XScale','log')
tomwalters@0 231 end
tomwalters@0 232 set(gca,'XTick',tix);
tomwalters@0 233 set(gca,'XTickLabel',ti);
tomwalters@0 234 set(gca,'YTickLabel',[]);
tomwalters@0 235 %
tomwalters@0 236 % if is_log
tomwalters@0 237 % scale_summe=getfrequencysum(current_frame);
tomwalters@0 238 % text(min_x_screen*1.9,-scale_summe/5,'time interval (ms)'); % this is at a nice position
tomwalters@0 239 % else
tomwalters@0 240 % text(120,-scale_summe/5,'time interval (ms)'); % this is at a nice position
tomwalters@0 241 % end
tomwalters@0 242
tomwalters@0 243
tomwalters@0 244
tomwalters@0 245 % and the other sum on the y-axis
tomwalters@0 246 rect=[0.857 0.2 0.10 0.75];
tomwalters@0 247 mysubplot(1,1,1,rect, hint);
tomwalters@0 248 fresumme=getfrequencysum(current_frame); % here it is calculated
tomwalters@0 249 % fresumme=smooth(fresumme,1);% glätte die Summe
tomwalters@0 250
tomwalters@0 251 % alle Werte auf den empirischen Wert skalieren und auf den Benutzerwert
tomwalters@0 252 fresumme=fresumme*norm_spektralhight;
tomwalters@0 253 fresumme=fresumme*profile_scale;
tomwalters@0 254
tomwalters@0 255 fresumme=setname(fresumme,'');
tomwalters@0 256 fresumme=setunit_x(fresumme,'');
tomwalters@0 257 fresumme=setunit_y(fresumme,'');
tomwalters@0 258
tomwalters@0 259 plot(fresumme,'r'); hold on
tomwalters@0 260 v=getvalues(fresumme);
tomwalters@0 261 x1=0;
tomwalters@0 262 x2=size(v,1)*47/42;
tomwalters@0 263 y1=0;
tomwalters@0 264 y2=1;
tomwalters@0 265 axis([x1 x2 y1 y2]);
tomwalters@0 266 view(-90,90);
tomwalters@0 267 % make y-Ticks
tomwalters@0 268 nr_labels=8;
tomwalters@0 269 nr_channels=getnrpoints(fresumme);
tomwalters@0 270 xstep=(nr_channels-1)/(nr_labels-1);
tomwalters@0 271 tix=1:xstep:nr_channels;
tomwalters@0 272 cfs=getcf(current_frame);
tomwalters@0 273 ti=cfs(floor(tix))/1000;
tomwalters@0 274 ti=round(ti*10)/10;
tomwalters@0 275 set(gca,'XTick',tix);
tomwalters@0 276 set(gca,'XTickLabel',ti);
tomwalters@0 277 set(gca,'YTickLabel',[]);
tomwalters@0 278 set(gca,'XAxisLocation','top');
tomwalters@0 279
tomwalters@0 280 n=length(pitch);
tomwalters@0 281 for i=n:-1:1
tomwalters@0 282 peak=pitch{i};
tomwalters@0 283 x=peak.spektral_profile.position;
tomwalters@0 284 hei=peak.spektral_profile.hight/2;
tomwalters@0 285 radius=max(5,dot_scaler*hei);
tomwalters@0 286 y=getbinvalue(fresumme,x);
tomwalters@0 287 plot(x,y,'r.','MarkerSize',radius);
tomwalters@0 288 end
tomwalters@0 289
tomwalters@0 290 % Special Effect: Make Region cool!
tomwalters@0 291 n=length(pitch);
tomwalters@0 292 cdat=get(rethand,'cdata');
tomwalters@0 293 cdat=zeros(size(cdat));
tomwalters@0 294
tomwalters@0 295 bereich=n:-1:1;
tomwalters@0 296 % bereich=1;
tomwalters@0 297 for i=bereich
tomwalters@0 298 peak=pitch{i};
tomwalters@0 299 cdat=coolregion(current_frame,cdat,peak);
tomwalters@0 300 end
tomwalters@0 301
tomwalters@0 302 set(rethand,'cdata',cdat);
tomwalters@0 303 % erzeuge eine Colormap, die genausoviel Farben hat, wie wir Quellen
tomwalters@0 304 colmap=hsv(n+1);
tomwalters@0 305 colmap(1,:)=0.85;
tomwalters@0 306 colormap(colmap);