IntoMindLearn

Chapter 3 · Middle school

Signal and noise

Is everything an electrode picks up coming from your brain? And how can you tell when a difference is real?

Signals that aren't from the brain

Your brain's signal at the scalp is tiny, a few millionths of a volt. Your eyes make much bigger electrical signals, so every blink shows up in EEG as a big, slow bump.

A signal in a recording that doesn't come from the brain is called an artifact.

Simulated Eyes open, and three blinks, recorded at the forehead, where blinks are largest. Each one is a slow bump many times bigger than the brain's own rhythms.

Your muscles make big signals too. Clenching your jaw, talking or moving your head all show up in EEG as fast, spiky activity on top of the brain's.

Everything in a measurement that isn't what you want to measure is called noise. When you measure alpha, a blink or a clenched jaw is noise.

Simulated Eyes closed, with alpha's steady rhythm, and the jaw clenched for a second: fast muscle activity on top of it.

Try it

What moves the number

One wearer per group, with the IntoMind One on and connected to the Alpha Flower demo, as in the lab. The skeptic calls each action for ten seconds, with ten seconds of stillness before it. The recorder writes down the number before and during each one.

Blink once a second with your eyes open. Then close your eyes, and with them closed: clench your jaw, then talk, then turn your head.

PredictThe action that will change the number most is .

ActionBeforeDuringUp, down or the same?
Blinking, eyes open
Clenching the jaw, eyes closed
Talking, eyes closed
Turning the head, eyes closed

You should seeMost actions lower the number, some much more than others.

Measure more than once

Every measurement wobbles a little, for many small reasons: how the electrodes touch the skin, a thought, a breath. That is why scientists measure more than once.

If a difference shows up every time, it is probably real. If it shows up only once, it could be luck. When the numbers overlap, you can't tell.

Simulated Five people's alpha numbers, three tries with eyes open and three with eyes closed. For four of them, closed is higher every time. For E, the tries overlap.

Try it

Your numbers, every time

Use your record sheet from Alpha Flower. Write down the lowest and highest of each wearer's eyes-open numbers, and of their eyes-closed numbers. Then put every wearer's numbers on the class's dot plot.

WearerOpen, lowestOpen, highestClosed, lowestClosed, highestDo they overlap?
1
2
3
4

You should seeFor most wearers, eyes closed higher every time. For some, the numbers overlap, and the difference can't be told from the wobble.

Talk about it

  1. What is an artifact? Give two examples.

  2. Which action changed the number most? Why might it?

  3. Why is one measurement not enough to be sure?

Chapter 3 · High school

Signal and noise

What else does an electrode pick up besides your brain, and how do you tell a real difference from the noise?

Eyes and muscles

An artifact is a signal from outside the brain. The eyes act like small batteries, so a blink or an eye movement makes a large, slow wave, mostly below 4 hertz, largest at the front of the head.

Muscles, in the jaw, the forehead and the neck, make fast, spiky activity, strongest above 20 hertz. Moving shifts the electrodes on the skin. And mains electricity can add a hum at 50 or 60 hertz, which the IntoMind One's filters remove.

Simulated Eyes open, and three blinks, recorded at the forehead, where blinks are largest: slow bumps many times bigger than the brain's own rhythms.

In a spectrum, a clenched jaw lifts everything from about 20 hertz up. Everything in a measurement that isn't what you want to measure is noise, so for alpha's share, both blinks and muscles are noise.

Simulated The spectrum with the eyes open, in gray, and with the eyes closed and the jaw clenched, in orange: muscle lifts everything above about 20 hertz, on top of alpha.

Try it

What moves the number

On the Alpha Flower demo, as in the lab. The wearer sits still with eyes open until the number is steady, then blinks once a second for ten seconds. Then the wearer closes their eyes until the number is steady again, and the skeptic calls one action at a time, for ten seconds each, with ten seconds of stillness between: clenching the jaw, talking, turning the head. The recorder writes down the number before and during each.

