实时数字上升和跌落边缘在声音信号上绘制
您好,我需要在同一子图上发声和数字信号。对于第一个和secong的图是声音信号,我可以很快阅读。我需要第三个数字信号才能查看。在这种情况下,当我按键按钮时,我需要一个数字高。当我编写Python Code 3rd Signal(键按)时,图中中间没有更改。我的意思是我看不到情节期间的上升和下降边缘。我该如何解决?
import numpy as np
import pyaudio
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
import time
plt.style.use('bmh')
BUFFER = 1024*4 # number of data points to read at a time
SAMPLERATE = 44100 # time resolution of the recording device (Hz)
p = pyaudio.PyAudio() # instantiate PyAudio
stream=p.open(format=pyaudio.paInt16,channels=1,rate=SAMPLERATE,input=True,
frames_per_buffer=BUFFER) # use default input device to open audio stream
pause = False
key = False
# üç satır bir sütün üç adet ax ekseni hazırla, fig class ı çağır
fig, (ax1,ax2,ax3) = plt.subplots(3,1,sharex=True)
#x-y veri dizilerini ayrı ayrı diziler oluştur
xdata, ydata, ydata2, ydata3= [], [], [], []
#ax1, ax2 ve ax3 ü çiz 2D obje olarak ln, ln2 ve ln3'e boş olarak döndür
ln, = ax1.plot([], [], lw=1)
ln2, = ax2.plot([], [],lw=1)
ln3, = ax3.step([],[], lw=2) #yükslen ve alçalan kenarı göstermek için .step
# xdata zaman ekseni olarak buffer kadar eşit aralıkta dizi oluştur.
xdata = np.linspace(0, BUFFER-1, BUFFER)
# methods for animation
def init():
ax1.set_xlim(0, BUFFER-1) # ax1 x ekseni sınırla
ax1.set_ylim(-100000, 100000) #ax1 y ekseni sınırla 100 000
ax2.set_ylim(-10000, 10000) # ax2 ye ekseni sınırla 10 000
ax3.set_ylim(-0.5,1.5) # ax3 0-1 arası dijital
return ln,ln2,ln3, # Artist objelerin geri döndür
def animate(i):
ydata = np.frombuffer(stream.read(BUFFER), dtype=np.int16)
#ydata2 = np.frombuffer(stream.read(BUFFER), dtype=np.int16)
ydata3= key
print("ydata3",ydata3)
ln.set_data(xdata, ydata) # xdata ve ydata yı ln 2D objesinde birleştir
ln2.set_data(xdata, ydata / 2) # ydata 10 a böl
ln3.set_data(xdata, ydata3)
return ln,ln2,ln3,
def onClick(event):
global pause
pause ^= True
if pause==False:
anim.resume()
else:
anim.pause()
#print(pause)
def onKey(event):
global key
#time.sleep(1)
key ^= True
#mouse klik oluşunca onClick fonksiyonuna git
fig.canvas.mpl_connect('button_press_event', onClick)
fig.canvas.mpl_connect('key_press_event', onKey)
anim = FuncAnimation(fig, animate, init_func=init, frames=200, interval=20,
blit=True)
plt.show()
# stop and close the audio stream
stream.stop_stream()
stream.close()
p.terminate()
Hello i need both sound singnal and a digital signal on the same subplots. for 1st and secong plots are sound signals and i can read it very fast. I need a 3rd digital digital signal to see. In this case when i press key button i need a digital HIGH. when i wrote the python code 3rd signal (key press) is not changing in the middle of the plot. i mean i cant see the rising and falling edges during the plot. how can i solve it?
import numpy as np
import pyaudio
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
import time
plt.style.use('bmh')
BUFFER = 1024*4 # number of data points to read at a time
SAMPLERATE = 44100 # time resolution of the recording device (Hz)
p = pyaudio.PyAudio() # instantiate PyAudio
stream=p.open(format=pyaudio.paInt16,channels=1,rate=SAMPLERATE,input=True,
frames_per_buffer=BUFFER) # use default input device to open audio stream
pause = False
key = False
# üç satır bir sütün üç adet ax ekseni hazırla, fig class ı çağır
fig, (ax1,ax2,ax3) = plt.subplots(3,1,sharex=True)
#x-y veri dizilerini ayrı ayrı diziler oluştur
xdata, ydata, ydata2, ydata3= [], [], [], []
#ax1, ax2 ve ax3 ü çiz 2D obje olarak ln, ln2 ve ln3'e boş olarak döndür
ln, = ax1.plot([], [], lw=1)
ln2, = ax2.plot([], [],lw=1)
ln3, = ax3.step([],[], lw=2) #yükslen ve alçalan kenarı göstermek için .step
# xdata zaman ekseni olarak buffer kadar eşit aralıkta dizi oluştur.
xdata = np.linspace(0, BUFFER-1, BUFFER)
# methods for animation
def init():
ax1.set_xlim(0, BUFFER-1) # ax1 x ekseni sınırla
ax1.set_ylim(-100000, 100000) #ax1 y ekseni sınırla 100 000
ax2.set_ylim(-10000, 10000) # ax2 ye ekseni sınırla 10 000
ax3.set_ylim(-0.5,1.5) # ax3 0-1 arası dijital
return ln,ln2,ln3, # Artist objelerin geri döndür
def animate(i):
ydata = np.frombuffer(stream.read(BUFFER), dtype=np.int16)
#ydata2 = np.frombuffer(stream.read(BUFFER), dtype=np.int16)
ydata3= key
print("ydata3",ydata3)
ln.set_data(xdata, ydata) # xdata ve ydata yı ln 2D objesinde birleştir
ln2.set_data(xdata, ydata / 2) # ydata 10 a böl
ln3.set_data(xdata, ydata3)
return ln,ln2,ln3,
def onClick(event):
global pause
pause ^= True
if pause==False:
anim.resume()
else:
anim.pause()
#print(pause)
def onKey(event):
global key
#time.sleep(1)
key ^= True
#mouse klik oluşunca onClick fonksiyonuna git
fig.canvas.mpl_connect('button_press_event', onClick)
fig.canvas.mpl_connect('key_press_event', onKey)
anim = FuncAnimation(fig, animate, init_func=init, frames=200, interval=20,
blit=True)
plt.show()
# stop and close the audio stream
stream.stop_stream()
stream.close()
p.terminate()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论