sleep

Prelude

Many ideas behind the projects of this blog originate from a long time ago, from the late 80ies.
Back then, me and a couple of friends were fascinated by exploring and manipulating our still young brains. We practiced meditation, autogenic training and we experimented with lucid dreaming, hypnosis, medical plants and psychoactive substances, with the ultimate goal to reprogram our brains and our realities. Great inspiration came from the books of Timothy Leary, William Burroughs, Paul Watzlawick, Robert A. Wilson and Carlos Castaneda.
Many of this ideas were part of the then emerging neo-psychedelic subculture, that soon merged into the commercial New Age movement and the beginning techno & trance scene. But at this time we found it exciting, when in Heidelberg the "Brain-Tech" shop opened, where we could try out Mind-Machines and biofeedback devices or lie in an float tank for the first time. Even the Spiegel magazine wrote an article about that.
Mind Machines promised to achieve in a couples of minutes the same effect as years of meditation. They were basically ski-glasses with a micro controller and some LEDs, that could play various "programs", accompanied by a 8-bit soundtrack. This costed about 1500 Mark, too much for us students.
Soon our clique dispersed into the world and we studied & worked ourselves into our particular life paradigms. What's left is my interest for psychedelic technologies, that explore, modify and intensify our perception and consciousness.

The phenomenon of sleep

I was always fascinated by the phenomenon of sleep, this daily crack in the continuity of my existence and the every morning Reboot, this moment of re-assembly of the own identity and reality, before everything continues towards it's daily routine. All my life I had problems with my day-night rhythm: I had problems to fall asleep, needed a long time to get awake and clear in the morning and I rarely remembered my dreams.
I wanted an alarm clock, that doesn't simply forcibly wake me at a certain time, but helps me to awake naturally when my body is ready. Also, it should involve the whole day-night rhythm, thus the falling asleep, the sleeping and the awakening. Like an external support system for the biological clock.
One problem with alarm clocks is that they don't take into account the current sleep-phase of the sleeper. There are (4) different phases of sleep that occur in cycles during sleep and between them there are almost-awake-moments, that are said to be better suited for waking up. A reliable detection of the sleep phases involves polysomnography, a comprehensive recording and analysis of various parameters, which requires being cabled to expensive equipment and the data analyzed by experts.
Today there exist a variety of sleep-phase alarm clocks as hardware devices or as smartphone apps, that use a simplified approach called actigraphy - the measurement of body movements during sleep -  to detect almost-awake-moments.
The reliability of actigraphy in comparison to polysomnography is subject of various studies and rated from very poor to fairly good, depending on who was responsible for the study.

My private Polysomnography

I decided to give it a try and build my own sleep laboratory. It quickly became obvious, that a pillow would be the perfect container for the sensors and would also provide possibilities to embed other useful things like loudspeakers. In most sleep-phase alarms the detection of nightly movements is accomplished by acceleration- or vibration sensors, but in my tests I found, that they also respond to my partners movement lying next to me. They are apparently more oriented towards singles.
I decided to additionally use capacitive sensors that measure the proximity of the head to the sensor and that basically consist of a sheet of copper foil. The heart of the pillow is a Teensy 3.2 microcontroller, that is similar to an Arduino, but more powerful, more cheap, much smaller and with build-in capacitive sensing. Additionally I embedded an accelerometer and a piezo vibration sensor to compare and calibrate the capacitive sensor.

I also added two miniature loudspeakers, which sound surprisingly good (with a bit of equalization
to compensate for the damping of the pillow). They behave more like headphones than stereo speakers, so I can enjoy binaural tracks while falling asleep.
Btw.: An amazing source for relaxing soundscapes is the mynoise.net website & app.

First results 

Next to the bed and connected to the pillow is a RaspberryPi, that saves the data for later analysis. Here are the visualizations of the first night.
The vibration sensor (blue) is not sensible enough to be useful, the three axis accelerometer (red, green and yellow) clearly show phases of rest with moments of movement between:
The three capacitive sensors are very noisy, but they show the same phases and movements like the accelerometer. Additionally they show if the head is on the pillow at all and on which side of the pillow the head is lying. And they don't respond to the partners movement or random vibrations.

After some digital signal processing, it's pretty easy to detect if the sleeper is in the bed and to distinguish the individual sleep phases. Each night shows a slightly different sleeping pattern. The third day, a Sunday, also features two short naps.

All in all it's look promising and I will continue to explore my sleeping patterns & experiment with the different transitions between sleep & awake .

biorhythm - cymatics (3/3)

