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
| """ 60GHz FMCW雷达信号处理
基本原理: 1. 发射线性调频连续波 2. 接收反射信号 3. 混频得到中频信号 4. FFT得到距离-多普勒图 5. CFAR检测目标 6. 估计生命体征
"""
import numpy as np from typing import Dict, List, Tuple, Optional from dataclasses import dataclass import scipy.signal as signal import scipy.fft as fft
@dataclass class RadarConfig: """雷达配置""" center_freq: float = 60e9 bandwidth: float = 4e9 chirp_duration: float = 100e-6 sampling_rate: float = 2e6 num_tx: int = 4 num_rx: int = 4 num_chirps: int = 64 num_samples: int = 256
@dataclass class DetectedObject: """检测到的目标""" range_m: float velocity_ms: float angle_deg: float snr_db: float rcs_dbsm: float is_human: bool breath_rate: Optional[float] heart_rate: Optional[float]
class FMCWRadarProcessor: """FMCW雷达信号处理器""" def __init__(self, config: RadarConfig): self.config = config self.c = 3e8 self.wavelength = self.c / config.center_freq self.range_resolution = self.c / (2 * config.bandwidth) self.velocity_resolution = self.wavelength / (2 * config.num_chirps * config.chirp_duration) self.max_range = config.num_samples * self.range_resolution / 2 self.max_velocity = self.wavelength / (4 * config.chirp_duration) self.cfar_guard_cells = 4 self.cfar_training_cells = 8 self.cfar_threshold = 10.0 def process_frame( self, adc_data: np.ndarray ) -> List[DetectedObject]: """ 处理一帧数据 Args: adc_data: ADC数据 Returns: objects: 检测到的目标列表 """ range_fft = self._range_fft(adc_data) range_doppler = self._doppler_fft(range_fft) detections = self._cfar_detection(range_doppler) objects = [] for det in detections: angle = self._estimate_angle(range_fft, det['range_idx'], det['doppler_idx']) range_m = det['range_idx'] * self.range_resolution velocity_ms = (det['doppler_idx'] - self.config.num_chirps // 2) * self.velocity_resolution breath_rate, heart_rate = self._estimate_vital_signs( adc_data, det['range_idx'], det['doppler_idx'] ) objects.append(DetectedObject( range_m=range_m, velocity_ms=velocity_ms, angle_deg=angle, snr_db=det['snr'], rcs_dbsm=det['rcs'], is_human=breath_rate is not None, breath_rate=breath_rate, heart_rate=heart_rate )) return objects def _range_fft(self, adc_data: np.ndarray) -> np.ndarray: """Range FFT""" num_rx, num_chirps, num_samples = adc_data.shape range_fft = fft.fft(adc_data, n=self.config.num_samples, axis=2) return range_fft def _doppler_fft(self, range_fft: np.ndarray) -> np.ndarray: """Doppler FFT""" doppler_fft = fft.fftshift( fft.fft(range_fft, n=self.config.num_chirps, axis=1), axes=1 ) range_doppler = np.abs(doppler_fft).mean(axis=0) return range_doppler def _cfar_detection( self, range_doppler: np.ndarray ) -> List[Dict]: """CFAR目标检测""" detections = [] num_range_bins = range_doppler.shape[0] num_doppler_bins = range_doppler.shape[1] for r in range(self.cfar_guard_cells + self.cfar_training_cells, num_range_bins - self.cfar_guard_cells - self.cfar_training_cells): for d in range(self.cfar_guard_cells + self.cfar_training_cells, num_doppler_bins - self.cfar_guard_cells - self.cfar_training_cells): cut_value = range_doppler[r, d] training_cells = [] for tr in range(-self.cfar_training_cells - self.cfar_guard_cells, self.cfar_training_cells + self.cfar_guard_cells + 1): for td in range(-self.cfar_training_cells - self.cfar_guard_cells, self.cfar_training_cells + self.cfar_guard_cells + 1): if abs(tr) > self.cfar_guard_cells or abs(td) > self.cfar_guard_cells: training_cells.append(range_doppler[r + tr, d + td]) noise_level = np.mean(training_cells) threshold = noise_level * (10 ** (self.cfar_threshold / 10)) if cut_value > threshold: snr = 10 * np.log10(cut_value / noise_level) detections.append({ 'range_idx': r, 'doppler_idx': d, 'snr': snr, 'rcs': snr + 20 * np.log10(range_m) - 40 }) return detections def _estimate_angle( self, range_fft: np.ndarray, range_idx: int, doppler_idx: int ) -> float: """角度估计(数字波束成形)""" virtual_array = range_fft[:, doppler_idx, range_idx] angle_fft = fft.fftshift(fft.fft(virtual_array, n=64)) angle_idx = np.argmax(np.abs(angle_fft)) angle = np.arcsin((angle_idx - 32) / 32) * 180 / np.pi return angle def _estimate_vital_signs( self, adc_data: np.ndarray, range_idx: int, doppler_idx: int ) -> Tuple[Optional[float], Optional[float]]: """ 估计生命体征 Returns: breath_rate: 呼吸频率 (BPM) heart_rate: 心率 (BPM) """ phase = np.angle(adc_data[0, :, range_idx]) phase_unwrapped = np.unwrap(phase) phase_detrended = signal.detrend(phase_unwrapped) frame_duration = self.config.num_chirps * self.config.chirp_duration freq = fft.fftfreq(self.config.num_chirps, frame_duration / self.config.num_chirps) phase_spectrum = np.abs(fft.fft(phase_detrended)) breath_band = (freq >= 0.1) & (freq <= 0.5) if breath_band.any(): breath_idx = np.argmax(phase_spectrum[breath_band]) breath_rate = freq[breath_band][breath_idx] * 60 else: breath_rate = None heart_band = (freq >= 0.8) & (freq <= 2.0) if heart_band.any(): heart_idx = np.argmax(phase_spectrum[heart_band]) heart_rate = freq[heart_band][heart_idx] * 60 else: heart_rate = None return breath_rate, heart_rate
class ChildPresenceDetector: """儿童存在检测器""" def __init__(self, radar_processor: FMCWRadarProcessor): self.radar = radar_processor self.breath_rate_range = (15, 40) self.heart_rate_range = (80, 140) self.min_detection_count = 5 self.detection_history = [] def detect(self, adc_data: np.ndarray) -> Dict: """ 检测儿童 Args: adc_data: ADC数据 Returns: result: 检测结果 """ objects = self.radar.process_frame(adc_data) child_candidates = [] for obj in objects: if obj.breath_rate is not None: if self.breath_rate_range[0] <= obj.breath_rate <= self.breath_rate_range[1]: child_candidates.append(obj) self.detection_history.append(len(child_candidates) > 0) if len(self.detection_history) > self.min_detection_count: self.detection_history.pop(0) child_detected = sum(self.detection_history) >= self.min_detection_count * 0.8 return { 'child_detected': child_detected, 'confidence': sum(self.detection_history) / len(self.detection_history) if self.detection_history else 0, 'num_candidates': len(child_candidates), 'candidates': [{ 'range': c.range_m, 'breath_rate': c.breath_rate, 'heart_rate': c.heart_rate } for c in child_candidates] }
if __name__ == "__main__": config = RadarConfig() processor = FMCWRadarProcessor(config) print("60GHz FMCW雷达参数:") print(f" 波长: {processor.wavelength * 1000:.2f} mm") print(f" 距离分辨率: {processor.range_resolution * 100:.2f} cm") print(f" 速度分辨率: {processor.velocity_resolution * 100:.2f} cm/s") print(f" 最大距离: {processor.max_range:.2f} m") print(f" 最大速度: {processor.max_velocity:.2f} m/s") cpd = ChildPresenceDetector(processor) print("\n儿童存在检测器初始化完成") print(f" 呼吸频率范围: {cpd.breath_rate_range} BPM") print(f" 心率范围: {cpd.heart_rate_range} BPM")
|