[英]Python: Frequency Analysis of Sound Files
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: 我有扬声器的频率响应曲线,并希望在Python中执行以下操作:
gnuplot
我需要一个文件的FFT并用gnuplot
绘制它 Does anyone know : 有人知道吗 :
I know you didn't mention Pylab/Matplotlib, but it works. 我知道你没有提到Pylab / Matplotlib,但它确实有效。 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))
you can use numpy and matPlotLib. 你可以使用numpy和matPlotLib。 Something like the code below: 类似下面的代码:
spectrum = numpy.fft.fft(signal)
frequencies = numpy.fft.fftfreq(len(spectrum))
pylab.plot(frequencies,spectrum)
pylab.show()
That will show a graph of the fft spectrum. 这将显示fft光谱的图表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.