python - FFT Does Not Detect Expected Frequencies in Experimental Data with Known Periodicities - Stack Overflow

I am analyzing experimental data where resistance Rxx is measured as a function of an angle Phi, which

I am analyzing experimental data where resistance Rxx is measured as a function of an angle Phi, which ranges from 0 to 360 degrees in steps of 2 degrees. The dataset consists of two columns: Phi (angle in degrees, from 0 to 360 with step 2°), Rxx (longitudinal resistance) which both only contain real numbers.

The Problem:

The dataset can be well described by a function consisting of the sum of two squared cosines: Rxx(Phi) = A * cos^2(Pi * (Phi - Phi_0) / 180) + B * cos^2(Pi * (Phi - Phi_0) / 90) + const

However, when I apply FFT I do not observe peaks at 2 or 4 cycles per 360°. Instead, I see a low-frequency artifact that do not correspond to the expected periodicities.

My Questions:

Why does FFT fail to detect the expected frequencies (2 and 4 cycles per 360°)? How to fix this?

The code I'm using:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.fft import fft, fftfreq


# import data

data = pd.read_csv("test")
x = data["Phi"].to_numpy()
Rxx = data["Rxx"].to_numpy()

angles = np.deg2rad(x) # convert degrees to radians
dPhi = np.deg2rad(angles[2]-angles[1]) # define angular step
N = len(angles) # number of points

fft_Rxx = fft(Rxx) # compute FFT
freqs = fftfreq(N, dPhi) / (2 * np.pi)  # compute frequency

amplitude_Rxx = np.abs(fft_Rxx) # compute magnitude spectrum

# plot results

plt.plot(freqs, amplitude_Rxx)
plt.show()

Here is a link to my dataset: link

I am analyzing experimental data where resistance Rxx is measured as a function of an angle Phi, which ranges from 0 to 360 degrees in steps of 2 degrees. The dataset consists of two columns: Phi (angle in degrees, from 0 to 360 with step 2°), Rxx (longitudinal resistance) which both only contain real numbers.

The Problem:

The dataset can be well described by a function consisting of the sum of two squared cosines: Rxx(Phi) = A * cos^2(Pi * (Phi - Phi_0) / 180) + B * cos^2(Pi * (Phi - Phi_0) / 90) + const

However, when I apply FFT I do not observe peaks at 2 or 4 cycles per 360°. Instead, I see a low-frequency artifact that do not correspond to the expected periodicities.

My Questions:

Why does FFT fail to detect the expected frequencies (2 and 4 cycles per 360°)? How to fix this?

The code I'm using:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.fft import fft, fftfreq


# import data

data = pd.read_csv("test")
x = data["Phi"].to_numpy()
Rxx = data["Rxx"].to_numpy()

angles = np.deg2rad(x) # convert degrees to radians
dPhi = np.deg2rad(angles[2]-angles[1]) # define angular step
N = len(angles) # number of points

fft_Rxx = fft(Rxx) # compute FFT
freqs = fftfreq(N, dPhi) / (2 * np.pi)  # compute frequency

amplitude_Rxx = np.abs(fft_Rxx) # compute magnitude spectrum

# plot results

plt.plot(freqs, amplitude_Rxx)
plt.show()

Here is a link to my dataset: link

Share Improve this question asked Mar 12 at 23:49 kuba_polkuba_pol 315 bronze badges 2
  • For context: the signal is so-called anisotropic magnetoresistance: resistance change in response to changing direction of magnetic field (magnetization to be strict). I'm trying to calculate FFTbecause for some values of magnetic field and temperature, I get a very nice fit of the two-cosine term, while for others the fit does not work. I suppose there is another component, and that amplitudes of all components are field- and temperature dependent. I'd like to obtain frequencies to improve the fitting accuracy and check how the amplitudes of all components depend on the field and temperature. – kuba_pol Commented Mar 12 at 23:56
  • Can you include a plot of the data and of the Fourier transform, and explain what you expected to see? It’s hard to give an answer to your question not being behind a computer right now. – Cris Luengo Commented Mar 13 at 0:55
Add a comment  | 

2 Answers 2

Reset to default 4

I observe a mistake here:

angles = np.deg2rad(x) # convert degrees to radians
dPhi = np.deg2rad(angles[2]-angles[1]) # define angular step

The degrees-to-radians conversion is being done twice.

Instead, I see a low-frequency artifact that do not correspond to the expected periodicities.

I disagree: I graphed x vs Rxx with this code:

plt.plot(x, Rxx)

Note the Y axis. The mean of this series is much larger than the variation within the series. This means that you should expect a large DC offset at frequency zero, much larger than any of the frequencies corresponding to your cosine term.

You can either ignore the zero frequency term, or remove it by subtracting the mean of Rxx from Rxx before running an FFT on it.

Here is a better depiction of the spectrum. If your peaks of interest don't show up here, then they probably don't exist.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import scipy.fft

data = pd.read_csv('test.csv')
x, Rxx = data[['Phi', 'Rxx']].to_numpy().T

angles = np.deg2rad(x)
d_phi = np.deg2rad(angles[1] - angles[0])  # angular step
n = len(angles)

fft = scipy.fft.rfft(Rxx)
freqs = scipy.fft.rfftfreq(n, d_phi)
amplitude = np.abs(fft)

plt.loglog(freqs, amplitude)
plt.show()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744725625a4590159.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信