7

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 speaker.

I have the frequency response curve of the speaker and want to do the following in Python:

  1. Plot the frequency spectrum of sound file. I need a take the FFT of the file and plot it with gnuplot
  2. Apply a nonlinear transfer function based on the frequency response curve in the data sheet.
  3. Plot the result after the function is applied.

Does anyone know :

  • What the simplest way to do this would be?
  • or of an Application (GNU/Linux based) that could do this for me?
4

3 回答 3

10

我知道你没有提到 Pylab/Matplotlib,但它确实有效。这是一个示例(假设单通道信号):

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))
于 2010-11-30T18:02:25.457 回答
4

你可以使用 numpy 和 matPlotLib。类似于下面的代码:

spectrum = numpy.fft.fft(signal)
frequencies = numpy.fft.fftfreq(len(spectrum))
pylab.plot(frequencies,spectrum)
pylab.show()

这将显示 fft 频谱图。

于 2010-11-30T20:33:16.923 回答
0

scipy有一个 FFT 并且很好地连接到 gnuplot 中。您应该能够使用信号模块进行数学运算。

于 2010-11-30T16:35:38.430 回答