Output
Back to main page: PRE2015_3_Groep4
To the input: Input
To the code: Code
Overview
The script called "OutputFunc_V3.m" controls the output of the system, which consists of making sounds and turning on lights. It has gone through several changes, with different versions having different pros and cons. This script is version 3, hence the suffix "_V3", and is the first and only script with an acceptable runtime, but previous versions would have been preferred if certain tasks didn't take so much time to complete. Nevertheless, version 3 does a very good job. We've looked at different possibilities for producing sounds. Ideally, we would have connected a speaker to the Arduino, because then it would potentially be able to do all the work, without the aid of a laptop. However, that would require programming the unit in C++, in which most of us are inexperienced, and the Arduino has very limited memory space, so therefor it had been decided to use Matlab and the laptop's speaker instead. The Arduino is used to produce light, though, with added on LEDs. The sound files used for the smart alarm and the standard alarm are "Birds-singing-in-the-morning.mp3" and "Loud-alarm-clock-sound.wav" respectively, both of which have been downloaded from http://www.orangefreesounds.com/. The sound of the smart alarm can be customized by copying a sound file of your own choice to the folder containing the script and changing the filename of the smart alarm, "Alarm1", in "runscript.m". The script is capable of running with sound files of all sizes, but users are advised to use files that aren't too long, because it greatly influences the runtime of the script. The audio of "Birds-singing-in-the-morning.mp3" is about 15 minutes long, so the script is guaranteed to work with sound files of 15 minutes long or less. The standard alarm could be customized in the same manner. However, the script doesn't take into account how long the audio is and just repeats it a number of times. The script could have been altered so that it could handle sound files of different sizes, but that would increase the complexity of the code a lot, which we didn't consider to be worth the trouble. After all, it doesn't seem likely to us that the user would wish to customize the standard alarm. The audio of "Loud-alarm-clock-sound.wav" is 11 seconds long, so if you really want to, you could use another audio file of about the same size instead. Longer sound files should work as well, but we haven't tested the limits, so we can't give any guarantees.
The output script is initiated when "Complete_script.m" finds a suitable moment to wake up its user. The script is a function with 6 parameters: a connection with the Arduino, the name of the pin that controls the LEDs, the file names of the smart and standard alarm, the moment the user must be awake (the moment the standard alarm is used as a last resort to wake up the user) and finally a vector containing the number of seconds in a second, a minute, an hour, a day, a month and a year, which is used to translate the time and date into seconds. First of all, the script stops the measuring of sound, because the Arduino can't send and receive data at the same time. Then both sound files are translated into sound samples "y1" and "y2", which are lists of numbers between -1 and 1, and sample frequencies "Fs1" and "Fs2" which indicate how many samples need to be played per second to create the proper sound. Afterwards, the maximal sound and light intensities, "Smax" and "Lmax", are calculated using a file called "Feedback.mat". If this file doesn't exist yet, it's created and the maximal intensities are set to their defaults, which is 3 in both cases. For the light this means a maximal Arduino pin voltage of 3 V. If the maximal intensities are calculated with the feedback file, it is checked whether these values are within their boundaries, which is between 1 and 5 in both cases. If not, the value is set to 1 or 5 and the user is notified that a boundary has been reached. The minimal value is 1 so that the sound/light is still audible/visible. The maximal value of the light intensity is 5 because the Arduino has a maximal output voltage of 5 V. There is no particular reason why the maximal sound volume is 5, but it seemed appropriate. The sound samples are multiplied with "Smax" to adjust their amplitude and with that the volume of the sound output. The first set of samples of the smart alarm, however, are scaled in such a way that during the first 5 minutes that the alarm is being played, the volume gradually increases from complete silence to maximal volume in order to wake up the user as lightly as possible. Every second while the volume is increasing, the voltage on the LEDs is increased as well, from 0 Volts to "Lmax" Volts. Contrary to the sound volume, this increase is quadratic instead of linear, as the relation between voltage and light intensity isn't linear. We don't know what the relation is exactly, but the increase in light intensity seems to be quite linear now, so we decided to keep it like this. The smart alarm keeps playing and is, if necessary, repeated until the user presses a button on the keyboard or until the standard alarm jumps into action. The standard alarm is at most played 10 times in a row while waiting for the user to press a button. Allowing it to be repeated indefinitely would have made the script much more complex, and we assumed anyone would have woken up during those 10 times, so we decided not to invest extra effort in that cause. When the user presses a button, the sound stops and the lights are shut off. Afterwards, the user is given the opportunity to provide feedback about the sound and light intensity seperately. The feedback is given as a number between 1 and 5, with 1 meaning "Too soft/dim", 2 meaning "Soft/dim", 3 meaning "OK", 4 meaning "Loud/bright" and 5 meaning "Too loud/bright" (although you technically could also pick decimal numbers between 1 and 5). This number is subtracted from the number 3, so 1, 2, 3, 4 and 5 turns into 2, 1, 0, -1 and -2, and the result is saved in "Feedback.mat" together with the value of "Smax" or "Lmax" during that night. At the beginning of the following night, the new values for the maximal intensities are calculated by taking the mean of the sum of the value of "Smax" or "Lmax" and the corresponding feedback number. So picking numbers 1 or 2 as feedback would increase the maximal intensity and 4 and 5 would decrease it, while the number 3 makes it stay the same. To make sure the size of "Feedback.mat" wouldn't grow indefinitely, and to make more recent feedback more important than older ones, the file has a size limit of 5 nights. So if this limit is passed, the oldest night is deleted from the file. And that's all you need to know about the script and how it works.
Description of the sound and light output
The sound and light are both two different output value’s that act separately. The sound is divided into two different audio files. On file is the sound of birds singing in the morning and the other one is the sound of an alarm clock. When the sound starts, it begins very softly with the sound of the birds singing in the morning. In the beginning, it’s barely hearable but over time, the volume becomes higher. This is because the sound is not supposed to wake you instantly, but gradually. The idea is that you are able to get used to the presence of sound before it wakes you up. When after a certain amount of time, you still didn’t wake up from the sound and therefore did not turn the alarm off, the second sound will start. This is the sound of an alarm clock as we all know it. It’s played at full volume to guarantee that you will wake up. This is not the nicest way to wake up because it will be very ‘sudden’, but it’s better than waking up too late.
The light output works in a similar way. Human beings have a natural clock build in our systems that reacts on the amount of light there is from the sun. In the early times, people did not have an alarm clock and had to wake up naturally. This was achieved by the light emitted by the sun. So that’s why we use a light pattern that’s similar to the sun’s sunrise. It’s not an exact match but it comes pretty close within the boundaries of the technology we use. The light starts at the same time as the sound does. Also, the light starts very minimally. When the sound output becomes the sound of an alarm clock, the light is also at its maximum.
After you have woken up there is the ability to give feedback to the system. With this feedback, you are able to calibrate how you want to have your light and sound input. For instance, the sound can be too loud too fast if this is the case you are able to adjust that so that next night the sound will take longer to gain in volume. If done right, it would be possible to wake up on exactly the right time in a nice way. The feedback system works as follows: You will have the opportunity to rate the output from 1-5. With 1 being too low and 5 being too loud/bright. The system then changes this for the next night. When entered 1 it will make sure that the light or sound will take higher values after a smaller amount of time, and the other way around if a 5 is given as feedback. When the feedback is 3, the output will act in the same way the next night.