anti_jamming_signal_algo.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import numpy as np
  2. from scipy import signal, fft, linalg
  3. from typing import Tuple, List
  4. SAMPLING_RATE = 10e6
  5. class AntiJammingSignalAlgo:
  6. @staticmethod
  7. def polarization_filter(rx_signal, sample_rate, polarization_params):
  8. """极化滤波算法"""
  9. # 应用极化参数
  10. angle_rad = np.deg2rad(polarization_params['angle'])
  11. ellipticity = polarization_params['ellipticity']
  12. # 构建极化滤波矩阵
  13. filter_matrix = np.array([
  14. [np.cos(angle_rad), -ellipticity * np.sin(angle_rad)],
  15. [np.sin(angle_rad), ellipticity * np.cos(angle_rad)]
  16. ])
  17. # 应用极化滤波
  18. polarized_signal = filter_matrix @ rx_signal.reshape(2, -1)
  19. return polarized_signal[0].real
  20. @staticmethod
  21. def frequency_agility(tx_signal, hop_sequence, sample_rate=SAMPLING_RATE):
  22. """频率捷变算法
  23. Args:
  24. tx_signal: 原始发射信号
  25. sample_rate: 采样率
  26. hop_sequence: 跳频序列 (包含频率点和驻留时间)
  27. """
  28. processed_signal = np.zeros_like(tx_signal)
  29. t = 0
  30. for freq, dwell in hop_sequence:
  31. n_samples = 100
  32. freq_shift = np.exp(1j*2*np.pi*freq/sample_rate*np.arange(n_samples))
  33. segment = tx_signal[t:t+n_samples] * freq_shift
  34. processed_signal[t:t+n_samples] = segment
  35. t += n_samples
  36. if t >= len(tx_signal):
  37. break
  38. return processed_signal
  39. @staticmethod
  40. def waveform_agility(tx_signal, waveform_params, sample_rate=SAMPLING_RATE):
  41. """波形捷变算法
  42. Args:
  43. tx_signal: 原始发射信号
  44. sample_rate: 采样率
  45. waveform_params: 波形参数 {
  46. 'type': 'LFM'/'NLFM'/'PhaseCode',
  47. 'bandwidth': 带宽(Hz),
  48. 'duration': 持续时间(s)
  49. }
  50. """
  51. t = np.linspace(0, waveform_params['duration'], int(sample_rate * waveform_params['duration']))
  52. if waveform_params['type'] == 'LFM':
  53. waveform = signal.chirp(t, f0=0, f1=waveform_params['bandwidth'], t1=waveform_params['duration'])
  54. elif waveform_params['type'] == 'NLFM':
  55. # 非线性调频波形
  56. beta = 2.5
  57. waveform = np.cos(2*np.pi* waveform_params['bandwidth'] * (t + beta*t**3))
  58. elif waveform_params['type'] == 'PhaseCode':
  59. # 相位编码波形
  60. code_length = 13
  61. phase_code = np.exp(1j*np.pi*np.random.randint(0,2,code_length))
  62. waveform = np.kron(phase_code, np.ones(int(sample_rate*waveform_params['duration']/code_length)))
  63. else:
  64. raise ValueError("不支持的波形类型")
  65. return tx_signal * waveform[:len(tx_signal)]