bleeck@3
|
1 % This external file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
2 % (c) 2011, University of Southampton
|
bleeck@3
|
3 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
4 % download of current version is on the soundsoftware site:
|
bleeck@3
|
5 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
6 % documentation and everything is on http://www.acousticscale.org
|
tomwalters@0
|
7
|
tomwalters@0
|
8 function [lowpasssig,maxinfo,mininfo]=peak_picker(sig,options);
|
tomwalters@0
|
9 % sophisticated peak picker
|
tomwalters@0
|
10 % the signal is first lowpassfilterd with the frequency given in options
|
tomwalters@0
|
11 % options comes with:
|
tomwalters@0
|
12
|
tomwalters@0
|
13
|
tomwalters@0
|
14
|
tomwalters@0
|
15 % frequency with witch the psth is filtered
|
tomwalters@0
|
16 % options.lowpassfrequency=500;
|
tomwalters@0
|
17 % search for peaks in the range from to:
|
tomwalters@0
|
18 % options.search_peak_start_search=0.001; % seach also before the offical latency
|
tomwalters@0
|
19 % options.search_peak_stop_search=0.025; % seach this time for peaks
|
tomwalters@0
|
20
|
tomwalters@0
|
21
|
tomwalters@0
|
22 % every distinct peak must comply the following conditions:
|
tomwalters@0
|
23 % a certain activity during the duration of the maximum (a spike count per
|
tomwalters@0
|
24 % presentation)
|
tomwalters@0
|
25 if ~isfield(options,'min_count_per_peak')
|
tomwalters@0
|
26 options.min_count_per_peak=-inf;% default: no certain activity: all peaks are significant
|
tomwalters@0
|
27 end
|
tomwalters@0
|
28 % a certain height of the maximum peak
|
tomwalters@0
|
29 if ~isfield(options,'min_height_of_heighest_peak')
|
tomwalters@0
|
30 options.min_height_of_heighest_peak=0; % default: no certain height: all peaks are significant
|
tomwalters@0
|
31 end
|
tomwalters@0
|
32
|
tomwalters@0
|
33
|
tomwalters@0
|
34
|
tomwalters@0
|
35 % return values are the filtered signal and information about the found
|
tomwalters@0
|
36 % peaks:
|
tomwalters@0
|
37 % maxinfo.values % the hights of the found maxima
|
tomwalters@0
|
38 % maxinfo.times % where are the found maxima
|
tomwalters@0
|
39 % maxinfo.contrast % the contrast is the relation between the maximum and the surrounding minima
|
tomwalters@0
|
40 % maxinfo.qvalue % how wide the maximum is at half height.
|
tomwalters@0
|
41 % maxinfo.activity % sum of activity between the adjacent minima
|
tomwalters@0
|
42
|
tomwalters@0
|
43 % every found maxima (except the first and the last) is surrounded by two
|
tomwalters@0
|
44 % minima. Same is true for the found minimas
|
tomwalters@0
|
45
|
tomwalters@0
|
46 % do we want some grafical output (for debugging)
|
tomwalters@0
|
47 grafix=options.grafix;
|
tomwalters@0
|
48 % define the return values
|
tomwalters@0
|
49 maxinfo=[];
|
tomwalters@0
|
50 mininfo=[];
|
tomwalters@0
|
51
|
tomwalters@0
|
52
|
tomwalters@0
|
53 %do the lowpassfiltering
|
tomwalters@0
|
54 lowpasssig=lowpass(sig,options.lowpassfrequency);
|
tomwalters@0
|
55 [atmax,ahmax]=getlocalmaxima(lowpasssig);
|
tomwalters@0
|
56 [atmin,ahmin]=getlocalminima(lowpasssig);
|
tomwalters@0
|
57
|
tomwalters@0
|
58 % restrict to the requiered range
|
tomwalters@0
|
59 indeces1=find(atmax>options.search_peak_start_search);
|
tomwalters@0
|
60 indeces2=find(atmax<options.search_peak_stop_search);
|
tomwalters@0
|
61 indeces=intersect(indeces1,indeces2);
|
tomwalters@0
|
62 tmax=atmax(indeces);
|
tomwalters@0
|
63 hmax=ahmax(indeces);
|
tomwalters@0
|
64 indeces1=find(atmin>options.search_peak_start_search);
|
tomwalters@0
|
65 indeces2=find(atmin<options.search_peak_stop_search);
|
tomwalters@0
|
66 indeces=intersect(indeces1,indeces2);
|
tomwalters@0
|
67 tmin=atmin(indeces);
|
tomwalters@0
|
68 hmin=ahmin(indeces);
|
tomwalters@0
|
69
|
tomwalters@0
|
70
|
tomwalters@0
|
71
|
tomwalters@0
|
72
|
tomwalters@0
|
73 % make an iterated search through all maxima and decide which ones to keep
|
tomwalters@0
|
74 finished=0;
|
tomwalters@0
|
75 while ~finished
|
tomwalters@0
|
76 % throw out exactly one maximum
|
tomwalters@0
|
77 [tmaxnew,tminnew,hmaxnew,hminnew]=try_reduce_maxima(tmax,tmin,hmax,hmin,options);
|
tomwalters@0
|
78 if length(tmaxnew)==length(tmax) || length(tmaxnew)==1 || length(tminnew)==1
|
tomwalters@0
|
79 finished=1;
|
tomwalters@0
|
80 end
|
tomwalters@0
|
81 tmax=tmaxnew; tmin=tminnew; hmax=hmaxnew; hmin=hminnew; % new values
|
tomwalters@0
|
82 % if grafix
|
tomwalters@0
|
83 % plotall(fignum,lowpasssig,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
84 % p=0;
|
tomwalters@0
|
85 % end
|
tomwalters@0
|
86 end
|
tomwalters@0
|
87
|
tomwalters@0
|
88
|
tomwalters@0
|
89 if grafix
|
tomwalters@0
|
90 fignum=figure;
|
tomwalters@0
|
91 set(gcf,'Number','off');
|
tomwalters@0
|
92 % set(gcf,'name',sprintf('peak picker (An:%s Un:%s Ex:%s) ',data.unitinfo.an_num,data.unitinfo.un_num,data.unitinfo.ex_num));
|
tomwalters@0
|
93 set(gcf,'name',('peak picker'));
|
tomwalters@0
|
94 plotall(fignum,lowpasssig,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
95 end
|
tomwalters@0
|
96
|
tomwalters@0
|
97 % if grafix
|
tomwalters@0
|
98 % plotall(lowpasssig,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
99 % end
|
tomwalters@0
|
100 % now only significant values are left!
|
tomwalters@0
|
101 % put them in the return structure:
|
tomwalters@0
|
102
|
tomwalters@0
|
103 nr_max=length(tmax);
|
tomwalters@0
|
104 maxinfo.values=hmax; % the hights of the found maxima
|
tomwalters@0
|
105 maxinfo.times=tmax; % where are the found maxima
|
tomwalters@0
|
106 [highest_peak_height,highest_peak_index]=max(hmax);
|
tomwalters@0
|
107
|
tomwalters@0
|
108 for i=1:nr_max
|
tomwalters@0
|
109 maxinfo.contrast(i)=getcontrast(i,tmax,tmin,hmax,hmin); % the contrast is the relation between the maximum and the surrounding minima
|
tomwalters@0
|
110 maxinfo.qvalue(i)=getquality(i,tmax,tmin,hmax,hmin); % how wide the maximum is at half height.
|
tomwalters@0
|
111 maxinfo.activity(i)=getactivity(i,lowpasssig,tmax,tmin,hmax,hmin,options.latency); % sum of activity between the adjacent minima
|
tomwalters@0
|
112 end
|
tomwalters@0
|
113
|
tomwalters@0
|
114 nr_min=length(tmin);
|
tomwalters@0
|
115 mininfo.values=hmin; % the hights of the found maxima
|
tomwalters@0
|
116 mininfo.times=tmin; % where are the found maxima
|
tomwalters@0
|
117 for i=1:nr_min
|
tomwalters@0
|
118 mininfo.contrast(i)=getmincontrast(i,tmax,tmin,hmax,hmin); % the contrast is the relation between the maximum and the surrounding minima
|
tomwalters@0
|
119 mininfo.qvalue(i)=getminquality(i,tmax,tmin,hmax,hmin); % how wide the maximum is at half height.
|
tomwalters@0
|
120 end
|
tomwalters@0
|
121
|
tomwalters@0
|
122 % now we have all peaks, find out which ones are significant for us
|
tomwalters@0
|
123 maxinfo.distinct_max=[];
|
tomwalters@0
|
124 count=1;
|
tomwalters@0
|
125 height_criterium=options.min_height_of_heighest_peak*highest_peak_height;
|
tomwalters@0
|
126 count_criterium=options.min_count_per_peak;
|
tomwalters@0
|
127
|
tomwalters@0
|
128 for i=1:nr_max
|
tomwalters@0
|
129 % it must have a certain contrast
|
tomwalters@0
|
130 if maxinfo.contrast(i)>=options.min_contrast_for_distinct_peak
|
tomwalters@0
|
131 % and it must have a certain height
|
tomwalters@0
|
132 if maxinfo.values(i)>=height_criterium
|
tomwalters@0
|
133 if maxinfo.activity(i)>=count_criterium
|
tomwalters@0
|
134 maxinfo.distinct_max(count).contrast=maxinfo.contrast(i);
|
tomwalters@0
|
135 maxinfo.distinct_max(count).qvalue=maxinfo.qvalue(i);
|
tomwalters@0
|
136 maxinfo.distinct_max(count).activity=maxinfo.activity(i);
|
tomwalters@0
|
137 maxinfo.distinct_max(count).hmax=hmax(i);
|
tomwalters@0
|
138 maxinfo.distinct_max(count).tmax=tmax(i);
|
tomwalters@0
|
139 count=count+1;
|
tomwalters@0
|
140 end
|
tomwalters@0
|
141 end
|
tomwalters@0
|
142 end
|
tomwalters@0
|
143 end
|
tomwalters@0
|
144
|
tomwalters@0
|
145
|
tomwalters@0
|
146 if grafix
|
tomwalters@0
|
147 nr_all_max=length(atmax);
|
tomwalters@0
|
148 for i=1:nr_all_max
|
tomwalters@0
|
149 plot(atmax(i)*1000,ahmax(i),'o','markersize',2,'Markerfacecolor','r','Markeredgecolor','r');
|
tomwalters@0
|
150 end
|
tomwalters@0
|
151 nr_all_min=length(atmin);
|
tomwalters@0
|
152 for i=1:nr_all_min
|
tomwalters@0
|
153 plot(atmin(i)*1000,ahmin(i),'o','markersize',2,'Markerfacecolor','g','Markeredgecolor','g');
|
tomwalters@0
|
154 end
|
tomwalters@0
|
155
|
tomwalters@0
|
156 % plot a dot for every disticnt maximum found
|
tomwalters@0
|
157 for i=1:nr_max
|
tomwalters@0
|
158 testmaxpos=maxinfo.times(i);
|
tomwalters@0
|
159 testmaxval=maxinfo.values(i);
|
tomwalters@0
|
160 contrast=maxinfo.contrast(i);
|
tomwalters@0
|
161 count=maxinfo.activity(i);
|
tomwalters@0
|
162 plot(testmaxpos*1000,testmaxval,'o','markersize',8,'Markerfacecolor','r','Markeredgecolor','r');
|
tomwalters@0
|
163 end
|
tomwalters@0
|
164 % plot a dot for every minimum found
|
tomwalters@0
|
165 for i=1:length(maxinfo.distinct_max);
|
tomwalters@0
|
166 testmaxpos=maxinfo.distinct_max(i).tmax;
|
tomwalters@0
|
167 testmaxval=maxinfo.distinct_max(i).hmax;
|
tomwalters@0
|
168 contrast=maxinfo.distinct_max(i).contrast;
|
tomwalters@0
|
169 count=maxinfo.distinct_max(i).activity;
|
tomwalters@0
|
170 text(testmaxpos*1000+1,testmaxval,sprintf('contr %3.3f',contrast),'fontsize',6,'ver','bottom');
|
tomwalters@0
|
171 text(testmaxpos*1000+1,testmaxval,sprintf('count %3.3f',count),'fontsize',6,'ver','top');
|
tomwalters@0
|
172 end
|
tomwalters@0
|
173 for i=1:nr_min
|
tomwalters@0
|
174 testminpos=mininfo.times(i);
|
tomwalters@0
|
175 testminval=mininfo.values(i);
|
tomwalters@0
|
176 plot(testminpos*1000,testminval,'o','markersize',4,'Markerfacecolor','g','Markeredgecolor','g');
|
tomwalters@0
|
177 end
|
tomwalters@0
|
178 end
|
tomwalters@0
|
179 return
|
tomwalters@0
|
180
|
tomwalters@0
|
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
184
|
tomwalters@0
|
185 function plotall(fignum,lowpasssig,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
186 figure(fignum);
|
tomwalters@0
|
187 clf
|
tomwalters@0
|
188 hold on
|
tomwalters@0
|
189 fill(lowpasssig,'b');
|
tomwalters@0
|
190 set(gca,'xlim',[0,60]);
|
tomwalters@0
|
191 for i=1:length(tmax)
|
tomwalters@0
|
192 plot(tmax(i)*1000,hmax(i),'Marker','o','MarkerSize',6,'MarkerFaceColor','r','MarkerEdgeColor','r')
|
tomwalters@0
|
193 end
|
tomwalters@0
|
194 for i=1:length(tmin)
|
tomwalters@0
|
195 % plot(time2bin(lowpasssig,tmin(i)),hmin(i),'Marker','o','MarkerSize',6,'MarkerFaceColor','g','MarkerEdgeColor','g')
|
tomwalters@0
|
196 end
|
tomwalters@0
|
197 xlabel('time (ms)');
|
tomwalters@0
|
198 ylabel('spikes / sweep / bin');
|
tomwalters@0
|
199 title(' PSTH plus found maxima');
|
tomwalters@0
|
200 % movegui(nfig,'northwest');
|
tomwalters@0
|
201 return
|
tomwalters@0
|
202
|
tomwalters@0
|
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
206
|
tomwalters@0
|
207 function [tmaxnew,tminnew,hmaxnew,hminnew]=try_reduce_maxima(tmax,tmin,hmax,hmin,options)
|
tomwalters@0
|
208 % throw out the peak with the smallest contrast
|
tomwalters@0
|
209 % if removed, the minimum to the right of it is removed too
|
tomwalters@0
|
210
|
tomwalters@0
|
211 nr_max=length(tmax);
|
tomwalters@0
|
212
|
tomwalters@0
|
213 % find the maximum with the neighbour that is closest in height and throw
|
tomwalters@0
|
214 % it out!
|
tomwalters@0
|
215 for i=1:nr_max
|
tomwalters@0
|
216 contrastr(i)=getrightcontrast(i,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
217 end
|
tomwalters@0
|
218 for i=1:nr_max
|
tomwalters@0
|
219 contrastl(i)=getleftcontrast(i,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
220 end
|
tomwalters@0
|
221 [mincontrastr,minconindexr]=min(abs(contrastr)); % thats the smallest right
|
tomwalters@0
|
222 [mincontrastl,minconindexl]=min(abs(contrastl)); % thats the smallest left
|
tomwalters@0
|
223
|
tomwalters@0
|
224 if mincontrastr<mincontrastl
|
tomwalters@0
|
225 side='right';
|
tomwalters@0
|
226 [mincontrast,minconindex]=min(contrastr);
|
tomwalters@0
|
227 else
|
tomwalters@0
|
228 side='left';
|
tomwalters@0
|
229 [mincontrast,minconindex]=min(contrastl);
|
tomwalters@0
|
230 end
|
tomwalters@0
|
231
|
tomwalters@0
|
232 testmaxpos=tmax(minconindex);
|
tomwalters@0
|
233 % if mincontrast<options.min_contrast_for_distinct_peak
|
tomwalters@0
|
234 if mincontrast<options.min_contrast_for_peak
|
tomwalters@0
|
235 switch side
|
tomwalters@0
|
236 case 'right'
|
tomwalters@0
|
237 [testminpos,testminval,indexmin]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
238 case 'left'
|
tomwalters@0
|
239 [testminpos,testminval,indexmin]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
240 end
|
tomwalters@0
|
241
|
tomwalters@0
|
242 % remove the minimum right of the maximum
|
tomwalters@0
|
243 tmaxnew=mysetdiff(tmax,tmax(minconindex));
|
tomwalters@0
|
244 hmaxnew=mysetdiff(hmax,hmax(minconindex));
|
tomwalters@0
|
245 if indexmin>0 && indexmin <length(tmin)
|
tomwalters@0
|
246 tminnew=mysetdiff(tmin,tmin(indexmin));
|
tomwalters@0
|
247 hminnew=mysetdiff(hmin,hmin(indexmin));
|
tomwalters@0
|
248 else
|
tomwalters@0
|
249 tminnew=tmin;
|
tomwalters@0
|
250 hminnew=hmin;
|
tomwalters@0
|
251 end
|
tomwalters@0
|
252 return % only remove one!
|
tomwalters@0
|
253 end
|
tomwalters@0
|
254
|
tomwalters@0
|
255 % if still here, then nothing happend
|
tomwalters@0
|
256 tmaxnew=tmax; tminnew=tmin; hmaxnew=hmax; hminnew=hmin;
|
tomwalters@0
|
257
|
tomwalters@0
|
258 return
|
tomwalters@0
|
259
|
tomwalters@0
|
260
|
tomwalters@0
|
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
264 function ret=mysetdiff(values,singleval)
|
tomwalters@0
|
265 % the same as setdiff, but without the sorting
|
tomwalters@0
|
266 ret=[];
|
tomwalters@0
|
267 for i=1:length(values)
|
tomwalters@0
|
268 if singleval~=values(i)
|
tomwalters@0
|
269 ret=[ret values(i)];
|
tomwalters@0
|
270 end
|
tomwalters@0
|
271 end
|
tomwalters@0
|
272 return
|
tomwalters@0
|
273
|
tomwalters@0
|
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
277 function contrast=getcontrast(peaknumber,tmax,tmin,hmax,hmin)
|
tomwalters@0
|
278 % return the contrast of the peak with the number
|
tomwalters@0
|
279 testmaxpos=tmax(peaknumber);
|
tomwalters@0
|
280 testmaxval=hmax(peaknumber);
|
tomwalters@0
|
281 [leftminpos,leftminval]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
282 [rightminpos,rightminval]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
283 if isempty(leftminpos) && isempty(rightminpos) % if both are empty, its difficult
|
tomwalters@0
|
284 contrast=0;
|
tomwalters@0
|
285 elseif isempty(leftminpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
286 contrast=(testmaxval-rightminval)/(testmaxval+rightminval);
|
tomwalters@0
|
287 elseif isempty(rightminpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
288 contrast=(testmaxval-leftminval)/(testmaxval+leftminval);
|
tomwalters@0
|
289 else
|
tomwalters@0
|
290 mean_min_val=mean([leftminval rightminval]);
|
tomwalters@0
|
291 contrast=(testmaxval-mean_min_val)/(testmaxval+mean_min_val);
|
tomwalters@0
|
292 end
|
tomwalters@0
|
293 return
|
tomwalters@0
|
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
297 function contrast=getrightcontrast(peaknumber,tmax,tmin,hmax,hmin)
|
tomwalters@0
|
298 % return the contrast with the right minimum of the peak with the number
|
tomwalters@0
|
299 testmaxpos=tmax(peaknumber);
|
tomwalters@0
|
300 testmaxval=hmax(peaknumber);
|
tomwalters@0
|
301 % [leftminpos,leftminval]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
302 [rightminpos,rightminval]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
303 % if isempty(leftminpos) && isempty(rightminpos) % if both are empty, its difficult
|
tomwalters@0
|
304 % contrast=0;
|
tomwalters@0
|
305 % elseif isempty(leftminpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
306 % contrast=(testmaxval-rightminval)/(testmaxval+rightminval);
|
tomwalters@0
|
307 if isempty(rightminpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
308 contrast=inf;
|
tomwalters@0
|
309 else
|
tomwalters@0
|
310 % mean_min_val=mean([leftminval rightminval]);
|
tomwalters@0
|
311 contrast=(testmaxval-rightminval)/(testmaxval+rightminval);
|
tomwalters@0
|
312 end
|
tomwalters@0
|
313 return
|
tomwalters@0
|
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
317 function contrast=getleftcontrast(peaknumber,tmax,tmin,hmax,hmin)
|
tomwalters@0
|
318 % return the contrast with the right minimum of the peak with the number
|
tomwalters@0
|
319 testmaxpos=tmax(peaknumber);
|
tomwalters@0
|
320 testmaxval=hmax(peaknumber);
|
tomwalters@0
|
321 [leftminpos,leftminval]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
322 % [rightminpos,rightminval]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
323 % if isempty(leftminpos) && isempty(rightminpos) % if both are empty, its difficult
|
tomwalters@0
|
324 % contrast=0;
|
tomwalters@0
|
325 % elseif isempty(leftminpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
326 % contrast=(testmaxval-rightminval)/(testmaxval+rightminval);
|
tomwalters@0
|
327 if isempty(leftminpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
328 contrast=inf;
|
tomwalters@0
|
329 else
|
tomwalters@0
|
330 % mean_min_val=mean([leftminval rightminval]);
|
tomwalters@0
|
331 contrast=(testmaxval-leftminval)/(testmaxval+leftminval);
|
tomwalters@0
|
332 end
|
tomwalters@0
|
333 return
|
tomwalters@0
|
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
337 function contrast=getmincontrast(troughnumber,tmax,tmin,hmax,hmin)
|
tomwalters@0
|
338 % return the contrast of the peak with the number
|
tomwalters@0
|
339 testminpos=tmin(troughnumber);
|
tomwalters@0
|
340 testminval=hmin(troughnumber);
|
tomwalters@0
|
341 [leftmaxpos,leftmaxval]=getmaximumleftof(testminpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
342 [rightmaxpos,rightmaxval]=getmaximumrightof(testminpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
343 if isempty(leftmaxpos) && isempty(rightmaxpos) % if both are empty, its difficult
|
tomwalters@0
|
344 contrast=0;
|
tomwalters@0
|
345 elseif isempty(leftmaxpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
346 contrast=(testminval-rightmaxval)/(testminval+rightmaxval);
|
tomwalters@0
|
347 elseif isempty(rightmaxpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
348 contrast=(testminval-leftmaxval)/(testminval+leftmaxval);
|
tomwalters@0
|
349 else
|
tomwalters@0
|
350 mean_max_val=mean([leftmaxval rightmaxval]);
|
tomwalters@0
|
351 contrast=(testminval-mean_max_val)/(testminval+mean_max_val);
|
tomwalters@0
|
352 end
|
tomwalters@0
|
353 return
|
tomwalters@0
|
354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
357 function peakheight=getpeakheight(peaknumber,tmax,tmin,hmax,hmin)
|
tomwalters@0
|
358 testmaxpos=tmax(peaknumber);
|
tomwalters@0
|
359 testmaxval=hmax(peaknumber);
|
tomwalters@0
|
360 [leftminpos,leftminval]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
361 [rightminpos,rightminval]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
362 if isempty(leftminpos) && isempty(rightminpos) % if both are empty, its difficult
|
tomwalters@0
|
363 peakheight=testmaxval;
|
tomwalters@0
|
364 elseif isempty(leftminpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
365 peakheight=testmaxval-rightminval;
|
tomwalters@0
|
366 elseif isempty(rightminpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
367 peakheight=testmaxval-leftminval;
|
tomwalters@0
|
368 else
|
tomwalters@0
|
369 mean_min_val=mean([leftminval rightminval]);
|
tomwalters@0
|
370 peakheight=testmaxval-mean_min_val;
|
tomwalters@0
|
371 end
|
tomwalters@0
|
372 return
|
tomwalters@0
|
373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
376 function troughheight=gettroughheight(troughnumber,tmax,tmin,hmax,hmin)
|
tomwalters@0
|
377 testminpos=tmin(troughnumber);
|
tomwalters@0
|
378 testminval=hmin(troughnumber);
|
tomwalters@0
|
379 [leftmaxpos,leftmaxval]=getminimumleftof(testminpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
380 [rightmaxpos,rightmaxval]=getminimumrightof(testminpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
381 if isempty(leftmaxpos) && isempty(rightmaxpos) % if both are empty, its difficult
|
tomwalters@0
|
382 troughheight=abs(testminval);
|
tomwalters@0
|
383 elseif isempty(leftmaxpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
384 troughheight=abs(testminval-rightmaxval);
|
tomwalters@0
|
385 elseif isempty(rightmaxpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
386 troughheight=abs(testminval-leftmaxval);
|
tomwalters@0
|
387 else
|
tomwalters@0
|
388 mean_min_val=mean([leftmaxval rightmaxval]);
|
tomwalters@0
|
389 troughheight=abs(testminval-mean_min_val);
|
tomwalters@0
|
390 end
|
tomwalters@0
|
391 return
|
tomwalters@0
|
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
395
|
tomwalters@0
|
396 function quality=getquality(peaknumber,tmax,tmin,hmax,hmin); % how wide the maximum is at the height of its surrounding minima
|
tomwalters@0
|
397 testmaxpos=tmax(peaknumber);
|
tomwalters@0
|
398 testmaxval=hmax(peaknumber);
|
tomwalters@0
|
399 [leftminpos,leftminval]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
400 [rightminpos,rightminval]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
401 if isempty(leftminpos) && isempty(rightminpos) % if both are empty, its difficult
|
tomwalters@0
|
402 quality=0;
|
tomwalters@0
|
403 elseif isempty(leftminpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
404 quality=0;
|
tomwalters@0
|
405 elseif isempty(rightminpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
406 quality=0;
|
tomwalters@0
|
407 else
|
tomwalters@0
|
408 diff_min_val=abs(leftminpos-rightminpos);
|
tomwalters@0
|
409 quality=testmaxval/diff_min_val;
|
tomwalters@0
|
410 end
|
tomwalters@0
|
411 return
|
tomwalters@0
|
412
|
tomwalters@0
|
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
416 function quality=getminquality(troughknumber,tmax,tmin,hmax,hmin); % how wide the maximum is at the height of its surrounding maxima
|
tomwalters@0
|
417 testminpos=tmin(troughknumber);
|
tomwalters@0
|
418 testminval=hmin(troughknumber);
|
tomwalters@0
|
419 [leftmaxpos,leftmaxval]=getmaximumleftof(testminpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
420 [rightmaxpos,rightmaxval]=getmaximumrightof(testminpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
421 if isempty(leftmaxpos) && isempty(rightmaxpos) % if both are empty, its difficult
|
tomwalters@0
|
422 quality=0;
|
tomwalters@0
|
423 elseif isempty(leftmaxpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
424 quality=0;
|
tomwalters@0
|
425 elseif isempty(rightmaxpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
426 quality=0;
|
tomwalters@0
|
427 else
|
tomwalters@0
|
428 diff_min_val=abs(leftmaxval-rightmaxval);
|
tomwalters@0
|
429 quality=testminval/diff_min_val;
|
tomwalters@0
|
430 end
|
tomwalters@0
|
431 return
|
tomwalters@0
|
432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
435
|
tomwalters@0
|
436 function activity=getactivity(peaknumber,sig,tmax,tmin,hmax,hmin,latency); % sum of activity between the adjacent minima
|
tomwalters@0
|
437 testmaxpos=tmax(peaknumber);
|
tomwalters@0
|
438 testmaxval=hmax(peaknumber);
|
tomwalters@0
|
439 [leftminpos,leftminval]=getminimumleftof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
440 [rightminpos,rightminval]=getminimumrightof(testmaxpos,tmax,tmin,hmax,hmin);
|
tomwalters@0
|
441 if isempty(leftminpos) && isempty(rightminpos) % if both are empty, its difficult
|
tomwalters@0
|
442 activity=0;
|
tomwalters@0
|
443 elseif isempty(leftminpos) % if only the left is empty, take the right instead
|
tomwalters@0
|
444 activity=0; % take the activity from the start of the signal instead
|
tomwalters@0
|
445 sr=1000/getsr(sig);
|
tomwalters@0
|
446 activity=sum(sig,latency,rightminpos)/sr;
|
tomwalters@0
|
447
|
tomwalters@0
|
448 elseif isempty(rightminpos) % if only the right is empty, take the left instead
|
tomwalters@0
|
449 activity=0;
|
tomwalters@0
|
450 else
|
tomwalters@0
|
451 sr=1000/getsr(sig);
|
tomwalters@0
|
452 activity=sum(sig,leftminpos,rightminpos)/sr;
|
tomwalters@0
|
453 end
|
tomwalters@0
|
454 return
|