Home > Enterprise >  Python FFT - Output fft is the same as input function?
Python FFT - Output fft is the same as input function?

Time:05-23

I am trying to perform an FFT on data from a simulation that has an oscilating shape. When I run the scipy FFT, the output is the same as the input and I can't figure out why. My code is below:

X = fftpack.rfft(Ax1)
freq = fftpack.rfftfreq(len(Ax1), dt1)

plt.plot(freq, np.abs(X))
plt.xlabel('Frequency (Hz)'), plt.ylabel('Power')
plt.show()

where Ax1 is the array of y data and dt1 is the time step between each point. The original curve and the fft output are shown below.

https://i.stack.imgur.com/8iPa8.png

https://i.stack.imgur.com/1Eja9.png

Any help would be much appreciated.

CodePudding user response:

Simple example shows sinusoid for source a and peak for fourier result.

from scipy.fftpack import rfft
import math, numpy
import matplotlib.pyplot as plt
a = [math.sin(i/5) for i in range(100)]
plt.plot(a)
plt.show()
fu = rfft(a)
plt.plot(numpy.abs(fu))
plt.show()

What code creates your first and second picture? Please show us reproducible example.

Result of rfft might overwrite source array if parameter overwrite_x is set, but it's default value is False

CodePudding user response:

I just tried this and the same thing is happening, where the output of the fft has the same plot as the original curve. I have tried regular fft as oposed to rfft also and the same issue occurs. The code is:

tstart = 7.5000000000039813e-2
rho = 0.80272956E-04
V = 4773.706375394508
Aref = 0.203911
Pnondim = 0.5 * rho * V**2 * Aref

df1 = pd.read_csv('screenP.csv')
P1 = -np.array(df1[:])/Pnondim
CT = 1.52
Ax1 = P1   CT
steps1 = len(P1)
dt1 = 2e-7
tend1 = tstart   steps1*dt1
t1 = np.linspace(tstart,tend1,steps1) * 1000
plt.plot(t1,Ax1)
plt.show()

X = fftpack.rfft(Ax1)
freq = fftpack.rfftfreq(len(Ax1), dt1)

plt.plot(freq, np.abs(X))
plt.xlabel('Frequency (Hz)'), plt.ylabel('Power')
plt.show()

where screenP is just a csv with data output from a CFD solver.

  • Related