|
| 1 | +function runLsBL=calcBedLgc(aktFull,timeFull,lenAktFilt,lenLieFilt,VLongSitBt) |
1 | 2 | % CALCBEDLGC Calculate bedtime logic using by filtering the activities |
2 | 3 | % |
3 | 4 | % %% Inputs %%%%%%%%%%%%%%%%% |
|
8 | 9 | % VLongSitBt - very long sit bouts to consider for bedtime filtering (4*3600 default) |
9 | 10 | % |
10 | 11 | % %% Outputs%%%%%%%%%%%%%%%%%%%% |
11 | | -% bedLgc [double-n] - A logical vector given at 1s epoch representing bedtime status |
| 12 | +% runLsBL {4 x1} - the run-length-encoded bedTime logic |
| 13 | +% runLsBL{1}= [m x1] type of bedtime: 1-primary, 2-extra, 0-nobedtime |
| 14 | +% runLsBL{2}= [m x1] run length (seconds) |
| 15 | +% runLsBL{3}= [m x1] start index of each run |
| 16 | +% runLsBL{4}= [m x1] end index of each run |
12 | 17 | % |
13 | 18 | % Copyright (c) 2021, Pasan Hettiarachchi . |
14 | 19 | % All rights reserved. |
|
36 | 41 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
37 | 42 | % POSSIBILITY OF SUCH DAMAGE. |
38 | 43 |
|
39 | | - |
40 | | -function [bedLgc,bedFlags]=calcBedLgc(aktFull,timeFull,lenAktFilt,lenLieFilt,VLongSitBt) |
41 | | - |
42 | | - |
43 | 44 | MinLieBt=3600; % minimum lying bout to consider for bedtime expanding |
44 | 45 | MinSitBt=7200; % try to connect sit bouts longer than this to adjacent lying or very-long sit bouts |
45 | 46 |
|
|
176 | 177 | end |
177 | 178 |
|
178 | 179 |
|
179 | | -%do a run-length-decoding and return the betime logical vector |
180 | | -bedLgc=rle(runLsBL); |
| 180 | + |
181 | 181 |
|
182 | 182 | %% scan through the full days to select primary bedtimes. |
183 | | -runLsBL=rle(bedLgc); % re-do the run-length-encoding (because we changed the encoding above) |
| 183 | +runLsBL=rle(rle(runLsBL)); % re-do the run-length-encoding (because we changed the encoding above) |
184 | 184 |
|
185 | | -startDay=dateshift(timeFull(1),'start','day'); % if the day starts dayStartMx hours or later starting day is next day, otherwise start day is today |
186 | | -endDay=dateshift(timeFull(end),'start','day'); % if the day ends dayEndMin or earlier last day is last-calander day, otherwise last-day is previous day |
| 185 | +startDay=dateshift(timeFull(1),'start','day'); % the start day |
| 186 | +endDay=dateshift(timeFull(end),'start','day'); % the last day |
187 | 187 |
|
188 | 188 | selDays=startDay:endDay; |
189 | 189 |
|
|
245 | 245 | end |
246 | 246 | end |
247 | 247 |
|
248 | | -bedFlags=[bedFlags,selScore,prod(selScore,2)]; |
| 248 | +runLsBL{1}(runLsBL{1}==1)=bedFlags; |
249 | 249 |
|
250 | 250 | % remove low scoring bedtimes from run-length-encoding |
251 | 251 | % runLsBL{1}(selBedtms(indDel))=0; |
|
0 commit comments