Signale und Systeme - Digitale Signalverarbeitung - Audiodaten filtern mit Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024
  • Die zu gehörigen Folien sind unter virtlab.fakult... zu finden.

ความคิดเห็น • 3

  • @rudigerheintz4583
    @rudigerheintz4583  3 วันที่ผ่านมา

    Quellcode:
    import multiprocessing as multiproc
    import numpy as np
    import soundfile as sf
    import pyaudio
    import matplotlib.pyplot as plt
    def run(value,value2,fig,fileName,saveValue=None):
    data, fs = sf.read(fileName)
    if(data.ndim>1): data=data[:,0]
    ts=1/fs
    nt=data.size
    T=nt*ts
    t = np.arange(0, T,ts)
    i = np.arange(-40, 40.1,1)
    fx= np.arange(-fs/2, fs/2,1/T)
    P=1+value/100*27
    Q=1+value2/100*10
    gabor=np.exp(-(i*i)*Q/(40*40))*np.sin(2*np.pi*P*i/len(i))
    res=np.convolve(data, gabor, mode='same')
    fig.clf()
    fig.suptitle(fileName+' fs='+str(fs)+" Hz", fontsize=16)
    ax = fig.add_subplot(3, 2, 1)
    ax.plot(t, data)
    ax = fig.add_subplot(3, 2, 2)
    ax.plot(fx,np.fft.fftshift(np.abs(np.fft.fft(data)))/nt)
    ax = fig.add_subplot(3, 2, 3)
    ax.plot(i, gabor)
    ax = fig.add_subplot(3, 2, 4)
    ax.plot(np.fft.fftshift(np.abs(np.fft.fft(gabor)))/nt)
    ax = fig.add_subplot(3, 2, 5)
    ax.plot(t, res)
    ax = fig.add_subplot(3, 2, 6)
    ax.plot(fx,np.fft.fftshift(np.abs(np.fft.fft(res)))/nt)

    fig.canvas.draw()
    res=res/np.max(np.abs(res))
    multiproc.Process(target=playAudio,args=(res,fs)).start()
    def playAudio(dat,samplerate):
    stream = pyaudio.PyAudio().open(format = pyaudio.paFloat32,channels = 1,rate = samplerate,output = True)
    stream.write(dat.astype(np.float32).tobytes())
    stream.close()
    if __name__ == '__main__':
    run(60,0,plt.figure(),"flying-mosquito-105770.mp3")
    plt.show()

  • @paweleliasz9642
    @paweleliasz9642 9 วันที่ผ่านมา

    Interesant Danke