Best practices "normalizing" sensor data into a min---max scale.

Hello,

I am harvesting load cell data with a frequency of 80 samples per second.
The raw data comes in a form of long values, starting at 8590300 +/-100 (zero load) and maxing out around 8850000 (with my current spring load configuration).

I am trying to map the data to a joystick axis in Windows and facing the following problems:

  1. My max-min delta is very insignificant compared to the integers I am reading: 250000 values on a scale of 9 million values is less than 3%.
  2. I don't need all 250000 values for my application. 4096 resolution steps (12bit) would be more than enough.

In my previous post there was a great suggestion to chop extra bits off the 24-bit sensor read data.

 dividedValue = Hx711.read() >> 12

This definitely helps with the issue #2, but it doesn't resolve the first problem where my delta will still be 3% of the absolute min-max.

What are the practices used to "narrow down" the absolute minimums and maximums so that my load is more significant on the data scale?

Thanks!

constrain to keep any overloads within range, then map to rescale.

int32_t loadCellMin = 8850000;
int32_t loadCellMax = 8590200;

auto loadCellValue = Hx711.read();
loadCellValue = constrain(loadCellValue, loadCellMin, loadCellMax);
int joystickValue = map( loadCellValue, loadCellMin, loadCellMax, 0, 4096);

Jiggy-Ninja:
constrain to keep any overloads within range, then map to rescale.

int32_t loadCellMin = 8850000;

int32_t loadCellMax = 8590200;

auto loadCellValue = Hx711.read();
loadCellValue = constrain(loadCellValue, loadCellMin, loadCellMax);
int joystickValue = map( loadCellValue, loadCellMin, loadCellMax, 0, 4096);

Thank you sir!

Looking at the last line of your snippet with the map() function - does that mean that I can remap to my new scale 0-4096 and no bit chopping is required (the line of code I included in OP)?

I just tested your suggestion and it worked like a charm. I answered my last question when testing the code. Thanks again!

Important note:

if the x is outside the range [a..b]

then map(x, a,b, c,d) will be outside the range [c..d] (linear interpolated)

you could do some print test if there's some change if you not shift bit or not. if all bit are zero, I think you can avoid it. but should always double check...

Regards.

Nitrof

nitrof:
Important note:

if the x is outside the range [a..b]

That is why I recommended constraining first.