Mercurial > hg > aimmat
comparison aim-mat/modules/usermodule/pitchstrength/displaypitchstrength.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 | |
children |
comparison
equal
deleted
inserted
replaced
3:20ada0af3d7d | 4:537f939baef0 |
---|---|
1 % generating function for 'aim-mat' | |
2 % | |
3 % INPUT VALUES: | |
4 % | |
5 % RETURN VALUE: | |
6 % | |
7 % | |
8 % (c) 2011, University of Southampton | |
9 % Maintained by Stefan Bleeck (bleeck@gmail.com) | |
10 % download of current version is on the soundsoftware site: | |
11 % http://code.soundsoftware.ac.uk/projects/aimmat | |
12 % documentation and everything is on http://www.acousticscale.org | |
13 | |
14 | |
15 function displaypitchstrength(sai,options,frame_number,ax) | |
16 if nargin<4 | |
17 ax=gca; | |
18 end | |
19 | |
20 | |
21 % ?????? per Definition ???? | |
22 % minimum_time_interval=0.1; % in ms | |
23 % maximum_time_interval=35; | |
24 | |
25 | |
26 ti_result=options.handles.data.usermodule{frame_number}.ti_result; | |
27 % f_result=options.handles.data.usermodule{frame_number}.f_result; | |
28 if ~isfield(ti_result,'peaks') | |
29 return; | |
30 end | |
31 | |
32 % fq_sum = f_result.smoothed_signal; | |
33 int_sum = ti_result.smoothed_signal; | |
34 cla; | |
35 hold on | |
36 | |
37 % TIP | |
38 % tip=getvalues(int_sum); | |
39 % the tip is in the form of a logarithmic signal, it must therfore be | |
40 % transformed back to linear: | |
41 | |
42 % tip_x = bin2time(int_sum, 1:length(tip)); % Get the times | |
43 % tip_x = tip_x((tip_x>=(minimum_time_interval/1000)) & tip_x<=(maximum_time_interval/1000)); | |
44 % tip = tip(time2bin(int_sum,tip_x(1)):time2bin(int_sum,tip_x(end))); | |
45 % % tip_x is in ms. Change to Hz | |
46 % tip_x = 1./tip_x; | |
47 % plot(tip_x, tip, 'b'); | |
48 | |
49 % plot the smoothed interval profile, from which the pitch was derived | |
50 smoothed_signal=ti_result.smoothed_signal; | |
51 % if ~isempty(smoothed_signal) | |
52 % smoothed_signal=linsigx(smoothed_signal); % change the logarithmic signal back to linear | |
53 % % smoothed_signal=reverse(smoothed_signal); | |
54 % smoothval=getvalues(smoothed_signal); | |
55 % s_x = bin2time(smoothed_signal, 1:length(smoothval)); % Get the times | |
56 % s_x = s_x((s_x>=(minimum_time_interval/1000)) & s_x<=(maximum_time_interval/1000)); | |
57 % | |
58 % smoothval=smoothval(time2bin(smoothed_signal,s_x(1)):time2bin(smoothed_signal,s_x(end))); | |
59 % % s_x=f2f(s_x,0,0.035,0.0001,0.035); | |
60 % % s_x=(s_x+0.0001); %?????????? | |
61 % % s_x=s_x*1.01; %?????????? | |
62 % s_x=1./s_x; | |
63 % plot(ax,s_x,smoothval,'b'); | |
64 % end | |
65 | |
66 % set(gca,'XScale','log'); | |
67 plot(smoothed_signal); | |
68 hold on | |
69 | |
70 % xlabel('Frequency [Hz]'); | |
71 set(gca, 'YAxisLocation','right'); | |
72 % pks = []; | |
73 | |
74 % nr_labels = 8; | |
75 % ti=50*power(2,[0:nr_labels]); | |
76 % for i=1:length(pks) | |
77 % ti = ti((ti>(pks(i)+pks(i)*0.1))|(ti<pks(i)-pks(i)*0.1)); | |
78 % end | |
79 % ti = [ti round(pks)]; | |
80 % ti = sort(ti); | |
81 % set(gca,'XTick', ti); | |
82 % set(gca, 'XLim',[1000/maximum_time_interval sai{frame_number}.channel_center_fq(end)]) | |
83 set(options.handles.checkbox6, 'Value',0); | |
84 set(options.handles.checkbox7, 'Value',0); | |
85 | |
86 | |
87 % if there is a target frequency, then plot this one also! | |
88 target_frequency=options.target_frequency; | |
89 % at least three possibilities: take the hight: | |
90 % pitchstrength=ti_result.free.highest_peak_hight; | |
91 % dominant_frequency_found= ti_result.free.highest_peak_frequency; | |
92 | |
93 | |
94 % three different pitch strengths | |
95 % select the one with the highest peak rate | |
96 | |
97 peaks=ti_result.peaks; | |
98 % select the one with the highest neigbouring_ratio | |
99 peaks2=sortstruct(peaks,'v2012_height_base_width_ratio'); | |
100 % peaks2=sortstruct(peaks,'peak_base_height_y'); | |
101 % peaks2=sortstruct(peaks,'y'); | |
102 | |
103 | |
104 if length(peaks2)>1 | |
105 % for ii=1:length(peaks) | |
106 for i=1:min(3,length(peaks)) | |
107 t=peaks2{i}.t; | |
108 ypeak=peaks2{i}.y; | |
109 % ps=peaks{ii}.pitchstrength; | |
110 ps=peaks2{i}.v2012_height_base_width_ratio; | |
111 | |
112 | |
113 if i==1 | |
114 plot(t,ypeak,'Marker','o','Markerfacecolor','b','MarkeredgeColor','b','MarkerSize',10); | |
115 text(t,ypeak*1.05,sprintf('%3.0f Hz: %4.2f ',1/t,ps),'VerticalAlignment','bottom','HorizontalAlignment','center','color','b','Fontsize',12); | |
116 else | |
117 plot(t,ypeak,'Marker','o','Markerfacecolor','g','MarkeredgeColor','w','MarkerSize',5); | |
118 text(t,ypeak*1.05,sprintf('%3.0f Hz: %4.2f ',1/t,ps),'VerticalAlignment','bottom','HorizontalAlignment','center','color','g','Fontsize',12); | |
119 end | |
120 plot(peaks2{i}.left.t,peaks2{i}.left.y,'Marker','o','Markerfacecolor','r','MarkeredgeColor','r','MarkerSize',5); | |
121 plot(peaks2{i}.right.t,peaks2{i}.right.y,'Marker','o','Markerfacecolor','r','MarkeredgeColor','r','MarkerSize',5); | |
122 | |
123 | |
124 ybase=peaks2{i}.v2012_base_where_widths; | |
125 line([t t],[ybase ypeak],'color','m'); | |
126 line([peaks2{i}.left.t peaks2{i}.right.t],[ybase ybase],'color','m'); | |
127 | |
128 end | |
129 | |
130 set(gca,'xscale','log') | |
131 set(gca,'xlim',[0.001 0.03]) | |
132 | |
133 fres=[500 300 200 150 100 70 50 20]; | |
134 set(gca,'xtick',1./fres); | |
135 set(gca,'xticklabel',fres); | |
136 xlabel('Frequency (Hz)') | |
137 ylabel('arbitrary normalized units') | |
138 end | |
139 | |
140 if target_frequency>0 % search only at one special frequency | |
141 found_fre=ti_result.fixed.highest_peak_frequency; | |
142 if found_fre>0 | |
143 yval=gettimevalue(smoothed_signal,1/found_fre); | |
144 else | |
145 yval=0; | |
146 end | |
147 plot(found_fre,yval,'Marker','o','Markerfacecolor','y','MarkeredgeColor','w','MarkerSize',5); | |
148 | |
149 found_ps=ti_result.fixed.highest_peak_hight; | |
150 plot(found_fre,yval,'Marker','o','Markerfacecolor','g','MarkeredgeColor','w','MarkerSize',10); | |
151 text(found_fre/1.1,yval*1.01, ['Pitchstrength at fixed ' num2str(round(found_fre)) 'Hz: ' num2str(fround(found_ps,2)) ],'VerticalAlignment','bottom','HorizontalAlignment','right','color','g','Fontsize',12); | |
152 bordery=get(gca,'Ylim'); | |
153 line([target_frequency target_frequency],[bordery(1) bordery(2)],'color','g') | |
154 min_fre=target_frequency/options.allowed_frequency_deviation; | |
155 max_fre=target_frequency*options.allowed_frequency_deviation; | |
156 line([min_fre min_fre],[bordery(1) bordery(2)],'color','g') | |
157 line([max_fre max_fre],[bordery(1) bordery(2)],'color','g') | |
158 end | |
159 | |
160 % maxy=sai{end}.ti_resultlt.peaks{1}.y; | |
161 maxy=max(int_sum); | |
162 if maxy==0 | |
163 maxy=1; | |
164 end | |
165 set(ax,'Ylim',[0,maxy*1.1]); | |
166 | |
167 | |
168 % plot the frequency profile | |
169 plot_frequency_profile=0; | |
170 if plot_frequency_profile | |
171 %Plot both profiles into one figure | |
172 % FQP | |
173 fqp = getvalues(fq_sum)'; | |
174 % fqp = fqp /1000; | |
175 plot(sai{frame_number}.channel_center_fq, fqp,'r'); | |
176 | |
177 peaks=f_result.peaks; | |
178 if length(peaks)>1 | |
179 % for ii=1:length(peaks) | |
180 for ii=1:1 | |
181 fre=1/peaks{ii}.t; | |
182 yval=peaks{ii}.y; | |
183 % ps=peaks{ii}.pitchstrength; | |
184 ps=peaks{ii}.y; | |
185 if ii==1 | |
186 plot(fre,yval,'Marker','o','Markerfacecolor','r','MarkeredgeColor','r','MarkerSize',10); | |
187 text(fre,yval*1.03,sprintf('%3.0f Hz: %4.2f ',fre,ps),'VerticalAlignment','bottom','HorizontalAlignment','center','color','r','Fontsize',12); | |
188 else | |
189 plot(fre,yval,'Marker','o','Markerfacecolor','g','MarkeredgeColor','w','MarkerSize',5); | |
190 text(fre,yval*1.03,sprintf('%3.0f Hz: %4.2f ',fre,ps),'VerticalAlignment','bottom','HorizontalAlignment','center','color','g','Fontsize',12); | |
191 end | |
192 end | |
193 end | |
194 hold off | |
195 end | |
196 | |
197 | |
198 return | |
199 | |
200 function fre=x2fre(sig,x) | |
201 t_log = bin2time(sig,x); | |
202 t=f2f(t_log,0,0.035,0.001,0.035,'linlog'); | |
203 fre=1/t; |