service.py 934 B

123456789101112131415161718192021222324252627282930313233343536
  1. import uhd
  2. import numpy as np
  3. try:
  4. # 创建USRP设备对象
  5. usrp = uhd.usrp.MultiUSRP()
  6. print('------SDR Devices initialize success!------')
  7. except RuntimeError as e:
  8. print('SDR设备异常', e)
  9. def send():
  10. # 设置中心频率、采样率和增益
  11. center_freq = 100e6 # 2.4 GHz
  12. sample_rate = 1e6 # 1 MS/s
  13. duration = 10 # 以秒为单位
  14. gain = 20 # [dB] 建议一开始设置小一点,按照实际情况调整
  15. # 生成发送信号
  16. num_samples = 1000
  17. tx_signal = np.random.randn(num_samples) + 0.1j * np.random.randn(num_samples) # 修复部分
  18. # 发送信号
  19. usrp.send_waveform(tx_signal, duration, center_freq, sample_rate, [0], gain)
  20. # 接收信号
  21. rx_signal = usrp.recv_num_samps(num_samples, sample_rate,center_freq)
  22. print('信号已发送:')
  23. print(rx_signal)
  24. print('信号已接收')
  25. #main方法
  26. if __name__ == '__main__':
  27. send()