簡體   English   中英

x和y必須在python中具有相同的第一維錯誤

[英]x and y must have same first dimension ERROR in python

我是python的新手,正在嘗試繪制具有不同頻率的正弦波的FFT。 我得到了正弦波圖,但發現很難繪制信號的FFT。

A = 2.0                     
fs = 5000                   
nsample = 200 
T=1.0/fs      
ff = np.array([200, 600, 1000]) # different freq under test

#Generating the test sinusoidals
x = np.arange(0,nsample)

normalisedFreq = 2*np.pi*ff/fs

# create the three sinusoids and generating waveform 
y = np.zeros(nsample)

for w in normalisedFreq :
   y=y+A*np.sin(w*x)

# generating Fast Fourier Transform
n_fft=len(y)

magnitude = 2*np.abs(scipy.fftpack.fft(y,n_fft))/n_fft

cutoff = m.ceil((n_fft+1)/2)             #nyquist frequency 

freq=np.array((0,cutoff-1)*(fs/n_fft))   #frequency vector

plt.subplot (211)
plt.plot(x,y)

plt.subplot(212)
plt.plot(freq,magnitude)

plt.show()

我收到以下錯誤:

ValueError: x and y must have same first dimension

當我嘗試繪制頻率和幅值時會發生此錯誤。

請幫助,謝謝

我不確定如何解決它,但似乎錯誤表明頻率長度和幅度長度不同。

我認為您要么需要創建與幅度相同長度的頻率,要么截斷幅度數組以匹配頻率

編譯len(magnitude)len(freg)可能是調試問題的合理第一步。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM