This is a static copy of a profile reportHome
calcNoiseIndices (1 call, 0.219 sec)
Generated 05-Aug-2011 13:00:34 using cpu time.
function in file /home/LeechJ/cbass_analysis/reduc/calcNoiseIndices.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
34 | feat = interp1(d.array.frame.u... | 1 | 0.153 s | 70.0% |  |
149 | if (onUTC(end) < tstr2mjd('... | 1 | 0.011 s | 5.0% |  |
124 | offEndPos = cat(1,offEndPos,fi... | 1 | 0.011 s | 5.0% |  |
122 | diffOff = diff(Indoff); | 1 | 0.011 s | 5.0% |  |
84 | if onUTC(1) < tstr2mjd('15-... | 1 | 0.011 s | 5.0% |  |
All other lines | | | 0.022 s | 10.0% |  |
Totals | | | 0.219 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
interp1 | function | 1 | 0.153 s | 70.0% |  |
tstr2mjd | function | 8 | 0.022 s | 10.0% |  |
Self time (built-ins, overhead, etc.) | | | 0.044 s | 20.0% |  |
Totals | | | 0.219 s | 100% | |
Code Analyzer results
Line number | Message |
40 | The value assigned to variable 'offStartPos' might be unused. |
41 | The value assigned to variable 'onEndPos' might be unused. |
42 | The value assigned to variable 'offEndPos' might be unused. |
43 | The value assigned to variable 'onStartPos' might be unused. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 243 |
Non-code lines (comments, blank lines) | 123 |
Code lines (lines that can run) | 120 |
Code lines that did run | 68 |
Code lines that did not run | 52 |
Coverage (did run/can run) | 56.67 % |
Function listing
time calls line
1 function [off1StartPos, onEndPos, off2EndPos, onStartPos, off1EndPos, off2StartPos, N] = calcNoiseIndices(d)
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % function [off1StartPos, onEndPos, off2EndPos, onStartPos, off1EndPos,
5 % off2StartPos, N] = calcNoiseIndices(d)
6 %
7 % This function finds all the noise diode off/on times in the data
8 % structure d.
9 % Inputs:
10 % data structure d
11 % Outputs:
12 % off1StartPos: list of indices of the start of the first noise diode off events
13 % onEndPos: list of indices of the end of the noise diode on events
14 % off2EndPos: list of indices of the end of the second noise diode off events
15 % onStartPos: list of indices of the start of the noise diode on events
16 % off1EndPos: list of indices of the end of first noise diode off events
17 % off2StartPos: list of indices of the start of second noise diode off event
18 % N: number of noise diode events
19 %
20 % Created by OGK on 1 March 2011 from MAS's new code.
21 %
22 % SJCM: modified March 18, 2011 to give more outputs, make sure all the
23 % vectors are the same length -- this is used by many pipeline plotting
24 % routines and caused the crashes for the time that I was gone.
25 %
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28
29 % Is the features register on the same time scale as the receiver register?
1 30 if length(d.array.frame.features) == length(d.antenna0.receiver.utc)
31 feat = d.array.frame.features;
1 32 else
33 % Interpolate features frame onto time scale of receiver data:
0.15 1 34 feat = interp1(d.array.frame.utc,...
35 double(d.array.frame.features),d.antenna0.receiver.utc);
1 36 end
37
38
1 39 N = 0;
1 40 offStartPos = [];
1 41 onEndPos = [];
1 42 offEndPos = [];
1 43 onStartPos = [];
44
45 % Noise diode on:
1 46 if(isfield(d, 'index'))
0.01 1 47 Indon = d.index.noise.fast;
48 else
49 Indon = bitand(feat,2^10) > 0;
50 end
51
52 % Find the start/stop times
1 53 diffOn = diff(Indon);
0.01 1 54 onStartPos = find(diffOn > 0) + 1;
1 55 onEndPos = find(diffOn < 0);
56
57
58 % No noise events.
1 59 if isempty(onStartPos)
60 return
61 end
62
63
64 % Check to see if we started or stopped in the middle of an event.
1 65 if onStartPos(1) > onEndPos(1)
66 onEndPos = onEndPos(2:end);
67 end
1 68 if onStartPos(end) > onEndPos(end)
69 onEndPos = cat(1,onEndPos,length(feat));
70 end
71
72 % Check to see if the noise on events are at least one second long.
1 73 onLength = (onEndPos - onStartPos) >= 100;
1 74 onStartPos = onStartPos(onLength);
1 75 onEndPos = onEndPos(onLength);
76
1 77 onUTC = d.antenna0.receiver.utc(onStartPos);
78
79 % Prep these arrays:
1 80 offStartPos = [];
1 81 offEndPos = [];
82
83 % Before we added the 2^11 tag for the Off events.
0.01 1 84 if onUTC(1) < tstr2mjd('15-May-2010:00:00:00')
85
86 % How many such noise vents do we have?
87 nRel = sum(onUTC < tstr2mjd('15-May-2010:00:00:00'));
88
89 % Take 3 seconds before the event as the Off state.
90 offStartPos = cat(1,offStartPos,onStartPos(1:nRel) - 400);
91 offEndPos = cat(1,offEndPos,onStartPos(1:nRel) - 100);
92
93 % Check to see if the first event is OK.
94 if offStartPos(1) < 1
95
96 % No remaining noise events.
97 if length(offStartPos) < 2
98 return
99 end
100
101 onStartPos = onStartPos(2:end);
102 onEndPos = onEndPos(2:end);
103 offStartPos = offStartPos(2:end);
104 offEndPos = offEndPos(2:end);
105
106 onUTC = onUTC(2:end);
107 end
108 end
109
110
111 % Do we have any events which are after the initial dark ages?
1 112 if onUTC(end) >= tstr2mjd('15-MAY-2010:00:00:00')
113
114 % Identify the Off states in the same way as we did on the On states.
1 115 if(isfield(d, 'index'))
1 116 Indoff = d.index.noise_event.fast & ~d.index.noise.fast;
117 else
118 Indoff = bitand(feat,2^11) > 0;
119 end
120
121 % Find the start/stop times
0.01 1 122 diffOff = diff(Indoff);
1 123 offStartPos = cat(1,offStartPos,find(diffOff > 0) + 1);
0.01 1 124 offEndPos = cat(1,offEndPos,find(diffOff < 0));
125
126
127
128 % Check to see if we started or stopped in the middle of an event.
1 129 if offStartPos(1) > offEndPos(1)
130 offStartPos = cat(1,1,offStartPos);
131 end
1 132 if offStartPos(end) > offEndPos(end)
133 offEndPos = cat(1,offEndPos,length(feat));
134 end
135
136 % Check to see if the noise on events are at least one second long.
1 137 offLength = (offEndPos - offStartPos) >= 100;
1 138 offStartPos = offStartPos(offLength);
1 139 offEndPos = offEndPos(offLength);
140
141
142 % Those noise events which are preceded by a noise-off event...
1 143 if (onUTC(1) < tstr2mjd('08-SEP-2010:19:00:00')) && ...
144 (offStartPos(1) > onStartPos(1))
145 % The first noise on event is not preceded by a noise off event.
146 onStartPos = onStartPos(2:end);
147 onEndPos = onEndPos(2:end);
148 end
0.01 1 149 if (onUTC(end) < tstr2mjd('08-SEP-2010:19:00:00')) && (offStartPos(end) > onStartPos(end))
150 % The last noise off event is not followed by a noise on event.
151 offStartPos = offStartPos(1:end-1);
152 offEndPos = offEndPos(1:end-1);
153 end
154
155
156 % Do we have any events which are preceded and
157 % followed by noise-off events?
1 158 if onUTC(end) >= tstr2mjd('08-SEP-2010:19:00:00')
159
160
1 161 nOff = length(offStartPos);
1 162 nOn = length(onStartPos);
163
164 % We make arrays which tell us whether to keep or discard a given
165 % on/off event.
1 166 offUsed = zeros(nOff,1);
1 167 onUsed = zeros(nOn,1);
168
169
170 % Anything prior to the new noise event scheme is given an
171 % automatic pass.
1 172 offUsed(onUTC < tstr2mjd('08-SEP-2010:19:00:00')) = 1;
1 173 onUsed(onUTC < tstr2mjd('08-SEP-2010:19:00:00')) = 1;
174
175
176 % How many events after the new noise scheme?
1 177 nRel = sum(onUTC >= tstr2mjd('08-SEP-2010:19:00:00'));
178
179
180 % We now loop over these states and attempt to associate noise off
181 % events with each noise on event.
1 182 for k=(nOn-nRel+1):nOn
183
184 % Check that we have a preceding event:
24 185 preOff = find(abs(onStartPos(k) - offEndPos) <= 500,1,'last');
186
187 % Check that we have a following event:
24 188 postOff = find(abs(offStartPos - onEndPos(k)) <= 500,1,'first');
189
190
191 % Missing preceding or following state.
24 192 if isempty(preOff) || isempty(postOff)
193 continue;
194 % Blended off state. Split it in half.
24 195 elseif offUsed(preOff) == 1
196 midPos = floor((offStartPos(preOff) + offEndPos(preOff)) / 2);
197
198 offStartPos = cat(1,offStartPos(1:preOff),midPos+1,offStartPos(preOff+1:end));
199 offEndPos = cat(1,offEndPos(1:preOff-1),midPos,offEndPos(preOff:end));
200
201 offUsed = cat(1,offUsed(1:preOff),1,offUsed(preOff+1:end));
202
203 postOff = postOff + 1;
204 end
205
206
207 % We mark the used events as good.
24 208 offUsed(preOff) = 1;
24 209 offUsed(postOff) = 1;
24 210 onUsed(k) = 1;
24 211 end
212
213 % Any events which were not used are discarded.
1 214 onStartPos = onStartPos(onUsed == 1);
1 215 onEndPos = onEndPos(onUsed == 1);
1 216 offStartPos = offStartPos(offUsed == 1);
1 217 offEndPos = offEndPos(offUsed == 1);
218
1 219 end
220
221 % No remaining noise events.
1 222 if isempty(onStartPos)
223 return
224 end
1 225 end
226
1 227 N = length(onStartPos);
228
1 229 if(length(onStartPos) ~= length(offStartPos))
230 % case where we have off_on_off
1 231 off1StartPos = offStartPos(1:2:2*N);
1 232 off1EndPos = offEndPos(1:2:2*N);
1 233 off2StartPos = offStartPos(2:2:2*N);
1 234 off2EndPos = offEndPos(2:2:2*N);
235 else
236 off1StartPos = offStartPos;
237 off2StartPos = offStartPos;
238 off1EndPos = offEndPos;
239 off2EndPos = offEndPos;
240 end
241
242
1 243 return;