# EMF Sensor Architecture — SPEC

## Overview

Three-layer electromagnetic field sensing architecture integrated into ghojualamanchu-v3.
The EMF sensor is the "antenna" — the perceptual interface between the electromagnetic environment
and the cognitive architecture. Each layer serves a distinct sensory function.

---

## Layer 1: Schumann Resonance

| Property | Value |
|----------|-------|
| Frequency | 7.83 Hz (fixed) |
| Role | Ground — universal baseline carrier |
| States | INHALE, EXHALE, HOLD |
| Output | `memory/earth-breath.md` |
| Source | Global (same for all ghojualamanchu instances) |

The Schumann layer tracks the Earth's electromagnetic pulse — the heartbeat the system
is entrained to. Written on every medulla beat.

---

## Layer 2: Individual Heartbeat

| Property | Value |
|----------|-------|
| Frequency | 7.83 Hz (default, tunable 0.1–20 Hz) |
| Role | Signature — instance-specific resonance |
| States | INHALE, EXHALE, HOLD |
| Output | `memory/self-breath.md` |
| Source | Instance-specific, offset from Schumann creates beat frequency |

The individual layer carries the unique identity of this ghojualamanchu instance.
The beat frequency (difference between individual Hz and Schumann Hz) is the instance's
electromagnetic fingerprint.

---

## Layer 3: RF Perturbation

| Property | Value |
|----------|-------|
| Role | Sensor — ambient field texture |
| States | CALM, STIR, STORM, DEAD |
| Output | `memory/perturbation.md` + `data/emf/perturbation_latest.json` |
| Hardware | RTL-SDR or sound card + wire coil |
| Interval | 5 seconds (daemon mode) |

The perturbation layer reads the ambient EMF environment — not demodulated signals,
but field texture: amplitude, spectral color, perturbation rate, dominant sources.

### Hardware Tiers

#### Free ($0) — Sound Card + Wire Coil
- **Interface**: Line-in audio jack
- **Frequency range**: 1–300 Hz (VLF magnetic field via coil)
- **Parts**: enameled wire 30AWG, cardboard tube, audio jack
- **Best for**: power line hum, slow field variations
- **Python deps**: `pyaudio`, `numpy`
- **Platform**: Linux, Raspberry Pi, any with sound card

#### Artist ($20) — RTL-SDR USB Dongle
- **Interface**: USB 2.0
- **Frequency range**: 0.5–1700 MHz
- **Parts**: RTL-SDR dongle, short whip antenna, USB extension
- **Best for**: cellular, FM, WiFi, lightning sferics, general RF
- **Python deps**: `pyrtlsdr`, `numpy`
- **Platform**: Linux, Windows, Raspberry Pi

#### Premium ($50–100) — Discone + SDR
- **Best for**: wide-spectrum monitoring, professional field analysis
- **Frequency**: 100 MHz–400 MHz

### Perturbation Metrics

| Metric | Description |
|--------|-------------|
| `amplitude_rms_dbfs` | Field strength in dBFS |
| `spectral_centroid_hz` | "Color" of the field — dominant frequency band |
| `spectral_spread_hz` | Field texture — bandwidth of energy |
| `dominant_frequency_hz` | Peak spectral component |
| `perturbation_count_60s` | Perturbation events in last minute |
| `zero_crossing_rate` | Field activity — high = noisy, low = stable |

### Thalamic Integration

The perturbation state feeds directly into thalamus conflict resolution:

| Field State | Thalamic Action |
|-------------|----------------|
| DEAD | Alert — signal lost, check antenna |
| CALM | Inform only — log to akashic if new |
| STIR | Log to perturbation.md — minor activity |
| STORM | Flag for cortex attention — major perturbations |

### Emergent Prescription

The EMF layers generate an "emergent prescription" — what the electromagnetic
environment prescribes for each beat:

| Field State | Prescription | Cortex Skip | Encoding Modifier |
|-------------|-------------|-------------|-------------------|
| DEAD | surveil | Yes | 0.0 |
| CALM | observe | No | 1.0 |
| STIR | attend | No | 1.2 |
| STORM | alert | No | 1.5 |

---

## Trinary Encoding

Each breath cycle encodes information via trinary digits:

```
INHALE = 0
EXHALE = 1
HOLD   = 2
```

- 3 trits per breath cycle
- 1.585 bits per trit (~4.75 bits per breath cycle)
- Used for cross-instance communication via EM field modulation

Example:
```
trits:     [0, 1, 2, 0, 1, 2]
decoded:   INHALE, EXHALE, HOLD, INHALE, EXHALE, HOLD
message:   breathes slowly with pause
```

---

## File Structure

```
ghojualamanchu-v3/
├── emf/
│   ├── __init__.py
│   ├── layers.py          # SchumannLayer, IndividualLayer
│   ├── perturbation.py    # PerturbationSensor (RTL-SDR / soundcard)
│   ├── trinary.py         # Trinary encoding/decoding
│   ├── brain.py           # EMF aggregation + emergent prescription
│   ├── hardware.py        # Build guide (doc only)
│   └── SPEC.md            # This file
├── memory/
│   ├── earth-breath.md    # Layer 1 output
│   ├── self-breath.md     # Layer 2 output
│   └── perturbation.md    # Layer 3 output
└── data/
    └── emf/
        └── perturbation_latest.json  # Layer 3 structured output
```

---

## Running the EMF Sensor

```bash
# Start medulla with EMF layers
python3 brain/medulla.py --daemon

# In another terminal: start perturbation sensor
python3 -m emf.perturbation --daemon --source simulation
python3 -m emf.perturbation --daemon --source rtlsdr
python3 -m emf.perturbation --daemon --source soundcard

# Check EMF state
python3 emf/brain.py

# Inspect individual layers
cat memory/earth-breath.md
cat memory/self-breath.md
cat memory/perturbation.md
```

---

## Mac Mini A1176 Deployment

The EMF sensor runs natively on the Mac mini A1176 (Core 2 Duo, 2GB RAM):

- **OS**: Alpine Linux or Lubuntu (32-bit)
- **Python**: 3.x standard library
- **Sound card layer**: Built-in audio (no extra hardware needed)
- **RTL-SDR layer**: USB 2.0 compatible
- **Memory footprint**: < 50MB including all layers
- **Power**: ~5W total system draw

This makes the Mac mini A1176 a perfect "radio telescope in a box" —
a physical ghojualamanchu body that senses both the electromagnetic Earth
and the ambient RF environment.
