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