Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - ValueError: x and y must have same first dimension, but have shapes (255,) and (256,)

I'm working on a .wav-file and doing some signal processing but i keep getting this value error in my TraceBack, _plot_args. I know it is about dimensions of vectors but I can't figure it out. My code is as follows:

newAudio = AudioSegment.from_wav(audio_path)
t1 = newAudio[:500]
t1.export("newSong.wav",format="wav")


audio_path_util = r'D:Master1TPDSProiectTPDS
ewSong.wav'
x , fs = librosa.load(audio_path_util)


#plot semnal audio util
plt.figure(figsize=(14, 5))
librosa.display.waveplot(x, sr=fs)


#play the audio
ipd.Audio(data=x,rate=fs)


X = librosa.stft(x)
Xdb = librosa.amplitude_to_db(abs(X))
plt.figure(figsize=(14,5))
librosa.display.specshow(Xdb,sr=fs,x_axis='time',y_axis='hz')

#aplicare transformata Fourier
Fs = 10000
t = np.arange(0,1,1/Fs)
f = 20
xf = fft(x)
n = np.size(t)
ns = int(n/2)
p = np.linspace(0,1,ns)
fr = (Fs/2)*p
xf_m = abs(xf[0:np.size(fr)])


xff_m = (2/n)*abs(xf[0:np.size(fr)])


#aplicare Hamming window
n = 4096
m = 513
t = np.arange(m)
#w = np.hanning(64)
w = get_window('hamming', m)
w_fft = np.fft.rfft(w, 4096)
freqs = np.fft.rfftfreq(n, 1./m)

#Generate windowed time-domain sequence
#window-blackman
N = 256
HK = np.zeros(N)
fx = np.linspace(0,1,N);
print("Merge")
hk = np.fft.ifftshift(np.fft.ifft(HK))
aa = np.arange(1,N)
plt.plot(aa,hk)

L = 65
w = np.blackman(L)
q = N/2+1-np.floor(L/2)
w = N/2+1+np.floor(L/2)
pp = np.arange(q,w)
hw = hk(pp)* w
#generate an ideal-filter sequence
fs = 64000
N = 64

xx = np.arange(0,N-1)
f = 3000
A = 1
yn = np.convolve(x, hw)

And the error is:

22050
9.856653e-05
0.2649552
-0.1929471
0.020418147
Merge
Traceback (most recent call last):

  File "D:Master1TPDSProiectTPDSProiect.py", line 95, in <module>
    plt.plot(aa,hk)

  File "C:UsersPatrickanaconda3libsite-packagesmatplotlibpyplot.py", line 2761, in plot
    return gca().plot(

  File "C:UsersPatrickanaconda3libsite-packagesmatplotlibaxes\_axes.py", line 1647, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]

  File "C:UsersPatrickanaconda3libsite-packagesmatplotlibaxes\_base.py", line 216, in __call__
    yield from self._plot_args(this, kwargs)

  File "C:UsersPatrickanaconda3libsite-packagesmatplotlibaxes\_base.py", line 342, in _plot_args
    raise ValueError(f"x and y must have same first dimension, but "

ValueError: x and y must have same first dimension, but have shapes (255,) and (256,)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...