Project A: The SSVEP speller
Boxes flicker at different rates; the back of your head flickers with whichever one you look at. A decoder reads the frequency out of the EEG and types the letter. Works in an afternoon, and it is the BCI that actually works.
On this pageOne afternoon to a demo, a week to a speller
Stare at a square flashing ten times a second and your visual cortex oscillates at ten hertz, strongly enough that a single electrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry at the back of the head shows a clean peak in the spectrumSpectrum A plot of how much of a signal lives at each frequency. Related: Fast Fourier transform (FFT)Fast Fourier transform (FFT) The algorithm that breaks a stretch of signal into the sinusoids that would add up to it, giving amplitude and phase at each frequency. , Power spectral density (PSD)Power spectral density (PSD) The spectrum expressed as power per hertz, the standard way to quantify how strong alpha is. . Glossary entry within two seconds. Put four squares on the screen at four different rates, decide which rate the EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry contains, and you have a four-way selector. Arrange letters behind the squares and you have a speller. The steady-state visual evoked potentialSteady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum. Related: Canonical correlation analysis (CCA)Canonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder., Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer.. Glossary entry is the most reliable non-invasive BCIBrain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. Related: DecoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. , Closed loopClosed loop A system in which the output feeds back to influence the input, such as a user adjusting their brain activity while watching the cursor it controls. . Glossary entry paradigm, it needs no training, and it works for nearly everyone with working eyes.
- Click different boxes and watch how long the decoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. , Kalman filterKalman filter An estimator that blends a prediction from a motion model with a noisy measurement, weighting each by how much it trusts it; the decoder behind most intracortical cursor control. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry takes to follow. That lag is the window length.
- Lower the SSVEPSteady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum. Related: Canonical correlation analysis (CCA)Canonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry strength until the decoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. , Kalman filterKalman filter An estimator that blends a prediction from a motion model with a noisy measurement, weighting each by how much it trusts it; the decoder behind most intracortical cursor control. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry starts making mistakes. Real people vary this much.
- Note that the decoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. , Kalman filterKalman filter An estimator that blends a prediction from a motion model with a noisy measurement, weighting each by how much it trusts it; the decoder behind most intracortical cursor control. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry’s score for the true frequency includes its second harmonic. Real SSVEPSteady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum. Related: Canonical correlation analysis (CCA)Canonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry has harmonics too.
Your monitor refreshes at 60 Hz. Which set of flicker frequencies can it display exactly?
Only frequencies that divide 60 evenly, because the screen can only change on a refresh. 10 Hz is on for three frames and off for three. 8.57 Hz (60/7) is on for three or four frames alternately, which still works. 9 Hz cannot be shown steadily on a 60 Hz screen and the actual stimulus will smear across nearby frequencies. This is the first practical constraint every SSVEPSteady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum. Related: Canonical correlation analysis (CCA)Canonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry designer meets.
The signal
The response sits at the flicker frequency and its harmonics, over occipital electrodesElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry (Oz strongest, O1 and O2 next). Amplitude is a few microvolts, which is small, but it is a pure tone, and pure tones are what spectra find best. Two to four seconds of data is enough to decide among four to eight frequencies for most people.
The decoder
Canonical correlation analysisCanonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder. Related: Steady-state visual evoked potential (SSVEP)Steady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum.. Glossary entry is the standard. For each candidate frequency, build reference signals: sine and cosine at f, at 2f, and at 3f. Find the combination of EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry channels that correlates most with the combination of those references. The frequency with the highest correlation wins. With one channel it reduces to fitting the references by least squares and comparing the fit, which is what the simulator does. With several occipital channels the multichannel version is meaningfully better.
import numpy as np
from sklearn.cross_decomposition import CCA
def refs(f, fs, n, harmonics=3):
t = np.arange(n) / fs
return np.column_stack([g(2*np.pi*h*f*t) for h in range(1, harmonics+1) for g in (np.sin, np.cos)])
def decode(X, freqs, fs): # X: samples × channels, a 2–4 s window
scores = []
for f in freqs:
cca = CCA(n_components=1).fit(X, refs(f, fs, len(X)))
u, v = cca.transform(X, refs(f, fs, len(X)))
scores.append(np.corrcoef(u[:, 0], v[:, 0])[0, 1])
return freqs[int(np.argmax(scores))], scores
The stimulus
PsychoPyPsychoPy Free Python software for presenting stimuli with precise timing and logging responses. Related: Lab Streaming Layer (LSL)Lab Streaming Layer (LSL) A protocol that timestamps and synchronizes streams from many devices and stimulus programs on a network; every BCI lab uses it. . Glossary entry, full screen, black background, four to eight white squares each toggling on a fixed frame schedule, with a letter or word under each. Push an LSLLab Streaming Layer (LSL) A protocol that timestamps and synchronizes streams from many devices and stimulus programs on a network; every BCI lab uses it. Related: PsychoPyPsychoPy Free Python software for presenting stimuli with precise timing and logging responses. , BrainFlowBrainFlow A library that talks to OpenBCI and most consumer EEG headsets with one API, in Python and other languages. . Glossary entry marker whenever the layout changes. Frame-locked toggling is the whole trick; do it inside the flip loop, never with timers.
The speller
A four-target selector spells slowly. The classic layout is a tree: four squares each holding a group of letters; look at a group to select it, then the letters in that group spread across the four squares, then select the letter. Two selections per character, about eight seconds each with a comfortable window: a character every fifteen to twenty seconds. Slow, and it works on the first try for most people, which no other paradigm can say.
Measure and report two numbers: accuracy (fraction of selections correct) and information transfer rateBrain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. Related: DecoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter., Closed loopClosed loop A system in which the output feeds back to influence the input, such as a user adjusting their brain activity while watching the cursor it controls.. Glossary entry in bits per minute, which combines accuracy, number of targets, and speed into one figure that lets you compare against the literature. The classification explainer has the formula.
- Set up the LSLLab Streaming Layer (LSL) A protocol that timestamps and synchronizes streams from many devices and stimulus programs on a network; every BCI lab uses it. Related: PsychoPyPsychoPy Free Python software for presenting stimuli with precise timing and logging responses. , BrainFlowBrainFlow A library that talks to OpenBCI and most consumer EEG headsets with one API, in Python and other languages. . Glossary entry pipeline from Phase 2: EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry stream, marker stream, LabRecorder.
- Write the PsychoPyPsychoPy Free Python software for presenting stimuli with precise timing and logging responses. Related: Lab Streaming Layer (LSL)Lab Streaming Layer (LSL) A protocol that timestamps and synchronizes streams from many devices and stimulus programs on a network; every BCI lab uses it. . Glossary entry stimulus with four frequencies from the divisors of your refresh rate (6, 7.5, 10, 12 Hz is a good set). Verify the flicker rates with a photodiode on a spare channel; the spectrumSpectrum A plot of how much of a signal lives at each frequency. Related: Fast Fourier transform (FFT)Fast Fourier transform (FFT) The algorithm that breaks a stretch of signal into the sinusoids that would add up to it, giving amplitude and phase at each frequency. , Power spectral density (PSD)Power spectral density (PSD) The spectrum expressed as power per hertz, the standard way to quantify how strong alpha is. . Glossary entry of the photodiode channel should show a sharp line at each frequency.
- Record yourself looking at each square for ten seconds in turn. Plot the Oz spectrumSpectrum A plot of how much of a signal lives at each frequency. Related: Fast Fourier transform (FFT)Fast Fourier transform (FFT) The algorithm that breaks a stretch of signal into the sinusoids that would add up to it, giving amplitude and phase at each frequency. , Power spectral density (PSD)Power spectral density (PSD) The spectrum expressed as power per hertz, the standard way to quantify how strong alpha is. . Glossary entry for each. The peak should move.
- Implement the CCACanonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder. Related: Steady-state visual evoked potential (SSVEP)Steady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum. . Glossary entry decoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. , Kalman filterKalman filter An estimator that blends a prediction from a motion model with a noisy measurement, weighting each by how much it trusts it; the decoder behind most intracortical cursor control. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry and run it offline on the recording with two-second windows. Report accuracy per window.
- Close the loop: decode live, highlight the winning square. Tune the window length for the best speed-accuracy trade for you.
- Build the two-level letter tree. Spell your name. Time it. Compute accuracy and ITR.
- Test on two friends (with the photosensitivity screening and under your lab’s protocol). Note how much the SSVEPSteady-state visual evoked potential (SSVEP) When you stare at something flickering at a fixed rate, visual cortex oscillates at that rate, and the frequency can be read straight out of the EEG spectrum. Related: Canonical correlation analysis (CCA)Canonical correlation analysis (CCA) Finding the combination of channels that correlates best with reference sinusoids at each candidate frequency; the standard SSVEP decoder. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry amplitude varies between people.