Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Confluence
For you

Electrical Engineering
Results will update as you type.
  • Aesthetic elements in Eagle
  • Actuators and Outputs
  • Aktuatoren (DE)
  • Analog Input
  • Analog Sensors
  • Arduino Grundlagen
  • Arduino Programmieren
  • Arduino und Processing
  • Shift Registers
  • Carvey
  • Capacitors
  • Bread Boards
  • Digitaler Input
  • Digitaler Output
  • Eagle
  • Energy Harvesting
  • H-Bridge
  • I2C (en)
  • Interrupt Service Routine
  • Mosfet Transistor
  • LED
  • PCBs Herstellen
  • Pololu Servo Controller
  • Relays as Switches
  • Pulse Width Modulation
  • RFiD
  • Schrittmotorentreiber
  • SD Karten
  • Signal Filtering
  • Transistors as Switches
  • Widerstand
  • PCB Manufacturing
  • PlatformIO
  • Lynx Smart Motion Servo
  • Electronics Basics (EN)
  • Arduino Basics (en)
  • Arduino Programming (EN)
  • Digital Outputs (en)
  • Digital Input (en)
  • Serial Communication (en)
  • Pulse Width Modulation (en)
  • Resistors (en)
  • Arduino and P5.js
  • Arduino and ml5.js
  • Project box 2021
  • Servo Motors
  • H-Bridge (DE)
  • Networking
  • Bit Shifting
  • C++ (Arduino) Variables
  • Stepper Motor Drivers
  • Interrupt Service Routine (en)
  • Common Arduino Problems
  • Finite State Machine
  • Voltage Regulators
  • Arduino USB HID (Human Interface Devices)

/
Signal Filtering

Signal Filtering

Sep 08, 2022

Values from some sensors may be jumpy or erratic. Generally, it's best to first try to solve the problem on the hardware side (is there a floating pin, or bad contact?). If that fails, we can use some code to clean up the values by calculating the running average. Alternatively, we can use the Weighted Moving Average, with more weight on new data and less on older data. This has the advantage of being very lightweight to implement on the Arduino, although we lose some response speed and we don't get a true average. We can easily adjust the ratio of the weighting depending on the amount of noise. 

The blue line indicates the original value, and red is the smoothed value. 

Smoothing
/*
  Weighted Moving Point Average  
  Luke Franzke 
  ZHdK
  2019
*/
#define analogInPin A0  // our sensor input pin 
int weightedAverage = 0; // where we we stored our average values
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
 // read the analog in value:
  int sensorValue = analogRead(analogInPin);
// calculate the weighted moving point average 
// our scaling factor should add up to 1, but this ratio can be adjusted depending on the amount of noise 
  weightedAverage = weightedAverage*0.7;
  weightedAverage += sensorValue*0.3;
  // print both results to the Serial Monitor:
  Serial.print("sensor: ");
  Serial.print(sensorValue);
  Serial.print(",");
  Serial.println(weightedAverage);
  delay(1);  // delay in between reads for stability
}
, multiple selections available,
{"serverDuration": 15, "requestCorrelationId": "0612300b6f19400ea52f3e4491e51e28"}