**3. EEG-emulated flip-flop**

A CNV flip-flop is an EEG emulation of the flip-flop digital circuit based on the contingent negative variation (CNV) event related potential (ERP). The concept of CNV flip-flop was introduced in 2005 [28].

The CNV potential [29] manifests an EEG a mental state of expectation. The CNV potential appears in an experimental procedure known as the CNV paradigm.

#### *EEG-Emulated Control Circuits for Brain-Machine Interface DOI: http://dx.doi.org/10.5772/intechopen.94373*

It is a well-known procedure (e.g., [30]) in which, in an open-loop way, a slow negative potential shift (the CNV) appears in the inter-stimulus interval of the S1- S2 stimulus pair. The negative slow potential shift is interpreted as an expectancy wave and is related to learning and memory. The classical CNV paradigm is an open-loop control system. After a stimulus S1 (visual or auditory), the brain is expecting stimulus S2 and is preparing to produce reaction R on S2. The ERP between S1 and S2 gradually develops to be a recognizable CNV. The CNV paradigm produces a ramp-like potential (the CNV) related to the pair S1-S2, but also produces a number of other evoked, cognitive, and preparatory potentials related to S1 and/or to S2.

The open-loop design for obtaining a CNV potential is given in **Figure 3**.

As **Figure 3** shows, while EEG is recorded, the user (subject) receives two sequential stimuli, by some time distance apart. The time distance between S1 and S2 (inter-stimulus interval) is fixed, 2 seconds. The time distance between S2 and next S1 (inter-trial interval) is random, 11 2 seconds. Here a three - state buffer represents a trial control, where EEG enters the CNV paradigm. After several repetitions, the subject learns that after S1 follows S2 and starts to expect it. As a result, a special event related potential (ERP) appears between S1 and S2. It is a negative shift of the EEG baseline and was named Contingent Negative Variation (CNV). If a standard ERP averaging is applied, a distinctive ramp-shape potential is visible. In the classical CNV paradigm, the goal was to show the existence of a CNV potential, so the experiment ends after CNV appears, as shown in **Figure 3**.

In 1988 a feedback loop was introduced in the classical CNV paradigm [5]. In 2005 [28] it was recognized that in such a way a CNV flip-flop is emulated by an EEG. The EEG emulated CNV flip-flop is shown in **Figure 4**.

