当我执行此代码时显示错误,我正在使用
matplotlib.mlab
psd
这是代码,
from matplotlib.mlab import psd
from rtlsdr import *
import matplotlib.pyplot as plt
sdr = RtlSdr()
# configure device
sdr.sample_rate = 2.4e6
p = sdr.center_freq = 95e6
sdr.gain = 'auto'
arr_db = []
arr_fq = []
def plot_graph():
print(len(arr_db))
print(len(arr_fq))
xlabel('Frequency (MHz)')
ylabel('Relative power (dB)')
#plt.plot(arr_db, arr_fq, color='blue')
plt.draw()
plt.pause(0.5)
plt.clf()
while True:
# use matplotlib to estimate and plot the PSD
samples = sdr.read_samples(256*1024)
a = psd(samples.real, NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=p/1e6)
p+= 1000000
for i in range(513):
b = a[0][i]
c = a[1][i]
arr_db.append(b)
arr_fq.append(c)
plot_graph()
sdr.close()
错误显示如下,
Traceback (most recent call last):
File "c:\Users\DELL\Desktop\Ismail\rtl_sdr\sample.py", line 27, in <module>
a = psd(samples.real, NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=p/1e6)
TypeError: psd() got an unexpected keyword argument 'Fc'
Found Rafael Micro R820T/2 tuner
谁能帮忙
你导入了错误的
psd
函数。
matplotlib.pyplot.psd
;你有matplotlib.mlab.psd
,它有不同的签名。
将导入更改为
-from matplotlib.mlab import psd
+from matplotlib.pyplot import psd
或者只使用
plt.psd
因为你有pyplot
导入为plt
.