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