PredictThe action that will lower the number most is , because .

ActionBeforeDuringChange
Blinking, eyes open
Clenching the jaw, eyes closed
Talking, eyes closed
Turning the head, eyes closed

You should seeMost actions lower the number, some much more than others.

Contact

Contact matters as much as any artifact. An electrode resting on hair instead of skin picks up less of the brain and more of everything else.

Parting the hair under each electrode, and pressing the IntoMind One down until it feels firm but not tight, improves contact. It matters most for thick, coarse or curly hair, where it may still not be enough. A weak signal is a limit of the method, not of the person.

Contact The IntoMind One's electrodes are on its underside. Resting on hair, they are held off the skin. With the hair parted under each one, they rest on skin.

Try it

Contact

With the wearer's eyes closed and still, note the number with the IntoMind One fitted carefully, hair parted. Then rest it lightly, without parting the hair, and note it again. Then fit it carefully again.

WearerFitted carefullyResting lightlyFitted again
1
2
3
4

You should seeA lower, less steady number when it rests lightly, for some wearers far more than others.

Measure more than once

Random noise shrinks when you average. The average of N measurements varies about the square root of N times less than one measurement does: four times as many measurements halve the spread.

That is why the Age Detector averages many four-second windows, and why a fair test of a model uses many readings.

Simulated Thirty averages of noisy measurements of the same value, taken one at a time, and four, sixteen and sixty-four at a time. The spread halves each time.

Try it

Averaging, in a spreadsheet

Make a column of 6,400 noisy measurements of a true value of 40: =40+40*(RAND()-0.5). In the next columns, take averages of 4, 16 and 64 measurements at a time, a hundred of each, with AVERAGE. Then find how much each set varies, with STDEV.

Measurements averagedHow much the averages vary
1
4
16
64

You should seeThe spread halving each time the number averaged goes up four times.

Talk about it

  1. Blinks lowered alpha's share, and so did clenching. Explain each with frequencies.

  2. To halve the noise in an average, how many more measurements do you need? Why?

  3. Careful fitting mattered more for some people. What does that mean for comparing people?

Sources

Goncharova, I. I., McFarland, D. J., Vaughan, T. M., and Wolpaw, J. R. (2003). EMG contamination of EEG: spectral and topographical characteristics. Clinical Neurophysiology.

Etienne, A., and others (2020). Novel electrodes for reliable EEG recordings on coarse and curly hair. Annual International Conference of the IEEE Engineering in Medicine and Biology Society.

Chapter 3 · College

Signal and noise

What else is in an EEG recording besides the brain, how do you recognize each kind by its spectrum, and when do you avoid it, reject it or correct it?

Signal, noise, and their ratio

Noise is everything in a measurement that isn't what you want. The signal-to-noise ratio divides the power of what you want by the power of everything else in the same band, often in decibels, 10 log10 of the ratio.

What counts as signal depends on the question. For alpha, it is the rhythm against the rest of the 4 to 30 hertz band. For a flickering light, as in the BCI Flight Simulator, it is the power at the flicker's rate against the power just beside it.

Simulated Four seconds from the back of the head: two blinks with the eyes open, then the eyes close and alpha rises, then the jaw clenches and fast muscle activity covers everything.

Artifacts and their signatures

An artifact is a signal from something other than the brain. Each common one has a signature in time, in frequency and on the head.

ArtifactWhere it comes fromIn the spectrumWhere it is largest
Blinks and eye movementsThe eye is a dipole, front positive, and the eyelid moves over itLarge and slow, mostly below 4 hertzAt the front of the head
MuscleThe jaw, forehead, scalp and neck musclesBroad, rising above about 20 hertzOver the muscle: the temples, forehead and neck
Electrode movementAn electrode shifting on the skin, or losing contactSteps and slow driftsAt that electrode, or every channel if it is the reference
Line noiseMains electricity in the roomA narrow peak at 50 or 60 hertz and its harmonicsEvery channel, worst with poor contact