Third Dimension

In order to apply the Chladni patterns in spatial, architectural settings, we need a third dimension. For this we can simply map one of the parameters to the y-axis. Here I added y to the m-parameter, so that the pattern evolves up and forms a Chladni-volume:

#declare chladni = function(x, y, z, l, m, n) {
    cos(n * x * pi / l) * cos(m * z * pi / l) -
    cos(m * x * pi / l) * cos(n * z * pi / l)
}

#declare height = 5;
#declare bottom = 0;
#declare n = 5; 
#declare m = 4;
#declare l = 2;

isosurface {
    function {      
        abs(chladni(x, y, z, l, m+y, n)) -0.15
    }
    contained_by {
        box { <-l,bottom,-l>, <l,bottom+height,l> }     
    }       
    accuracy 0.001
    max_gradient 32    
}

Animating a thin slice along the y-axis illustrates clearly how the pattern unfolds in time and space:
Then I defined three zeroes of the function pouring out into the floors of the building.

Some visual experiments. The first one shows the complete amplitudes of the standing waves instead only the zeroes, with a second threshold inside in red:



Finally some excerpts from the early biorhythm-brochure from Nik based on the Chladni pattern:




biorhythm - cymatics (2/3)

Visualization of the Chladni figures

A simple formula for the amplitude of a standing wave for a point (x,y) on a quadratic surface with a support in the center exists :

cos(n * x * pi / l) * cos(m * z * pi / l) - 
cos(m * x * pi / l) * cos(n * z * pi / l)

with l is the length of the plate and m and n are integer factors for the various modes.
Locations where this formula evaluates (close) to zero are the areas where the sand settles and forms the Chladni pattern.

More information and background at the amazing website of Paul Bourke.

POVRay

For the visualization of the Chladni figures I used POVRay, a free 3D visualization software that achieves an amazing rendering quality by using raytracing with radiosity and photon-mapping and is capable of volume rendering.
Scenes in POVRay are  defined in a textual scene description language, similar to a programming language. POVRay is not limited to rendering polygons and surface meshes, but can also directly render various forms of mathematical formulas, like parametric and implicit surfaces.
Implicit surfaces or isosurfaces are defined by a equation f(x,y,z)=0 which means their surface is defined and rendered in space where their function evaluates to zero.
With isosurfaces we can directly render the Chladni figure in POVRay. However the node-lines are currently still infinitely thin, because only the zeroes of the function are rendered. In reality, the sand collects also on locations, where the vibrations are very soft. but not zero. Therefore I thickened the isosurface a bit by taking it's absolute value and subtracting a small constant, that controls the thickness of the nodal lines.
Here the first simple POVRay scene:

camera{ 
  orthographic
  up y 
  right x 
} 

background { rgb 1 }

#declare l = 0.4;                            
#declare n = 5; 
#declare m = 1;

isosurface {
  function {                   
    abs(cos(n*pi*x/l) * cos(m*pi*y/l) - cos(m*pi*x/l) * cos(n*pi*y/l)) -0.1
  }
  contained_by { 
    box { <-l,-l,0>, <l,l,0.1> }    
  } 
}

Now the parameters can be varied and animated. In the visualization we are not limited to integer values but can also use continous values. In the next example n=5 and m is animated between 1 and 5:


In the next post I'll show how to extend the figure into the third dimension...

biorhythm - cymatics (1/3)

Around 2005 I created a couple of visualizations and algorithmic design-patterns for my friend Nik Schweiger. Nik just founded his design label 3deluxe/biorhythm in Berlin and was working on a concept for the conversion of the Café Moskau into a multifunctional venue and recreation center.
His design subdivided the building into areas of contemplation, communication und conclusion.
The formal aesthetics, the ornamentation and the layout of the spatial organization should be deduced from the phases of the chladni figures.


Ernst Chladni invented a way to visualize the modes of vibration of a rigid plate. By drawing a violin bow over the edge of a sand-covered metal plate he made the plate resonate. At certain frequencies of resonance, the sand forms into spontaneous and symmetric patterns.



Today this is more commonly achieved with loudspeakers and a electronic frequency generators. The effect is not limited to sand but works similar with fluids or grain.



When the plate vibrates with certain frequencies, it begins to resonate - the waves running through the plate and their reflections from the edges interfere with each other - they amplify or soften each other and therefore create standing waves. Various areas of the plate vibrate in opposite directions and at the boundary lines between them, where there are no or only few vibrations, the sand particles settle and collect.


In the next post I will describe a simple method to visualize the various chladni figures in software...