Reputation: 13
I tried to calculate the fourier transform of the set of experimental data. I ended up looking at data where 0 Hz component is higher. Any idea on how to remove this? What does the 0 Hz component actually represent?
#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")
Upvotes: 1
Views: 7018
Reputation: 145
If the average of the data set before processing is made to be zero then the 0Hz component should be negligible. This would be equivalent to detrending {scipy detrend} the data with option 'constant'.
This is sometimes used as a preconditioning step in low precision systems as finite precision numerical processing of data with large DC offsets will generate related numerical errors.
Upvotes: 1
Reputation: 215
The 0 Hz component represents the DC offset of your signal.
You can remove it with any high-pass filter, just put the cutoff frequency as low as possible (the filter could be digital or analogue, I don't know what your experimental setup is).
A simple possibility is just to force that value to 0 (modifying the FFT in this way is equivalent to applying a high pass FIR filter).
Upvotes: 0