Project C: Motor imagery
Imagine moving your left hand or your right. A classifier tries to tell which from rhythms over motor cortex. Months of work, subject-dependent, and the project that teaches you why BCI is not solved.
On this pageMonths, on and off
When you move your right hand, the mu rhythmSensorimotor rhythm (mu) An 8 to 13 Hz rhythm over motor cortex that weakens when you move, or imagine moving, the corresponding body part. Related: Motor imageryMotor imagery Imagining a movement without making it, which changes rhythms over motor cortex in a way a classifier can sometimes detect., Event-related desynchronization (ERD)Event-related desynchronization (ERD) The drop in rhythmic power over a cortical area when it becomes active, such as mu weakening when you imagine moving your hand.. Glossary entry over the left motor cortex drops. When you imagine moving it vividly, it drops too, less. A classifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. Related: Linear discriminant analysis (LDA)Linear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. , Support vector machine (SVM)Support vector machine (SVM) A classifier that finds the boundary with the widest margin between classes; strong on small datasets. , Cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. . Glossary entry trained on the pattern of mu and beta power across 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 over motor cortex can, for most people, tell left from right imagery better than chance. That is motor imageryMotor imagery Imagining a movement without making it, which changes rhythms over motor cortex in a way a classifier can sometimes detect. Related: Sensorimotor rhythm (mu)Sensorimotor rhythm (mu) An 8 to 13 Hz rhythm over motor cortex that weakens when you move, or imagine moving, the corresponding body part., Event-related desynchronization (ERD)Event-related desynchronization (ERD) The drop in rhythmic power over a cortical area when it becomes active, such as mu weakening when you imagine moving your hand., BCI inefficiencyBCI inefficiency The finding that around one in five people cannot control a motor-imagery BCI even after training; once called "BCI illiteracy," a label the field is retiring.. Glossary entry, the paradigm behind wheelchair and cursor demos, and it is marked humbling on this site because it is: accuracies are modest, they vary enormously between people, they drift between days, and about one person in five cannot do it at all. Doing this project well means finding all of that out for yourself and reporting it honestly.
You collect 40 trials of left and 40 of right imagery and your classifier gets 62 percent. Is it working?
Probably not. With 80 trials and two classes, chance produces accuracies up to about 61 percent one time in twenty just by luck (the binomial 95 percent upper bound). 62 is barely above that. You would need around 70 percent on 80 trials, or 62 percent on 400 trials, to be confident. The statistics explainer has the calculation, and motor imageryMotor imagery Imagining a movement without making it, which changes rhythms over motor cortex in a way a classifier can sometimes detect. Related: Sensorimotor rhythm (mu)Sensorimotor rhythm (mu) An 8 to 13 Hz rhythm over motor cortex that weakens when you move, or imagine moving, the corresponding body part. , Event-related desynchronization (ERD)Event-related desynchronization (ERD) The drop in rhythmic power over a cortical area when it becomes active, such as mu weakening when you imagine moving your hand. , BCI inefficiencyBCI inefficiency The finding that around one in five people cannot control a motor-imagery BCI even after training; once called "BCI illiteracy," a label the field is retiring. . Glossary entry is where you will need it most.
The paradigm
The Graz protocol. A fixation cross. At second two, an arrow left or right. From second three to seven, imagine the movement: the feeling of squeezing a ball, not the picture of a hand. Rest. Randomized order, forty trials per class per run, three or four runs. 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 at C3, Cz, C4 and their neighbours (FC3, FC4, CP3, CP4), referenced to an earlobe, then re-referenced to a Laplacian.
The classic pipeline
Band-pass 8 to 30 Hz (mu and beta). Take the window from 0.5 to 2.5 seconds after the cue. Common spatial patternsCommon spatial patterns (CSP) Spatial filters that maximize the variance of one class while minimizing the other, the classic feature extractor for motor imagery. Related: Motor imageryMotor imagery Imagining a movement without making it, which changes rhythms over motor cortex in a way a classifier can sometimes detect., ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples.. Glossary entry: find the spatial filtersFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry that maximize variance for left and minimize it for right, and vice versa, using the training trials. Take the log-variance of the first and last few CSPCommon spatial patterns (CSP) Spatial filters that maximize the variance of one class while minimizing the other, the classic feature extractor for motor imagery. Related: Motor imageryMotor imagery Imagining a movement without making it, which changes rhythms over motor cortex in a way a classifier can sometimes detect. , ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. . Glossary entry components as features. LDALinear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples.. Glossary entry. This pipeline, with two or three lines of MNEMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. . Glossary entry and scikit-learn, is what most of the literature before 2015 used, and it still holds up.
from mne.decoding import CSP
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import cross_val_score, StratifiedKFold
clf = make_pipeline(CSP(n_components=6, log=True), LinearDiscriminantAnalysis())
scores = cross_val_score(clf, X, y, cv=StratifiedKFold(5, shuffle=False)) # X: trials × channels × samples
The shuffle=False matters: with runs recorded in order, unshuffled folds approximate testing on later data, which is closer to the truth than shuffled folds.
The modern pipeline
A RiemannianRiemannian geometry classifiers Methods that treat each trial's covariance matrix as a point on a curved space and classify by distance there; the strongest simple baseline for EEG today. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples., Common spatial patterns (CSP)Common spatial patterns (CSP) Spatial filters that maximize the variance of one class while minimizing the other, the classic feature extractor for motor imagery.. Glossary entry classifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. Related: Linear discriminant analysis (LDA)Linear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. , Support vector machine (SVM)Support vector machine (SVM) A classifier that finds the boundary with the widest margin between classes; strong on small datasets. , Cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. . Glossary entry: compute each trial’s covariance matrix, project to the tangent space at the mean, classify with logistic regression. pyRiemann does this in three lines and it is the strongest simple baseline on every public dataset. Then EEGNetEEGNet A compact convolutional neural network for EEG, published in 2018, that became the standard deep-learning baseline because it is small enough to train on a laptop. Related: BraindecodeBraindecode A PyTorch library of deep-learning models for EEG, including EEGNet and ShallowConvNet, with dataset loaders.. Glossary entry via BraindecodeBraindecode A PyTorch library of deep-learning models for EEG, including EEGNet and ShallowConvNet, with dataset loaders. Related: EEGNetEEGNet A compact convolutional neural network for EEG, published in 2018, that became the standard deep-learning baseline because it is small enough to train on a laptop. , MOABBMOABB Mother of All BCI Benchmarks: a library that runs classifiers across many public EEG datasets the same way so results are comparable. . Glossary entry, if you want to find out how deep learning does on your own eighty trials (usually no better).
What you will find
Within one session, 65 to 85 percent for most people with the classic pipeline, higher with feedback and practice. Across sessions, a drop of five to fifteen points unless you recalibrate. Across people, everything from 95 to 50. Your own number is data, not a grade.
Feedback and training
Close the loop: show a bar that grows left or right with the classifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. Related: Linear discriminant analysis (LDA)Linear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. , Support vector machine (SVM)Support vector machine (SVM) A classifier that finds the boundary with the widest margin between classes; strong on small datasets. , Cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. . Glossary entry’s output during imagery. People improve over sessions with feedback, sometimes a lot. This is a skill being learned by the user as much as a pattern being learned by the machine, and the co-adaptation is the interesting part.
- Implement the Graz paradigm in 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 with 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 markers.
- Record four runs on yourself. Before any classifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. Related: Linear discriminant analysis (LDA)Linear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. , Support vector machine (SVM)Support vector machine (SVM) A classifier that finds the boundary with the widest margin between classes; strong on small datasets. , Cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. . Glossary entry, plot the C3 and C4 spectra for left versus right imagery. Is there a visible difference? If not, the classifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. Related: Linear discriminant analysis (LDA)Linear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. , Support vector machine (SVM)Support vector machine (SVM) A classifier that finds the boundary with the widest margin between classes; strong on small datasets. , Cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. . Glossary entry will not find one.
- Run CSPCommon spatial patterns (CSP) Spatial filters that maximize the variance of one class while minimizing the other, the classic feature extractor for motor imagery. Related: Motor imageryMotor imagery Imagining a movement without making it, which changes rhythms over motor cortex in a way a classifier can sometimes detect. , ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. . Glossary entry + LDALinear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. . Glossary entry with unshuffled 5-fold cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. Related: Data leakageData leakage Information from the test set sneaking into training, for example by shuffling trials from one session across both; it inflates accuracy and is the most common flaw in student BCI papers. , OverfittingOverfitting A model that has memorized its training data, including its noise, and fails on anything new. . Glossary entry. Compute the chance upper bound for your trial count. Report both.
- Run the Riemannian pipeline. Compare.
- Record a second session on another day. Train on day one, test on day two. Report the drop.
- Add online feedback. Do five sessions over two weeks. Plot your accuracy over sessions.
- Recruit two friends under your lab’s protocol. Report their numbers next to yours without commentary.
Why this project is here anyway
Because it is the paradigm that promises the most (control by thought alone, no eyes or muscles) and delivers the least reliably, and understanding exactly why is the beginning of a real education in the field. Everything in the classification and statistics explainers exists because of projects like this one.