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
| import numpy as np
class CPDRadarSystem60GHz: """ 60GHz毫米波雷达CPD系统 """ def __init__(self): self.radar_config = { 'frequency': 60e9, 'bandwidth': 4e9, 'chirps_per_frame': 128, 'samples_per_chirp': 256, 'frame_rate': 20 } self.vital_signs_thresholds = { 'breathing_rate': (10, 40), 'heart_rate': (60, 140), 'movement_amplitude': 0.01 } self.detection_state = { 'detected': False, 'location': None, 'vital_signs': None, 'confidence': 0.0 } def acquire_radar_data(self): """ 获取雷达数据(模拟) Returns: radar_data: (n_chirps, n_samples, n_rx) 复数雷达数据 """ n_chirps = self.radar_config['chirps_per_frame'] n_samples = self.radar_config['samples_per_chirp'] n_rx = 4 radar_data = np.random.randn(n_chirps, n_samples, n_rx) + \ 1j * np.random.randn(n_chirps, n_samples, n_rx) return radar_data def process_radar_frame(self, radar_data): """ 处理单帧雷达数据 Steps: 1. 距离-多普勒FFT 2. 目标检测 3. 生命体征提取 Returns: detections: 检测结果列表 """ range_fft = np.fft.fft(radar_data, axis=1) doppler_fft = np.fft.fft(range_fft, axis=0) detections = self.cfar_detection(doppler_fft) for det in detections: vital_signs = self.extract_vital_signs(radar_data, det) det['vital_signs'] = vital_signs return detections def cfar_detection(self, doppler_fft): """ CFAR目标检测 """ energy = np.abs(doppler_fft) ** 2 energy_mean = np.mean(energy, axis=(0, 1), keepdims=True) threshold = 10 * energy_mean peaks = energy > threshold detections = [] indices = np.where(peaks) for i in range(min(len(indices[0]), 10)): detection = { 'range_idx': indices[1][i], 'doppler_idx': indices[0][i], 'snr': energy[indices[0][i], indices[1][i]] / energy_mean[0, 0] } detections.append(detection) return detections def extract_vital_signs(self, radar_data, detection): """ 提取生命体征 Args: radar_data: 原始雷达数据 detection: 检测点信息 Returns: vital_signs: {'breathing': float, 'heart_rate': float} """ range_idx = detection['range_idx'] phase_signal = np.angle(radar_data[:, range_idx, 0]) unwrapped_phase = np.unwrap(phase_signal) n_chirps = len(unwrapped_phase) frame_duration = n_chirps / self.radar_config['frame_rate'] fft_result = np.fft.fft(unwrapped_phase) freqs = np.fft.fftfreq(n_chirps, d=frame_duration / n_chirps) breathing_band = (0.1, 0.5) breathing_idx = np.where((freqs >= breathing_band[0]) & (freqs <= breathing_band[1])) breathing_power = np.max(np.abs(fft_result[breathing_idx])) heart_band = (1.0, 2.5) heart_idx = np.where((freqs >= heart_band[0]) & (freqs <= heart_band[1])) heart_power = np.max(np.abs(fft_result[heart_idx])) breathing_rate = freqs[breathing_idx][np.argmax(np.abs(fft_result[breathing_idx]))] * 60 heart_rate = freqs[heart_idx][np.argmax(np.abs(fft_result[heart_idx]))] * 60 return { 'breathing': abs(breathing_rate), 'heart_rate': abs(heart_rate), 'breathing_power': breathing_power, 'heart_power': heart_power } def classify_target(self, vital_signs): """ 分类目标(婴儿/儿童/成人/宠物/物体) Args: vital_signs: 生命体征数据 Returns: classification: { 'type': 'infant' | 'child' | 'adult' | 'pet' | 'object', 'confidence': float } """ breathing = vital_signs['breathing'] heart_rate = vital_signs['heart_rate'] if vital_signs['breathing_power'] < 0.1: return {'type': 'object', 'confidence': 0.9} if 30 <= breathing <= 60 and 100 <= heart_rate <= 160: return {'type': 'infant', 'confidence': 0.85} if 15 <= breathing <= 35 and 70 <= heart_rate <= 130: return {'type': 'child', 'confidence': 0.8} if 10 <= breathing <= 25 and 60 <= heart_rate <= 100: return {'type': 'adult', 'confidence': 0.75} if 15 <= breathing <= 45 and 80 <= heart_rate <= 150: return {'type': 'pet', 'confidence': 0.7} return {'type': 'unknown', 'confidence': 0.5} def run_detection_cycle(self): """ 运行检测周期 Returns: result: 检测结果 """ radar_data = self.acquire_radar_data() detections = self.process_radar_frame(radar_data) results = [] for det in detections: classification = self.classify_target(det['vital_signs']) if classification['type'] in ['infant', 'child', 'pet']: results.append({ 'type': classification['type'], 'confidence': classification['confidence'], 'vital_signs': det['vital_signs'], 'location': self.range_idx_to_location(det['range_idx']) }) return results def range_idx_to_location(self, range_idx): """ 将距离索引转换为物理位置 """ max_range = 3.0 n_samples = self.radar_config['samples_per_chirp'] location = range_idx / n_samples * max_range if location < 1.0: return 'front_seat' elif location < 2.0: return 'rear_left' elif location < 3.0: return 'rear_right' else: return 'trunk'
if __name__ == "__main__": cpd_system = CPDRadarSystem60GHz() results = cpd_system.run_detection_cycle() print(f"检测到 {len(results)} 个目标") for i, result in enumerate(results): print(f"目标{i+1}: {result['type']} (置信度: {result['confidence']:.2f})") print(f" 位置: {result['location']}") print(f" 呼吸: {result['vital_signs']['breathing']:.1f} 次/分") print(f" 心跳: {result['vital_signs']['heart_rate']:.1f} 次/分")
|