|
| 1 | +""" |
| 2 | +Mock CSI data generator for testing and development. |
| 3 | +
|
| 4 | +This module provides synthetic CSI (Channel State Information) data generation |
| 5 | +for use in development and testing environments ONLY. The generated data mimics |
| 6 | +realistic WiFi CSI patterns including multipath effects, human motion signatures, |
| 7 | +and noise characteristics. |
| 8 | +
|
| 9 | +WARNING: This module uses np.random intentionally for test data generation. |
| 10 | +Do NOT use this module in production data paths. |
| 11 | +""" |
| 12 | + |
| 13 | +import logging |
| 14 | +import numpy as np |
| 15 | +from typing import Dict, Any, Optional |
| 16 | + |
| 17 | +logger = logging.getLogger(__name__) |
| 18 | + |
| 19 | +# Banner displayed when mock mode is active |
| 20 | +MOCK_MODE_BANNER = """ |
| 21 | +================================================================================ |
| 22 | + WARNING: MOCK MODE ACTIVE - Using synthetic CSI data |
| 23 | +
|
| 24 | + All CSI data is randomly generated and does NOT represent real WiFi signals. |
| 25 | + For real pose estimation, configure hardware per docs/hardware-setup.md. |
| 26 | +================================================================================ |
| 27 | +""" |
| 28 | + |
| 29 | + |
| 30 | +class MockCSIGenerator: |
| 31 | + """Generator for synthetic CSI data used in testing and development. |
| 32 | +
|
| 33 | + This class produces complex-valued CSI matrices that simulate realistic |
| 34 | + WiFi channel characteristics including: |
| 35 | + - Per-antenna and per-subcarrier amplitude/phase variation |
| 36 | + - Simulated human movement signatures |
| 37 | + - Configurable noise levels |
| 38 | + - Temporal coherence across consecutive frames |
| 39 | +
|
| 40 | + This is ONLY for testing. Production code must use real hardware data. |
| 41 | + """ |
| 42 | + |
| 43 | + def __init__( |
| 44 | + self, |
| 45 | + num_subcarriers: int = 64, |
| 46 | + num_antennas: int = 4, |
| 47 | + num_samples: int = 100, |
| 48 | + noise_level: float = 0.1, |
| 49 | + movement_freq: float = 0.5, |
| 50 | + movement_amplitude: float = 0.3, |
| 51 | + ): |
| 52 | + """Initialize mock CSI generator. |
| 53 | +
|
| 54 | + Args: |
| 55 | + num_subcarriers: Number of OFDM subcarriers to simulate |
| 56 | + num_antennas: Number of antenna elements |
| 57 | + num_samples: Number of temporal samples per frame |
| 58 | + noise_level: Standard deviation of additive Gaussian noise |
| 59 | + movement_freq: Frequency of simulated human movement (Hz) |
| 60 | + movement_amplitude: Amplitude of movement-induced CSI variation |
| 61 | + """ |
| 62 | + self.num_subcarriers = num_subcarriers |
| 63 | + self.num_antennas = num_antennas |
| 64 | + self.num_samples = num_samples |
| 65 | + self.noise_level = noise_level |
| 66 | + self.movement_freq = movement_freq |
| 67 | + self.movement_amplitude = movement_amplitude |
| 68 | + |
| 69 | + # Internal state for temporal coherence |
| 70 | + self._phase = 0.0 |
| 71 | + self._frequency = 0.1 |
| 72 | + self._amplitude_base = 1.0 |
| 73 | + |
| 74 | + self._banner_shown = False |
| 75 | + |
| 76 | + def show_banner(self) -> None: |
| 77 | + """Display the mock mode warning banner (once per session).""" |
| 78 | + if not self._banner_shown: |
| 79 | + logger.warning(MOCK_MODE_BANNER) |
| 80 | + self._banner_shown = True |
| 81 | + |
| 82 | + def generate(self) -> np.ndarray: |
| 83 | + """Generate a single frame of mock CSI data. |
| 84 | +
|
| 85 | + Returns: |
| 86 | + Complex-valued numpy array of shape |
| 87 | + (num_antennas, num_subcarriers, num_samples). |
| 88 | + """ |
| 89 | + self.show_banner() |
| 90 | + |
| 91 | + # Advance internal phase for temporal coherence |
| 92 | + self._phase += self._frequency |
| 93 | + |
| 94 | + time_axis = np.linspace(0, 1, self.num_samples) |
| 95 | + |
| 96 | + csi_data = np.zeros( |
| 97 | + (self.num_antennas, self.num_subcarriers, self.num_samples), |
| 98 | + dtype=complex, |
| 99 | + ) |
| 100 | + |
| 101 | + for antenna in range(self.num_antennas): |
| 102 | + for subcarrier in range(self.num_subcarriers): |
| 103 | + # Base amplitude varies with antenna and subcarrier |
| 104 | + amplitude = ( |
| 105 | + self._amplitude_base |
| 106 | + * (1 + 0.2 * np.sin(2 * np.pi * subcarrier / self.num_subcarriers)) |
| 107 | + * (1 + 0.1 * antenna) |
| 108 | + ) |
| 109 | + |
| 110 | + # Phase with spatial and frequency variation |
| 111 | + phase_offset = ( |
| 112 | + self._phase |
| 113 | + + 2 * np.pi * subcarrier / self.num_subcarriers |
| 114 | + + np.pi * antenna / self.num_antennas |
| 115 | + ) |
| 116 | + |
| 117 | + # Simulated human movement |
| 118 | + movement = self.movement_amplitude * np.sin( |
| 119 | + 2 * np.pi * self.movement_freq * time_axis |
| 120 | + ) |
| 121 | + |
| 122 | + signal_amplitude = amplitude * (1 + movement) |
| 123 | + signal_phase = phase_offset + movement * 0.5 |
| 124 | + |
| 125 | + # Additive complex Gaussian noise |
| 126 | + noise = np.random.normal(0, self.noise_level, self.num_samples) + 1j * np.random.normal( |
| 127 | + 0, self.noise_level, self.num_samples |
| 128 | + ) |
| 129 | + |
| 130 | + csi_data[antenna, subcarrier, :] = ( |
| 131 | + signal_amplitude * np.exp(1j * signal_phase) + noise |
| 132 | + ) |
| 133 | + |
| 134 | + return csi_data |
| 135 | + |
| 136 | + def configure(self, config: Dict[str, Any]) -> None: |
| 137 | + """Update generator parameters. |
| 138 | +
|
| 139 | + Args: |
| 140 | + config: Dictionary with optional keys: |
| 141 | + - sampling_rate: Adjusts internal frequency |
| 142 | + - noise_level: Sets noise standard deviation |
| 143 | + - num_subcarriers: Updates subcarrier count |
| 144 | + - num_antennas: Updates antenna count |
| 145 | + - movement_freq: Updates simulated movement frequency |
| 146 | + - movement_amplitude: Updates movement amplitude |
| 147 | + """ |
| 148 | + if "sampling_rate" in config: |
| 149 | + self._frequency = config["sampling_rate"] / 1000.0 |
| 150 | + if "noise_level" in config: |
| 151 | + self.noise_level = config["noise_level"] |
| 152 | + if "num_subcarriers" in config: |
| 153 | + self.num_subcarriers = config["num_subcarriers"] |
| 154 | + if "num_antennas" in config: |
| 155 | + self.num_antennas = config["num_antennas"] |
| 156 | + if "movement_freq" in config: |
| 157 | + self.movement_freq = config["movement_freq"] |
| 158 | + if "movement_amplitude" in config: |
| 159 | + self.movement_amplitude = config["movement_amplitude"] |
| 160 | + |
| 161 | + def get_router_info(self) -> Dict[str, Any]: |
| 162 | + """Return mock router hardware information. |
| 163 | +
|
| 164 | + Returns: |
| 165 | + Dictionary mimicking router hardware info for testing. |
| 166 | + """ |
| 167 | + return { |
| 168 | + "model": "Mock Router", |
| 169 | + "firmware": "1.0.0-mock", |
| 170 | + "wifi_standard": "802.11ac", |
| 171 | + "antennas": self.num_antennas, |
| 172 | + "supported_bands": ["2.4GHz", "5GHz"], |
| 173 | + "csi_capabilities": { |
| 174 | + "max_subcarriers": self.num_subcarriers, |
| 175 | + "max_antennas": self.num_antennas, |
| 176 | + "sampling_rate": 1000, |
| 177 | + }, |
| 178 | + } |
0 commit comments