The IntoMind One filters on the device as shipped, with narrow notches at both mains frequencies and their harmonics, so in its recordings line noise shows as dips rather than peaks.

Muscle is the hardest: it overlaps the brain's own fast rhythms, and a share or a band power can change between conditions because the muscles did.

Simulated The spectrum with the eyes open, and with the eyes closed and the jaw clenched: muscle lifts everything above about 20 hertz, on top of alpha, washed.

Contact, and averaging

The IntoMind One's electrodes are dry, so contact depends on parting the hair and pressing down. A noisy channel almost always means poor contact at that electrode, and every channel noisy at once means the reference.

Noise that is independent from one measurement to the next shrinks when you average: the spread of a mean of N falls as 1/√N. Averaging can't remove what repeats, such as a blink in every trial.

Drawn to explain Electrodes resting on hair are held off the skin, and pick up less of the brain and more noise. Parted, each touches skin.

Artifacts in a spectrum

Try it

Four recordings

With the IntoMind One on the forehead, over Fpz, record twenty seconds each: at rest with the eyes open, blinking every two seconds, clenching the jaw for a second in every three, and reading a sentence aloud, over and over. Then plot their spectra on the same axes, in decibels.

cd python
python3 record_and_export.py --seconds 20 --label rest
python3 record_and_export.py --seconds 20 --label blinks
python3 record_and_export.py --seconds 20 --label jaw
python3 record_and_export.py --seconds 20 --label talking
import numpy as np
import mne
import matplotlib.pyplot as plt
from scipy.signal import welch

for label in ("rest", "blinks", "jaw", "talking"):
    # the path each recording's program printed
    raw = mne.io.read_raw_bdf(f"{label}.bdf", preload=True, verbose="error")
    fs = raw.info["sfreq"]
    x = raw.get_data(picks="eeg") * 1e6          # microvolts
    f, p = welch(x, fs=fs, nperseg=int(2 * fs))
    plt.plot(f, 10 * np.log10(p.mean(axis=0)), label=label)
plt.xlim(1, 150)
plt.xlabel("hertz")
plt.ylabel("decibels, against 1 µV² per hertz")
plt.legend()
plt.show()

You should seeBlinks lifting the lowest frequencies, the jaw lifting everything above about 20 hertz, and talking doing both. Dips at the mains frequency and its harmonics, where the device's notches take out line noise.

Avoid, reject or correct

Avoiding an artifact, with clear instructions, a good fit and a quiet room, costs least. Detecting contaminated windows, by amplitude or by power in a band where the brain has little, and rejecting them, costs data, and can bias a comparison if one condition loses more. Correcting them, for example by independent component analysis, separates sources by their statistics, which needs many more channels than four and makes assumptions you should check.

Whatever you choose, report it: how many windows each condition lost, and why.

Problems

  1. Alpha's share rises in one condition. Which artifacts could produce that without any change in alpha, and how would you check?

  2. When would you reject contaminated windows rather than correct them?

  3. A flicker's rate shows four times the power of the frequencies just beside it. What is that signal-to-noise ratio in decibels?

  4. To halve the noise in an average, how many more windows do you need? What can't averaging remove?

  5. All four channels turn noisy at once. What is the likeliest cause, and the fix?

Sources

Goncharova, I. I., McFarland, D. J., Vaughan, T. M., and Wolpaw, J. R. (2003). EMG contamination of EEG: spectral and topographical characteristics. Clinical Neurophysiology.

Urigüen, J. A., and Garcia-Zapirain, B. (2015). EEG artifact removal: state-of-the-art and guidelines. Journal of Neural Engineering.

Chapter 3 · Graduate

Signal and noise

What else is in a scalp recording, how do you tell it from the brain, and what does each correction cost?

The noise floor

