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
| """ mmWave雷达座舱生命体征监测 - 信号处理实现
基于 TI IWR6843AOP 和 IEEE Trans. Radar Systems 2025 论文方法 依赖: pip install numpy scipy matplotlib
测试数据格式: IWR6843AOP raw ADC → complex baseband """
import numpy as np from scipy.signal import butter, filtfilt, find_peaks from scipy.fft import fft, fftfreq from typing import Tuple, Dict
class mmWaveVitalSigns: """ 77GHz mmWave雷达生命体征监测 硬件: TI IWR6843AOP - 频率: 60-64GHz (实例代码以60GHz为例) - 天线: 3发4收 - 帧率: 20 fps - 距离分辨率: ~4cm 也适用于77GHz (LinpoWave/Infineon) """ def __init__(self, fs: float = 20.0, n_rx: int = 4): """ Args: fs: 帧率 (Hz), 典型值 10-20 n_rx: 接收天线数量 """ self.fs = fs self.n_rx = n_rx def range_profile(self, adc_data: np.ndarray) -> np.ndarray: """ 计算距离像(Range-FFT) Args: adc_data: ADC原始数据, shape=(n_chirps, n_samples) Returns: range_profile: 距离像, shape=(n_chirps, n_range_bins) """ range_fft = fft(adc_data, axis=1) return np.abs(range_fft) def find_target_bin(self, range_profile: np.ndarray, search_range: Tuple[float, float] = (0.3, 1.5)) -> int: """ 找到驾驶员所在距离bin Args: range_profile: 距离像, shape=(n_frames, n_range_bins) search_range: 搜索范围(米) Returns: target_bin: 目标距离bin索引 """ range_res = 0.04 bin_low = int(search_range[0] / range_res) bin_high = int(search_range[1] / range_res) search_region = np.mean(range_profile[:, bin_low:bin_high], axis=0) target_bin = bin_low + np.argmax(search_region) return target_bin def extract_phase(self, adc_data: np.ndarray, target_bin: int) -> np.ndarray: """ 提取目标距离bin的相位序列 这是生命体征检测的核心——胸壁微位移编码在相位中 Args: adc_data: shape=(n_frames, n_samples) target_bin: 目标距离bin Returns: phase_series: 相位序列(弧度), shape=(n_frames,) """ range_fft = fft(adc_data, axis=1) complex_signal = range_fft[:, target_bin] phase = np.angle(complex_signal) phase_unwrapped = np.unwrap(phase) return phase_unwrapped def separate_vital_signs(self, phase: np.ndarray) -> Dict[str, np.ndarray]: """ 分离呼吸和心跳信号 Args: phase: 解缠后相位序列, shape=(n_frames,) Returns: dict: { 'breathing': 呼吸波形, 'heartbeat': 心跳波形, 'breathing_rate': 呼吸率(次/分), 'heart_rate': 心率(次/分) } """ nyq = self.fs / 2 b_resp, a_resp = butter(4, [0.1/nyq, 0.5/nyq], btype='band') breathing = filtfilt(b_resp, a_resp, phase) b_heart, a_heart = butter(4, [0.8/nyq, 2.0/nyq], btype='band') heartbeat = filtfilt(b_heart, a_heart, phase) def estimate_rate(signal: np.ndarray, fs: float) -> float: """FFT峰值法估计频率""" n = len(signal) freqs = fftfreq(n, 1/fs) spectrum = np.abs(fft(signal)) pos_mask = freqs > 0 pos_freqs = freqs[pos_mask] pos_spectrum = spectrum[pos_mask] peaks, _ = find_peaks(pos_spectrum, height=np.max(pos_spectrum)*0.3) if len(peaks) > 0: peak_idx = peaks[np.argmax(pos_spectrum[peaks])] rate_hz = pos_freqs[peak_idx] return rate_hz * 60 return 0.0 br_rate = estimate_rate(breathing, self.fs) hr_rate = estimate_rate(heartbeat, self.fs) return { 'breathing': breathing, 'heartbeat': heartbeat, 'breathing_rate': br_rate, 'heart_rate': hr_rate } def remove_motion_artifact(self, phase: np.ndarray, imu_data: np.ndarray = None) -> np.ndarray: """ 运动伪影消除 Args: phase: 相位序列 imu_data: 可选IMU数据用于参考消除 Returns: cleaned_phase: 去伪影后相位 """ from scipy.signal import medfilt median_filtered = medfilt(phase, kernel_size=5) residual = phase - median_filtered if imu_data is not None: from scipy.signal import lfilter cleaned = phase - 0.1 * imu_data else: cleaned = residual return cleaned
if __name__ == "__main__": detector = mmWaveVitalSigns(fs=20.0, n_rx=4) np.random.seed(42) n_frames = 600 n_samples = 64 t = np.arange(n_frames) / 20.0 true_breathing = 2.0 * np.sin(2*np.pi*0.2*t) true_heartbeat = 0.3 * np.sin(2*np.pi*1.2*t) noise = 0.1 * np.random.randn(n_frames) true_phase = true_breathing + true_heartbeat + noise adc_data = np.random.randn(n_frames, n_samples) + 1j * np.random.randn(n_frames, n_samples) target_bin = 15 for i in range(n_frames): adc_data[i, target_bin] = 10 * np.exp(1j * true_phase[i]) range_prof = detector.range_profile(adc_data) found_bin = detector.find_target_bin(range_prof) print(f"目标bin: {found_bin} (真实: {target_bin})") phase = detector.extract_phase(adc_data, found_bin) phase = detector.remove_motion_artifact(phase) results = detector.separate_vital_signs(phase) print(f"\n=== 生命体征检测结果 ===") print(f"呼吸率: {results['breathing_rate']:.1f} 次/分 (真实: 12.0)") print(f"心率: {results['heart_rate']:.1f} 次/分 (真实: 72.0)") print(f"呼吸波形长度: {len(results['breathing'])} samples") print(f"心跳波形长度: {len(results['heartbeat'])} samples")
|