TypeError: psd() 有一个意外的关键字参数 'Fc'

问题描述 投票:0回答:1

当我执行此代码时显示错误,我正在使用

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

谁能帮忙

python psd
1个回答
0
投票

你导入了错误的

psd
函数。

您正在寻找

matplotlib.pyplot.psd
;你有
matplotlib.mlab.psd
,它有不同的签名。

将导入更改为

-from matplotlib.mlab import psd
+from matplotlib.pyplot import psd

或者只使用

plt.psd
因为你有
pyplot
导入为
plt
.

© www.soinside.com 2019 - 2024. All rights reserved.