Signale und Systeme - Digitale Signalverarbeitung - Harmonische Schwingung finden

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024
  • Die zu gehörigen Folien sind unter virtlab.fakult... zu finden.

Комментарии • 1

  • @rudigerheintz4583
    @rudigerheintz4583  6 дней назад

    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):
    ts=0.002
    fs=1/ts
    nt=500
    T=nt*ts
    t = np.arange(0, T,ts)
    fx= np.arange(-fs/2, fs/2,1/T)
    f=value/100*66+1
    data=np.sin(2*np.pi*f*t)+(np.random.rand(nt)-0.5)*20*value2/100
    fdata=np.fft.fftshift(np.abs(np.fft.fft(data)))/nt
    pos =np.argmax(fdata[int(len(fdata)/2):])+int(len(fdata)/2)
    fig.clf()
    fig.suptitle(str(f)+" "+str(fx[pos]), fontsize=16)
    ax = fig.add_subplot(3, 2, 1)
    ax.plot(t, data)
    ax = fig.add_subplot(3, 2, 2)
    ax.plot(fx,fdata)
    ax.scatter(fx[pos],fdata[pos],linewidth=5,color="r")
    data=np.hstack((data,np.zeros(9*nt)))
    fdata=np.fft.fftshift(np.abs(np.fft.fft(data)))/nt
    pos =np.argmax(fdata)
    nt=5000
    T=nt*ts
    t = np.arange(0, T,ts)
    fx= np.arange(-fs/2, fs/2,1/T)
    ax = fig.add_subplot(3, 1, 2)
    ax.set_title(str(fx[pos]))
    ax.tick_params(labelcolor=(1.,1.,1., 0.0), top='off', bottom='off', left='off', right='off')
    ax._frameon = False
    ax = fig.add_subplot(3, 2, 3)
    ax.plot(t, data)
    ax = fig.add_subplot(3, 2, 4)
    ax.plot(fx,fdata)
    nt=5000
    T=nt*ts
    t = np.arange(0, T,ts)
    fx= np.arange(-fs/2, fs/2,1/T)
    f=value/100*66+1
    data=np.sin(2*np.pi*f*t)+(np.random.rand(nt)-0.5)*20*value2/100
    fdata=np.fft.fftshift(np.abs(np.fft.fft(data)))/nt
    pos =np.argmax(fdata)
    ax = fig.add_subplot(3, 1, 3)
    ax.set_title(str(fx[pos]))
    ax.tick_params(labelcolor=(1.,1.,1., 0.0), top='off', bottom='off', left='off', right='off')
    ax._frameon = False
    ax = fig.add_subplot(3, 2, 5)
    ax.plot(t, data)
    ax = fig.add_subplot(3, 2, 6)
    ax.plot(fx,fdata)
    fig.canvas.draw()
    if __name__ == '__main__':
    run(10,10,plt.figure(),"flying-mosquito-105770.mp3")
    plt.show()