With its inputs shorted, the IntoMind One's converter adds 0.14 µV root mean square at 250 samples a second. On a head, the floor is set by the contact. A source resistance R adds thermal noise of √(4kTRB) over a bandwidth B, and the junction of skin and electrode adds more, mostly at low frequencies, and more again when it moves. Dry electrodes meet the skin with no gel, at higher and less stable impedance than wet ones, and with more sensitivity to movement and to hair (Lopez-Gordo, Sanchez-Morillo and Pelayo Valle, 2014).

Mains power couples into the body as a voltage common to every electrode. The amplifier rejects what is common to its inputs, but unequal contact impedances turn part of it into a difference: roughly the common voltage times the impedances' difference over the amplifier's common-mode input impedance (Huhta and Webster, 1973). Metting van Rijn, Peper and Grimbergen (1990) treat how to reduce it. With dry contacts the mismatch is large, which is why the device notches out the mains by default.

Artifacts and their signatures

SourceSignatureWhere it is largest
Blinks and eye movementsLarge and slow: the eye is a dipole, cornea positive, and it moves with the lids and the gaze.Near the eyes, falling toward the back.
Saccadic spike potentialA brief broadband transient at the start of each saccade, microsaccades included, which passes for induced gamma (Yuval-Greenberg and others, 2008).Near the eyes and the temples.
MuscleBroadband from about 20 hertz up. Under neuromuscular blockade, scalp power above 20 hertz fell 10- to 200-fold (Whitham and others, 2007).Over the jaw, the temples, the forehead and the neck.
HeartThe electrocardiogram at about once a second, and the pulse moving an electrode.Over arteries, such as at the temples, and with references low on the head.
Movement and contactSteps, drifts and bursts as an electrode shifts on the skin.Wherever contact is poorest.
Skin and sweatVery slow drifts as the skin's potential changes.Anywhere, more in warm rooms.
Mains50 or 60 hertz and their harmonics.Wherever contacts are unequal.

Filters and their costs

The IntoMind One filters on the device, and the stream carries only the result. By default the chain is a high-pass at 0.5 hertz, notches four hertz wide at 48 to 52, 58 to 62, 98 to 102, 118 to 122, 148 to 152 and 178 to 182 hertz, each nulled at its middle and run as two sections, and a low-pass at four tenths of the rate, 200 hertz at 500 a second. The chain can be read, changed or cleared, and a report states the one in force.

Every filter changes the signal it passes, as well as removing what it is meant to. A high-pass removes slow potentials and leaves a deflection of the opposite sign when they end (Acunzo, MacKenzie and van Rossum, 2012). Inappropriate high-pass filters have produced effects that were not in the data (Tanner, Morgan-Short and Luck, 2015). Causal filters delay, zero-phase filters spread an event backward in time, and a notch rings after a step (Widmann, Schröger and Maess, 2015). The filter follows the question: what has to survive it.

What four channels rule out

Independent component analysis separates at most as many sources as there are channels (Jung and others, 2000). Four channels close together can't separate the eyes, the muscles, the heart and the brain, and regressing out the eyes needs a channel that records them. What is left is to design the recording so artifacts are rare, and to detect, reject and count what remains.

An artifact that follows the condition is worse than one that doesn't, since it becomes the signal. Blinks are fewer with the eyes closed, muscles tense with effort, and the eyes move toward what is attended. A decoder trained on two states that differ in any of these can learn the artifact.

Analysis

Analysis

What filters cost, and what a detector finds

First, put a 20 µV shift lasting one second through a high-pass at 0.5 hertz, causal and zero-phase, and a 50 µV step through the 58 to 62 hertz notch. The device's high-pass order isn't stated, so a second-order Butterworth stands in for it.

import numpy as np
from scipy.signal import butter, iirnotch, lfilter, filtfilt, sosfilt, sosfiltfilt

