How lack of sleep turned my vision red (or: combating insomnia with science)

If, like me, you tend to suffer from sleeplessness you will know it can be exhausting; being awake until the early morning, knowing the number of hours until the alarm buzzes is rapidly decreasing. Staying up late and waking up late might seem like a solution, but it only gets more exhausting. As it turns out, knowing the role a hormone named melatonin plays in your natural wake-sleep cycle enables you to take action to change some of your habits to induce better, more and healthier sleep.

Now, melatonin is the opposite of adrenaline. The latter has an effect of making you more aware, short-cutting the rational mind and switching back to your pre-historic instincts. Melatonin, however, is a hormone produced by the pineal gland somewhere in the middle of your brain and leads to calmness and sleepiness.

Normally, the production and re-uptake of melatonin is synchronous with sunset and sunrise. When the sun rises, the blue and to a lesser degree the green light (or more precisely, light with a wavelength above 530nm) on your retina will inhibit the production of melatonin. In the absence of such light, melatonin is produced and makes one sleepy.

Delayed inhibitation

Now, it is not as simple as stated above of course. For one, melatonin is produced from serotonin, a neurotransmitter that is associated with mood. Depression is caused by a lack of serotonin (in many cases because the serotonin re-uptake is too active or due to a lack of physical activity during the day), so it is no surprise that both insomnia and depression go hand in hand.

Some people also have a delayed inhibition, either by some internal cause but usually due to external light. Especially within IT, people tend to stay up late and sit behind their laptop screens. And guess what, these emit the green light inhibiting the production of melatonin!

Reprogramming the brain

There are various methods one could utilize to help the brain stay in sync with the day and night outside. In many countries, melatonin supplements can be bought (over the counter or in higher dosage with a prescription). Since melatonin is a hormone produced by the body, it is relatively safe to take synthesized melatonin from these supplements.

While these can be very effective (I have found very positive effects with a dosage of 3mg, although off-the-shelf dosage is usually around 0.1mg), there has been very little study regarding the long-term effects. Given that the role in the circadian rhythm is just one of many for melatonin, it might be wise to exercise some caution.

Reprogram your brain

A better and more natural way of resetting your biological rhythm is to pay attention to the light in your environment. This starts in the morning (yes, waking up properly is an important condition for a good nights rest). When you wake up, stare outside for 5 to 10 minutes and get a good dose of green light. This will reset your pineal gland, and stop the production of melatonin.

In winter, it might still be dark when you get up. In that case, you might want to consider getting a full-spectrum lamp, or at least a lamp that has as significant amount of greens and blues in its spectrum. Fluorescent lighting might also do the trick, but be aware that these normally produce very narrow spikes in the visible spectrum on the green, blue and red wavelengths and might therefore be less effective.

Software to make you sleep better

In the evening, a good start is to do the inverse: dim the light, use incandescent light which tends to lack greens and blues. But also take a look at your computer or laptop screen. This is a very rich source of green and blue light, so staying up late behind your laptop will inhibit the onset of melatonin production and delay your sleepiness.

One, quite ridiculous, suggestion is to stop working on your laptop an hour before you plan to get to sleep. I know, it’s heretic. Luckily, we can be a bit smarter about it by simply reducing the green and blue emitted from the screen!

Until recently I used the compiz compositing window manager for the sole reason that it let’s me apply a rendering function to my screen. Rendering functions are transformations applied within your graphics card that combine the red, green, blue and alpha value your software draws on the screen into the output you see.

Compiz has a ‘color filter’ plugin, which can be used to apply a rendering filter. I wrote a simple rendering function (in GPU assembly) that averages the red, green and blue channels and then writes this average to the red channel (leaving the blue and green channel dark). This has the effect of making your desktop monochrome, like a black-and-white tv but with red light instead of white.

This worked wonders. Next to dimming the roomlights in the evening, switching to this red view had a great effect on my ability to fall asleep.

But, recently I switched to xmonad; is a much more rudimentary and efficient window manager. It does support compositing somewhat, but only for useless effects such as transparent terminal backgrounds.

After discussing the matter at my hackerspace, I was put onto the path forward. To start with, one can use gamma correction to color-shift the image on the screen. This is a tedious process though, and getting it right requires some insight in how gamma-values actually influence color.

Luckily, there is software that takes care of all of that. The first I tried was f.lux, but it wasn’t optimal. For one, it was not open source, you could only get a binary. But more annoying, I tend to have at least 2 monitors and f.lux only works on one. So while my laptop screen would redshift, my external screen wouldn’t and the effect would be ruined.

But a bit of additional research led me to redshift. This is open-source and available in most linux distributions (for eg., apt-get install redshift in debian, or apt-get install gtk-redshift to get the applet as well).

I start it after I log in to an X session聽 (a windows version is available as well) and tell it where I am (by specifying latitude and longitude). It then knows when sunset and sunrise take place, and starts shifting the color of my display in small steps towards less green and blue and more red in the evening and back to the normal whiteness again in the morning.

Note that your phone also is a source of melatonin-production-inhibiting light. If, like me, you tend to check some rss feeds and maybe twitter in bed before you close your eyes, consider using something to redshift your phone display in the evening. Personally, I use an android phone with Cyanogenmod. This aftermarket firmware for your android phone already contains something called ‘rendering effects’. I placed a widget on my home screen that lets me choose between normal and ‘monochrome red’.

Good night, sleep well

The body is an intriguing complex of interacting processes, and while the above tends to work out really well it is not the panacea of sleep problems. There are many other interactions that may interfere with your ability to get a good healthy night of sleep.

For example, depression is known to cause a lack of serotonin and therefore may lead to decreased melatonin production. However, an unhealthy sleep rhythm (not in sync with planetary movement) has again a catalytic effect on depression.

I found that the above techniques (look into the light in the morning, redshift in the evening) greatly increased my ability to sleep at the right times and long enough, and be awake during the day without having to rely on stimulants. I feel more energetic and migraine has become a rare event as opposed to a weekly recurring disaster.

Your mileage may, of course, vary. But just give it a try. And let me know!

Ps: if you use caffeine to wake up in the morning or stay up late, disregard the above entirely; your circadian rhythm is too fucked up and the effects of my advice will likely be unnoticeable.

Flattr this

3 Responses to “How lack of sleep turned my vision red (or: combating insomnia with science)”

  1. Jos Says:

    Great tip! I’ve installed redshift straight away. I do not see a direct need, but i’ll try it for fun. I’m using it like this:
    redshift -l 52:6

  2. loupgaroublond Says:

    Kinda weird that you had issues with flux not working on both screens. I’ve been using that four different systems on three different OSes and i haven’t had a single issue with it (other than it’s closed source). It also really helps with the eyestrain, it has this uncanny ability to kick in right when my eyes are getting tired. Curiously enough, that’s when the sun sets too. I do drink copious amounts of caffeine but i still notice a difference if i follow that advice in how well i sleep. It makes a difference even if you’re not fully conscious of it.

  3. Jeee Says:

    http://www.startbreakingfree.com/961/how-i-learned-to-live-with-dsps/

Leave a Reply