As **Figure 4** shows, a CNV flip-flop has two binary states, like an ordinary flipflop, Q and inverse of Q (Q'). In state Q, an EEG signal is recorded as in a classical CNV paradigm, ERP is extracted after each trial, and it is tested whether the ERP is a CNV. In other words, it is tested whether the expectation *expect (S2|S1)*, is

**Figure 3.** *The classical CNV paradigm.*

**Figure 4.** *An EEG emulated CNV flip-flop.*

developed in the brain. However, as distinct to the classical CNV paradigm, once the CNV potential is recognized inside the recorded EEG, the flip-flop enters the sate no-Q (i.e., Q'). In this state the stimulus S2 is disabled. As a result, the CNV potential will degrade beyond recognition, which will trigger the reactivation of the S2 signal, and the flip-flop will enter the state Q again. The digital outputs Q and Q' here are used to control S2 but, can also be used to control other external devices.

**Figure 5** shows the block diagram of the 1988 CNV-based BCI experiment [5–8].

As can be seen from **Figure 5**, the subject generates an EEG which contains an ERP due to the stimuli S1 and S2. The EEG undergoes initial signal processing, after which the procedure of ERP extraction follows. The final CNV pattern recognition procedure tests whether the observed ERP is a CNV. Once the presence or absence of CNV is recognized, the control signal (Enable/Disable) is sent to the controlled buzzer.

The BCI procedure starts with building CNV potential in the subject by generating S1-S2 pairs of sounds. By classical conditioning, an expectation of S2, E(S2) is being built. After repetitions, which are part of the learning process, the expectation to S2 is formed in the subject's brain, and a CNV is manifested. That event, recognition of a CNV, can be used to control an external device, such as a sound generator, a robot, or something else. In the case that expectation is not built, the CNV will gradually degrade and disappear. That point, recognition of no-CNV (no expectation) event, can also be used to control an external device, in our 1988 experiment to enable the buzzer.

A standard way of building expectation is using a reaction R(S2) to stop the duration of the S2 signal, usually by pressing a button. Pressing a button is not essential, because a subject develops expectation regardless of a motor reaction [31].

Note that the subject could willingly control the process by ceasing to build expectation, i.e., by not paying attention to the S2 stimulus. But in that case, there is no adaptive interaction between the subject and BCI, and adaptive interaction is what makes this BCI interesting.

An important feature of the CNV flip flop paradigm is that it was the first bidirectional adaptive BCI, in which both the human brain and machine are engaged to adapt to each other. This paradigm was used to study adaptive behavior in adaptive learning systems [32].

Moreover, the 1988 CNV based BCI was the first to respond to the second BCI challenge, building a method for extracting an ERP beyond the classical averaging. The need for that appeared because in the CNV flip-flop paradigm the ERP is constantly changing so the classical ensemble averaging is not applicable. An adaptive filter was needed, and the following adaptive filter was implemented.

The feature extraction module extracts the Event Related Potential (ERP). Since the paradigm requests that the obtained signal be time-variant, i.e., it forms and

#### **Figure 5.**

*The first CNV-based brain-computer interface, developed in 1988. It shows a control of a buzzer using CNV potential.*

*EEG-Emulated Control Circuits for Brain-Machine Interface DOI: http://dx.doi.org/10.5772/intechopen.94373*

decays, a classical averaging technique is not suitable, so we used our own adaptive filter, namely

$$\text{ERP}(\mathbf{s}, \mathbf{t}) = \mathbf{p} \text{ERP}(\mathbf{s}, \mathbf{t} - \mathbf{1}) + \mathbf{q} \text{EEG}(\mathbf{s}, \mathbf{t}) \tag{1}$$

where.

s is the sample number in a trial (s = 1,2, … , N),

t is the trial number in an experiment (t = 1,2, … ,T), and.

p and q are weighted parameters, satisfying p + q = 1.

Several parameters are collected for the current shape of the ERP, particularly important being the regression angle and the amplitudes near S1 and S2. The pattern recognition module decides whether the current ERP can be classified as a CNV. The key parameters are the slope of the regression angle and the ERP amplitude difference near S1 and S2. In the forming phase of the CNV, three consecutive confirmation trials are needed before a CNV appearance can be acknowledged.

From a practical use of a BCI, it is important that the use of a CNV flip-flop does not require separate subject training. The mental development of an expectation state is taking place in the course of the CNV experimental paradigm. In the CNV paradigm, the subject learns to expect. S/he learns that after event S1 comes event S2, and s/he adjusts her/his mental state accordingly. The mental action produces a cognitive state "after S1 expect S2."

#### **3.1 Non-invasive BMI control of a robotic arm using a CNV flip-flop**

In 2009 a BMI was built to control a robotic arm using a CNV flip-flop [33]. The task we considered was the Tower of Hanoi puzzle with two disks, the TOH(2) task.

The Towers of Hanoi, TOH(n) task, is a well known puzzle in Computer Science [34]. It has been pointed out that the solution space has a fractal structure [35]. Given a stack of n disks with different diameters, a tower is defined as a stack of disks in which the smaller disk is always above the larger one. The task is stated as follows: given three spots, A, B, and C, if the initial tower is in the spot A, move it to the spot C, using a "buffer" tower in the spot B. At each step of the task, the concept of a tower is preserved, a smaller disk always being above a larger one. It is known that to solve the TOH(n) problem, the number of required moves of disks is 2<sup>n</sup> -1.

The BMI setup we used is shown in **Figure 6**.

The equipment used consists of a 4-channel biosignal amplifier from Biopac. The subject is connected to the biosignal amplifier with EEG electrodes placed on Cz and mastoid, while the forehead is the ground. A Windows based personal computer was used, as well as a Lynxmotion with 6-degrees-of-freedom robotic arm. We wrote the complete software in C#.

**Figure 6.** *BMI setup for control of a robot arm to solve TOH(2).*

The preprocessing part of the software shows the obtained raw EEG and considers the EOG artifacts. The ERP extraction part extracts the ERP between S1 and S2. The CNV recognition part observes when the ERP builds a recognizable CNV, as well as when the CNV decays beyond recognition, and becomes a non-specific ERP.

The CNV flip-flop recognizes series of appearances and disappearances of the CNV potential, and triggers a behavior execution part, which moves the robotic arm toward the completion of the Towers of Hanoi task.

The robot control software receives a flip-flop signal from the CNV recognition software that a CNV is not recognizable (state Q) or is recognizable (state Q'). The flip-flop activates one of the robot behaviors stored in the memory. If there are 2 disks, i.e., the task is TOH(2), there are 22 –1 = 3 behaviors stored. The behaviors 1 and 3 are activated by the state Q' and behavior 2 by the state Q. Each behavior is a trajectory to move a disk from current spot to the next, at a particular height. The sequence of behaviors is a solution of the TOH task. Behavior-based robotics [36] is a widely used approach in robot control.

**Figure 7** is a photo of the experimental setup [37].

As **Figure 7** shows, the subject having EEG and EOG electrodes, observes the progress of TOH(2) solution, as he oscillated the state of expectation it his brain.

**Figure 8** shows our graphical user interface which the experimenter observes during each trial [33].

The screen shows six rows (channels) out of which the first four are acquisition channels and the last two are mathematically computed channels. The first channel is the EEG acquisition channel, the second is the EMG acquisition from the arm pressing the button, the third is the EOG signal channel, and the fourth is the pressbutton recognition channel. The sixth channel is the event related potential extracted so far. If an appearance or disappearance of CNV is recognized on that channel, the signal is given to the robot to move and that is recorded on the fifth channel in **Figure 8**. In this case channel 6 shows a recognizable CNV potential, and that is signaled on channel 5. Note that CNV potential (expectancy state) is recognized before the EMG reaction signal is recognized.

TOH(2) requires 22 –1 = 3 moves to complete the task. To see the number of BMI trials needed for solving the TOH(2) task we carried out 4 experiments and obtained results as shown in **Table 1** [33].

The data in the **Table 1** show the trial number in which the event occurred. For example, in the first experiment, the first appearance of CNV was in trial 16, the

**Figure 7.** *Experimental setup for BMI control of a robotic arm based on a CNV flip-flop.*

*EEG-Emulated Control Circuits for Brain-Machine Interface DOI: http://dx.doi.org/10.5772/intechopen.94373*

#### **Figure 8.**

*An experiment trial of CNV flip-flop for robot control.*


#### **Table 1.**

*Experiments of using a CNV flip-flop to control a robotic arm to solve TOH(2).*

#### **Figure 9.**

*The considered TOH(3) problem to be solved by two robotic arms controlled by a CNV flip-flop.*

first CNV disappearance was in trial 22, and the second CNV appearance was in trial 26. As can be seen from **Table 1**, in each experiment, the two-disk Towers of Hanoi task was executed successfully within 30 trials, using this brain-machine interface.

#### **3.2 Non-invasive BMI control of two robotic arms using a CNV flip-flop**

The next BMI task considered using a CNV flip flop in a BMI setup was collaboration of two robot arms in solving the Tower of Hanoi problem with three disks, TOH(3). The task is depicted in **Figure 9** [38].

The approach is the following: Robot1 is activated by a CNV appearance event and Robot2 is activated by a CNV disappearance event. Both robots have predefined behaviors. Robots and their behaviors are triggered by a brain state recognition

system, which recognizes the existence and non-existence of the brain expectancy state represented by the CNV potential.

If the height of a particular disk is denoted with a number between 1 and 3 (height 1 being the bottom), the needed sequence of robot behaviors can be defined as: A3toC1, A2toB1, C1toB2, A1to C1, B2 to A1, B1 to C2, A1 to C3. Let us note that an artificial Intelligence program was previously written for solving the general TOH(n) problem [39], where from the knowledge was used to solve this TOH(3) problem.

Once the problem is decomposed into a sequence of robot behaviors, the CNV flip-flop generates an oscillatory process that will drive the two robots with corresponding behaviors. Robot1 behaviors are activated whenever the ERP shapes into a CNV, while Robot2 behaviors are activated whenever the ERP loses its CNV shape.

In order to solve the TOH(3) task the number of moves is 2<sup>3</sup> –1 = 7. The research hypothesis for the experimental investigation is that healthy subjects will be able to carry out the oscillatory expectancy process in the brain long enough to solve the TOH(3) problem. The subject should produce the appearance of the CNV four times and the disappearance of the CNV three times. It is assumed that the TOH(3) task gives enough achievement motivation for completing the task.

The experimental setup consists of an EEG-event recognition part and a robot behavior execution part. The event recognition part recognizes the appearance/ disappearance of the brain state of expectation, while the behavior execution part activates the controlled devices.

The two controlled robotic arms and the Towers of Hanoi disk set are shown in a photo in **Figure 10** [38].

Each robot is controlled by a servo controller connected to the computer by a USB-to-COM cable.

The subject is sitting and observing his/her progress toward the solution of the TOH(3) task, which gives a motivation for achievement. The EEG electrodes are placed on Cz and mastoid, while the forehead is the ground. A personal computer receives the signals and processes them. A Biopac four-channel biosignal amplifier receives the biosignal information from the subject. A USB cable connects the biosignal amplifier to the computer.

**Figure 11** shows the BMI experiment screen [38].

As **Figure 11** shows, a raw EEG is recorded in channel 1, and EMG and EOG channels are recorded in channel 2 and 3. Channel 4 shows the recognized EMG and

**Figure 10.** *Experimental setup, two robotic arms and the TOH(3) disk set.*

#### **Figure 11.**

*The BMI experiment screen. An experimental trial. A developed CNV potential, triggers a behavior in one of the two robots.*


#### **Table 2.**

*Results of experiments of controlling two cooperating robots by a CNV flip-flop.*

channel 5 the recognized CNV signal which is sent to execute Behavior 1 in Robot1. Channel 6 shows the current ERP which is recognized as CNV.

**Table 2** shows results of 12 experiments [38].

As **Table 2** shows all the experiments were successful. A human user developed her/his CNV potential in average in the 14th trial, lost it in average in the 22nd trial and so on. The task is completed in average 60 trials of a CNV flip-flop paradigm.
