Python Real-Time EEG & BCI Signal WebSocket Streaming Service
Low-latency Python WebSocket server designed for Brain-Computer Interface (BCI) applications and neural signal processing. Receives high-frequency EEG channel packets, applies digital SciPy Butterworth FIR bandpass filters (8-30Hz Alpha/Beta waves), and streams real-time feature vectors.
Appended directly to the LLM system prompt for tailored code output.
Generated Code
⚡ Instant Boilerplate| 1 | import asyncio |
| 2 | import json |
| 3 | import numpy as np |
| 4 | from scipy.signal import butter, sosfilt |
| 5 | import websockets |
| 6 | |
| 7 | SAMPLING_RATE = 250 |
| 8 | CHANNELS = 8 |
| 9 | sos_filter = butter(4, [8.0/125.0, 30.0/125.0], btype='band', output='sos') |
| 10 | |
| 11 | async def handler(websocket): |
| 12 | async for message in websocket: |
| 13 | data = json.loads(message) |
| 14 | raw = np.array(data.get("channels", [0.0]*8)) |
| 15 | filtered = sosfilt(sos_filter, raw) |
| 16 | await websocket.send(json.dumps({"filtered": filtered.tolist()})) |
| 17 | |
| 18 | async def main(): |
| 19 | async with websockets.serve(handler, "0.0.0.0", 8765): |
| 20 | await asyncio.Future() |
| 21 | |
| 22 | if __name__ == "__main__": |
| 23 | asyncio.run(main()) |
| 24 |
Deploy this boilerplate automatically in 1 click.
Related Generators
View AllMNE & Scikit-Learn Common Spatial Pattern (CSP) EEG Classifier
Machine learning pipeline for Motor Imagery EEG classification using MNE-Python Common Spatial Patterns (CSP) and Linear Discriminant Analysis (LDA).
PythonPyTorch EEGNet Neural Network for BCI Signal Decoding
PyTorch deep learning implementation of EEGNet: a compact convolutional neural network engineered for EEG-based Brain-Computer Interfaces.
PythonPython SciPy Welch Power Spectral Density (PSD) Band Power Extractor
Bio-signal analytics module in Python using SciPy scipy.signal.welch to compute absolute and relative band power (Delta, Theta, Alpha, Beta, Gamma).