Ultra fast closed loop applications combining our actiCHamp amplifier with LabStreamingLayer (LSL)

by Dominik Dietze
Product Manager (Brain Products)

The current definition of closed loop applications are manifold. If one would like to generalize, a closed loop application is typically controlling something by interpreting an incoming physiological signal without the necessity for the investigator to actively intervene during the experiment. Translating this into the world of neurophysiology or the world of EEG, a closed loop application is typically interpreting/analyzing incoming EEG data and as a consequence of the analysis controls either Software or Hardware. A lot of BCI (Brain Computer Interfaces) applications can be considered as closed loop applications. The incoming EEG signal is interpreted, analyzed and the result is presented in the form of screen movements, letters, or even used to control an exoskeleton. A current hot topic in the neurophysiological research community are closed loop applications for brainstate dependent stimulation. Here obviously fast access or “real time access” to EEG data is the desire to precisely place the stimulation at the desired brainstate.

As you can see by reading through the two publications, the importance of fast access to the EEG data is the limiting factor to elicit the required stimulation at the exact point in time where needed. What people want to achieve is to time the stimuli at a specific part or component of the EEG Signal. To simplify it we will make an arbitrary example. In this example the goal is to place a TMS pulse at a negative peak of an alpha wave.

So what is needed?

Obviously an EEG Signal that is provided with zero or minimum delay and more importantly with as little jitter as possible. We also need a software application that can detect and identify alpha activity, positive and negative peaks in the signal and issue a Trigger with precise timing.

Let’s make some assumptions and preparatory calculations

Alpha frequency is per definition neural oscillations in the frequency range of 7.5–12.5 Hz. In the following example we will assume that the alpha frequency of our subject is at 10 Hz. At 10 Hz we have an interpeak interval of 100 ms and a duration of a negative peak of 50 ms (see Figure 1).

In order to now stimulate on a negative alpha peak one pre-requisite is to clearly identify whether it is alpha activity or not. The methods for this are for sure manifold and of different complexity. Let’s keep the example simple and stick to the method of measuring the time distance between zero crossings. Is the time distance between two zero crossings in reality enough to be certain that it is alpha, for sure not! For our example it is good enough. As we see in Figure 1 the time distance between two zero crossings is 50 ms, given that, we know now that we have oscillations in the alpha frequency band at a frequency of 10 Hz.

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 1: Idealized alpha activity at 10 Hz

The next critical thing and a science on its own in digital signal processing is the peak detection

I will not elaborate on this in our example. For this simple illustration, it is enough if we know if the zero crossing is from negative to positive or from positive to negative (see Figure 2). We of course follow the EEG convention of negative up.

In Figure 2 we see 3 zero crossings and their direction. As described before we identified the signal frequency as 10 Hz by measuring the distance between 2 zero crossings. We clearly identified a peak because one can assume that there is a peak between 2 zero crossings. Now we need to identify whether it is a positive or a negative peak. A negative peak is obviously a peak where the first zero crossing direction is from positive to negative and the second zero crossing is from negative to positive.

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 2: Zero crossings and direction

The next step is to determine the time when the Stimulus trigger should be released

As you see in Figure 3: Peak 1 can be clearly identified as negative Peak due to the zero crossings directions, furthermore it is alpha due to the time distance between the zero crossings. Now we also know the time distance for the trigger from the last zero crossing to exactly release the stimulus at the next negative peak (see also Figure 3). Our closed loop system now needs to release a Trigger pulse exactly 75 ms after the detection of the second zero crossing. This sounds easy but there are a lot more pitfalls that need to be considered. One of the biggest unknowns is the delay of data transmission.

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 3: Stimulus timing

To understand the origin of the delay we need to understand the signal processing chain of a typical EEG System

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 4: EEG signal processing chain (simplified)

