# rafinhafpb/eeg_from_scratch architecture

> Architecture diagram of the GitHub repository rafinhafpb/eeg_from_scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rafinhafpb/eeg_from_scratch
- Repository: https://github.com/rafinhafpb/eeg_from_scratch

## Overview

EEG_from_scratch is a single-channel EEG capture and analysis application, with simulation and recording playback as alternate sources. The principal workflow is to configure or choose a source, feed samples into a rolling buffer, filter and analyze them, then present waveforms, spectra, band power, and threshold-based eyes-open/closed indications. The README also documents impedance testing and ESP32/ADS1292R hardware. Edges are grounded in the README and SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`GUI/main_window.py`](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/main_window.py) (Main window), [`buffer/data_buffer.py`](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/buffer/data_buffer.py) (Rolling sample buffer), [`acquisition/config_acquisition.py`](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/config_acquisition.py) (Live acquisition), [`GUI/config_acquisition_dialog.py`](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/config_acquisition_dialog.py) (Hardware setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sources["Signal sources"]
  node_hardware["ESP32 firmware<br/>[esp_to_ads1292r.c]"]
  node_serial_acq["Live acquisition"]
  node_simulation["Signal generator"]
  node_playback["Recording playback<br/>[load_recording.py]"]
end

subgraph group_runtime["Application runtime"]
  node_app["App launcher<br/>[main.py]"]
  node_params["Acquisition parameters<br/>[data.py]"]
  node_buffer[("Rolling sample buffer<br/>[data_buffer.py]")]
end

subgraph group_analysis["Signal analysis"]
  node_processor["Filter processor"]
  node_fft["FFT analysis<br/>[fft_calculation.py]"]
end

subgraph group_interface["User interface"]
  node_window["Main window<br/>[main_window.py]"]
  node_serial_dialog["Hardware setup"]
  node_simulation_dialog["Simulation setup"]
  node_file_dialog["Recording picker"]
  node_controls["Processing controls"]
  node_raw_plot["Waveform plots"]
  node_spectrum["Spectrum plot"]
  node_band_power["Band power view"]
  node_detector["Band threshold detector"]
end

node_user(("Operator"))
node_device{{"ADS1292R / ESP32"}}
node_recordings["Recording files"]

node_user -->|"launches"| node_app
node_app -->|"creates"| node_window
node_user -->|"operates"| node_window
node_window -->|"opens setup"| node_serial_dialog
node_serial_dialog -->|"configures"| node_params
node_serial_dialog -->|"configures"| node_serial_acq
node_device -.->|"streams data"| node_serial_acq
node_hardware -.->|"controls"| node_device
node_window -->|"opens setup"| node_simulation_dialog
node_window -->|"creates"| node_simulation
node_window -->|"opens picker"| node_file_dialog
node_window -->|"loads recording"| node_playback
node_recordings -.->|"provides files"| node_playback
node_serial_acq -->|"writes samples"| node_buffer
node_simulation -->|"writes samples"| node_buffer
node_playback -->|"writes samples"| node_buffer
node_window -->|"initializes"| node_buffer
node_window -->|"initializes"| node_processor
node_controls -->|"sets filters"| node_processor
node_processor -->|"reads samples"| node_buffer
node_window -->|"updates plots"| node_raw_plot
node_window -->|"updates spectrum"| node_spectrum
node_spectrum -->|"computes spectrum"| node_fft
node_window -->|"updates power"| node_band_power
node_window -->|"updates detection"| node_detector
node_detector -->|"triggers buzzer"| node_serial_acq

click node_app "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/main.py"
click node_window "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/main_window.py"
click node_params "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/utl/data.py"
click node_serial_dialog "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/config_acquisition_dialog.py"
click node_hardware "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/ESP32/esp_to_ads1292r.c"
click node_serial_acq "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/config_acquisition.py"
click node_simulation_dialog "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/create_simulation_dialog.py"
click node_simulation "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/simulate_acquisition.py"
click node_file_dialog "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/load_file_dialog.py"
click node_playback "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/load_recording.py"
click node_recordings "https://github.com/rafinhafpb/eeg_from_scratch/tree/main/acquisition/recordings"
click node_buffer "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/buffer/data_buffer.py"
click node_processor "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/signal_processing/signal_processor.py"
click node_controls "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/processing_controls.py"
click node_fft "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/signal_processing/fft_calculation.py"
click node_raw_plot "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/signal_visualization.py"
click node_spectrum "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/fft_plotter_widget.py"
click node_band_power "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/band_power_widget.py"
click node_detector "https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/band_detector_widget.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_hardware,node_serial_acq,node_simulation,node_playback toneBlue
class node_app,node_params,node_buffer toneAmber
class node_processor,node_fft toneMint
class node_window,node_serial_dialog,node_simulation_dialog,node_file_dialog,node_controls,node_raw_plot,node_spectrum,node_band_power,node_detector toneRose
class node_user,node_device toneIndigo
class node_recordings toneTeal
```

## Components

### Signal sources

- [ESP32 firmware](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/ESP32/esp_to_ads1292r.c): `ESP32/esp_to_ads1292r.c`
- [Live acquisition](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/config_acquisition.py): `acquisition/config_acquisition.py`
- [Signal generator](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/simulate_acquisition.py): `acquisition/simulate_acquisition.py`
- [Recording playback](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/acquisition/load_recording.py): `acquisition/load_recording.py`

### Application runtime

- [App launcher](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/main.py): `main.py`
- [Acquisition parameters](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/utl/data.py): `utl/data.py`
- [Rolling sample buffer](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/buffer/data_buffer.py): `buffer/data_buffer.py`

### Signal analysis

- [Filter processor](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/signal_processing/signal_processor.py): `signal_processing/signal_processor.py`
- [FFT analysis](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/signal_processing/fft_calculation.py): `signal_processing/fft_calculation.py`

### User interface

- [Main window](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/main_window.py): `GUI/main_window.py`
- [Hardware setup](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/config_acquisition_dialog.py): `GUI/config_acquisition_dialog.py`
- [Simulation setup](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/create_simulation_dialog.py): `GUI/create_simulation_dialog.py`
- [Recording picker](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/load_file_dialog.py): `GUI/load_file_dialog.py`
- [Processing controls](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/processing_controls.py): `GUI/processing_controls.py`
- [Waveform plots](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/signal_visualization.py): `GUI/signal_visualization.py`
- [Spectrum plot](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/fft_plotter_widget.py): `GUI/fft_plotter_widget.py`
- [Band power view](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/band_power_widget.py): `GUI/band_power_widget.py`
- [Band threshold detector](https://github.com/rafinhafpb/eeg_from_scratch/blob/main/GUI/band_detector_widget.py): `GUI/band_detector_widget.py`

### Other components

- **Operator**
- **ADS1292R / ESP32**
- [Recording files](https://github.com/rafinhafpb/eeg_from_scratch/tree/main/acquisition/recordings): `acquisition/recordings`

## Connections

- Operator → App launcher: launches (evidence: `README.md`)
- App launcher → Main window: creates (evidence: `main.py`)
- Operator → Main window: operates (evidence: `README.md`)
- Main window → Hardware setup: opens setup (evidence: `GUI/main_window.py`)
- Hardware setup → Acquisition parameters: configures (evidence: `GUI/config_acquisition_dialog.py`)
- Hardware setup → Live acquisition: configures (evidence: `GUI/config_acquisition_dialog.py`)
- ADS1292R / ESP32 → Live acquisition: streams data (evidence: `README.md`)
- ESP32 firmware → ADS1292R / ESP32: controls (evidence: `README.md`)
- Main window → Simulation setup: opens setup (evidence: `GUI/main_window.py`)
- Main window → Signal generator: creates (evidence: `GUI/main_window.py`)
- Main window → Recording picker: opens picker (evidence: `GUI/main_window.py`)
- Main window → Recording playback: loads recording (evidence: `GUI/main_window.py`)
- Recording files → Recording playback: provides files (evidence: `README.md`)
- Live acquisition → Rolling sample buffer: writes samples (evidence: `acquisition/config_acquisition.py`)
- Signal generator → Rolling sample buffer: writes samples (evidence: `acquisition/simulate_acquisition.py`)
- Recording playback → Rolling sample buffer: writes samples (evidence: `acquisition/load_recording.py`)
- Main window → Rolling sample buffer: initializes (evidence: `GUI/main_window.py`)
- Main window → Filter processor: initializes (evidence: `GUI/main_window.py`)
- Processing controls → Filter processor: sets filters (evidence: `GUI/processing_controls.py`)
- Filter processor → Rolling sample buffer: reads samples (evidence: `signal_processing/signal_processor.py`)
- Main window → Waveform plots: updates plots (evidence: `GUI/main_window.py`)
- Main window → Spectrum plot: updates spectrum (evidence: `GUI/main_window.py`)
- Spectrum plot → FFT analysis: computes spectrum (evidence: `GUI/fft_plotter_widget.py`)
- Main window → Band power view: updates power (evidence: `GUI/main_window.py`)
- Main window → Band threshold detector: updates detection (evidence: `GUI/main_window.py`)
- Band threshold detector → Live acquisition: triggers buzzer
