Jan 272016

With new graphing tools available in the Physiology Viewer 2.0, previous recordings can be reexamined and studied in more detail.

September 10, 2015 was the 5th day of a 7-day sesshin (meditation retreat) at Tahoma Monastery. At the end of the day, after the last round of formal meditation, I recorded my brainwaves, as I did each day of the retreat.

Below is a graph that was derived from an EEG recording of fifteen minutes of meditation. It shows signal power for beta and gamma frequency bands measured at the left front sensor.

absolute power - full session


We note that for a period of about 400 seconds near the beginning, there is a gradual and relatively uniform increase in beta and gamma power. Let us focus on a region of interest, the interval from 50-450 seconds.

We replot the graph for the region of interest and then label two sub-regions, each two minutes long, “first 2 min” and “4 min later”. The purpose of this is simply to have an earlier and a later region to compare.

absolute power - zoomed in

Characteristics of the two intervals can also be compared by examining the two radar charts below.  In these charts, absolute band power for all four sensors is included.


The signal at the left front sensor is of particular interest as it shows a significant increase in beta and gamma power. The Physiology Viewer, shown below provides new ways of examining the data. In particular, a spectrogram and a Power Spectral Density (PSD) graph are part of the suite data visualization tools.

Physiology Viewer 2.0


We have chosen to identify two 120-second intervals with the names “zazen – first 2 min” and “zazen – 4 min later”. Selecting these individual intervals allows us to examine the EEG signal in more detail.

A spectrogram is a graph of frequency vs. time. Frequency is plotted on the vertical axis and time along the x-axis.

We select the Spectrogram for the left front sensor (lf) during the entire session. The result is a frequency vs. time graph where the intensity of each frequency is indicated by color. Here, yellow indicates greater intensity than blue. The associated color bar serves as a legend.


Note that during the “first 2 min” interval, there is less yellow in the frequency range from 12-50Hz (and hence, less power in the beta and gamma bands) than there is during the “4 min later” interval.

In addition, a horizontal yellow band runs through the entire session at a frequency value of about 8 Hz. This is in the alpha band. It will be readily apparent when we view these data using PSD graphs.

Note: Regarding the ‘vertical bands’ in the spectrogram, see a later post, Correlations of brain waves with respiration cycle.

Power Spectral Density (PSD) Graph

The PSD graph displays a spectrum of the signal. Frequency (Hz) is plotted on the horizontal axis and intensity of the signal (dB/Hz) on the vertical axis. The graphs below show the spectral composition of the two selected intervals with frequency bands indicated in color.

PSD - first 2 min

PSD - 4 min later

We see clearly how the beta and gamma intensity have increased over the course of a few minutes. While there are several peaks in the beta and gamma bands, it is unclear at this time whether a given peak is characteristic of an individual over a long time, as the alpha peak seems to be, or whether different individuals display commonly identifiable peaks.


Jan 272016

This post is directed to programmers who are interested in seeing the code I’ve written to display graphs. Others may want to skip ahead.

The Physiology Viewer program has undergone a reorganization that makes it faster and more stable. In addition, there are two new features for visualizing signals in the frequency domain: spectrograms and graphs of power spectral density (PSD). Finally, it is now possible to overlay the breath signal over a spectrogram, which provides a new tool for investigating the correlation between brain waves and breath.

Physiology Viewer 2.0 Main tab

The combo box just beneath the title is used to select a particular recording. The text box displays comments referring to that recording.

There are up to four lines to the right of the text box indicating which kind of data was recorded and at what sampling rate (EEG, heart, breath and button press).

The check boxes to the right of Time Series, d, t, a, b, g correspond to the frequency bands delta, theta, alpha, beta and gamma. Data can be displayed either as absolute band power or relative. Median or mean values can be superimposed on the graph as desired.

Check boxes p and v refer to respiration (pressure) and electrocardiogram (voltage) signals. The check box s refers to input from a button device ( a custom current probe connected to the LabQuest logging device).

The letters c and m represent the Concentration and Mellow values that are automatically computed from a Muse proprietary algorithm. Since we don’t know what this algorithm is, I have not used it in my research, but have made it available in case we want to compare our results with these functions later.

Check boxes j and k are used to indicate jaw clench and eye blink events, which are detected by the Muse headband. Jaw clench and eye blinks may be a useful way for subjects to indicate internal mental states.

On the right-hand side is a graphic representing the subject’s head (nose facing upward, ears to the side). The four radio buttons surrounding the head graphic are used to select the sensor of interest.

Clicking on the Display button brings up a graph or chart corresponding to current selection of Time Series, Spectrogram, PSD vs. frequency, Raw EEG, Radar Chart and Table. Checking the Overlay breath check box next to Spectrogram brings up a spectrogram with the breath signal superimposed. The dropdown list box next to Table provides options for mean, median, standard deviation and mean combined with standard deviation.

The rows beneath Intervals, t_initial and t_final can be used to assign arbitrary names to time intervals within the session. Any region of interest can be named. The Save button must be clicked to save these data into the Excel workbook, EEG_CardioRespSessions.xls.

Below is an example of a spectrogram for an interval of zazen which shows the typical alpha signal around 8 Hz and an unusually strong signal in the beta band.


Below is the PSD spectrum for the same interval, showing the beta peak to be centered around 28 Hz.

PSD showing unusually strong beta peak

Both spectrograms and PSD graphs use the Fast Fourier Transform (FFT) algorithm operating upon sequential series of 1024 samples within the time series data. Spectrograms are generated using the specgram() function in the matplotlib library.

Our PSD graphs are generated using the psd() function from the matplotlib library. It uses Welch’s method with NFFT=1024, noverlap=512, the default ‘hanning’ window and a sampling rate of 220 samples/s. Color patches were added using the add_patch method of figure subplots.

The Physiology Viewer, written in Python 3.4 and is available at


Jun 162015

In September 2014 I enrolled in an online course Exploring Neural Data offered by Brown University via coursera.org. The basic premise of the course was that students would be able to access data coming from various neuroscience labs around the country and learn techniques for analyzing that data, forming hypotheses and testing them. Participation in the course required learning the Python programming language. It sounded like an opportunity I couldn’t pass up. I had already completed two coursera online courses, Duke University’s Medical Neuroscience and Hebrew University of Jerusalem’s Synapses, Neurons and Brains, which gave me a bit of orientation to neuroscience (my background is physics and astronomy). I also discovered some good online tutorials on Python, so I could start familiarizing myself with a new language.

The final project for the Exploring Neural Data course was to apply some of our programming skills to a new data set. I chose to collect respiration and and electrocardiogram (ECG) data for subjects during meditation and reading. I chose to develop a new application I called the Cardiorespiratory Viewer. Written in Python, using the Anaconda Spyder programming environment, it imports program modules from the Tkinter, numpy, scipy and matplotlib libraries. The application reads data files generated by the LabQuest recorder, displays simultaneous plots of EKG voltage and breath pressure, and enables the user to specify time segments and signal threshold levels for analysis.

Cardiorespiratory Viewer

Program for displaying and analyzing ECG and respiration signals

PDF for final project, Exploratory Investigation of Cardiorespiratory System during Meditation