0
$\begingroup$

so I'm pretty sure that I'm plotting the wrong frequency domain against my FFT values because I keep getting basically the same graph shape every single time. I think that I just don't comprehend the context of some of the values, as I'm quite new to signal processing. Attached below is the frequency domain I'm attempting to use, which is what I'm seeing on most websites. Is T the actual period of your data? It doesn't really matter whether or not I have user input or hardcode a value in, the same graph shape remains. Same goes with completely different data sets, always the same shape remains.

import matplotlib.pyplot as plt
from scipy.fft import fft, ifft

transform = fft(data)
per = input("What's your period: ")
T = int(per)
f = np.linspace(0, 1 / T, N)
plt.plot(f, np.abs(transform)*(1/N))
$\endgroup$
2
$\begingroup$

I'm not familiar with this type of code, but I can take a guess at what you want to do. Your variable names are inappropriate. I suggest you change your code to something like the following (comments are inside brackets):

spectrum = fft(data) [Assumes you've transformed a data sequence whose length is 'N' samples.]

fs = input("What's the 'data' sampling rate (in Hz): ")

delta_freq = fs/N ['delta_freq' is the frequency spacing (measured in Hz) between the spectral samples contained in the 'spectrum' sequence]

freq_axis = np.linspace(0, delta_freq, (N-1)*delta_freq)

plt.plot(freq_axis[:N//2], np.abs(spectrum)[:N//2]*(1/N)) [Plots the normalized (i.e., the 1/N scaling) spectral magnitude over the positive-frequency range]

$\endgroup$
1
$\begingroup$

To complete the answer given above, depending on the nature of the data you're trying to analyse, maybe you could try to plot the spectral magitude using a logarithmic scale to adjust the dynamic ?

$\endgroup$
1
  • $\begingroup$ Nathan, that is a good suggestion. $\endgroup$ May 14 '20 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.