3

I am trying to implement an algorithm from a research paper where we use accelerometers for detecting activity patterns. The authors mention in the paper that use a High Pass Filter with a cutoff frequency of 1Hz to remove the effect of low frequency gravity components which I have applied on my dataset with x,y,z accelerometer values like this

sos = signal.butter(1, 1, 'highpass', output='sos', fs=12.5, analog=False)
filtered = signal.sosfilt(sos, segments)

where segments is a numpy array with slices of 50 values (4 second x,y,z values sampled at 12.5Hz). I then make new segments where the each of the values on separate axes are segmented together so e.g. 50 values for x, 50 values for y and so on. I then proceed on to apply a Fast Fourier Transform on these filtered values but no matter whichever segment I choose the highest amplitude is always at 0 Hz leading me to believe that the High Pass Filter is not implemented correctly.

Here's a sample:

freq_data = np.fft.fft(features_segments[0][0])
y = 2/N * np.abs(freq_data[0:np.int(N/2)])

The features_segments[0][0] implies the first segment and the x axis values only which gives a result of

time_signal = np.linspace(0,4,50)
plt.plot(time_signal, features_segments[0][0])

enter image description here

plt.plot(frequency, y)
plt.title('Frequency domain Signal')

enter image description here

This is just one example for every fft that I try to get the 0Hz amplitude is always the highest on the order of 50-100x than the other amplitudes.

m.umar
  • 855
  • 4
  • 13
  • 23
  • 2
    If you look at `plot(time_signal, filtered)`, you'll probably see a significant transient near t=0, because the filter is starting from zero initial conditions. Instead of `filtered = signal.sosfilt(sos, segments)`, you could try the forward-backward filter `filtered = signal.sosfiltfilt(sos, segments)`. You might also consider increasing the order of the Butterworth filter (but you shouldn't need too much if you use `sosfiltfilt`, because it effectively applies the filter twice). – Warren Weckesser Mar 30 '20 at 13:00
  • yes that seems to do the trick. Also I was making another mistake, rather than applying the high pass filter to 50 subsequent values on each axis, i was applying the filter on each x,y,z value. So now the shape of each segment is (3,50) where previously it was (50,3) which was the wrong way to go about this – m.umar Mar 30 '20 at 15:40
  • Also can you give a comment on one more thing that I have not been able to understand. The writers in the paper say "For each segment of the 3 time series we extract ten different features. These features are the maximum, minimum, standard deviation, amplitude, energy and top 5 magnitudes of the fast Fourier transform (FFT). Consequently, each feature vector was comprised of a total of 30 features." Why do they mention amplitude and energy as a singular? Am i missing something here because amplitude and energy will always be an array. Do they mean max amplitude or something of that sort? – m.umar Mar 30 '20 at 15:43

0 Answers0