fs = 500
t = np.arange(0, 6, 1 / fs)
slow = 20.0 * ((t >= 2) & (t < 3))            # a 20 uV shift lasting one second
blip = np.zeros_like(t); blip[t >= 4.5] = 50.0  # a 50 uV step, as when an electrode shifts

# A stand-in for the device's 0.5 Hz high-pass: second-order Butterworth.
hp = butter(2, 0.5, "highpass", fs=fs, output="sos")
causal, zero_phase = sosfilt(hp, slow), sosfiltfilt(hp, slow)
at = lambda x, s: x[int(s * fs)]
for when, s in (("0.5 s before it begins", 1.5), ("0.9 s into the shift", 2.9),
                ("just after it ends", 3.02), ("0.5 s after it ends", 3.5)):
    print(f"{when:24s} causal {at(causal, s):5.1f} uV   zero-phase {at(zero_phase, s):5.1f} uV")

# The 58 to 62 Hz band, nulled at 60 Hz, run as two sections: how long a step makes it ring.
b, a = iirnotch(60, 60 / 4, fs=fs)
rung = lfilter(b, a, lfilter(b, a, blip)) - blip
tail = np.abs(rung[t >= 4.5])
last = np.nonzero(tail > 0.01 * 50)[0].max() / fs
print(f"the notch rings for {1000 * last:.0f} ms after the step, above 1% of its size")

You should seeThe causal filter undoes the shift within a second, overshooting to −3.6 µV, and when it ends drops to −21.1 µV, a deflection that was never in the signal. The zero-phase filter keeps more of it, 7.3 µV, and shows −1.8 µV half a second before it begins. The notch rings for about 100 milliseconds after the step.

Then flag the Alpha Flower forehead recordings in 1-second windows, for blinks by their peak-to-peak size and for muscle by their power from 30 to 45 hertz, and check the flags against the blinks the analyst wrote down. Change the thresholds and watch both kinds of error.

import numpy as np
import mne
from scipy.signal import welch

