0
我試圖想象竇發電機,但得到可視化竇發電機在Python3.5,pyaudio,numpy的,matplotlib
ValueError: x and y must have same first dimension
我認爲尺寸是相同的錯誤,但顯然他們不是。 竇發生器是一個標準的
import pyaudio
import numpy as np
p = pyaudio.PyAudio()
volume = 0.08 # range [0.0, 1.0]
fs = 192000 # sampling rate, Hz, must be integer
duration = 3.0 # in seconds, may be float
f = 257.0 # sine frequency, Hz, may be float
f2 = 258.0
f3 = 300.0
f4 = 301.0
oma = 2000.0
a = (np.sin(2*np.pi*np.arange(fs*duration)*f/fs)).astype(np.float32)
b = (np.sin(2*np.pi*np.arange(fs*duration)*f2/fs)).astype(np.float32)
c = (np.sin(2*np.pi*np.arange(fs*duration)*f3/fs)).astype(np.float32)
d = (np.sin(2*np.pi*np.arange(fs*duration)*f4/fs)).astype(np.float32)
om = (np.sin(2*np.pi*np.arange(fs*duration)*oma/fs)).astype(np.float32)
# generate samples, note conversion to float32 array
samples = om*(a+b+c+d)
# for paFloat32 sample values must be in range [-1.0, 1.0]
stream = p.open(format=pyaudio.paFloat32,
channels=2,
rate=fs,
output=True)
# play. May repeat with different volume values (if done interactively)
stream.write(volume*samples)
stream.stop_stream()
stream.close()
p.terminate()
要我加matplotlib但不能去上班。我試圖在間隔0 - 2 * np.pi中可視化,個人波和聚合函數。
在線有一個解決方案,但它僅限於兩個頻率。 Wave interference beat frequency
PLT的最新迭代是
import matplotlib.pyplot as plt
x = np.mgrid[0:2*np.pi]
plt.rc('lines', linewidth=4)
plt.plot(samples,x)
plt.show()
謝謝,那是一個明確的答案。 –