FILTERING and AVERAGE

Hey guys…Hopefully you can help me this one I just need to filter and averaging my data of my Drag and Lift force ,maybe due to some noises and vibrations in my project which is wind tunnel.

Example of the data that i gather!!!
(Only the Dragforce)

5
4
6
10
15
8
20
13
3
4
9
11
15
20
5
1
3
7
13

all i need is to filter the number between 3-8
…and averaging them by atleast 10number…

Here is my code…

#include “HX711.h”

// HX711 circuit wiring
const int DF_DOUT = 2; // DOUT for drag
const int DF_SCK = 4; // SCK for Drag

const int LF_DOUT = 11; // DOUT for Lift
const int LF_SCK = 12; // SCK for Lift

//HX711 constructor:
HX711 DFORCE;
HX711 LFORCE;

void setup() {
Serial.begin(38400);
Serial.println();
Serial.println(“Starting Set Up…”);
DFORCE.begin(DF_DOUT, DF_SCK);
DFORCE.set_scale();
DFORCE.tare();

LFORCE.begin(LF_DOUT, LF_SCK);
LFORCE.set_scale();
LFORCE.tare();

}

void loop() {
long DragOrigRead = DFORCE.read ();
long Drag2ndRead;
long Drag1stRead;

long LiftOrigRead = LFORCE.read ();
long Lift2ndRead;
long Lift1stRead;

Serial.println();
Serial.println();
Serial.println(“Start The Fan And Set A Desired Velocity”);

Drag1stRead = (-000.524* LiftOrigRead) -127008.2+14000;

Lift1stRead = (-000.525* DragOrigRead) +37008.2+52000;

Serial.print(“Drag Force Reading Is:”);
Serial.print(Drag1stRead);

Serial.println();
Serial.print(“Lift Force Reading Is:”);
Serial.print(Lift1stRead);

delay(10000);

}

Really appreciated your help guys…Thank you❤️

That code shows no filtering and no averaging. What have you tried? Please post your best effort. A typical way to average something is to declare an array of the average size so you can store the values. When a new value arrives, toss the oldest and insert the newest and calculate the average. You can also keep a running total to speed things up. Google will give you lots and lots of hits…

What’s all that stuff trying to do? Drag is now a function of lift? Lift is now a function of Drag?

-jim lee

try adopt this

    matrix.Clear();
    for (byte c = '0'; c <= '9'; c++) {
        matrix.ShowChar5x7(c, 2, -1, 0, 128, 255);
        matrix.Draw();
        delay(250);
    }
for ( Lift1stRead c ='3'; c <= '8'; c++)

by the way its for the calibration sir

ill try this one sir…thank you soo much❤️

i did try this one sir…but it gives me a false data … maybe there’s something wrong with my code.

#include "HX711.h"

// Declare functions
enum MeasurementType {drag, lift};
long takeMeasurement(MeasurementType type);
long getAverage(MeasurementType type, int N_Measurement);

// HX711 circuit wiring
const int DF_DOUT = 2; // DOUT for drag
const int DF_SCK = 4; // SCK for Drag

const int LF_DOUT = 11; // DOUT for Lift
const int LF_SCK = 12; // SCK for Lift

//HX711 constructor:
HX711 DFORCE;
HX711 LFORCE;

void setup() {
  Serial.begin(38400);
  Serial.println();
  Serial.println("Starting Set Up…");
  DFORCE.begin(DF_DOUT, DF_SCK);
  DFORCE.set_scale();
  DFORCE.tare();

  LFORCE.begin(LF_DOUT, LF_SCK);
  LFORCE.set_scale();
  LFORCE.tare();

}

void loop() {
  long DragRead = getAverage(DFORCE, drag, 5);  // Get the drag average of 5 measurements
  long LiftRead = getAverage(LFORCE, lift, 5);  // Get the lift average of 5 measurements

  Serial.print("Drag Force Reading Is:");
  Serial.print(DragRead);

  Serial.println();
  Serial.print("Lift Force Reading Is:");
  Serial.print(LiftRead);

  // THE CODE YOU WANT HERE

  delay(10000);
}

long takeMeasurement(HX711 FORCE, MeasurementType type) {
  long measurement = 0;
  switch (type) {
    case drag:
      measurement = (-000.524 * FORCE.read ()) - 127008.2 + 14000;
      break;
    case lift:
      measurement = (-000.525 * FORCE.read ()) + 37008.2 + 52000;
      break;
  }
  return measurement;
}

long getAverage(HX711 FORCE, MeasurementType type, int N_Measurements) {
  long average = 0;
  for (int i = 0; i < N_Measurements; i++) {
    average += takeMeasurement(FORCE, type) / N_Measurements;
  }
  return average;
}

You can not pass around HX711 objects to other functions. That just makes a copy. You need to pass a reference to your already created objects.

long takeMeasurement(HX711 &FORCE, MeasurementType type) {
  long measurement = 0;
  switch (type) {
    case drag:
      measurement = (-000.524 * FORCE.read ()) - 127008.2 + 14000;
      break;
    case lift:
      measurement = (-000.525 * FORCE.read ()) + 37008.2 + 52000;
      break;
  }
  return measurement;
}

long getAverage(HX711 &FORCE, MeasurementType type, int N_Measurements) {
  long average = 0;
  for (int i = 0; i < N_Measurements; i++) {
    average += takeMeasurement(FORCE, type) / N_Measurements;
  }
  return average;
}

Notice the ‘&’ in front of FORCE. Google will explain it all…