ADXL345 Filter design

Hi everyone, I am trying to use ADXL345 and I want to measure steps. I found Analog Dialogue about it. It says, signal needs to be smoother so he used this.

So what I want to ask, For example, if I add 4 values ​​and then average them, is it a filter?

I'm reading code instructions for detect steps. It says,

INITIATE THE VALUES OF THE MAX AND MIN VALUES FOR COMPARING
MAKE THE MAXIMUM REGISTER MIN AND MINIMUM REGISTER MAX, SO THAT THEY CAN BE UPDATED AT THE NEXT CYCLE IMMEDIATELY

I don't understand this. Why should I make max to min and min to max ?
In the arduino forum, I found something like this

 if(sampling == 0)
  {
    maxave = ave;
    minave = ave;
  }

I don't understand how this work :smiley: How can i reflect this approach in code ?

the typical algorithm to find the min and max of a future flow of data is to initialise the min and max to out of range values so that they will be overridden when you get the first data in the flow. In order to make sure they are overriden, you need to pick a super low value for the max and a super high value for the min.

example:

int maxValue = -20000;   // impossible value as the range is 0 to 1024
int minValue = 20000;    // impossible value as the range is 0 to 1024

for (int i = 0; i < 100; i++) {
  int v = analogRead(A0); // will be between 0 and 1024
  if (v > maxValue) maxValue = v;
  if (v < minValue) minValue = v;
}

Serial.print("Min = ");  Serial.println(minValue);
Serial.print("Max = ");  Serial.println(maxValue);

if you are looking for the min and max in an array (not a flow of unknown value) usually you initialise the min and max with the first entry of the array and then let those evolve as you go through the array. that might be the second option you presented

jackson has presumably addressed your min/max issue

no. the diagram below is accurate and more general

"x" represents input samples and "y" output.
triangular boxes represents a multipliers.
boxes with "z" represent a delay.

the current input is multiplied by b0, the previous input by b1 and the sample before that by b2. they are all added together and are a component of the output, "y".

but the output, "y", is also feed back. the previous output is multiplied by -a1 and the one prior to that -a2 which are also added to the output, "y"

an FIR filter without the feedback elements is often used

ifir

thank you for your explanation.

Thank you for your explanation, so I need to determine delay and multiplied value for my application. After that, I have a filter for signal.

the delays are fixed. there's a known sampling frequency that affects the coefficient values

but the simplest low-pass filter is

avg += (samp - avg) * 1/N;

where N is like an RC time constant, if the samp is a step function (0 to 1), it will take ~3N samples for the avg to be ~ the value of samp

Thank you for your explanation. I am going to try to implement that. So last question, I shared this photo :

and you shared

an FIR filter without the feedback elements is often used

Does the filter meant to be described in the photo I shared mean the same as the filter you shared?


This is the author's code map. He used X_AXIS_RESULT= ()/4. So thats why I think to sum of the 4 value of X.

yes, he's just averaging the last four values. could shift each value thru some sort of pipe, sum all the values and average them, or use an array and replace the oldest value, sum and average.

i wouldn't describe this as a digital filter

do whatever you feel comfortable with.

Yep, nor would I. Just simple averaging which programmers commonly refer to as smoothing.

Averaging is not what I would call filtering, unless one just wants to call it time-differential averaging of the unbiased kind. Smoothing does "filter" spikes from the results, so in a crude way it is ceiling/floor filtering.

6 microcontroller digital filtering algorithms explained Embedded Technology Information EmbedIc

Yes, averaging is one form of a low pass filter, with uniform weights. Here is the frequency response of a "running average" filter.

Obviously, the description on that page is wrong, and the colors are in fact reversed:

Below is a plot of the magnitude of this function for L = 4 (red), 8 (green), and 16 (blue)

There are many other types of low pass filter.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.