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
| """ 60GHz FMCW 雷达座舱感知处理管道
核心算法: 1. Range FFT:距离估计 2. Doppler FFT:速度估计 3. 相位解调:呼吸/心跳提取 4. 微运动检测:儿童存在判定 """
import numpy as np from scipy.fft import fft, fft2d from scipy.signal import butter, filtfilt from typing import Tuple, Dict
def range_fft(radar_data: np.ndarray, num_chirps: int = 128) -> np.ndarray: """ Range FFT:距离维快速傅里叶变换 Args: radar_data: 雷达原始数据, shape=(num_chirps, num_samples) num_chirps: chirp数量 Returns: range_profile: 距离剖面, shape=(num_chirps, num_samples) Example: >>> data = np.random.randn(128, 256) >>> range_prof = range_fft(data) >>> print(f"Range profile shape: {range_prof.shape}") """ range_profile = fft(radar_data, axis=1) range_mag = np.abs(range_profile) return range_mag
def doppler_fft(range_profile: np.ndarray) -> np.ndarray: """ Doppler FFT:速度维快速傅里叶变换 Args: range_profile: 距离剖面, shape=(num_chirps, num_samples) Returns: range_doppler_map: Range-Doppler图, shape=(num_doppler, num_range) Example: >>> rd_map = doppler_fft(range_profile) >>> print(f"Range-Doppler map shape: {rd_map.shape}") """ rd_map = fft2(range_profile) rd_map = np.abs(np.fft.fftshift(rd_map, axes=0)) return rd_map
def extract_breathing_signal(phase_data: np.ndarray, fps: int = 30) -> np.ndarray: """ 从相位数据提取呼吸信号 Args: phase_data: 相位数据序列, shape=(N,) fps: 帧率 Returns: breathing_signal: 呼吸波形 IMS落地应用: 呼吸频率范围:0.1-0.5 Hz (6-30 次/分钟) 儿童呼吸频率:20-40 次/分钟 成人呼吸频率:12-20 次/分钟 """ nyquist = fps / 2 low_cutoff = 0.1 / nyquist high_cutoff = 0.5 / nyquist b, a = butter(2, [low_cutoff, high_cutoff], btype='band') breathing_signal = filtfilt(b, a, phase_data) return breathing_signal
def extract_heartbeat_signal(phase_data: np.ndarray, fps: int = 30) -> np.ndarray: """ 从相位数据提取心跳信号 Args: phase_data: 相位数据序列, shape=(N,) fps: 帧率 Returns: heartbeat_signal: 心跳波形 IMS落地应用: 心跳频率范围:0.8-2.5 Hz (48-150 bpm) 儿童心率:80-120 bpm 成人心率:60-100 bpm """ nyquist = fps / 2 low_cutoff = 0.8 / nyquist high_cutoff = 2.5 / nyquist b, a = butter(2, [low_cutoff, high_cutoff], btype='band') heartbeat_signal = filtfilt(b, a, phase_data) return heartbeat_signal
def calculate_vital_signs(breathing: np.ndarray, heartbeat: np.ndarray, fps: int = 30) -> Dict: """ 计算生命体征(呼吸频率、心率) Args: breathing: 呼吸波形 heartbeat: 心跳波形 fps: 帧率 Returns: vital_signs: { 'respiration_rate': 次/分钟, 'heart_rate': bpm, 'breathing_amplitude': 幅度, 'heartbeat_amplitude': 幅度 } Example: >>> vital_signs = calculate_vital_signs(breathing_sig, heartbeat_sig) >>> print(f"呼吸频率: {vital_signs['respiration_rate']} 次/分钟") >>> print(f"心率: {vital_signs['heart_rate']} bpm") """ breathing_peaks = detect_peaks(breathing) respiration_rate = len(breathing_peaks) / (len(breathing) / fps) * 60 heartbeat_peaks = detect_peaks(heartbeat) heart_rate = len(heartbeat_peaks) / (len(heartbeat) / fps) * 60 breathing_amplitude = np.std(breathing) heartbeat_amplitude = np.std(heartbeat) return { 'respiration_rate': respiration_rate, 'heart_rate': heart_rate, 'breathing_amplitude': breathing_amplitude, 'heartbeat_amplitude': heartbeat_amplitude }
def detect_peaks(signal: np.ndarray, threshold: float = 0.5) -> np.ndarray: """ 检测信号峰值 Args: signal: 输入信号 threshold: 峰值阈值 Returns: peak_indices: 峰值索引 """ normalized = (signal - np.mean(signal)) / np.std(signal) peaks = [] for i in range(1, len(normalized) - 1): if normalized[i] > normalized[i-1] and normalized[i] > normalized[i+1]: if normalized[i] > threshold: peaks.append(i) return np.array(peaks)
def detect_child_presence(rd_map: np.ndarray, vital_signs: Dict, threshold: float = 0.3) -> Tuple[bool, float]: """ 检测儿童存在 Args: rd_map: Range-Doppler图 vital_signs: 生命体征 threshold: 微运动阈值 Returns: is_child: 是否检测到儿童 confidence: 置信度 IMS落地应用: 儿童判定逻辑: 1. Range-Doppler图中有微运动目标 2. 呼吸频率:20-40 次/分钟(儿童特征) 3. 心率:80-120 bpm(儿童特征) 4. 幅度阈值:呼吸幅度 > threshold """ low_speed_region = rd_map[:, 10:20] micro_motion_intensity = np.max(low_speed_region) / np.mean(rd_map) is_child = False confidence = 0.0 if vital_signs['breathing_amplitude'] > threshold: if 20 <= vital_signs['respiration_rate'] <= 40: if 80 <= vital_signs['heart_rate'] <= 120: is_child = True confidence = 0.9 elif vital_signs['heart_rate'] > 0: confidence = 0.6 elif vital_signs['respiration_rate'] > 0: confidence = 0.3 return is_child, confidence
if __name__ == "__main__": num_chirps = 128 num_samples = 256 fps = 30 time = np.linspace(0, 60, num_chirps) breathing_phase = 0.2 * np.sin(2 * np.pi * 0.35 * time) heartbeat_phase = 0.05 * np.sin(2 * np.pi * 1.3 * time) phase_data = breathing_phase + heartbeat_phase + 0.01 * np.random.randn(num_chirps) breathing_sig = extract_breathing_signal(phase_data, fps) heartbeat_sig = extract_heartbeat_signal(phase_data, fps) vital_signs = calculate_vital_signs(breathing_sig, heartbeat_sig, fps) print("="*50) print("儿童生命体征检测结果(模拟)") print("="*50) print(f"呼吸频率: {vital_signs['respiration_rate']:.1f} 次/分钟") print(f"心率: {vital_signs['heart_rate']:.1f} bpm") print(f"呼吸幅度: {vital_signs['breathing_amplitude']:.4f}") print(f"心跳幅度: {vital_signs['heartbeat_amplitude']:.4f}") rd_map = np.random.randn(128, 256) * 0.1 rd_map[50, 15] = 2.0 is_child, confidence = detect_child_presence(rd_map, vital_signs) print(f"\n儿童存在判定: {is_child}") print(f"置信度: {confidence:.2f}")
|