-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightdarkcomparison.m
More file actions
71 lines (57 loc) · 2.25 KB
/
Copy pathlightdarkcomparison.m
File metadata and controls
71 lines (57 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [activity,lux] = lightdarkcomparison(timeArray,activityArray,luxArray,lightStart,lightStop,buffer)
%LIGHTDARKCOMPARISON average values for light and dark periods
% time is in MATLAB date time series format
% activity from a Daysimeter or Dimesimeter
% lux is illuminance
% lightStart and lightStop are in hour of day
% buffer is in minutes
% Convert time to hours
hour = datenum2hour(timeArray);
% Convert buffer from minutes to hours
buffer = buffer/60;
% Chop low value illuminance to threshold of sensor
% threshold = 0.001;
% luxArray = choptothreshold(luxArray,threshold);
% Find indicies of time during light period
idxLight = hour >= lightStart + buffer & hour <= lightStop - buffer;
% Find indicies of time during dark/dim period
idxMorning = hour <= lightStart - buffer;
idxEvening = hour >= lightStop + buffer;
idxDark = idxMorning | idxEvening;
% Preallocate activity output struct
activity = struct(...
'light', {[]},...
'percentLight', {[]},...
'morning', {[]},...
'percentMorning', {[]},...
'evening', {[]},...
'percentEvening', {[]},...
'dark', {[]},...
'percentDark', {[]},...
'total', {[]},...
'ldRatio', {[]});
% Analyze activity
activity.light = mean(activityArray(idxLight));
activity.morning = mean(activityArray(idxMorning));
activity.evening = mean(activityArray(idxEvening));
activity.dark = mean(activityArray(idxDark));
activity.total = activity.light + activity.dark;
activity.percentLight = activity.light * 100 / activity.total;
activity.percentMorning = activity.morning * 100 / activity.total;
activity.percentEvening = activity.evening * 100 / activity.total;
activity.percentDark = activity.dark * 100 / activity.total;
activity.ldRatio = activity.light/activity.dark;
% Preallocate activity output struct
lux = struct(...
'light', {[]},...
'morning', {[]},...
'evening', {[]},...
'dark', {[]},...
'ldRatio', {[]});
% Analyze illuminance
lux.light = mean(luxArray(idxLight));
lux.morning = mean(luxArray(idxMorning));
lux.evening = mean(luxArray(idxEvening));
lux.dark = mean(luxArray(idxDark));
lux.ldRatio = lux.light / lux.dark;
end