Python: Frequency Analysis of Sound Files

前端 未结 3 580
感情败类
感情败类 2021-02-01 10:37

I am generating some sound files that play tones at various frequencies with a certain number of harmonics.
Ultimately, these sounds will be played on a device with a small

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 11:39

    I know you didn't mention Pylab/Matplotlib, but it works. Here is an example (assumes single-channel signal):

    x, fs, nbits = audiolab.wavread('schubert.wav')
    audiolab.play(x, fs)
    N = 4*fs    # four seconds of audio
    X = scipy.fft(x[:N])
    Xdb = 20*scipy.log10(scipy.absolute(X))
    f = scipy.linspace(0, fs, N, endpoint=False)
    pylab.plot(f, Xdb)
    pylab.xlim(0, 5000)   # view up to 5 kHz
    
    Y = X*H
    y = scipy.real(scipy.ifft(Y))
    

提交回复
热议问题