我正在尝试对wav文件执行FFT,结果效果很好,但是在我的绘图中,我看到0 Hz时振幅很大。我以为这是直流偏移。我的目的是在我的绘图中或直接在代码中忽略此DC偏移,因为这会阻止我看到实际的噪声。在我的示例中,我记录了一个大约6.1kHz的噪声,如果我在那个点进行缩放,我可以清楚地看到它,但是由于0Hz振幅,通常无法观察到它。如果您告诉我如何忽略0Hz(或DC偏置),我会很高兴的。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import scipy.io.wavfile as wavfile
import scipy
import scipy.fftpack
import numpy as np
from matplotlib import pyplot as plt
fs_rate, signal = wavfile.read("file.wav")
print ("Frequency sampling", fs_rate)
l_audio = len(signal.shape)
print ("Channels", l_audio)
if l_audio == 2:
signal = signal.sum(axis=1) / 2
N = signal.shape[0]
print ("Complete Samplings N", N)
secs = N / float(fs_rate)
print ("secs", secs)
Ts = 1.0/fs_rate # sampling interval in time
print ("Timestep between samples Ts", Ts)
t = scipy.arange(0, secs, Ts) # time vector as scipy arange field / numpy.ndarray
FFT = abs(scipy.fft(signal))
FFT_side = FFT[range(N/4)] # one side FFT range
freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0])
fft_freqs = np.array(freqs)
freqs_side = freqs[range(N/4)] # one side frequency range
fft_freqs_side = np.array(freqs_side)
print (abs(FFT_side))
plt.subplot(211)
p1 = plt.plot(t, signal, "g") # plotting the signal
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.subplot(212)
p2 = plt.plot(freqs_side, abs(FFT_side), "b") # plotting the positive fft spectrum
plt.xlabel('Frequency (Hz)')
plt.ylabel('Count single-sided')
plt.show()