1

I'm calculating the RFFT of a signal of length 3000 (sampled at 100 Hz) with only real valued entries:

from scipy.fft import rfft
coeffs = rfft(values)
coeffs = np.abs(coeffs)

With rfft I'm only getting half of the coefficients, i.e. the symmetric ones are dicarded (due to real valued input).

Is it correct to scale the values by coeffs = (2 / len(values)) * coeffs to get the amplitudes?

Edit: Below I have appended a plot of the amplitudes vs. Frequency (bins) for accelerometer and gyroscope (shaded area is standard deviation). For accelerometer the energy in the first FFT bin is much higher than in the other bins (> 2 in the first bin and around < 0.4 in the other bins). For gyroscope it is different and the energy is much more distributed.

Does that mean that for acccelerometer the FFT looks good but for gyroscope it is worse? Further, is it reasonable to cut the FFT at 100 Hz (i.e. take only bins < 100 Hz) or take the first few bins until 95% of the energy is kept?

enter image description here

enter image description here

machinery
  • 5,972
  • 12
  • 67
  • 118

1 Answers1

1

The approximate relationship I provided in this post holds whether you throw out half the coefficients or not.

So, if the conditions indicated in that post apply to your situation, then you could get an estimate of the amplitude of a dominant sinusoidal component with

approx_sinusoidal_amplitude = (2 / len(values)) * np.abs(coeffs[k])

for some index k corresponding to the frequency of the sinusoidal component (which according to the limitations indicated in my other post has to be at or near a multiple of 100/3000 ~ 0.033Hz in your case). For a dominant sinusoidal component, this index would typically correspond to a local peak in the frequency spectrum. Note however that if your signal is a mixture of various frequency components, the individual components may affect the frequency spectrum in such a way that the peak does not appear clearly.

SleuthEye
  • 14,379
  • 2
  • 32
  • 61
  • In my case, it is accelerometer readings from a smartphone (e.g. x-direction). The sensor samples at 100 Hz and I look at a window of 30 seconds (= 3000 elements). How can I check if the limitations you mentioned hold? – machinery Feb 16 '21 at 14:34
  • In general if you plot the spectrum you should see whether the energy is concentrated on a single FFT bin. If that's the case the approximation would likely be reasonable. But for your specific type of application that you just mentioned, it's quite likely (unless the smartphone were to be strapped to a apparatus with a fairly precise periodic motion) that the energy be spread over 2 or more adjacent bins at which point the approximation rapidly degrades. – SleuthEye Feb 17 '21 at 00:53
  • I have edited my original post with two plots and additional information. – machinery Feb 17 '21 at 18:16
  • Do you know some answer to the problems I'm stating in the edit? – machinery Feb 18 '21 at 16:15
  • A few things : 1) the energy in bin 0 represent the constant bias of your signal. I'd guess your x component from your accelerometer is pointing down and reports values which are on average positive due to gravity. 2) If you actually have any periodic sinusoidal signal from your accelerometer it is relatively small compared to this constant bias, so kinda lost in there. 3) On the gyroscope you don't have that sort of bias, so you can better see the 'rest' of the signal. But with such relatively broad spectrum, the signal is unlikely to have much of a distinguisable periodic sinusoidal form. – SleuthEye Feb 19 '21 at 00:44
  • In that case hoping to get the signal's time-domain amplitude with Fourier coefficients (which are provided under the assumption that the signal is periodic) would not give great results. You may get a general sense of how 'strong' the signal is by using an RMS approach computed in time-domain (in which case you might as well use min/max to get the actual amplitude), or computed in frequency-domain and applying Parseval's theorem to get the corresponding time-domain RMS value. – SleuthEye Feb 19 '21 at 00:51
  • 4) You can cut the spectrum at 100Hz if your signal of interest is below 100Hz. That's up to your application. In this case it looks like it goes beyond 100Hz. – SleuthEye Feb 19 '21 at 00:51
  • Thanks a lot for your comments. How do I calculate the RMS in frequency-domain and then apply Parseval's theorem? Is it not possible to first apply RMS to x,y,z and thenn doing the FFT? – machinery Feb 19 '21 at 10:25
  • Do you have some hints for me regarding the RMS in frequency-domain and Parseval's theorem? Thanks a lot. – machinery Feb 22 '21 at 13:39
  • [See wiki](https://en.wikipedia.org/wiki/Discrete_Fourier_transform#The_Plancherel_theorem_and_Parseval's_theorem). Specifically the Plancherel theorem special case. Computing the FFT on the RMS is not the same thing. Also, depending on you application, you may very well want to leave the x,y and z component separate. – SleuthEye Feb 23 '21 at 00:37