在下面代码中加入接收端的收到的复信号的时域图,再加一个隔直流的代码,用python import time import adi import matplotlib.pyplot as plt import numpy as np from scipy import signal # Create radio sdr = adi.Pluto() # Configure properties sdr.rx_rf_bandwidth = 4000000 sdr.rx_lo = 1900000000 sdr.tx_lo = 2000000000 sdr.tx_cyclic_buffer = True sdr.tx_hardwaregain_chan0 = -30 sdr.gain_control_mode_chan0 = "slow_attack" # Read properties print("RX LO %s" % (sdr.rx_lo)) print(sdr.sample_rate) # Create a sinewave waveform fs = int(sdr.sample_rate) N = 1024 fc = int(3000000 / (fs / N)) * (fs / N) ts = 1 / float(fs) t = np.arange(0, N * ts, ts) i = np.cos(2 * np.pi * t * fc) * 2 ** 14 q = np.sin(2 * np.pi * t * fc) * 2 ** 14 i=i+2**15 q=q+2**15 iq = i + 1j * q # Send data sdr.tx(iq) # Collect data for r in range(20): x = sdr.rx() print(x) y=abs(x) print(y) print('------------------------') plt.figure(0) plt.plot(y) f, Pxx_den = signal.periodogram(x, fs) #plt.clf() # plt.figure(1) plt.semilogy(f, Pxx_den) plt.ylim([1e-7, 1e4]) plt.xlabel("frequency [Hz]") plt.ylabel("PSD [V**2/Hz]") plt.draw() plt.pause(0.05) time.sleep(0.1) plt.show()
时间: 2023-11-22 15:53:51 浏览: 83
timefeature_timefeature_时域特征提取_
5星 · 资源好评率100%
以下是加入接收端的收到的复信号的时域图和隔直流的代码的修改后的完整代码:
```python
import time
import adi
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
# Create radio
sdr = adi.Pluto()
# Configure properties
sdr.rx_rf_bandwidth = 4000000
sdr.rx_lo = 1900000000
sdr.tx_lo = 2000000000
sdr.tx_cyclic_buffer = True
sdr.tx_hardwaregain_chan0 = -30
sdr.gain_control_mode_chan0 = "slow_attack"
# Read properties
print("RX LO %s" % (sdr.rx_lo))
print(sdr.sample_rate)
# Create a sinewave waveform
fs = int(sdr.sample_rate)
N = 1024
fc = int(3000000 / (fs / N)) * (fs / N)
ts = 1 / float(fs)
t = np.arange(0, N * ts, ts)
i = np.cos(2 * np.pi * t * fc) * 2 ** 14
q = np.sin(2 * np.pi * t * fc) * 2 ** 14
i = i + 2 ** 15
q = q + 2 ** 15
iq = i + 1j * q
# Send data
sdr.tx(iq)
# Collect data
for r in range(20):
x = sdr.rx()
print(x)
y = abs(x)
y_dc = y - np.mean(y) # remove DC component
print(y_dc)
print('------------------------')
plt.figure(0)
plt.subplot(211)
plt.plot(y_dc)
plt.xlabel("Time [samples]")
plt.ylabel("Amplitude")
plt.subplot(212)
f, Pxx_den = signal.periodogram(x, fs)
plt.semilogy(f, Pxx_den)
plt.ylim([1e-7, 1e4])
plt.xlabel("Frequency [Hz]")
plt.ylabel("PSD [V**2/Hz]")
plt.draw()
plt.pause(0.05)
time.sleep(0.1)
plt.show()
```
在这个代码中,我们加入了一个隔直流的代码,用于移除接收到的信号的DC分量。这个代码为:
```python
y_dc = y - np.mean(y) # remove DC component
```
我们在时域图上画出了处理后的信号,并在频域图上画出了信号的功率谱密度(PSD)。
注意:这个代码只能在连接了PlutoSDR设备并安装了必要的包后才能运行。
阅读全文