anti_jamming_signal_algo_20250421152138.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 or not np.iscomplexobj(rx_signal):
  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(signal, polarization_params):
  29. """极化滤波算法"""
  30. # 实现极化域滤波处理
  31. covariance = np.cov(signal.reshape(2, -1))
  32. eig_vals, eig_vecs = np.linalg.eig(covariance)
  33. return (eig_vecs[:, np.argmax(eig_vals)] @ signal.reshape(2, -1)).real