Coors Light & Fourier Transforms

I wanted to use the same methodology from a previous post (Coffee Run) to analyze a new set of data,  so I took a  different route  around the block to buy a six pack of Coors Light at the corner store. I also wanted to test out my iPhone 5s’ M7 motion co-processor, so I kept my phone in my left pant’s pocket and used the Argus app to note the number of steps (any app should give the same results, since it’s just calling an API from the M7).  I used the correlationwindower.m script from an earlier post on the raw data (beerrundata), and generated the following result using the first block of steps just before t=100 as the sample data:

Plot of the Correlation of a Sample Signal (91<t<97) With the Dataset (blue) ontop of the Raw Data (Green)

Immediately, you can tell something is wrong because from 260 < t < 310 on the X axis, when I am clearly standing in line not moving, the correlation is really high. This led me to think about micro-oscillations that might be showing up in the noise during periods of non-motion, so I wanted to look at the data in frequency rather than time. I built a simple script to perform a discrete Fourier transform on the data using the fft command in Matlab (quickdft.m), and produced the following plot:

Fourier Transform of the Data from Each Axis

I was pretty excited by this data. First, the data from the three axes are all very consistent with each other, which gave me a lot of confidence that I can ultimately build an algorithm that can extract motion from any axis (versus just the X axis, currently). Secondly, I thought it was very interesting that the peaks for the Y and Z axis were greatest around 1 Hz, while the X axis peak was greatest at around 2 Hz. I timed my gate, and found that each step takes about a half second, so what must be going on is that the X axis is oscillating with each step, while the Y and Z axes are oscillating with each stepping cycle (i.e. both the left and right foot). This makes sense, given that my hand was positioned as follows:

Logger Positioning During Normal Walking Motion

So, you get an acceleration in the X axis with every step as you bob up and down while walking, you probably get some lurching back and forth in the Y axis which occurs with each step pair, and in the Z axis you sway side to side a bit with each step pair since no two legs are exactly the same length. It is also interesting to note the 2Hz frequency component of the Y axis signal, which is probably capturing some of that same individual step motion as the X axis because some part of my the raising and lowering with each step is actually occurring in the Y axis. At the same time, the absence of any 2Hz signal in the Z axis is very comforting as it reinforces the idea that the Z axis is experiencing a side to side sway.

I thought that perhaps creating a band pass filter might solve the problem of the phantom correlation data during periods of no motion; perhaps there was a high frequency noise signal with lower frequency elements that were seeping into the data. So, I created the following filter in Matlab’s filter design tool, which was launched with the fdatool command.

A Simple Bandpass Filter

I used the bandpass filter on the X axis raw data, and produced the plot below:

X Axis Data After Bandpass Filtering

Running a simple peak detection on this data  ([x_pks, x_locs] = findpeaks(xf,’MINPEAKHEIGHT’,.1,’MINPEAKDISTANCE’,10);) counted 549 steps, which is pretty close to the 539 recorded by my Fitbit Flex and the 536 recorded by the iPhone 5s. I then changed the parameters of the filter to focus even more tightly on the 2Hz frequency with the following settings (fstop 1.5, fpass1 = 1.8, fpass2 = 2.2, fstop2 = 2.5), and counted only 507 steps, which led me to believe that the previous answer was mostly just lucky, although it is possible that tightening the filter might have excluded steps which occurred at a slower pace. Overall, I was a little disappointed with this experiment in frequency, but I learned a lot which can hopefully be applied to future experiments.