Median Filtresi

A graph with two peaks with the input closely following the target signal.

A statistically robust alternative to the moving-average filter is the median filter. Where a moving average filter takes the arithmetic mean of the input over a moving sample window, a median filter (per the name) takes a median instead.

Median filtresi, bir giriş akışından ara sıra aykırı değerleri kaldırmak için çok kullanışlıdır. Bu, ara sıra parazitlere eğilimli olan mesafe sensörlerinden gelen girdileri filtrelemek için özellikle uygun hale getirir. Hareketli bir ortalamanın aksine; median filtresi, ne kadar aşırı olursa olsun, az sayıdaki aykırı değerlerden tamamen etkilenmeyecektir.

The median filter is supported in WPILib through the MedianFilter class (Java, C++, , Python).

MedianFilter Oluşturma

Not

C++ MedianFilter sınıfı, girdi için kullanılan veri türüne göre şablonlanır.

Not

Filtrelerin “belleği” olduğundan, her giriş akışı kendi filtre nesnesini gerektirir. Birden çok giriş akışı için aynı filtre nesnesini kullanmaya çalışmayın.

Bir MedianFilter oluşturmak basittir:

// Creates a MedianFilter with a window size of 5 samples
MedianFilter filter = new MedianFilter(5);
// Creates a MedianFilter with a window size of 5 samples
frc::MedianFilter<double> filter(5);
from wpimath.filter import MedianFilter

# Creates a MedianFilter with a window size of 5 samples
filter = MedianFilter(5)

MedianFilter kullanma

Filtreniz oluşturulduktan sonra kullanımı kolaydır - filtrelenmiş çıktıyı elde etmek için en son girdiyle calculate() yöntemini çağırmanız yeterlidir:

// Calculates the next value of the output
filter.calculate(input);
// Calculates the next value of the output
filter.Calculate(input);
# Calculates the next value of the output
filter.calculate(input)