Code
Back to main page: PRE2015_3_Groep4
To the input: Input
To the output: Output
Determining moment of waking up
From our measurements we've got information about the respiration during your sleep. Out of this information, we get a globel line of of the sleepphase during the night. Out of these line, we've to determine what's the best moment to wake someone between a given interval. The best moment to wake someone is just after the REM-sleep. So this is the first or second nREM-sleep stage. (see literature, add reference). In our algorithm are developed two methods which can determine which moment you've to wake someone. The first method is looking to the slope of the line. During REM-sleep, the respiration is at his highest point. So we can detect the end of the REM-phase with a declining line. (slope is negative) Another method is looking to position relative to the mean of the line. With this method, we can detect a 'good' moment when the line is under the mean of the whole night. But the mean is probably a too low value, so we've to increase the value with a factor of the variation.
However, during the REM-sleep, the respiration variates a lot (see literature, add referece), so we've to be sure that a declining line, or the position below the mean, is realy the end of the REM-sleep, and not just the variation during the REM-sleep. This can be done by detecting two or three times a declining line over two/three frames. (two/three frames is around 8/12 minutes).
In the comming days, we will test both methods before we chose the best one. Another option is to combinate the two methods. So we could call it a good moment of waking up when the line is declining and when the line is under the mean + variationfactor.
Room Brightness Control
function that calculates the brightness of sunlight based on the date/time
to-report light[day time] let psi 51.4408 ;; lat. ehv let Gsc 1367 ;; w/m2 solar constant let LC (15 * 1 - 5.4778) / 15 ;; timezone corrected longitude let c 0.21 ;; fraction of extraterrestrial sunlight that reaches ; the surface (clear weather ;; most of the following formulas are from wikipedia, they need to be verified and sourced. let Ext Gsc * (1 + 0.034 * cos(360 / 365 * (day - 2))) ;; day let theta 360 * (day - 1) / 365.242 let d 23.45 * sin(360 * (day + 10) / 365) let eqt 0.258 * cos(theta) - 7.416 * sin(theta) - 3.648 * cos(2 * theta) - 9.228 * sin(2 * theta) let w time + eqt / 60 - LC let as asin(cos((w - 12) / 24 * 360) * cos(psi) * cos(d) + sin(psi) * sin(d)) let Edv Ext * exp(- c / sin(as)) * sin(90 - as) * (max list 0 as) / as report Edv * 93;;lm/w http://physics.ucsd.edu/~tmurphy/papers/lumens-per-watt.pdf end
Temperature Control
simple model to calculate the room temperature
globals [T k h Tr Ti dT] to setup Clear-all set T T0;; input starting temperature set k -0.03 set h 0.02 set Tr 50 set Ti 12 set dT 0 reset-ticks end to Go ifelse Heater;; Heater = true when the heater is on [set dT h * (Tr - T)] [set dT 0] set T T + k * (T - Ti) + dT tick end