Software Logic

I’m not going into great detail about the system coding here (Unity and C# by the way), I’m just presenting the broad structure. 

Start Up

The first step is to open the Ganglion ready for package collection.  SInce I only have one Ganglion, I have hard-coded the serial number. 

The user then chooses between two button options for the session, a Calibration session or a Motor Imagery session.  I’ll look at calibration later but let’s start with the choice of Motor Imagery.  The current Calibration File is read in and stored in an array to be used as a measure of background activity band power for each electrode at each frequency. This is also displayed on the User Interface screen. With the headwear in place, and impedances having been checked using the OpenBCI GUI, the user then clicks the Start Stream button to begin the session. 

Once Start Stream has been clicked, the prompting function is also set in motion.  It will start with a Centre prompt, both displaying and speaking the prompt with an instruction to imagine stillness, and then continually displaying this for a random number of seconds  before switching to the next prompt, Left or Right.  The range of seconds at time of writing is set to between 5 and 10 but this is a variable which may be adjusted to give shorter or longer prompt durations.

Package Collection and Processing

A package of data from the Ganglion is then requested and, when complete, it is processed as follows.

  • Apply a Notch Filter using the BrainFlow software to eliminate the 50Hz (in the UK) signal distortion due to mains power supply.
  • Reduce signal noise using the BrainFlow software.
  • Calculate the band power at each electrode at the two frequency ranges mu (8Hz to 13Hz) and beta (14Hz to 30Hz) and store these numbers in an array. BrainFlow software again.

Remove Unrealistic Values

The band powers are then processed to get rid of unlikely values.  This process involves judgement and so has parameters that can be altered.

The band powers are considered as pairs, left and right hemisphere at each frequency band, because it is the change in this balance with differing prompts that we are trying to identify.  We have to identify any pairs where the relative values are unrealistic so that the measured balance is not skewed. 

The first check is whether each value in the pair is valid before we look to the balance between left and right sides.  This is done by setting a pair of parameters as tolerance levels, one is for mu and the other for beta. These are used for checking the band power against the calibration value.  For example, if the band power is much higher or much lower than the calibration value, this may be a blip.  The mu and beta frequencies are given their own tolerance values. Pairs with a power outside these limits are rejected.

An adjusted band power for each electrode at each frequency is then calculated using the calibration value. The ratio between left and right is clamped to a reasonable range to avoid jumping.  These adjusted band powers for each pair are then turned into percentages. Left and right add up to 100% but the higher band power, left or right, has the higher percentage.

Update the User Interface

Tables on the screen are updated to show running values for each pair, C3/C4 and P3/P4, at each frequency band.  The size of the blue circles on the screen is adjusted to represent the percentage of the band power at each frequency on each side. The objective of the user is to use these circles as feedback for their imagery.  Because of ERD (which is explained on the Session Logs page) we should see the size of the circle on the opposite side to the prompt reduce in size.  For example, my current technique is that when the prompt says imagine movement on the right hand side of the body, I imagine squeezing the circle on the left with my right hand, like a tennis ball, to shrink its size because it should be getting smaller representing less power in the left motor cortex at the frequency band being measured.

The processing then looks at the adjusted band powers and works out a Lateralisation Index. That sounds technical, but it simply shows whether the left or right side of the brain was more suppressed in the mu and beta frequency ranges.

Next, a suppression ratio (ERD) is calculated for every channel. Values below 1.0 mean the rhythm was suppressed compared to baseline, values above 1.0 mean it rebounded.

All of this is written into the Packet Log (see Session Logs page). If suppression is detected on the correct side for the prompt, the system records a success.

Get the Next Packet

That’s it.  We then go back and get the next packet from the Ganglion.   

Calibration Session

The calibration process is similar to the imagery logic described above.  The main differences are :

  • The subject imagines stillness throughout.
  • The band powers at the end of the DataFlow processing are the values used as calibration data.
  • The median value of this band power at each electrode/frequency of all the packets processed so far is calculated.
  • The session does not have a fixed time.  The subject stops the stream when they judge the values to have stabilised.
  • The median value of all samples taken in the session is written as eight numbers to the Calibration file.  This will be used for Imagery sessions that follow.