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 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
| import numpy as np from typing import Dict, List, Tuple from enum import Enum
class CPDDetectionType(Enum): """CPD检测类型""" EMPTY = 0 CHILD_PRESENT = 1 PET_PRESENT = 2 ADULT_PRESENT = 3 OBJECT = 4
class TI_AWRL6432: """ TI AWRL6432 60GHz雷达 特性: - 超低功耗(<5mW待机) - 高精度呼吸检测 - 宽检测角度(±60°) - 7秒快速检测 """ def __init__(self, detection_threshold: float = 0.99, false_alarm_rate: float = 0.01): """ 初始化 Args: detection_threshold: 检测阈值 false_alarm_rate: 误报率 """ self.chip_config = { 'frequency': 60, 'tx_channels': 1, 'rx_channels': 2, 'bandwidth': 4, 'max_range': 3, 'range_resolution': 0.04, 'velocity_resolution': 0.1, 'angular_resolution': 15, 'power_consumption': { 'active': 150, 'idle': 5, 'sleep': 0.1 } } self.detection_threshold = detection_threshold self.false_alarm_rate = false_alarm_rate self.fft_size = 256 self.cfar_threshold = 10 self.breathing_rate_range = (10, 40) self.heart_rate_range = (80, 160) def configure_for_cpd(self) -> Dict: """ 配置为CPD模式 Returns: config: 配置参数 """ config = { 'chirp_config': { 'num_chirps': 64, 'chirp_duration': 50, 'chirp_interval': 100, 'frame_period': 100, }, 'processing_chain': { 'range_fft': True, 'doppler_fft': True, 'angle_fft': False, 'cfar_detection': True, 'vital_signs': True }, 'power_management': { 'mode': 'duty_cycle', 'active_time': 100, 'sleep_time': 900, 'detection_latency': 7 } } return config def process_radar_data(self, adc_data: np.ndarray, timestamp: float) -> Dict: """ 处理雷达数据 Args: adc_data: ADC数据 (num_chirps, num_samples, num_rx) timestamp: 时间戳 Returns: result: 处理结果 """ result = { 'range_profile': None, 'doppler_profile': None, 'detections': [], 'vital_signs': None, 'classification': CPDDetectionType.EMPTY } range_fft = self._range_fft(adc_data) result['range_profile'] = range_fft doppler_fft = self._doppler_fft(range_fft) result['doppler_profile'] = doppler_fft detections = self._cfar_detection(doppler_fft) result['detections'] = detections if detections: vital_signs = self._extract_vital_signs(adc_data, detections) result['vital_signs'] = vital_signs result['classification'] = self._classify_target(vital_signs) return result def _range_fft(self, adc_data: np.ndarray) -> np.ndarray: """ Range FFT Args: adc_data: ADC数据 Returns: range_fft: Range FFT结果 """ range_fft = np.fft.fft(adc_data, axis=1) range_fft = np.abs(range_fft) return range_fft def _doppler_fft(self, range_fft: np.ndarray) -> np.ndarray: """ Doppler FFT Args: range_fft: Range FFT结果 Returns: doppler_fft: Doppler FFT结果 """ doppler_fft = np.fft.fft(range_fft, axis=0) doppler_fft = np.fft.fftshift(doppler_fft, axes=0) doppler_fft = np.abs(doppler_fft) return doppler_fft def _cfar_detection(self, doppler_fft: np.ndarray) -> List[Dict]: """ CFAR检测 Args: doppler_fft: Doppler FFT结果 Returns: detections: 检测结果列表 """ detections = [] threshold = np.mean(doppler_fft) + self.cfar_threshold peak_indices = np.where(doppler_fft > threshold) if len(peak_indices[0]) > 0: max_idx = np.argmax(doppler_fft[peak_indices]) doppler_idx = peak_indices[0][max_idx] range_idx = peak_indices[1][max_idx] range_m = range_idx * self.chip_config['range_resolution'] velocity = (doppler_idx - self.fft_size // 2) * 0.1 detections.append({ 'range': range_m, 'velocity': velocity, 'snr': doppler_fft[doppler_idx, range_idx] / np.mean(doppler_fft) }) return detections def _extract_vital_signs(self, adc_data: np.ndarray, detections: List[Dict]) -> Dict: """ 提取生命体征 Args: adc_data: ADC数据 detections: CFAR检测结果 Returns: vital_signs: 生命体征 """ vital_signs = { 'breathing_rate': None, 'heart_rate': None, 'presence_confidence': 0.0 } if not detections: return vital_signs detection = detections[0] range_idx = int(detection['range'] / self.chip_config['range_resolution']) phase_series = np.angle(adc_data[:, range_idx, 0]) phase_unwrapped = np.unwrap(phase_series) breathing_signal = self._bandpass_filter( phase_unwrapped, lowcut=0.1, highcut=0.5, fs=10 ) breathing_fft = np.abs(np.fft.fft(breathing_signal)) breathing_freq = np.argmax(breathing_fft) * 10 / len(breathing_fft) vital_signs['breathing_rate'] = breathing_freq * 60 if self.breathing_rate_range[0] <= vital_signs['breathing_rate'] <= self.breathing_rate_range[1]: vital_signs['presence_confidence'] = 0.95 else: vital_signs['presence_confidence'] = 0.6 return vital_signs def _bandpass_filter(self, signal: np.ndarray, lowcut: float, highcut: float, fs: float) -> np.ndarray: """带通滤波""" from scipy.signal import butter, filtfilt nyq = fs / 2 low = lowcut / nyq high = highcut / nyq b, a = butter(2, [low, high], btype='band') filtered = filtfilt(b, a, signal) return filtered def _classify_target(self, vital_signs: Dict) -> CPDDetectionType: """ 分类目标 Args: vital_signs: 生命体征 Returns: classification: 分类结果 """ if vital_signs['presence_confidence'] < self.detection_threshold: return CPDDetectionType.EMPTY breathing_rate = vital_signs['breathing_rate'] if self.breathing_rate_range[0] <= breathing_rate <= self.breathing_rate_range[1]: return CPDDetectionType.CHILD_PRESENT elif 5 <= breathing_rate <= 20: return CPDDetectionType.PET_PRESENT elif 10 <= breathing_rate <= 25: return CPDDetectionType.ADULT_PRESENT else: return CPDDetectionType.OBJECT
class EuroNCAP_CPD_Interface: """ Euro NCAP CPD检测接口 """ def __init__(self): self.radar = TI_AWRL6432() self.config = self.radar.configure_for_cpd() def detect_child_presence(self, radar_frames: List[np.ndarray]) -> Dict: """ 检测儿童存在 Args: radar_frames: 雷达帧序列 Returns: result: Euro NCAP格式结果 """ combined_result = { 'child_detected': False, 'confidence': 0.0, 'location': None, 'breathing_rate': None, 'alert_required': False } confidences = [] classifications = [] for frame in radar_frames: result = self.radar.process_radar_data(frame, 0) if result['vital_signs']: confidences.append(result['vital_signs']['presence_confidence']) classifications.append(result['classification']) if confidences: avg_confidence = np.mean(confidences) combined_result['confidence'] = avg_confidence child_count = sum(1 for c in classifications if c == CPDDetectionType.CHILD_PRESENT) if child_count > len(classifications) / 2: combined_result['child_detected'] = True combined_result['alert_required'] = True return combined_result
if __name__ == "__main__": radar = TI_AWRL6432() print("TI AWRL6432配置:") for key, value in radar.chip_config.items(): print(f" {key}: {value}") adc_data = np.random.randn(64, 256, 2) + 1j * np.random.randn(64, 256, 2) result = radar.process_radar_data(adc_data, 0) print("\n处理结果:") print(f" 检测数量: {len(result['detections'])}") print(f" 分类结果: {result['classification'].name}") if result['vital_signs']: print(f" 呼吸频率: {result['vital_signs']['breathing_rate']:.1f} 次/分钟") print(f" 置信度: {result['vital_signs']['presence_confidence']:.2f}")
|