Multimodal biometric authentication and AES-256 cryptography using ECG + EEG signals with feature-level fusion and a Random Forest classifier. Final-year capstone project, BMSCE.
- Motivation
- Key Contributions
- System Architecture
- Methodology
- Results
- Demo
- Repository Structure
- Tech Stack
- How to Run
- Limitations
- Future Work
- Ethics and Privacy
- Authors
- Acknowledgments
- References
- Citation
- License
Traditional authentication systems — passwords, PINs, tokens — can be stolen, leaked, or replicated. Even widely deployed biometrics like fingerprints and facial recognition are vulnerable to spoofing (lifted prints, 3D masks, high-resolution photos), and the templates, once leaked, cannot be reset.
Equally important, most existing systems treat identity verification and data encryption as separate processes: a user logs in, then encryption keys are retrieved from a database. If the database is compromised, the keys are exposed.
This project addresses both gaps by building a system where:
- Internal physiological signals (ECG and EEG) serve as the biometric — they inherently embed liveness because they originate from real-time cardiac and neural activity, making them very difficult to forge.
- The cryptographic key is derived dynamically from the user's biometric template — if the user is not present, the key does not exist.
- Multimodal feature-level fusion of ECG and EEG signals using time, frequency, wavelet (Daubechies db4), and non-linear (Approximate Entropy, Sample Entropy, Higuchi Fractal Dimension, Poincaré) features — yielding an 89-dimensional unified biometric template per heartbeat.
- Random Forest classifier with majority voting over a session of beats, gated by a confidence threshold (60% majority + 70% mean confidence) for robust identity verification.
- Biometric-driven AES-256 cryptosystem in CBC mode, with the 256-bit key derived via SHA-256 hashing of the per-user mean biometric template plus a fixed salt.
- End-to-end Gradio web prototype that accepts a ZIP of ECG (WFDB) + EEG (CSV) files, performs authentication, and decrypts a per-user secret message on success.
The system follows a modular pipeline-based design with three primary layers: a Data Acquisition Layer that ingests raw signals, a Processing & Logic Layer that handles feature extraction, fusion, classification, and cryptography, and a Presentation Layer built on Gradio.
The pipeline consists of six phases:
1. Signal acquisition and preprocessing. ECG records (WFDB format: .dat, .hea) are read using the wfdb library; R-peaks are detected via the annotation channel. Each beat is segmented as a fixed window of 200 samples before and 200 samples after the R-peak (400 samples total at 500 Hz sampling rate). Boundary beats are zero-padded to maintain a consistent input shape. EEG data (CSV) is synchronized to match the number of extracted ECG beats by truncation or repetition.
2. Feature extraction. Four feature families are computed per beat:
- Time domain (15 features): mean, std, variance, median, max, min, peak-to-peak, RMS, energy, zero-crossing rate, derivative statistics, R-amplitude, pre/post slopes around the R-peak.
- Frequency domain (10 features, via Welch's method): total power, dominant frequency, band powers (0–5 Hz, 5–15 Hz, 15–40 Hz), spectral centroid, mean/median frequency, spectral entropy, spectral flatness.
- Wavelet domain (20 features, Daubechies db4 at level 4): mean, variance, energy, and entropy of each of 5 sub-bands.
- Non-linear (6 features): Approximate Entropy, Sample Entropy, Higuchi Fractal Dimension, and Poincaré (SD1, SD2, ratio) over RR intervals.
ECG yields 51 features per beat; EEG contributes 38 pre-computed features. Feature-level fusion via horizontal concatenation produces an 89-dimensional template per beat.
3. Model training. A Random Forest classifier (n_estimators=300, random_state=42) is trained on a 70/30 stratified split. Random Forest was chosen for its robustness to high-dimensional features, implicit feature selection, and resistance to overfitting on small datasets.
4. Authentication via majority voting. During verification, every beat in the session is classified independently. The session is accepted only if the majority predicted class matches the claimed ID, the majority fraction ≥ 0.6, and the mean classifier confidence ≥ 0.7.
5. Biometric key generation. On successful authentication, the per-user mean biometric template is normalized to [0, 255], cast to bytes, concatenated with a fixed salt (ECG_EEG_BIOMETRIC_SALT), and hashed with SHA-256 to produce a deterministic 256-bit key.
6. Cryptography. A pre-encrypted user-specific message is decrypted using AES-256 in CBC mode with the regenerated key. If authentication fails, the key is never derived and the ciphertext remains opaque.
The system was evaluated on a 5-subject ECG + EEG dataset (40 beats per subject, 200 samples total) with a 70/30 stratified train-test split.
| Metric | Value |
|---|---|
| Training samples | 140 beats |
| Testing samples | 60 beats |
| Test accuracy | 100% (60/60 correctly classified) |
| Classifier | Random Forest (300 trees) |
| Feature dimension | 89 (51 ECG + 38 EEG) |
| Mean inference confidence | 0.94 |
| Property | Value |
|---|---|
| Key length | 256 bits (32 bytes) |
| Hashing | SHA-256 with per-system salt |
| Encryption | AES-256, CBC mode |
| Key storage | None — regenerated on the fly from the biometric template |
| End-to-end pipeline latency | < 5 seconds per session (Google Colab CPU) |
On successful authentication of, for example, Person 2, the system successfully decrypted the ciphertext to:
"This is a secret message protected by ECG+EEG for person 2."
When an imposter attempted authentication (claimed ID 2, biometric data from Person 3), the system correctly denied access with Accepted: False, Majority fraction: 1.000, indicating the predicted ID did not match the claim.
Important caveat on the 100% figure. This result is on a small (5-subject), within-session dataset and should be interpreted as a proof-of-concept of the multimodal fusion + cryptography pipeline, not a generalizable accuracy claim. See Limitations.
A Gradio web interface allows the user to enter a claimed person ID and upload a ZIP containing their ECG (WFDB) + EEG (CSV) files, then receive an authentication decision and (on success) the decrypted message.
| Successful authentication | Failed authentication (imposter) |
![]() |
![]() |
The interface itself:
ECG-EEG-Biometric-Cryptography/
├── README.md
├── LICENSE
├── requirements.txt
├── ecg_eeg_biometric_pipeline.ipynb # Main notebook — full pipeline + Gradio
├── docs/
│ ├── project_report.pdf # Full academic report
│ ├── architecture.png
│ ├── activity_diagram.png
│ ├── use_case_diagram.png
│ └── confusion_matrix.png
├── screenshots/
│ ├── gradio_interface.png
│ ├── auth_success.png
│ └── auth_failed.png
└── data/
└── README.md # Dataset description and download instructions
- Language: Python 3.10+
- Signal processing:
wfdb,scipy,numpy - Wavelets:
pywavelets - Machine learning:
scikit-learn - Cryptography:
pycryptodome - UI:
gradio - Environment: Google Colab (Jupyter notebook)
1. Clone the repository
git clone https://github.com/Chiranthan7/ECG-and-EEG-based-Biometric-Encryption-using-Machine-Learning.git
cd ECG-and-EEG-based-Biometric-Encryption-using-Machine-Learning2. Install dependencies
pip install -r requirements.txt3. Prepare the dataset
The dataset zip in this repository contains 5 subjects' ECG (WFDB format) and EEG (CSV) files. Extract it to a local directory and update the BASE_DIR constant in the notebook to point at it. See data/README.md for the expected folder layout.
4. Run the notebook
Open ecg_eeg_biometric_pipeline.ipynb in Jupyter or Google Colab and execute cells sequentially. The final cell launches the Gradio interface; click the local URL to interact.
5. Authenticate
In the Gradio UI:
- Enter a claimed person ID (1–5)
- Upload a ZIP containing that person's ECG WFDB files (e.g.,
rec_1.*,rec_2.*) and EEG CSV (e.g.,EEG_person_2_realistic.csv) - Click Authenticate to see the result and (on success) the decrypted message
The authors believe transparent disclosure of limitations is essential, especially in a security-related project:
- Small dataset. The system is evaluated on 5 subjects with 40 beats each — sufficient for proof-of-concept but not for population-level claims. Realistic deployment requires evaluation on benchmark datasets such as PhysioNet ECG-ID, PTB, MIT-BIH (for ECG) and BED, DEAP, or PhysioNet EEG Motor/Mental (for EEG), each with tens to hundreds of subjects.
- Within-session evaluation only. Train and test beats come from the same recording session. Cross-session and cross-day evaluation — where physiological state drift is real — would be a stronger test. This is standard in the biometrics literature.
- Identification metrics rather than verification metrics. Accuracy is reported here; production biometric systems are characterized by False Accept Rate (FAR), False Rejection Rate (FRR), and Equal Error Rate (EER) over ROC/DET curves. These are appropriate next-step metrics.
- The cryptographic scheme uses a stored reference template. Truly noise-tolerant biometric key generation requires fuzzy extractors (Dodis et al.), fuzzy commitments, or secure sketches, which can regenerate the exact key from a noisy live measurement without storing the template. The current system stores the per-user mean template, which works as a prototype but is not a true biometric cryptosystem in the cryptographic sense.
- AES-CBC is unauthenticated. A production system would use AES-GCM or AES-CBC + HMAC to defend against ciphertext tampering.
- No presentation attack detection (PAD). While ECG/EEG are harder to spoof than fingerprints, a defensive deployment would include explicit liveness checks (e.g., heart-rate variability sanity, signal quality indices).
- Cancelability. Biometric templates cannot be reset if compromised. Future work should integrate cancelable-biometric techniques such as random projection, BioHashing, or salting within a fuzzy extractor framework so a leaked template can be revoked and reissued.
- Deep learning feature extraction. Replace handcrafted features with end-to-end 1D CNN, LSTM, or hybrid CNN-LSTM models trained on raw signals.
- Fuzzy extractor integration. Replace the current SHA-256-of-template scheme with a proper fuzzy extractor or secure-sketch construction so the exact key can be regenerated from noisy live signals without storing the template.
- Real-time hardware deployment. Port the trained model to embedded edge devices (Raspberry Pi, NVIDIA Jetson) integrated with consumer ECG/EEG sensors (AD8232, OpenBCI) for live authentication.
- Continuous authentication. Move beyond static login to background continuous verification using a wrist-worn sensor, locking the session if the wearer changes.
- Larger and cross-session benchmarks. Evaluate on full PhysioNet databases with 50+ subjects and report FAR / FRR / EER over multiple sessions and days.
- Threat model formalization. Explicit defenses against replay, presentation, template inversion, hill-climbing, and cross-matching attacks.
ECG and EEG signals are health-related biometric data and require careful handling:
- Informed consent. Any future data collection for this system must follow IRB / ethics-committee-approved consent protocols, with subjects informed about how their physiological data will be stored, processed, and (eventually) deleted.
- Data minimization. Only the features needed for authentication should be retained; raw signals should not be persisted longer than necessary for model training.
- Template protection. Because biometrics cannot be reset like passwords, future versions should integrate cancelable-biometric schemes (random projection, BioHashing, fuzzy extractors with per-user salts) so a leaked template can be revoked.
- No medical inference. This system is designed for authentication; ECG/EEG signals also carry medical information (arrhythmia indicators, neurological markers). Any deployment must strictly separate authentication features from medical inference and comply with applicable health-data regulations (HIPAA, GDPR, India's DPDPA).
This work was carried out as part of the Project Work – 2 course (Course Code: 24AM7PWPW2) for the 7th semester of the B.E. in Artificial Intelligence and Machine Learning programme at B.M.S. College of Engineering, Bengaluru, an Autonomous Institute affiliated with Visvesvaraya Technological University (VTU), Belagavi.
| Name | USN | Role |
|---|---|---|
| C M Chiranthan Gowda | 1BM22AI035 | Team Lead |
| Anand Naik H | 1BM22AI013 | Team Member |
| Amogh G | 1BM22AI011 | Team Member |
| Om Arya B S | 1BM22AI086 | Team Member |
Project guide: Prof. Spoorthi G S, Assistant Professor, Department of Machine Learning, BMSCE.
The authors thank Prof. Spoorthi G S for her guidance throughout the project, Dr. M. Dakshayini (Professor and Head, Department of Machine Learning, BMSCE) for her valuable suggestions, and Dr. Bheemsha Arya (Principal, BMSCE) for providing the facilities and academic environment that made this work possible. The authors also acknowledge the PhysioNet community for the WFDB tooling that underpins the ECG processing pipeline.
- L. Breiman, "Random Forests," Machine Learning, vol. 45, no. 1, pp. 5–32, 2001, doi: 10.1023/A:1010933404324.
- J. Daemen and V. Rijmen, The Design of Rijndael: AES — The Advanced Encryption Standard. Berlin, Heidelberg: Springer-Verlag, 2002.
- A. L. Goldberger, L. A. N. Amaral, L. Glass, J. M. Hausdorff, P. Ch. Ivanov, R. G. Mark, J. E. Mietus, G. B. Moody, C.-K. Peng, and H. E. Stanley, "PhysioBank, PhysioToolkit, and PhysioNet: Components of a New Research Resource for Complex Physiologic Signals," Circulation, vol. 101, no. 23, pp. e215–e220, 2000, doi: 10.1161/01.CIR.101.23.e215.
- G. B. Moody, R. G. Mark, and A. L. Goldberger, "PhysioNet: A Web-Based Resource for the Study of Physiologic Signals," IEEE Engineering in Medicine and Biology Magazine, vol. 20, no. 3, pp. 70–75, May/June 2001, doi: 10.1109/51.932728.
- N. Karimian, Z. Guo, M. Tehranipoor, and D. Forte, "Highly Reliable Key Generation From Electrocardiogram (ECG)," IEEE Transactions on Biomedical Engineering, vol. 64, no. 6, pp. 1400–1411, Jun. 2017, doi: 10.1109/TBME.2016.2607020.
- H. M. Lynn, S. B. Pan, and P. Kim, "A Deep Bidirectional GRU Network Model for Biometric Electrocardiogram Classification Based on Recurrent Neural Networks," IEEE Access, vol. 7, pp. 145395–145405, 2019, doi: 10.1109/ACCESS.2019.2939947.
- N. Ibtehaz, M. E. H. Chowdhury, A. Khandakar, S. Kiranyaz, M. S. Rahman, A. Tahir, Y. Qiblawey, and T. Rahman, "EDITH: ECG Biometrics Aided by Deep Learning for Reliable Individual Authentication," IEEE Transactions on Emerging Topics in Computational Intelligence, vol. 6, no. 4, pp. 928–940, Aug. 2022, doi: 10.1109/TETCI.2021.3131374.
- A. J. Bidgoly, H. J. Bidgoly, and Z. Arezoumand, "A Survey on Methods and Challenges in EEG Based Authentication," Computers & Security, vol. 93, p. 101788, Jun. 2020, doi: 10.1016/j.cose.2020.101788.
- H. B. Hwang, J. Lee, H. Kwon, B. Chung, J. Lee, and I. Y. Kim, "Preliminary Study of Novel Bio-Crypto Key Generation Using Clustering-Based Binarization of ECG Features," Sensors, vol. 24, no. 5, p. 1556, Feb. 2024, doi: 10.3390/s24051556.
- A. Rahman, M. E. H. Chowdhury, A. Khandakar, S. Kiranyaz, K. H. Shahriar Zaman, M. B. I. Reaz, M. T. Islam, M. Ezeddin, and M. A. Kadir, "Multimodal EEG and Keystroke Dynamics Based Biometric System Using Machine Learning Algorithms," IEEE Access, vol. 9, pp. 94625–94643, 2021, doi: 10.1109/ACCESS.2021.3092840.
If you use this work or build upon it, please cite:
@misc{chiranthan2025ecgeeg,
title = {ECG and EEG Based Biometric Cryptography Using Machine Learning},
author = {C M Chiranthan Gowda, and Anand Naik H, and Amogh G, and Om Arya B S},
year = {2025},
institution = {B.M.S. College of Engineering, Bengaluru},
howpublished = {\url{https://github.com/Chiranthan7/ECG-and-EEG-based-Biometric-Encryption-using-Machine-Learning}},
note = {Project Work, B.E. in Artificial Intelligence and Machine Learning, Semester 6 & 7}
}This project is released under the MIT License. The included dataset is for academic and research purposes only.





