diff --git a/content/tutorials/EdwardBurnsPhotos/check_setup b/content/tutorials/EdwardBurnsPhotos/check_setup new file mode 100644 index 00000000..0f2a64ef Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/check_setup differ diff --git a/content/tutorials/EdwardBurnsPhotos/components.png b/content/tutorials/EdwardBurnsPhotos/components.png new file mode 100644 index 00000000..c88db2c1 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/components.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/fill.png b/content/tutorials/EdwardBurnsPhotos/fill.png new file mode 100644 index 00000000..cab241bf Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/fill.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/fitness.png b/content/tutorials/EdwardBurnsPhotos/fitness.png new file mode 100644 index 00000000..c6168db6 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/fitness.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/image.jpg b/content/tutorials/EdwardBurnsPhotos/image.jpg new file mode 100644 index 00000000..71f1d0a8 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/image.jpg differ diff --git a/content/tutorials/EdwardBurnsPhotos/img.png b/content/tutorials/EdwardBurnsPhotos/img.png new file mode 100644 index 00000000..4049cb28 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/img.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/movement.png b/content/tutorials/EdwardBurnsPhotos/movement.png new file mode 100644 index 00000000..9d8fbd08 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/movement.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/moving_average_fitler.svg b/content/tutorials/EdwardBurnsPhotos/moving_average_fitler.svg new file mode 100644 index 00000000..7734bbcf --- /dev/null +++ b/content/tutorials/EdwardBurnsPhotos/moving_average_fitler.svg @@ -0,0 +1,866 @@ + + + Lissage d'un sinus bruité par la méthode de la moyenne glissante + + + + image/svg+xml + + Lissage d'un sinus bruité par la méthode de la moyenne glissante + 2014-03-26 + + + Christophe Dang Ngoc Chan + + + + + moving average smoothing + noisy sine + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 2 + + + 4 + + + 6 + + + 1 + + + 3 + + + 5 + + + 7 + + + 0.5 + + + 1.5 + + + 2.5 + + + 3.5 + + + 4.5 + + + 5.5 + + + 6.5 + + + + + + + + + + + + + + + + + + + 0 + + + -1 + + + 1 + + + -1.4 + + + -1.2 + + + -0.8 + + + -0.6 + + + -0.4 + + + -0.2 + + + 0.2 + + + 0.4 + + + 0.6 + + + 0.8 + + + 1.2 + + + 1.4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/content/tutorials/EdwardBurnsPhotos/readData.png b/content/tutorials/EdwardBurnsPhotos/readData.png new file mode 100644 index 00000000..541032b1 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/readData.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/setup.png b/content/tutorials/EdwardBurnsPhotos/setup.png new file mode 100644 index 00000000..643b7b3e Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/setup.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/sma.png b/content/tutorials/EdwardBurnsPhotos/sma.png new file mode 100644 index 00000000..b9fdcd21 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/sma.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/subroutine.png b/content/tutorials/EdwardBurnsPhotos/subroutine.png new file mode 100644 index 00000000..6eb9e544 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/subroutine.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/winow.png b/content/tutorials/EdwardBurnsPhotos/winow.png new file mode 100644 index 00000000..942cd126 Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/winow.png differ diff --git a/content/tutorials/EdwardBurnsPhotos/wired.jpg b/content/tutorials/EdwardBurnsPhotos/wired.jpg new file mode 100644 index 00000000..d3ab77bc Binary files /dev/null and b/content/tutorials/EdwardBurnsPhotos/wired.jpg differ diff --git a/content/tutorials/EdwardBurnsTutorial.md b/content/tutorials/EdwardBurnsTutorial.md new file mode 100644 index 00000000..e66758ec --- /dev/null +++ b/content/tutorials/EdwardBurnsTutorial.md @@ -0,0 +1,109 @@ +--- +title: Smoothing Average Accelerometer Tutorial +date: 2025-06-08 +authors: + - name: Edward Burns +--- + +# Smoothing Average Accelerometer Tutorial + +## Introduction + +Ever used an accelerometer, but the data was super **_jittery_**? Well you're in the right place. +In this tutorial, you'll learn how to hook up your accelerometer and implement a moving average filter to smooth out your data! +### Learning Objectives + +- Learn how accelerometers work +- Learn about filtering techniques +- Learn how to extract meaningful signal from a moving average filter + + +### Background Information + +The problem is that these accelerometer readings are often very noisy, especially for cheap parts that students like us have access to. The read values from each access will "jitter" significantly, even when not being moved. This presents a particular challenge when trying to extract weak signals from a relatively high noise floor, or when your other algorithms and data flows are sensitive to jitter. + +One of the best ways to reduce noise and make your accelerometer curves smoother for analysis (like step detection) is to employ a moving average filter. There's lots of different types of smoothing filters to choose from, but a good place to start is with the easiest, the Simple Moving Average Filter (SMA). + +![relevant graphic or workshop logo](EdwardBurnsPhotos/sma.png) + +![relevant graphic or workshop logo](EdwardBurnsPhotos/moving_average_fitler.svg) + +## Getting Started + +First, hook up your 3-axis accelerometer to your devboard. The ADXL335 is great for those new to the world of embedded systems being all three axes have their own dedicated analog pin, so you don't have to interface with anything more complicated (like I2C or SPI). In this case, the bottom two pins are VCC and GND, and the middle three are X, Y, and Z. Leave the top pin floating + +![relevant graphic or workshop logo](EdwardBurnsPhotos/wired.jpg) + +Moving to Arduino, declare your analog pins. + +![img.png](EdwardBurnsPhotos/img.png) + +Then define your moving average window. This window keeps track of the number of samples you are averaging over at a time. There's no perfect number for how big your moving average window should be, and it's something that you can experimentally tune for results. However, a couple factors that you should keep in mind are Sampling Rate in Hz, and how much of a delayed response you want your filter to have + +### Defining your window +![img.png](EdwardBurnsPhotos/winow.png) + +The above window takes 1000 samples, which, at a sampling rate of 100 Hz, is 10 seconds of movement to average over (which is probably very overkill for your application, but is an example of what's possible) + +### Reading data and filling your window + +![img.png](EdwardBurnsPhotos/readData.png) + +Since accelerometer data is 3 axis, you often want to reduce these three values into a single dimension. There's plenty of different tecniquest to accomplish this, each with their benefits and drawbacks, but the simplest technique is to just sum all three values into a single variable + +![img.png](EdwardBurnsPhotos/fill.png) + +Here we actually fill the moving average window with the sum. We also have to increment the move window index, using the modulo operator to make sure we don't go out of the window's bounds. + +### Computing the Rolling Average +![img.png](EdwardBurnsPhotos/subroutine.png) + +Here we've written a little subroutine to compute the rolling average (aka the SMA). Basically it takes a pointer to the window, and the window size (n), and computes the unweighted average along every element. Note: there are much more efficient routines for doing this, but this one is the most conceptually simple + +### Ok now what do we do with this? +One of the easiest applications of our new and glorious rolling average filter is movement detection! + +### Movement Detection +![img.png](EdwardBurnsPhotos/movement.png) + +Again, there are plenty of more adavanced movement detection techniques, but a simple start is thresholding! Basically, you define a hard coded value (which you determine experimentally) and if the current accelerometer summed reading exceeds this value + the rolling average, you say that this is detected movement. This actually works quite well with the rolling average, because it eliminates random jitter and establishes a steadier value to work off of + +### What about setup? +Excellent point, what do we do while the Moving Average Window isn't filled yet? This is the calibration step, that comes as a part of many sensor workflows. We too have to handle this case: +![img.png](EdwardBurnsPhotos/setup.png) + +We define a variable the size of our rolling average window, that will be decremented during the setup. When it hits zero, we know our window is full. +Until then, we won't want to check for movement. + +![img_1.png](EdwardBurnsPhotos/check_setup) + + + +### Required Downloads and Installations +- Arduino IDE + +### Required Components + +![img.png](EdwardBurnsPhotos/components.png) +List your required hardware components and the quantities here. + +| Component Name | Quanitity | +|-----------------|-----------| +| ADXL335 | 1 | +| Male-Male Wires | 5 | +| Esp32 Devboard | 1 | +| BreadBoard | 1 | + + + +### Example and Inspiration + +Fitness Tamagotchi! Our project team used a modified version of the above rolling average algorithm to count steps and make a fitness pet that gets stronger as you get active +![img.png](EdwardBurnsPhotos/fitness.png) + +## Additional Resources + +### Useful links + +List any sources you used, documentation, helpful examples, similar projects etc. +https://en.wikipedia.org/wiki/Moving_average