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
| import numpy as np from typing import Tuple
class UWBRadarProcessor: """ Calterah UWB 雷达信号处理器(概念实现) 基于分层参数设计: - 默认参数:适配大部分车型/环境 - 微调参数:少量参数针对特定车型 """ def __init__(self, config: str = 'default'): """ Args: config: 'default' 或 'custom_vehicle' """ self.default_params = { 'range_resolution': 0.015, 'velocity_resolution': 0.05, 'detection_range': 2.0, 'clutter_removal': 'mean_subtract', 'static_threshold': 0.3, 'breathing_freq_range': (0.3, 0.8), 'heart_rate_range': (1.0, 2.0), } self.tuning_params = { 'antenna_delay': 0, 'clutter_map': None, } def process_cir(self, cir_data: np.ndarray) -> Dict: """ 处理 Channel Impulse Response 数据 Args: cir_data: CIR 数据, shape=(N_frames, N_rx, N_samples) Returns: 特征字典 """ clean_data = self._remove_clutter(cir_data) range_doppler = self._compute_range_doppler(clean_data) breathing = self._extract_breathing(clean_data) heart_rate = self._extract_heart_rate(clean_data) features = { 'range_profile': self._range_profile(clean_data), 'doppler_profile': range_doppler, 'breathing_rate': breathing, 'breathing_amplitude': np.max(np.abs(breathing)), 'heart_rate': heart_rate, 'motion_level': np.var(clean_data, axis=0).mean(), 'static_energy': np.mean(np.abs(clean_data)), } return features def _remove_clutter(self, data: np.ndarray) -> np.ndarray: """均值减法去杂波""" return data - np.mean(data, axis=0, keepdims=True) def _compute_range_doppler(self, data: np.ndarray) -> np.ndarray: """计算距离-多普勒图""" doppler = np.fft.fft(data, axis=0) range_doppler = np.fft.fft(doppler, axis=-1) return np.abs(range_doppler) def _extract_breathing(self, data: np.ndarray) -> np.ndarray: """提取呼吸信号(带通滤波 0.3-0.8 Hz)""" from scipy.signal import butter, filtfilt fs = 20 low, high = self.default_params['breathing_freq_range'] b, a = butter(4, [low/(fs/2), high/(fs/2)], btype='band') breathing = np.zeros_like(data) for rx in range(data.shape[1]): for rng in range(data.shape[2]): breathing[:, rx, rng] = filtfilt(b, a, data[:, rx, rng]) return breathing def _extract_heart_rate(self, data: np.ndarray) -> np.ndarray: """提取心率信号(带通滤波 1.0-2.0 Hz)""" from scipy.signal import butter, filtfilt fs = 20 low, high = self.default_params['heart_rate_range'] b, a = butter(4, [low/(fs/2), high/(fs/2)], btype='band') hr = np.zeros_like(data) for rx in range(data.shape[1]): for rng in range(data.shape[2]): hr[:, rx, rng] = filtfilt(b, a, data[:, rx, rng]) return hr def _range_profile(self, data: np.ndarray) -> np.ndarray: """距离剖面""" return np.abs(np.fft.fft(data, axis=-1)).mean(axis=0)
if __name__ == "__main__": np.random.seed(42) processor = UWBRadarProcessor() t = np.arange(100) / 20.0 breathing_signal = 0.1 * np.sin(2 * np.pi * 0.4 * t) cir = np.random.randn(100, 4, 64) * 0.01 cir += 0.5 cir[:, :, 20] += breathing_signal.reshape(-1, 1, 1) features = processor.process_cir(cir) print("=== UWB 雷达特征 ===") print(f"静态能量: {features['static_energy']:.4f}") print(f"运动水平: {features['motion_level']:.6f}") print(f"呼吸幅度: {features['breathing_amplitude']:.4f}") print(f"距离剖面峰值位置: 门{np.argmax(features['range_profile'][0])}")
|