annotate aim-mat/tools/AIpitch.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=AIpitch(framestruct_a);
tomwalters@0 16 % plots the current frame (cframe) together with its sum
tomwalters@0 17 % all relevant data must be in the frame-object
tomwalters@0 18 % the return value "pitch" is the result from the call to "calcresidualprobability"
tomwalters@0 19
tomwalters@0 20 if ~isstruct(framestruct_a)
tomwalters@0 21 % error('AIsum must be called with a structure');
tomwalters@0 22 framestruct.current_frame=framestruct_a;
tomwalters@0 23 else
tomwalters@0 24 framestruct=framestruct_a;
tomwalters@0 25 end
tomwalters@0 26
tomwalters@0 27 if ~isfield(framestruct,'show_time');
tomwalters@0 28 show_time=1;
tomwalters@0 29 else
tomwalters@0 30 show_time=framestruct.show_time;
tomwalters@0 31 end
tomwalters@0 32
tomwalters@0 33 if ~isfield(framestruct,'plot_scale');
tomwalters@0 34 plot_scale=1;
tomwalters@0 35 else
tomwalters@0 36 plot_scale=framestruct.plot_scale;
tomwalters@0 37 end
tomwalters@0 38
tomwalters@0 39
tomwalters@0 40 if ~isfield(framestruct,'minimum_time_interval');
tomwalters@0 41 minimum_time_interval=1;
tomwalters@0 42 else
tomwalters@0 43 minimum_time_interval=framestruct.minimum_time_interval;
tomwalters@0 44 end
tomwalters@0 45
tomwalters@0 46 if ~isfield(framestruct,'maximum_time_interval');
tomwalters@0 47 maximum_time_interval=35;
tomwalters@0 48 else
tomwalters@0 49 maximum_time_interval=framestruct.maximum_time_interval;
tomwalters@0 50 end
tomwalters@0 51
tomwalters@0 52 if ~isfield(framestruct,'is_log');
tomwalters@0 53 is_log=1;
tomwalters@0 54 else
tomwalters@0 55 is_log=framestruct.is_log;;
tomwalters@0 56 end
tomwalters@0 57 current_frame=framestruct.current_frame;
tomwalters@0 58
tomwalters@0 59
tomwalters@0 60 % schmeisse die physikalisch nicht sinnvollen Bereiche raus!
tomwalters@0 61 % current_frame=extractpitchregion(current_frame);
tomwalters@0 62
tomwalters@0 63 pitch=calcresidualprobability(current_frame,0);
tomwalters@0 64
tomwalters@0 65 % max_pitch_strength=pitch(1).pitchstrength;
tomwalters@0 66 % max_pitch_fre=pitch(1).fre;
tomwalters@0 67
tomwalters@0 68 scale_summe=getsumscale(current_frame);
tomwalters@0 69
tomwalters@0 70 % start plotting:
tomwalters@0 71 clf;
tomwalters@0 72 rect=[-0.04 0.15 0.9 0.85];
tomwalters@0 73 hint=1; % this indicate that we dont want a title
tomwalters@0 74 mysubplot(1,1,1,rect, hint);
tomwalters@0 75 plot_struct.t_min=minimum_time_interval/1000;
tomwalters@0 76 plot_struct.t_max=maximum_time_interval/1000;
tomwalters@0 77 plot_struct.has_axis=0;
tomwalters@0 78 plot_struct.is_log=is_log;
tomwalters@0 79 plot_struct.has_y_axis=0;
tomwalters@0 80
tomwalters@0 81 plot(current_frame,plot_struct);
tomwalters@0 82 set(gca,'zlim',[0 1/plot_scale]);
tomwalters@0 83
tomwalters@0 84 if show_time
tomwalters@0 85 srate=getsr(current_frame);
tomwalters@0 86 text_x=0.9*maximum_time_interval*srate/1000;
tomwalters@0 87 text_y=getnrchannels(current_frame)+5;
tomwalters@0 88 str=getstructure(current_frame);
tomwalters@0 89 if ~isfield(str,'current_frame_start_time')
tomwalters@0 90 str.current_frame_start_time=0.0;
tomwalters@0 91 end
tomwalters@0 92 frame_number=str.current_frame_number;
tomwalters@0 93 frame_time=str.current_frame_start_time*1000;
tomwalters@0 94 text(text_x,text_y,sprintf('%d : %4.0fms',frame_number,frame_time),'FontSize',8);
tomwalters@0 95 % text(text_x,text_y,sprintf('%d',frame_number),'FontSize',8);
tomwalters@0 96 end
tomwalters@0 97
tomwalters@0 98 % and the sum
tomwalters@0 99 rect=[-0.04 0 0.9 0.2];
tomwalters@0 100 mysubplot(1,1,1,rect, hint);
tomwalters@0 101 summe=getsum(current_frame); % here it is calculated
tomwalters@0 102
tomwalters@0 103 srate=getsr(current_frame);
tomwalters@0 104 if is_log
tomwalters@0 105
tomwalters@0 106 t=minimum_time_interval;
tomwalters@0 107 ti=[t 2*t 4*t 8*t 16*t 32*t 64*t];
tomwalters@0 108 tix=(ti)/1000*srate; % there shell be the tix
tomwalters@0 109
tomwalters@0 110 ti=(ti);
tomwalters@0 111 ti=round(ti*100)/100;
tomwalters@0 112
tomwalters@0 113 psumme=getpart(summe,getminimumtime(summe),0);
tomwalters@0 114 rsumme=reverse(psumme);
tomwalters@0 115 sumvalues=getvalues(rsumme);
tomwalters@0 116
tomwalters@0 117 min_x_screen=minimum_time_interval/1000*srate; % thats the first point we want to see on the screen
tomwalters@0 118 max_x_screen=maximum_time_interval/1000*srate; % thats the first point we want to see on the screen
tomwalters@0 119
tomwalters@0 120 else % its not logarithmic!
tomwalters@0 121 summe=getpart(summe,-maximum_time_interval/1000,-minimum_time_interval/1000);
tomwalters@0 122
tomwalters@0 123 nr_labels=8;
tomwalters@0 124 xbis=getnrpoints(summe);
tomwalters@0 125 tix=0:xbis/nr_labels:xbis;
tomwalters@0 126 xstep=(maximum_time_interval-minimum_time_interval)*1000/nr_labels; %works from -35 to 5
tomwalters@0 127 xstep=round(xstep);
tomwalters@0 128 ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000])/1000;
tomwalters@0 129 ti=round(ti*10)/10;
tomwalters@0 130 sumvalues=getvalues(reverse(summe));
tomwalters@0 131
tomwalters@0 132 min_x_screen=0;
tomwalters@0 133 max_x_screen=(maximum_time_interval-minimum_time_interval)/1000*srate; % thats the first point we want to see on the screen
tomwalters@0 134
tomwalters@0 135 end
tomwalters@0 136
tomwalters@0 137 h=plot(sumvalues); hold on
tomwalters@0 138 axis([min_x_screen max_x_screen 0 scale_summe]);
tomwalters@0 139
tomwalters@0 140 % Ein roter Punkt dort, wo der pitch vermutet wird
tomwalters@0 141 % maximal n verschiedene Punkte
tomwalters@0 142 n=length(pitch.fre);
tomwalters@0 143 % pfre(1)=pitch.fre(1); % das ist die höchtste
tomwalters@0 144 %
tomwalters@0 145 % nr_res2=length(res);
tomwalters@0 146 % for i=1:nr_res2
tomwalters@0 147 % if pitch(fre(i
tomwalters@0 148 % end
tomwalters@0 149
tomwalters@0 150 for i=n:-1:1
tomwalters@0 151 timex=-1/pitch.fre(i);
tomwalters@0 152 hei=gettimevalue(summe,timex);
tomwalters@0 153 bin=time2bin(summe,timex);
tomwalters@0 154 if i==1
tomwalters@0 155 radius=max(1,20*pitch.pitchstrength(i));
tomwalters@0 156 if pitch.pitchstrength(i) > pitch.domfre(i)
tomwalters@0 157 plot(max_x_screen-bin+2,hei,'r.','MarkerSize',radius);
tomwalters@0 158 else
tomwalters@0 159 plot(max_x_screen-bin+2,hei,'b.','MarkerSize',radius);
tomwalters@0 160 end
tomwalters@0 161 texthei=hei*1.2;
tomwalters@0 162 if texthei>max(summe)/1.4
tomwalters@0 163 texthei=max(summe)/1.4;
tomwalters@0 164 end
tomwalters@0 165 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
tomwalters@0 166 else
tomwalters@0 167 radius=max(2,10*pitch.pitchstrength(i));
tomwalters@0 168 plot(max_x_screen-bin+2,hei,'b.','MarkerSize',radius);
tomwalters@0 169 end
tomwalters@0 170 end
tomwalters@0 171
tomwalters@0 172 set(gca,'XDir','reverse') % turn them around, because the higher values shell end on the right
tomwalters@0 173 if is_log
tomwalters@0 174 set(gca,'XScale','log')
tomwalters@0 175 end
tomwalters@0 176 set(gca,'XTick',tix);
tomwalters@0 177 set(gca,'XTickLabel',ti);
tomwalters@0 178 set(gca,'YTickLabel',[]);
tomwalters@0 179
tomwalters@0 180 if is_log
tomwalters@0 181 text(min_x_screen*1.9,-scale_summe/5,'time interval (ms)'); % this is at a nice position
tomwalters@0 182 else
tomwalters@0 183 text(120,-scale_summe/5,'time interval (ms)'); % this is at a nice position
tomwalters@0 184 end
tomwalters@0 185
tomwalters@0 186
tomwalters@0 187
tomwalters@0 188 % and the other sum on the y-axis
tomwalters@0 189 rect=[0.856 0.19 0.1 0.81];
tomwalters@0 190 mysubplot(1,1,1,rect, hint);
tomwalters@0 191 fresumme=sumfresig(current_frame); % here it is calculated
tomwalters@0 192 fresumme=smooth(fresumme,1);% glätte die Summe
tomwalters@0 193
tomwalters@0 194 fresumme=setname(fresumme,'');
tomwalters@0 195 fresumme=setunit_x(fresumme,'');
tomwalters@0 196 fresumme=setunit_y(fresumme,'');
tomwalters@0 197
tomwalters@0 198 plot(fresumme); hold on
tomwalters@0 199 v=getvalues(fresumme);
tomwalters@0 200 x1=0;
tomwalters@0 201 x2=size(v,1)*47/42;
tomwalters@0 202 y1=0;
tomwalters@0 203 y2=100000;
tomwalters@0 204 axis([x1 x2 y1 y2]);
tomwalters@0 205 view(-90,90);
tomwalters@0 206 % make y-Ticks
tomwalters@0 207 nr_labels=8;
tomwalters@0 208 nr_channels=getnrpoints(fresumme);
tomwalters@0 209 xstep=(nr_channels-1)/(nr_labels-1);
tomwalters@0 210 tix=1:xstep:nr_channels;
tomwalters@0 211 cfs=getcf(current_frame);
tomwalters@0 212 ti=cfs(floor(tix))/1000;
tomwalters@0 213 ti=round(ti*10)/10;
tomwalters@0 214 set(gca,'XTick',tix);
tomwalters@0 215 set(gca,'XTickLabel',ti);
tomwalters@0 216 set(gca,'YTickLabel',[]);
tomwalters@0 217 set(gca,'XAxisLocation','top');
tomwalters@0 218
tomwalters@0 219 % [fremins,fremaxs,frewomin,frewomax]=getminmax(fresumme,0.0);
tomwalters@0 220 fremins=pitch.fresum.fremins;
tomwalters@0 221 fremaxs=pitch.fresum.fremaxs;
tomwalters@0 222 frewomin=pitch.fresum.frewomins;
tomwalters@0 223 frewomax=pitch.fresum.frewomaxs;
tomwalters@0 224 contrasts=pitch.fresum.contrasts;
tomwalters@0 225
tomwalters@0 226 nr=size(fremaxs,2);
tomwalters@0 227 for i=1:nr
tomwalters@0 228 x1=time2bin(fresumme,frewomax(i));
tomwalters@0 229 y1=fremaxs(i);
tomwalters@0 230 % plot(x1,y1,'r.','MarkerSize',contr);
tomwalters@0 231
tomwalters@0 232 radius=max(1,10*pitch.fresum.spektralpitch(i));
tomwalters@0 233 % if pitch.pitchstrength(1) < pitch.fresum.spektralpitch(i)
tomwalters@0 234 plot(x1,y1,'r.','MarkerSize',radius);
tomwalters@0 235 text(x1-2,y1,sprintf('%5.3f',pitch.fresum.spektralpitch(i))); % this is at a nice position
tomwalters@0 236
tomwalters@0 237 % else
tomwalters@0 238 % plot(x1,y1,'b.','MarkerSize',radius);
tomwalters@0 239 % end
tomwalters@0 240
tomwalters@0 241 end
tomwalters@0 242 nr=size(fremins,2);
tomwalters@0 243 for i=1:nr
tomwalters@0 244 x2=time2bin(fresumme,frewomin(i));
tomwalters@0 245 y2=fremins(i);
tomwalters@0 246 plot(x2,y2,'g.','MarkerSize',5);
tomwalters@0 247 end
tomwalters@0 248 hold off