anti_jamming_signal_algo_20250421164110.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import numpy as np
  2. from scipy import signal, fft, linalg
  3. from typing import Tuple, List
  4. class AntiJammingSignalAlgo:
  5. @staticmethod
  6. def time_frequency_filter(rx_signal, sample_rate):
  7. """时频域联合滤波算法"""
  8. # 输入信号维度检查
  9. if rx_signal.size == 0:
  10. return np.zeros_like(rx_signal)
  11. # 确保信号为1维数组
  12. rx_signal = np.atleast_1d(rx_signal).ravel()
  13. spectrum = np.fft.fft(rx_signal)
  14. filtered_spectrum = spectrum * np.hamming(len(spectrum))
  15. return np.fft.ifft(filtered_spectrum).real
  16. @staticmethod
  17. def adaptive_filter(rx_signal, reference_signal):
  18. """自适应滤波算法"""
  19. # 实现基于LMS的自适应滤波
  20. lms_step = 0.01
  21. weights = np.zeros(10)
  22. for i in range(len(rx_signal)-10):
  23. x = rx_signal[i:i+10]
  24. error = reference_signal[i] - np.dot(weights, x)
  25. weights += lms_step * error * x
  26. return np.convolve(weights, rx_signal, mode='valid')
  27. @staticmethod
  28. def polarization_filter(rx_signal, sample_rate, polarization_params):
  29. """极化滤波算法"""
  30. # 应用极化参数
  31. angle_rad = np.deg2rad(polarization_params['angle'])
  32. ellipticity = polarization_params['ellipticity']
  33. # 构建极化滤波矩阵
  34. filter_matrix = np.array([
  35. [np.cos(angle_rad), -ellipticity * np.sin(angle_rad)],
  36. [np.sin(angle_rad), ellipticity * np.cos(angle_rad)]
  37. ])
  38. # 应用极化滤波
  39. polarized_signal = filter_matrix @ rx_signal.reshape(2, -1)
  40. return polarized_signal[0].real