AI-Assisted Signal Quality Assessment and Lightweight Mental State Classification
A Lightweight, Quality-Aware EEG Processing Framework Using Machine Learning, Artefact Detection and Subject-Independent Evaluation
Developed and evaluated a lightweight, two-stage EEG processing framework that assesses signal quality before performing mental-state classification. Using recordings from 30 subjects and a 1,560-epoch quality dataset, the research compared rule-based filtering with machine-learning approaches and evaluated classification of neutral, relaxed and focused states. The random forest quality model achieved a cross-validated Macro F1 of 0.851, demonstrating the potential of compact AI models for EEG signal reliability assessment.
Brain–Computer InterfacesBCI ResearchElectroencephalographyEEG Signal ProcessingArtificial IntelligenceMachine LearningSignal Quality AssessmentEEG Artefact DetectionQuality-Aware ClassificationMental State ClassificationNeurotechnologyBiomedical Signal ProcessingRandom ForestLogistic RegressionSupport Vector MachineGradient BoostingFeature EngineeringSignal FilteringFrequency AnalysisSubject-Grouped Cross-ValidationSynthetic Data AugmentationLightweight AIEdge Computing ResearchHuman–Computer InteractionPythonMNE-PythonAcademic ResearchResearch Book ChapterSpringer Book SubmissionManuscript Under Review
Brain–Computer Interfaces (BCIs) allow computer systems to interpret patterns in neural activity and use them for communication, interaction and control.
One widely studied approach uses electroencephalography (EEG), which measures electrical activity through electrodes positioned on the scalp. EEG is non-invasive and has applications in neurological research, assistive technology and human–computer interaction.
However, EEG data can be highly sensitive to signal contamination. Electrode movement, poor contact, muscle activity, electrical interference and recording limitations can introduce distortions that make the signals less reliable for machine-learning analysis.
These challenges are particularly relevant when exploring affordable BCI systems. Although consumer-oriented EEG devices can reduce equipment costs and improve accessibility, the captured signals may contain artefacts that reduce the reliability of subsequent predictions.
The research was motivated by the need to investigate whether the quality of an EEG recording could be assessed automatically before the recording was passed to a mental-state classifier.
Instead of attempting to classify every recorded segment regardless of quality, the study explores a preliminary evaluation stage capable of identifying signals that may not contain dependable information.
The project aims to contribute to the development of more reliable and computationally efficient EEG analysis pipelines suitable for future low-cost BCI research.
02
Research Problem and Proposed Approach
Conventional EEG classification pipelines generally consist of signal acquisition, preprocessing, feature extraction and machine-learning classification.
Although preprocessing removes some unwanted signal components, the resulting data may still contain artefacts that influence the classifier's output.
A classifier trained to recognise mental states may assign a prediction even when the incoming signal is heavily corrupted.
This creates a distinction between two questions: whether an EEG recording contains sufficiently reliable information and what mental state the recorded information may represent.
The research proposes treating these as separate classification problems.
The first stage evaluates signal integrity using a dedicated quality-assessment model.
Only EEG epochs accepted by the quality gate are permitted to proceed to the second stage, where a lightweight classifier attempts to identify the recorded mental state.
Epochs rejected by the quality gate are excluded from state prediction, allowing the system to abstain from producing an interpretation when the input is considered unreliable.
The study compares machine-learning quality assessment with conventional rule-based filtering and investigates whether the additional quality gate improves the behaviour of the overall classification pipeline.
03
Two-Stage EEG Processing Architecture
The proposed architecture consists of an EEG preprocessing pipeline followed by two specialised machine-learning stages.
The first stage evaluates EEG signal quality. It receives a preprocessed epoch, extracts features related to waveform integrity and determines whether the signal is suitable for further classification.
The quality assessment is designed to identify abnormalities such as excessive amplitude, flat signal segments, sudden transitions, abnormal frequency content and other characteristics associated with signal corruption.
The second stage performs mental-state classification. It receives an accepted EEG epoch and calculates features associated with statistical properties, signal dynamics and spectral activity.
These features are then used by a trained classifier to assign one of three labels: Neutral, Relaxed or Focused.
The quality gate connects the two learning stages by controlling which EEG epochs are permitted to reach the mental-state classifier.
This separation allows each stage to be trained, evaluated and improved independently.
The implementation also makes it possible to compare different operating configurations: direct classification without a quality gate, classification after fixed-threshold filtering and classification after machine-learning-based quality assessment.
04
EEG Dataset Selection and Experimental Setup
The experimental study used an existing EEG recording collection containing data from 30 subjects.
Each subject contributed four recording sessions, resulting in a total of 120 EDF files.
The recordings contained 14 EEG channels sampled at 256 Hz, with each session lasting approximately 180 seconds.
The channel arrangement included AF3, F7, F3, FC5, T7, P7, O1, O2, P8, T8, FC6, F4, F8 and AF4.
Three sessions per subject were associated with the mental-state categories used in the experiment.
Session E01 represented Neutral, E02 represented Relaxed and E03 represented Focused.
The fourth session was retained within the source collection but was not included in the reported mental-state classification task.
The resulting target-state dataset contained 90 recordings, equally distributed across the three classes.
Before processing, the files were examined for consistency in channel information, sampling frequency, recording duration and file readability.
Metadata was maintained to associate the derived EEG epochs with their original subjects and recording sessions.
This was important for implementing subject-grouped cross-validation, where the same participant must not appear in both training and validation groups.
05
EEG Preprocessing and Epoch Generation
Before extracting features, the EEG recordings were processed to obtain a consistent representation suitable for machine-learning analysis.
The preprocessing pipeline began with validating the signals and checking for missing values, invalid numerical data and abnormal signal conditions.
A 50 Hz notch filter was applied to reduce electrical power-line interference.
Band-pass filtering was then used to suppress unwanted frequency components and baseline disturbances.
The recordings were resampled from their original frequency of 256 Hz to 128 Hz, reducing the amount of data required for subsequent processing.
Average referencing was applied by subtracting the mean signal across the available channels, providing a consistent reference arrangement for feature extraction.
Following preprocessing, each selected 180-second recording was divided into six non-overlapping epochs of 30 seconds each.
This generated a total of 540 epochs from the 90 target-state recordings.
At 128 Hz, each 30-second epoch contained 3,840 samples per EEG channel.
The resulting representation consisted of 540 epochs, each containing 14 channels and 3,840 samples per channel.
This structured dataset provided the foundation for signal-quality assessment, feature extraction and experimental classification.
06
Synthetic Artefact Generation and Dataset Construction
A significant component of the research involved creating a controlled dataset for training and evaluating EEG signal-quality classifiers.
Following preprocessing, the original 540 epochs were screened for signals suitable to serve as clean-reference examples.
A total of 390 epochs were retained, while 150 were excluded because the P8 channel had been flagged during signal validation.
The retained reference data was subsequently used to construct a signal-quality dataset containing both clean and artificially corrupted EEG samples.
Six categories of synthetic corruption were introduced.
Gaussian noise was used to represent general sensor or electronic noise, while 50 Hz sinusoidal interference simulated power-line contamination.
Baseline drift represented slowly changing disturbances, and electrode-pop artefacts simulated sudden disturbances associated with changes in electrode contact.
Flatline artefacts reproduced periods of missing or constant signal information, while clipping simulated saturation or restricted amplitude range.
Different severity levels were applied to investigate the response of the quality-assessment system to varying degrees of corruption.
The final quality dataset contained 390 clean-reference epochs and 1,170 synthetically corrupted epochs, producing 1,560 samples.
This represented a 25% clean and 75% corrupted distribution.
The approach enabled controlled experimentation, although performance against synthetic artefacts cannot automatically be assumed to transfer to every form of real-world EEG contamination.
07
EEG Signal-Quality Feature Engineering
The quality-assessment model relies on engineered features that describe properties of the EEG waveform.
Rather than processing the complete high-dimensional signal directly through a large neural network, the framework extracts a compact representation of characteristics associated with signal integrity.
The feature extraction process includes measurements intended to identify excessive amplitudes, abnormal changes in signal variance, flatline behaviour, sudden transitions, drift and unusual frequency components.
The methodology examines fourteen signal characteristics at the channel level and aggregates their information into a final 57-feature quality representation.
This allows the quality classifier to operate on a structured set of measurements rather than the original multi-channel waveform.
The feature-engineering approach was selected because it provides a relatively compact representation suitable for conventional machine-learning algorithms.
It also makes the assessment process easier to investigate because the input features correspond to interpretable properties of the recorded signal.
The resulting feature matrix was used to compare rule-based detection with logistic regression and random forest classification.
This stage establishes the distinction between raw EEG acquisition and the information required to assess whether a recording is suitable for further analysis.
08
Rule-Based and Machine-Learning Quality Assessment
Three approaches were evaluated for determining whether an EEG epoch should be accepted or rejected.
The first method used manually specified thresholds to identify signal abnormalities.
These thresholds considered factors such as flatline fraction, clipping fraction, peak amplitude, sudden gradient events and abnormal frequency characteristics.
The rule-based approach provided a relatively interpretable baseline because individual rejection decisions could be associated with explicit conditions.
However, the experimental results revealed that the thresholds were excessively restrictive for the available dataset.
The second approach used logistic regression to classify signal quality from the extracted features.
The third approach used a random forest model with 100 decision trees and balanced class weighting to address the unequal number of clean and corrupted examples.
The machine-learning approaches were evaluated using five-fold subject-grouped cross-validation.
Logistic regression achieved a Macro F1 score of 0.794, while random forest achieved 0.851.
The random forest model was therefore selected as the main quality-assessment component of the proposed pipeline.
The findings demonstrated that learned quality-assessment boundaries provided stronger performance than the manually configured baseline under the experimental conditions.
09
Mental-State Feature Extraction and Classification
After quality assessment, the next stage attempted to classify accepted EEG recordings into three mental-state categories.
The research considered Neutral, Relaxed and Focused states, using the labels associated with the selected recording sessions.
Unlike the signal-quality model, which focused primarily on detecting corruption, this stage examined waveform properties that might help distinguish patterns associated with the three states.
A total of 27 features were calculated for each of the 14 EEG channels, producing 378 features per epoch.
These included time-domain statistics such as mean, variance, standard deviation, root mean square, skewness, kurtosis and zero-crossing rate.
Hjorth activity, mobility and complexity were also calculated to characterise signal dynamics.
Frequency-related features included power measurements in the delta, theta, alpha, beta and gamma bands, together with spectral ratios and entropy-related measurements.
A feature-selection stage reduced the original 378-dimensional representation to the 100 highest-ranked features within each training fold.
Four lightweight classifiers were compared: logistic regression, linear support vector machine, random forest and histogram gradient boosting.
The strongest result came from logistic regression, with a subject-grouped Macro F1 of 0.352.
This result was only slightly above the approximate three-class chance reference, indicating that the implemented feature set did not provide reliable subject-independent separation of the mental-state categories.
10
Subject-Grouped Validation and Experimental Results
A major methodological consideration was preventing participant-level data leakage during model evaluation.
EEG characteristics can differ substantially between individuals. If recordings from the same person appear in both training and validation datasets, a classifier may learn subject-specific patterns rather than features that generalise to unseen participants.
To reduce this risk, the research implemented five-fold subject-grouped cross-validation.
The quality-assessment and mental-state classifiers were evaluated using participant groups that prevented the same subject from appearing in both training and validation partitions.
For signal-quality assessment, the random forest achieved a Macro F1 of 0.851, outperforming logistic regression at 0.794.
This represented the strongest cross-validated result of the study.
The mental-state classifiers performed considerably less effectively.
Logistic regression achieved a Macro F1 of 0.352, followed by linear SVM at 0.349, random forest at 0.318 and histogram gradient boosting at 0.317.
These outcomes highlighted a substantial difference between identifying controlled signal artefacts and classifying mental states.
The quality-assessment problem was comparatively tractable, while reliable generalisation of the mental-state predictions remained unresolved.
This contrast became one of the principal findings of the research.
11
Quality-Gate Ablation and Robustness Analysis
The research also investigated how the addition of a quality gate affected the behaviour of the complete EEG classification pipeline.
Three configurations were compared: classification without quality gating, classification after a rule-based quality check and classification after a machine-learning quality check.
The evaluation considered four measures: the proportion of epochs accepted, retention of clean-reference epochs, conditional classification Macro F1 and the error rate among accepted epochs.
In the reported in-sample experiment, the ungated configuration achieved a conditional Macro F1 of 0.595 while accepting every epoch.
The rule-based quality gate accepted only 13.4% of epochs and achieved a lower conditional Macro F1 of 0.514.
The machine-learning gate accepted approximately 26.7% of epochs and achieved a conditional Macro F1 of 0.686.
The machine-learning configuration also retained all 390 clean-reference epochs within the evaluated corpus.
However, the models used for this ablation experiment had already been fitted on the same corpus. The results therefore demonstrate exploratory in-sample filtering behaviour rather than independently validated improvement on unseen subjects.
Additional robustness experiments examined how the trained gate responded to different synthetic artefact categories and severity levels.
The results indicated that the quality gate rejected most strongly corrupted groups, but also highlighted the trade-off between rejecting unreliable data and retaining enough samples for useful classification.
The experiment demonstrated that quality filtering is not automatically beneficial unless both the reliability and coverage of accepted signals are considered.
12
Computational Efficiency and Lightweight AI
One of the objectives of the research was to investigate whether the complete processing pipeline could operate using relatively modest computational resources.
The selected models were based on conventional machine-learning techniques rather than large deep neural networks.
The random forest quality classifier occupied approximately 2.29 MB, while the logistic regression mental-state classifier required approximately 18.7 KB.
Together, the stored models required less than 2.5 MB.
Computational performance was evaluated using an input representing a 30-second EEG epoch with fourteen channels and 3,840 samples per channel.
After preliminary warm-up runs, the pipeline was benchmarked over one hundred timed executions on a laptop CPU.
The complete pipeline required approximately 331 milliseconds per epoch.
The largest processing costs occurred during feature extraction, with signal-quality feature extraction requiring approximately 152 milliseconds and mental-state feature extraction requiring approximately 157 milliseconds.
Model inference itself required considerably less processing time.
These findings suggest that the selected models are computationally lightweight relative to the preprocessing and feature-extraction stages.
However, the research did not measure live EEG streaming performance, total system power consumption or execution on microcontroller-class hardware.
The efficiency results therefore support further investigation into edge deployment rather than confirming that the entire implementation has already been validated on embedded devices.
13
Research Conclusions, Limitations and Future Scope
The study demonstrates the usefulness of treating EEG signal reliability and mental-state classification as separate machine-learning problems.
Its strongest result was the random forest quality-assessment model, which achieved a subject-grouped Macro F1 of 0.851 when distinguishing clean-reference epochs from controlled synthetic corruption.
The mental-state classification results were considerably weaker. The best model achieved a Macro F1 of only 0.352, indicating that the selected feature-engineering and classification methods did not establish dependable subject-independent recognition of Neutral, Relaxed and Focused states.
The exploratory gating experiment suggested that rejecting unreliable signals can improve conditional classification behaviour within the evaluated corpus, although the reported improvement requires confirmation through genuinely held-out testing.
The research also demonstrated that the model files were compact and that the complete CPU-based processing pipeline could analyse a 30-second EEG window in approximately 331 milliseconds.
These findings support the potential of lightweight, quality-aware EEG processing while identifying several important limitations.
Future development should incorporate recordings with expert-labelled real-world artefacts, additional subjects and more diverse mental-state sessions.
Further work should also investigate more expressive but efficient classification architectures, including compact neural networks such as EEGNet.
The quality gate and mental-state classifier could eventually be integrated into a reliability-aware output system that considers both input integrity and prediction confidence.
Live streaming, low-power device testing and evaluation on resource-constrained hardware are necessary before the system can be considered ready for practical embedded BCI deployment.
The project's principal contribution is a reproducible research direction: assess the reliability of EEG data before trusting the interpretation generated from it.
The research provides a foundation for further studies in affordable neurotechnology, signal-quality assessment and computationally efficient BCI systems.