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
| import numpy as np from typing import Tuple
class FMCWRadar60GHz: """ 60GHz FMCW雷达信号处理 应用: 1. 儿童存在检测(CPD) 2. 乘员监测(OMS) 3. 生命体征检测(呼吸/心跳) 优势: - 高分辨率(mm级) - 可检测微弱运动(呼吸/心跳) - 穿透非金属材料(毛毯/座椅) """ def __init__(self): self.fc = 60e9 self.c = 3e8 self.bandwidth = 4e9 self.num_chirps = 128 self.num_samples = 256 self.chirp_duration = 100e-6 self.range_resolution = self.c / (2 * self.bandwidth) self.max_velocity = self.c / (4 * self.fc * self.chirp_duration) def generate_chirp_signal(self) -> Tuple[np.ndarray, np.ndarray]: """ 生成FMCW chirp信号 Chirp信号:频率随时间线性变化的信号 f(t) = fc + (B/T) * t 其中: - fc: 起始频率 - B: 带宽 - T: chirp持续时间 """ t = np.linspace(0, self.chirp_duration, self.num_samples) alpha = self.bandwidth / self.chirp_duration phase = 2 * np.pi * (self.fc * t + 0.5 * alpha * t ** 2) tx_signal = np.exp(1j * phase) return t, tx_signal def simulate_reflected_signal( self, tx_signal: np.ndarray, target_distance: float, target_velocity: float ) -> np.ndarray: """ 模拟反射信号 Args: tx_signal: 发射信号 target_distance: 目标距离(米) target_velocity: 目标速度(米/秒) Returns: rx_signal: 接收信号 """ tau = 2 * target_distance / self.c fd = 2 * target_velocity * self.fc / self.c rx_signal = tx_signal * np.exp(1j * 2 * np.pi * fd * tau) noise = np.random.randn(len(rx_signal)) * 0.01 rx_signal = rx_signal + noise return rx_signal def range_fft(self, rx_signal: np.ndarray) -> np.ndarray: """ 距离FFT(Range FFT) 提取目标距离信息 Args: rx_signal: 接收信号, shape=(num_chirps, num_samples) Returns: range_profile: 距离剖面, shape=(num_chirps, range_bins) """ range_profile = np.fft.fft(rx_signal, axis=1) return range_profile def velocity_fft(self, range_profile: np.ndarray) -> np.ndarray: """ 速度FFT(Doppler FFT) 提取目标速度信息 Args: range_profile: 距离剖面, shape=(num_chirps, range_bins) Returns: range_doppler_map: 距离-多普勒图 """ range_doppler_map = np.fft.fftshift( np.fft.fft(range_profile, axis=0), axes=0 ) return range_doppler_map def detect_vital_signs(self, rx_signal: np.ndarray) -> dict: """ 检测生命体征(呼吸/心跳) 原理: 1. 呼吸引起胸腔位移:1-5mm,频率0.1-0.5Hz 2. 心跳引起胸腔位移:0.1-0.5mm,频率0.8-2Hz Args: rx_signal: 接收信号(多帧) Returns: { "breathing_rate": float, # 呼吸频率(次/分钟) "heart_rate": float, # 心率(次/分钟) "presence": bool, # 是否存在生命体征 } """ phase = np.angle(rx_signal) phase_unwrapped = np.unwrap(phase) freqs = np.fft.fftfreq(len(phase_unwrapped), d=self.chirp_duration * self.num_chirps) spectrum = np.abs(np.fft.fft(phase_unwrapped)) breathing_idx = np.logical_and(freqs >= 0.1, freqs <= 0.5) breathing_freq = freqs[breathing_idx][np.argmax(spectrum[breathing_idx])] breathing_rate = breathing_freq * 60 heart_idx = np.logical_and(freqs >= 0.8, freqs <= 2.0) heart_freq = freqs[heart_idx][np.argmax(spectrum[heart_idx])] heart_rate = heart_freq * 60 presence = np.max(spectrum[breathing_idx]) > 0.1 or np.max(spectrum[heart_idx]) > 0.05 return { "breathing_rate": breathing_rate, "heart_rate": heart_rate, "presence": presence, }
if __name__ == "__main__": radar = FMCWRadar60GHz() print(f"距离分辨率: {radar.range_resolution * 1000:.1f} mm") print(f"最大检测速度: {radar.max_velocity:.1f} m/s") t, tx_signal = radar.generate_chirp_signal() target_distance = 1.0 target_velocity = 0.01 rx_signal = radar.simulate_reflected_signal(tx_signal, target_distance, target_velocity) rx_frame = np.tile(rx_signal, (128, 1)) range_profile = radar.range_fft(rx_frame) range_doppler_map = radar.velocity_fft(range_profile) vital_signs = radar.detect_vital_signs(rx_frame.flatten()) print(f"\n生命体征检测结果:") print(f" 呼吸频率: {vital_signs['breathing_rate']:.1f} 次/分钟") print(f" 心率: {vital_signs['heart_rate']:.1f} 次/分钟") print(f" 存在生命体征: {vital_signs['presence']}")
|