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
| import numpy as np from scipy import signal as sig from scipy.signal import butter, filtfilt, find_peaks
class FMCWRadarVitalSignExtractor: """ FMCW雷达生命体征提取器 论文实现:arXiv:2511.21314 IEEE Sensors Journal, 2025 三阶段处理链: 1. VMD (变分模态分解) - 降噪 2. 梳状滤波器 - 去除呼吸谐波 3. 回归模型 - 精确心率估计 """ def __init__(self, fs: float = 20.0, chirp_duration: float = 0.05): self.fs = fs self.chirp_duration = chirp_duration def extract_range_profile(self, adc_data: np.ndarray) -> np.ndarray: """ 从ADC数据提取距离-时间矩阵 Args: adc_data: (num_chirps, num_samples) ADC原始数据 Returns: range_profile: (num_chirps, num_range_bins) 距离剖面 """ range_fft = np.fft.fft(adc_data, axis=1) return range_fft def isolate_target(self, range_profile: np.ndarray, target_range_bin: int) -> np.ndarray: """ 隔离目标距离单元的相位信号 Args: range_profile: (num_chirps, num_range_bins) target_range_bin: 目标所在距离单元索引 Returns: phase_signal: (num_chirps,) 相位序列 """ target_bin_data = range_profile[:, target_range_bin] phase_signal = np.angle(target_bin_data) phase_signal = np.unwrap(phase_signal) phase_signal = self._correct_dc_offset(phase_signal) return phase_signal def _correct_dc_offset(self, signal: np.ndarray) -> np.ndarray: """NLLS DC偏移校正""" t = np.arange(len(signal)) A = np.vstack([np.ones_like(t, dtype=float), t]).T offset, _ = np.linalg.lstsq(A, signal, rcond=None)[0] return signal - offset - t * _ def vmd_denoise(self, signal: np.ndarray, num_modes: int = 4, alpha: float = 2000, tau: float = 0, dc: int = 0, init: int = 1, tol: float = 1e-7) -> np.ndarray: """ 变分模态分解(VMD)降噪 将信号分解为多个本征模态函数(IMF), 选择包含心跳分量的IMF组合 Args: signal: 输入信号 num_modes: 模态数(建议3-6) alpha: 带宽约束参数 tau: 噪声容限 dc: 直流约束(0/1) init: 初始化方式 tol: 收敛阈值 Returns: denoised: 降噪后的信号 """ f_mirrors = np.concatenate([signal[::-1], signal, signal[::-1]]) T = len(f_mirrors) freqs = np.fft.fftfreq(T, 1.0/self.fs) * 2 * np.pi u_hat = np.zeros((num_modes, T), dtype=complex) omega = np.zeros(num_modes) for _ in range(500): for k in range(num_modes): u_hat_plus = u_hat.sum(axis=0) - u_hat[k] u_hat[k] = (f_mirrors - u_hat_plus) / (1 + alpha * (freqs - omega[k])**2) omega[k] = np.sum(freqs * np.abs(u_hat[k])**2) / np.sum(np.abs(u_hat[k])**2) denoised = np.real(np.fft.ifft(u_hat[0] + u_hat[1])) n = len(signal) return denoised[n:2*n] def comb_filter(self, signal: np.ndarray, breathing_freq: float = 0.25, num_harmonics: int = 5) -> np.ndarray: """ 梳状滤波器:去除呼吸频率及其谐波 心跳信号常被呼吸的谐波淹没 梳状滤波器在呼吸频率的整数倍处设置陷波 Args: signal: VMD降噪后的信号 breathing_freq: 估计的呼吸频率(Hz) num_harmonics: 滤除的谐波数 Returns: filtered: 去除呼吸谐波后的信号 """ nyquist = self.fs / 2 filtered = signal.copy() for h in range(1, num_harmonics + 1): notch_freq = breathing_freq * h if notch_freq < nyquist: Q = 30.0 w0 = notch_freq / nyquist b, a = sig.iirnotch(w0, Q) filtered = filtfilt(b, a, filtered) return filtered def estimate_heart_rate(self, signal: np.ndarray) -> float: """ 回归模型心率估计 从梳状滤波后的信号中提取心率 Args: signal: 滤波后的信号 Returns: hr: 估计心率(BPM) """ freqs = np.fft.fftfreq(len(signal), 1.0/self.fs) spectrum = np.abs(np.fft.fft(signal)) hr_mask = (freqs >= 0.67) & (freqs <= 3.0) hr_freqs = freqs[hr_mask] hr_spectrum = spectrum[hr_mask] peaks, properties = find_peaks(hr_spectrum, height=0.1*np.max(hr_spectrum)) if len(peaks) > 0: peak_freq = hr_freqs[peaks[np.argmax(hr_spectrum[peaks])]] hr = peak_freq * 60 else: hr = np.sum(hr_freqs * hr_spectrum) / np.sum(hr_spectrum) * 60 return max(40, min(180, hr)) def estimate_breathing_rate(self, signal: np.ndarray) -> float: """ 呼吸率估计 Args: signal: VMD降噪后的信号 Returns: br: 估计呼吸率(BPM) """ freqs = np.fft.fftfreq(len(signal), 1.0/self.fs) spectrum = np.abs(np.fft.fft(signal)) br_mask = (freqs >= 0.1) & (freqs <= 0.5) br_freqs = freqs[br_mask] br_spectrum = spectrum[br_mask] peaks, _ = find_peaks(br_spectrum, height=0.1*np.max(br_spectrum)) if len(peaks) > 0: peak_freq = br_freqs[peaks[np.argmax(br_spectrum[peaks])]] br = peak_freq * 60 else: br = np.sum(br_freqs * br_spectrum) / np.sum(br_spectrum) * 60 return max(6, min(30, br)) def process_multi_subject(self, adc_data: np.ndarray, subject_range_bins: list) -> list: """ 多人生命体征处理 Args: adc_data: (num_chirps, num_samples) 原始ADC数据 subject_range_bins: 每个目标对应的距离单元列表 Returns: results: list of dict containing HR, BR for each subject """ range_profile = self.extract_range_profile(adc_data) results = [] for idx, rbin in enumerate(subject_range_bins): phase_signal = self.isolate_target(range_profile, rbin) denoised = self.vmd_denoise(phase_signal, num_modes=4) br = self.estimate_breathing_rate(denoised) filtered = self.comb_filter(denoised, breathing_freq=br/60) hr = self.estimate_heart_rate(filtered) results.append({ 'subject': idx + 1, 'heart_rate_bpm': round(hr, 1), 'breathing_rate_bpm': round(br, 1), 'range_bin': rbin, 'signal_snr': round(self._compute_snr(denoised, filtered), 2) }) return results def _compute_snr(self, raw, filtered): """计算信噪比""" noise = raw - filtered signal_power = np.mean(filtered**2) noise_power = np.mean(noise**2) if noise_power > 0: return 10 * np.log10(signal_power / noise_power) return 0.0
if __name__ == "__main__": extractor = FMCWRadarVitalSignExtractor(fs=20.0) np.random.seed(42) num_chirps = 600 num_samples = 128 t = np.arange(num_chirps) / 20.0 adc_data = np.zeros((num_chirps, num_samples), dtype=complex) hr1, br1 = 72/60, 16/60 chest_motion1 = 0.5*np.sin(2*np.pi*br1*t) + 0.1*np.sin(2*np.pi*hr1*t) adc_data[:, 30] = np.exp(1j * chest_motion1 * 4 * np.pi / 0.0039) + 0.1*np.random.randn(num_chirps) hr2, br2 = 85/60, 18/60 chest_motion2 = 0.4*np.sin(2*np.pi*br2*t) + 0.08*np.sin(2*np.pi*hr2*t) adc_data[:, 60] = np.exp(1j * chest_motion2 * 4 * np.pi / 0.0039) + 0.1*np.random.randn(num_chirps) results = extractor.process_multi_subject(adc_data, [30, 60]) print("=" * 60) print("多人生命体征监测结果") print("=" * 60) for r in results: print(f"\n目标 {r['subject']}:") print(f" 心率: {r['heart_rate_bpm']} BPM") print(f" 呼吸率: {r['breathing_rate_bpm']} BPM") print(f" 距离单元: {r['range_bin']}") print(f" SNR: {r['signal_snr']} dB") print("\n" + "=" * 60) print("FPGA vs 软件性能对比") print("=" * 60) fpga_exec_time = 0.013e-3 sw_exec_time = 0.1 speedup = sw_exec_time / fpga_exec_time print(f"FPGA执行时间: {fpga_exec_time*1e6:.1f} μs") print(f"软件执行时间: {sw_exec_time*1e3:.1f} ms") print(f"加速比: {speedup:.0f}x") print(f"FPGA LUT: 11,247 (比前代省18.4%)") print(f"FPGA时钟频率: 200 MHz")
|