This is a static copy of a profile reportHome
smooth>moving (30 calls, 0.404 sec)
Generated 05-Aug-2011 13:03:50 using cpu time.
subfunction in file /home/LeechJ/cbass_analysis/matutils/smooth.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
smooth | function | 30 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
213 | c = filter(ones(width,1)/width... | 30 | 0.175 s | 43.2% |  |
209 | xreps = any(diff(x)==0); | 30 | 0.087 s | 21.6% |  |
218 | c = [cbegin;c(width:end);cend]... | 30 | 0.077 s | 18.9% |  |
204 | ynan = isnan(y); | 30 | 0.022 s | 5.4% |  |
215 | cbegin = cbegin(1:2:end)./(1:2... | 30 | 0.011 s | 2.7% |  |
All other lines | | | 0.033 s | 8.1% |  |
Totals | | | 0.404 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 54 |
Non-code lines (comments, blank lines) | 6 |
Code lines (lines that can run) | 48 |
Code lines that did run | 14 |
Code lines that did not run | 34 |
Coverage (did run/can run) | 29.17 % |
Function listing
time calls line
201 function c = moving(x,y, span)
202 % moving average of the data.
203
0.02 30 204 ynan = isnan(y);
30 205 span = floor(span);
30 206 n = length(y);
30 207 span = min(span,n);
30 208 width = span-1+mod(span,2); % force it to be odd
0.09 30 209 xreps = any(diff(x)==0);
30 210 if width==1 && ~xreps && ~any(ynan), c = y; return; end
30 211 if ~xreps && ~any(ynan)
212 % simplest method for most common case
0.17 30 213 c = filter(ones(width,1)/width,1,y);
30 214 cbegin = cumsum(y(1:width-2));
0.01 30 215 cbegin = cbegin(1:2:end)./(1:2:(width-2))';
30 216 cend = cumsum(y(n:-1:n-width+3));
30 217 cend = cend(end:-2:1)./(width-2:-2:1)';
0.08 30 218 c = [cbegin;c(width:end);cend];
219 elseif ~xreps
220 % with no x repeats, can take ratio of two smoothed sequences
221 yy = y;
222 yy(ynan) = 0;
223 nn = double(~ynan);
224 ynum = moving(x,yy,span);
225 yden = moving(x,nn,span);
226 c = ynum ./ yden;
227 else
228 % with some x repeats, loop
229 notnan = ~ynan;
230 yy = y;
231 yy(ynan) = 0;
232 c = zeros(n,1);
233 for i=1:n
234 if i>1 && x(i)==x(i-1)
235 c(i) = c(i-1);
236 continue;
237 end
238 R = i; % find rightmost value with same x
239 while(R<n && x(R+1)==x(R))
240 R = R+1;
241 end
242 hf = ceil(max(0,(span - (R-i+1))/2)); % need this many more on each side
243 hf = min(min(hf,(i-1)), (n-R));
244 L = i-hf; % find leftmost point needed
245 while(L>1 && x(L)==x(L-1))
246 L = L-1;
247 end
248 R = R+hf; % find rightmost point needed
249 while(R<n && x(R)==x(R+1))
250 R = R+1;
251 end
252 c(i) = sum(yy(L:R)) / sum(notnan(L:R));
253 end
254 end
Other subfunctions in this file are not included in this listing.