ROS2 Sensor Noise Filtering: Moving Average

Easy Signal Processing 0% pass rate

Practice the ROS2 Sensor Noise Filtering: Moving Average coding problem in Signal Processing. Browser-based execution with automated grading — no local ROS install required. 0% of engineers pass this challenge.

Problem Statement

Implement moving_average(data, N) — a sliding window average filter.

Function Signature

def moving_average(data: list[float], N: int) -> list[float]:

Requirements

  • For each index i in data, compute the average of the last N values ending at index i
  • For indices i < N-1 (before a full window is available), average only the values from index 0 to i (inclusive)
  • Return a list of the same length as data
  • Handle edge cases: empty list returns [], N=1 returns a copy of data

Example

data = [1.0, 3.0, 5.0, 7.0, 9.0], N = 3

i window average
0 [1.0] 1.0
1 [1.0, 3.0] 2.0
2 [1.0, 3.0, 5.0] 3.0
3 [3.0, 5.0, 7.0] 5.0
4 [5.0, 7.0, 9.0] 7.0

Result: [1.0, 2.0, 3.0, 5.0, 7.0]

🤖 Why This Matters in Real Robots

This is the exact filter used in RPLIDAR drivers for range smoothing, in IMU preprocessing for accelerometer denoising, and in battery monitoring for SoC estimation. The window size N controls the trade-off: larger N = smoother signal but more lag. Real applications choose N based on sensor frequency and acceptable latency.

Frequently asked questions

What is the ROS2 Sensor Noise Filtering: Moving Average practice problem?

It is a hands-on Signal Processing challenge on SimuCode where you implement and run ROS2 code in the browser with runtime-verified tests.

How do I practice ROS2 Sensor Noise Filtering: Moving Average online?

Open this page, sign in, and solve the problem in the built-in IDE. Your solution is graded against real ROS2 execution checks.

What skills does ROS2 Sensor Noise Filtering: Moving Average test?

This Easy problem focuses on Signal Processing skills used in robotics interviews and production systems.