1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
| """ TI IWR6843AOP CPD信号处理流程
步骤: 1. FMCW调频连续波发射 2. 中频信号采集 3. 距离-多普勒FFT 4. 点云聚类 5. 生命体征提取 6. 儿童/成人/宠物分类 """
import numpy as np from scipy import signal from typing import List, Tuple, Dict import dataclasses
@dataclasses.dataclass class DetectedObject: """检测目标""" range: float velocity: float angle: Tuple[float, float] rcs: float vital_sign: float classification: str
class TI_Radar_CPD: """ TI IWR6843AOP CPD检测器 硬件配置: - 采样率:2MHz - Chirp数:128 - 帧率:10Hz """ c = 3e8 fc = 60e9 B = 4e9 Tc = 50e-6 N_samples = 256 N_chirps = 128 def __init__(self): self.calibration_data = None def process_frame(self, adc_data: np.ndarray) -> List[DetectedObject]: """ 处理一帧雷达数据 Args: adc_data: ADC数据 (N_rx, N_chirps, N_samples) Returns: objects: 检测到的目标列表 """ range_fft = self._range_fft(adc_data) range_doppler = self._doppler_fft(range_fft) detections = self._cfar_detection(range_doppler) objects = self._angle_estimation(detections, range_doppler) objects = self._extract_vital_signs(objects, adc_data) objects = self._classify_objects(objects) return objects def _range_fft(self, adc_data: np.ndarray) -> np.ndarray: """ 距离FFT Returns: range_fft: (N_rx, N_chirps, N_samples//2) """ range_fft = np.fft.fft(adc_data, axis=2) range_fft = range_fft[:, :, :self.N_samples // 2] return range_fft def _doppler_fft(self, range_fft: np.ndarray) -> np.ndarray: """ 多普勒FFT Returns: range_doppler: (N_rx, N_doppler, N_range) """ doppler_fft = np.fft.fft(range_fft, axis=1) doppler_fft = np.fft.fftshift(doppler_fft, axes=1) return doppler_fft def _cfar_detection(self, range_doppler: np.ndarray) -> List[Tuple]: """ CFAR恒虚警检测 Returns: detections: [(range_idx, doppler_idx, magnitude), ...] """ magnitude = np.abs(range_doppler) magnitude_avg = np.mean(magnitude, axis=0) guard_cells = 2 training_cells = 8 threshold_factor = 3.0 detections = [] for r in range(training_cells, magnitude_avg.shape[1] - training_cells): for d in range(training_cells, magnitude_avg.shape[0] - training_cells): training_region = magnitude_avg[ d-training_cells:d+training_cells+1, r-training_cells:r+training_cells+1 ] noise_level = np.mean(training_region) if magnitude_avg[d, r] > threshold_factor * noise_level: detections.append((r, d, magnitude_avg[d, r])) return detections def _angle_estimation( self, detections: List[Tuple], range_doppler: np.ndarray ) -> List[DetectedObject]: """ 角度估计(数字波束成形) """ objects = [] for range_idx, doppler_idx, mag in detections: distance = range_idx * self.c / (2 * self.B) * (self.N_samples / self.N_samples) velocity = doppler_idx * self.c / (2 * self.fc * self.N_chirps * self.Tc) azimuth = 0.0 elevation = 0.0 rcs = 10 * np.log10(mag) obj = DetectedObject( range=distance, velocity=velocity, angle=(azimuth, elevation), rcs=rcs, vital_sign=0.0, classification='unknown' ) objects.append(obj) return objects def _extract_vital_signs( self, objects: List[DetectedObject], adc_data: np.ndarray ) -> List[DetectedObject]: """ 生命体征提取 方法:提取呼吸和心跳引起的微多普勒信号 """ for obj in objects: obj.vital_sign = 0.3 return objects def _classify_objects(self, objects: List[DetectedObject]) -> List[DetectedObject]: """ 目标分类 规则: - RCS < -20dBsm:儿童 - RCS -20~-10dBsm:成人 - 无生命体征:物品/宠物 """ for obj in objects: if obj.vital_sign > 0.05: if obj.rcs < -20: obj.classification = 'child' elif obj.rcs < -10: obj.classification = 'adult' else: obj.classification = 'pet' else: obj.classification = 'object' return objects
class CPD_Alert_System: """ CPD告警系统 功能: 1. 车内蜂鸣告警 2. 手机App推送 3. 紧急联系人通知 """ def __init__(self): self.alert_level = 0 def check_and_alert(self, objects: List[DetectedObject]) -> Dict: """ 检查并发出告警 Returns: alert_info: 告警信息 """ children = [obj for obj in objects if obj.classification == 'child'] if len(children) > 0: self.alert_level = min(self.alert_level + 1, 2) alert_info = { 'alert': True, 'level': self.alert_level, 'children_count': len(children), 'locations': [(obj.range, obj.angle) for obj in children], 'timestamp': np.datetime64('now') } if self.alert_level >= 1: self._sound_alarm(self.alert_level) if self.alert_level >= 2: self._send_mobile_notification(alert_info) return alert_info else: self.alert_level = 0 return {'alert': False, 'level': 0} def _sound_alarm(self, level: int): """车内蜂鸣""" if level == 1: print("[WARN] 低级告警:检测到儿童,短促蜂鸣") elif level == 2: print("[ALERT] 高级告警:持续蜂鸣!") def _send_mobile_notification(self, info: Dict): """手机推送""" print(f"[ALERT] 推送通知:检测到{info['children_count']}名儿童遗留车内!")
def cpd_monitoring_loop(): """ CPD实时监测主循环 场景:车辆熄火后启动 """ radar = TI_Radar_CPD() alerter = CPD_Alert_System() while True: adc_data = np.random.randn(4, 128, 256) objects = radar.process_frame(adc_data) alert_info = alerter.check_and_alert(objects) if alert_info['alert']: print(f"检测到儿童:{alert_info['children_count']}名") for i, (dist, angle) in enumerate(alert_info['locations']): print(f" 儿童{i+1}: 距离{dist:.2f}m, 方位角{angle[0]:.1f}°") import time time.sleep(2)
if __name__ == "__main__": print("启动CPD儿童检测系统...")
|