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
| class TemporalStatisticalFeatures: """ RadarMind 时序统计特征提取器 论文核心:从微多普勒谱图中提取 统计特征而非深度学习特征 优势: 1. 可解释——每个特征有物理意义 2. 轻量——无需GPU,CPU即可 3. 泛化——统计特征跨用户鲁棒 """ def extract_all(self, spectrogram: np.ndarray) -> dict: """ 从微多普勒谱图提取完整特征集 Args: spectrogram: (freq_bins, time_bins) Returns: features: dict of feature_name → value """ features = {} features.update(self._temporal_stats(spectrogram)) features.update(self._spectral_stats(spectrogram)) features.update(self._joint_tf_stats(spectrogram)) features.update(self._morphology_stats(spectrogram)) return features def _temporal_stats(self, spec: np.ndarray) -> dict: """时域统计特征""" temporal_envelope = np.sum(spec, axis=0) return { 'temporal_mean': np.mean(temporal_envelope), 'temporal_std': np.std(temporal_envelope), 'temporal_max': np.max(temporal_envelope), 'temporal_min': np.min(temporal_envelope), 'temporal_range': np.ptp(temporal_envelope), 'temporal_skew': float(self._skewness(temporal_envelope)), 'temporal_kurtosis': float(self._kurtosis(temporal_envelope)), 'zero_crossing_rate': self._zcr(temporal_envelope), 'energy_ratio': np.sum(temporal_envelope ** 2) / ( np.sum(spec ** 2) + 1e-8 ), } def _spectral_stats(self, spec: np.ndarray) -> dict: """频域统计特征""" spectrum = np.sum(spec, axis=1) freqs = np.arange(len(spectrum)) centroid = np.sum(freqs * spectrum) / (np.sum(spectrum) + 1e-8) bandwidth = np.sqrt( np.sum(((freqs - centroid) ** 2) * spectrum) / (np.sum(spectrum) + 1e-8) ) geometric_mean = np.exp(np.mean(np.log(spec + 1e-10))) arithmetic_mean = np.mean(spec) flatness = geometric_mean / (arithmetic_mean + 1e-10) return { 'spectral_centroid': float(centroid), 'spectral_bandwidth': float(bandwidth), 'spectral_flatness': float(flatness), 'spectral_roll_off': float(self._roll_off(spectrum, 0.85)), 'spectral_flux': float(self._spectral_flux(spec)), } def _joint_tf_stats(self, spec: np.ndarray) -> dict: """时频联合特征""" peak_idx = np.unravel_index(np.argmax(spec), spec.shape) peak_freq, peak_time = peak_idx spec_norm = spec / (np.sum(spec) + 1e-10) entropy = -np.sum(spec_norm * np.log2(spec_norm + 1e-10)) sparsity = np.sum(np.abs(spec)) ** 2 / ( np.sum(spec ** 2) + 1e-10 ) return { 'tf_peak_frequency': float(peak_freq), 'tf_peak_time': float(peak_time), 'tf_entropy': float(entropy), 'tf_sparsity': float(sparsity), 'freq_modulation_rate': float( self._frequency_modulation_rate(spec) ), } def _morphology_stats(self, spec: np.ndarray) -> dict: """微多普勒形态特征""" binary = (spec > np.mean(spec) + np.std(spec)).astype(float) from scipy.ndimage import label, center_of_mass labeled, num_features = label(binary) if num_features > 0: areas = [np.sum(labeled == i) for i in range(1, num_features + 1)] max_area = max(areas) total_area = sum(areas) centroids = center_of_mass(binary, labeled, range(1, num_features + 1)) else: max_area = 0 total_area = 0 centroids = [] return { 'morph_num_components': int(num_features), 'morph_max_area': float(max_area), 'morph_total_area': float(total_area), 'morph_area_ratio': float(max_area / (total_area + 1e-8)), } def _skewness(self, x): m = np.mean(x) s = np.std(x) return np.mean(((x - m) / s) ** 3) if s > 0 else 0 def _kurtosis(self, x): m = np.mean(x) s = np.std(x) return np.mean(((x - m) / s) ** 4) - 3 if s > 0 else 0 def _zcr(self, x): return np.mean(np.diff(np.sign(x)) != 0) def _roll_off(self, spectrum, ratio=0.85): cumsum = np.cumsum(spectrum) total = cumsum[-1] idx = np.searchsorted(cumsum, ratio * total) return idx / len(spectrum) def _spectral_flux(self, spec): diff = np.diff(spec, axis=1) return np.sum(diff ** 2) / (spec.shape[1] - 1) def _frequency_modulation_rate(self, spec): peak_freqs = np.argmax(spec, axis=0) return np.std(np.diff(peak_freqs)) if len(peak_freqs) > 2 else 0
def extract_features_from_radar(adc_cube: np.ndarray) -> np.ndarray: """完整特征提取管道""" preprocessor = RadarPreprocessor() feature_extractor = TemporalStatisticalFeatures() spec = preprocessor.micro_doppler_spectrogram(adc_cube) features_dict = feature_extractor.extract_all(spec) feature_vector = np.array(list(features_dict.values())) return feature_vector
|