如何过滤 fft 输出以去除 0 Hz 分量



我试图计算实验数据集的傅里叶变换。我最终查看了 0 Hz 分量较高的数据。关于如何删除它的任何想法?0 Hz 分量实际上代表什么?

#Program for Fourier Transformation
# last update 131003, aj
import numpy as np
import numpy.fft as fft
import matplotlib.pyplot as plt
def readdat( filename ):
    """
        Reads experimental data from the file
    """
    # read all lines of input files
    fp = open( filename, 'r')
    lines = fp.readlines() # to read the tabulated data
    fp.close()
    # Processing the file data
    time = []
    ampl = []
    for line in lines:
        if line[0:1] == '#':
            continue # ignore comments in the file
        try:
            time.append(float(line.split()[0]))
            #first column is time
            ampl.append(float(line.split()[1]))
            # second column is corresponding amplitude
        except:
            # if the data interpretation fails..
            continue
    return np.asarray(time), np.asarray(ampl)
if __name__ == '__main__':
    time, ampl = readdat( 'VM.dat')
    print time
    print ampl
    spectrum = fft.fft(ampl)
    # assume samples at regular intervals
    timestep = time[1]-time[0] 
    freq = fft.fftfreq(len(spectrum),d=timestep)
    freq=fft.fftshift(freq)
    spectrum = fft.fftshift(spectrum)
    plt.figure(figsize=(5.0*1.21,5.0))
    plt.plot(freq,spectrum.real)
    plt.title("Measured Voltage")
    plt.xlabel("frequency(rad/s)")
    plt.ylabel("Spectrum")
    plt.xlim(0.,5.)
    plt.ylim(ymin=0.)
    plt.grid()
    plt.savefig("VM_figure.png")

如果将处理前数据集的平均值设为零,则 0Hz 分量应该可以忽略不计。这等效于使用选项"常量"对数据进行去趋势化 {scipy 去趋势化}。

这有时用作低精度系统中的预处理步骤,因为对具有大直流偏移的数据进行有限精度数值处理会产生相关的数值误差。

0 Hz 分量表示信号的直流偏移。

你可以用任何高通滤波器去掉它,只需把截止频率放得尽可能低(滤波器可以是数字的或模拟的,我不知道你的实验设置是什么)。

一个简单的可能性是将该值强制为 0(以这种方式修改 FFT 等效于应用高通 FIR 滤波器)。

最新更新