As you can imagine all the processing steps take time and can therefore cause delays. Added to that the majority of EEG Systems are operated using Microsoft Windows®, a task based operating system. As a result of this we have a delay between the real physiological process (e.g. alpha oscillations) and the availability of the corresponding data for further analysis and processing. This delay is the sum of 2 components, (a) delay caused from the data acquisition system and (b) delay caused from the task based operating system. For closed loop, applications delays of category (a) are not that critical since they are constant and the application can compensate for them. Delays of category (b) are the critical ones because they are not constant and cause a variance, which is unwanted and can’t be compensated in the application. Nonetheless, for closed loop applications it is in all cases beneficial to have as little delay as possible and therefore as little shift between the real physiological processes and the corresponding measured signal.

Now let’s talk about what Brain Products can offer to support your closed loop research

We are combining our actiCHamp amplifier with the LabStreamingLayer (LSL) application. LSL is an open source tool, developed at the Schwartz Center for Computational Neuroscience at the Universtiy of California San Diego.  We have optimized the LSL actiCHamp server in a way that recorded data is written in an ultra fast fashion into the LSL data stream. This LSL data stream can be accessed from any application sitting on the same PC or from anywhere in the same network (see Figure 5). This all runs within Microsoft Windows® as we know the vast majority of our customers are used to working with a Windows® operating system.

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 5: Schematics of a LSL based closed loop arrangement

Is it out of the box? Yes and No, the data provision part – LSL Server is out of the box and can be provided. The application part, that analyses the data and derives the required actions as a result of the analysis is not standard. As already mentioned, closed loop applications are manifold and it would be impossible to cover these with a standardized approach. Therefore, we provide a simple sample application including the commented source code in C programming language. This sample application (LSL Level Trigger APP) shows how to access the LSL data stream, how to do a simple analysis for example a level trigger and how to create and send a trigger pulse via the virtual serial port of our TriggerBox.

Let’s come back to the timing

As mentioned before, delays between the real physiological process and the availability of the data is what makes closed loop applications difficult. What timings can be achieved with the presented approach? We measured the delay between a hardware generated level Trigger (real time) and a Software generated Trigger from the LSL Level Trigger App (see Figure 5). All of this was run on a Windows® based computer, which is not real time but a task based operating system.

In order to come up with statistically meaningful data we took over 3000 test measurements. The results of our tests are pretty convincing and can be seen in table 1.

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Table 1: Delays

The deviations of our measured values from the average delay are presented in a Gaussian normal distribution curve (Figure 6).

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 6: Gaussian normal distribution of measured values

What does this tell us about achievable precision for the closed loop application? According to the nature of the Gaussion normal distribution (see Figure 7) it means that we can release the stimulus trigger at a precision of ± 2 standard deviations with a 95,54 % predictability. In other words 95,54 % of our stimuli can be placed with a precision of ± 1 ms.

Ultra fast closed loop applications combining our actiCHamp amplifier with Lab Streaming Layer (LSL)

Figure 7: Standard Gaussian normal distribution

Back to our alpha activity example … let’s do some number crunching

Out of 100 Stimulation 68 Stimuli will hit the negative peak with a precision of ± 0.5 ms, from the remaining 32 Stimuli 27 will hit the negative peak with a precision of ± 1 ms. With that it is now easy to calculate the maximum stimuli phase shift for the alpha peak. 68 Stimulations will hit the target at a maximum phase shift of ± 0,031 Rad and 27 Stimulations will hit the target at a maximum phase shift of ± 0,062 Rad.

The required precision strongly depends on the desired experiment. The above describes the precision we can offer. Precision, complexity and of course costs for the hardware are directly connected. Higher precision comes with higher complexity and of course higher initial investment.

As always Brain Products’ focus concentrated on usability and value for investment

This is why we used components that are already well established like our actiCHamp and why we decided to stay with a Windows® based solution. The precision our solution delivers is good enough for the vast majority of closed loop applications. We are looking forward to working with you and to help you get your closed loop application off the ground.

Most recent articles

Want to know more? … Get in touch!
Chat
Contact form
Email
Local distributor