I have read other posts here on using the Butterworth filter in Mathematica, however, I am having a hard time understanding the chain of functions and their parameters as applied to my case, and I am not confident with what I am seeing.

I sampled the 3 axes of my accelerometer at 128 Hz in the field, and can successfully import, view and plot the CSV file in Mathematica.

I select only the column of data I am interested in, the 5th column, the Z-axis (colinear with gravity), and plot it. So far so good.

data2 = Query[All, {5}] @data

However, when I go to chain the two functions, RecurrenceFilter and ToDiscreteTimeModel, with the ButterworthFilterModel (assigned to LPF) as an argument to ToDiscreteTimeModel like so:

LPF = ButterworthFilterModel [{"Lowpass", 1, 5}]

filtered = RecurrenceFilter[ToDiscreteTimeModel [LPF, 1], data2]

I can see the adjusted outputted list, which appears in the same form as the input list with the newly calculated values, however, the plot doesn't seem right:

Final plot of filtered Z-axis data

I am not sure of the syntax of the chained functions, nor the choice of 1 as the period argument given to the function ToDiscreteTimeModel, since I think that should be 0.0078125 (1/128), but neither seem to plot the way I would expect with either 1 or 0.0078125 (1/128) in there.

I would have expected a smoothed curve of the raw data before applying the filter as shown here (column 2 is just the integer index of the sample. I used just column 5 when doing the last step):

Plot of raw data - column 2 and column 5

Edit: I should mention that this is with the accelerometer on a large rotating turntable at the periphery, and I was attempting to find any impulses in the Z-axis as it spun around. If you have sampled date, why do you need to 'sample' it again using ToDiscreteTimeModel, if I am correct in this assumption?

Any feedback on whether this is simply a plotting, syntax, or function use issue would be much appreciated. Thank you.

  • $\begingroup$ There might be something wrong with the parameters of filter, but the more serious problem is, the structure of data2 is improper. Please modify definition of data2 to data2 =data[[All, 5]] and try again. (Don't forget the compare the difference between new and old data2. ) $\endgroup$ – xzczd Aug 16 '18 at 6:42
  • $\begingroup$ Can you explain in words what you want to filter out and what do you want to display in Fig. $\endgroup$ – Alex Trounev Aug 16 '18 at 8:15
  • $\begingroup$ data2 is the selection of the 5th column of data (the acceleration in z-axis). The other columns are timestamp, tick (integer index), x-axis, y-axis. The way I have it Mathematica is returning the 5th column. I am trying to apply a single-pole Butterworth low-pass filter with a 5 Hz cut-off frequency. The sensor was sampling at 128 Hz. $\endgroup$ – Eggy Aug 16 '18 at 19:23
  • $\begingroup$ Alex, I am following a specification that requires that the sensor data I sampled at 128 Hz is then: "The acquired test data shall be post-processed, with a 4-pole, single pass, Butterworth low pass filter using a corner frequency (Fn) of 5 Hz.". My guess is that it is to smooth out the data, and not register impulses of less than 1/5 s? $\endgroup$ – Eggy Aug 16 '18 at 19:29

Your Answer

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

Browse other questions tagged or ask your own question.