def flags(path, ptp_uv=100, z=5):
    """Each 1-s window flagged for a blink (peak to peak) or for muscle (30 to 45 Hz power)."""
    raw = mne.io.read_raw_bdf(path, preload=True, verbose="error")
    fs = int(raw.info["sfreq"])
    x = 1e6 * raw.get_data(picks="eeg")
    w = x[:, : x.shape[1] // fs * fs].reshape(x.shape[0], -1, fs)   # channels, windows, samples
    ptp = np.ptp(w, axis=2).max(axis=0)
    f, p = welch(w, fs=fs, nperseg=fs // 2, axis=2)
    high = p[:, :, (f >= 30) & (f < 45)].mean(axis=2).max(axis=0)
    mad = np.median(np.abs(high - np.median(high)))
    return ptp > ptp_uv, high > np.median(high) + z * 1.4826 * mad, w, fs

def compare(flagged, marks, slack=1):
    """Marks with a flagged window within `slack` s, marks missed, flagged windows unmarked."""
    hit = [m for m in marks if flagged[max(0, int(m) - slack):int(m) + slack + 1].any()]
    near = np.zeros(len(flagged), bool)
    for m in marks:
        near[max(0, int(m) - slack):int(m) + slack + 1] = True
    return len(hit), len(marks) - len(hit), int((flagged & ~near).sum())

blink, muscle, w, fs = flags("w1-fpz.bdf")      # the path the program printed
marks = [3.5, 9, 15.5, 21, 27, 33.5, 40]        # the analyst's blink times from the sheet
found, missed, unmarked = compare(blink, marks)
print(f"{blink.sum()} windows flagged for blinks, {muscle.sum()} for muscle, of {len(blink)}")
print(f"marks found {found}, missed {missed}; flagged windows with no mark near {unmarked}")

def share(seg):
    f, p = welch(seg, fs=fs, nperseg=2 * fs)
    band = lambda lo, hi: p[:, (f >= lo) & (f < hi)].sum(axis=1)
    return float(np.mean(band(8, 13) / band(4, 30)))

keep = ~(blink | muscle)
for name, block in (("open", slice(3, 45)), ("closed", slice(48, 90))):
    every = np.concatenate(list(w[:, block].transpose(1, 0, 2)), axis=1)
    kept = np.concatenate([w[:, i] for i in range(len(keep))[block] if keep[i]], axis=1)
    print(f"{name}: share {share(every):.3f} with every window, "
          f"{share(kept):.3f} without the flagged")

Open problems

  1. Gamma from the scalp. Most scalp power above 20 hertz is muscle (Whitham and others, 2007), and induced gamma can be eye movement (Yuval-Greenberg and others, 2008). Separating neural gamma without many channels and an eye tracker is unsolved.
  2. Contact for everyone. Electrodes struggle through thick, coarse and curly hair, and EEG research has excluded people with such hair, by design or by neglect (Choy, Baker and Stavropoulos, 2022). Electrodes and methods that work equally well for every head are an open engineering problem.
  3. Cleaning with few channels. Methods that repair rather than reject, such as artifact subspace reconstruction (Mullen and others, 2015), rely on clean calibration data and redundancy across channels. With four channels close together, the best practice is unsettled.

Problems

  1. An electrode contact of 500 kΩ at 310 K: what thermal noise does it add between 0.5 and 100 hertz? Compare it with the converter's 0.14 µV.

  2. 10 mV of mains sits on the body. The two contacts are 200 and 300 kΩ, and the amplifier's common-mode input impedance is 1 GΩ. About how much mains appears in the channel? And with a mismatch of 1 MΩ?

  3. In the analysis, why does the end of the shift produce a large deflection of the opposite sign through the causal high-pass?

  4. A study reports more 40-hertz power from 200 to 300 milliseconds after pictures appear, at frontal sites. What could produce it besides the brain, and what control would rule each out?

  5. In the Mind-Controlled Light Switch, a wearer teaches Off as resting and On as clenching a fist, and the head scores well. What might it have learned, and how would you find out?

Sources

Huhta, J. C., and Webster, J. G. (1973). 60-Hz interference in electrocardiography. IEEE Transactions on Biomedical Engineering.

Metting van Rijn, A. C., Peper, A., and Grimbergen, C. A. (1990). High-quality recording of bioelectric events. Part 1: interference reduction, theory and practice. Medical and Biological Engineering and Computing.

Jung, T.-P., and others (2000). Removing electroencephalographic artifacts by blind source separation. Psychophysiology.

Whitham, E. M., and others (2007). Scalp electrical recording during paralysis: quantitative evidence that EEG frequencies above 20 Hz are contaminated by EMG. Clinical Neurophysiology.

Yuval-Greenberg, S., Tomer, O., Keren, A. S., Nelken, I., and Deouell, L. Y. (2008). Transient induced gamma-band response in EEG as a manifestation of miniature saccades. Neuron.

Acunzo, D. J., MacKenzie, G., and van Rossum, M. C. W. (2012). Systematic biases in early ERP and ERF components as a result of high-pass filtering. Journal of Neuroscience Methods.

Lopez-Gordo, M. A., Sanchez-Morillo, D., and Pelayo Valle, F. (2014). Dry EEG electrodes. Sensors.

Mullen, T. R., and others (2015). Real-time neuroimaging and cognitive monitoring using wearable dry EEG. IEEE Transactions on Biomedical Engineering.

Tanner, D., Morgan-Short, K., and Luck, S. J. (2015). How inappropriate high-pass filters can produce artifactual effects and incorrect conclusions in ERP studies of language and cognition. Psychophysiology.

Widmann, A., Schröger, E., and Maess, B. (2015). Digital filter design for electrophysiological data: a practical approach. Journal of Neuroscience Methods.

Choy, T., Baker, E., and Stavropoulos, K. (2022). Systemic racism in EEG research: considerations and potential solutions. Affective Science.