Doğrusal Filtreler

WPILib’in desteklediği ilk (ve en yaygın kullanılan) filtre türü, doğrusal bir filtre veya daha spesifik olarak, doğrusal zamanla değişmeyen-linear time-invariant (LTI) filtredir.

An LTI filter is, put simply, a weighted moving average - the value of the output stream at any given time is a localized, weighted average of the inputs near that time. The difference between different types of LTI filters is thus reducible to the difference in the choice of the weighting function (also known as a “window function” or an “impulse response”) used. The mathematical term for this operation is convolution.

impuls yanıtlarının iki geniş “sorts-türü” vardır: sonsuz dürtü yanıtları (IIR) ve sonlu dürtü yanıtları (FIR).

Sonsuz dürtü tepkilerinin sonsuz “desteği” vardır - yani, sonsuz büyüklükte bir bölgede sıfırdan farklıdırlar. Bu, genel olarak, sonsuz “hafızaya” sahip oldukları anlamına gelir - giriş akışında bir değer göründüğünde, sonraki tüm çıktıları sonsuza kadar etkileyecektir. Bu, katı bir sinyal işleme perspektifinden tipik olarak istenmeyen bir durumdur, ancak sonsuz dürtü yanıtlarına sahip filtrelerin, basit özyineleme ilişkileri ile ifade edilebildikleri için hesaplanması çok kolay olma eğilimindedir.

Sonlu dürtü yanıtlarının sonlu “desteği” vardır - yani, sınırlı bir bölgede sıfırdan farklıdırlar. “Arketipik” FIR filtresi düz hareketli bir ortalamadır - yani, basitçe çıktıyı son n girdinin ortalamasına eşit olarak ayarlamaktır. FIR filtreleri, IIR filtrelerinden daha çok istenen özelliklere sahip olma eğilimindedir, ancak hesaplamaları daha maliyetlidir.

Linear filters are supported in WPILib through the LinearFilter class (Java, C++, , Python).

LinearFilter - Doğrusal Filtre Oluşturma

Not

C ++ LinearFilter 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 *.

Özel bir filtre oluşturmak için `` LinearFilter ‘’ sınıfını doğrudan somutlaştırmak mümkün olsa da, bunun yerine sağlanan fabrika yöntemlerinden birini kullanmak çok daha uygundur (ve yaygındır):

singlePoleIIR - tek Kutuplu IIR

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

The singlePoleIIR() factory method creates a single-pole infinite impulse response filter which performs exponential smoothing. This is the “go-to,” “first-try” low-pass filter in most applications; it is computationally trivial and works in most cases.

// Creates a new Single-Pole IIR filter
// Time constant is 0.1 seconds
// Period is 0.02 seconds - this is the standard FRC main loop period
LinearFilter filter = LinearFilter.singlePoleIIR(0.1, 0.02);
// Creates a new Single-Pole IIR filter
// Time constant is 0.1 seconds
// Period is 0.02 seconds - this is the standard FRC main loop period
frc::LinearFilter<double> filter = frc::LinearFilter<double>::SinglePoleIIR(0.1_s, 0.02_s);
from wpimath.filter import LinearFilter

# Creates a new Single-Pole IIR filter
# Time constant is 0.1 seconds
# Period is 0.02 seconds - this is the standard FRC main loop period
filter = LinearFilter.singlePoleIIR(0.1, 0.02)

” time constant- zaman sabiti” parametresi, filtrenin dürtü yanıtının “karakteristik zaman ölçeğini” belirler; filtre, bundan önemli ölçüde daha kısa zaman ölçeklerinde meydana gelen sinyal dinamiklerini iptal edecektir. Benzer şekilde, aynı zamanda tanıtılan yaklaşık zaman ölçeğidir: ref: “faz gecikmesi <docs/software/advanced-controls/filters/introduction:Phase Lag>”. 2 pi ile çarpılan bu zaman ölçeğinin tersi, filtrenin “cutoff frequency-kesme frekansı” dır.

” period - dönem” parametresi, filtrenin ``calculate() `` yönteminin çağrılacağı dönemdir. Uygulamaların büyük çoğunluğu için bu, 0,02 saniyelik standart ana robot döngüsü süresi olacaktır. -

movingAverage - hareketliOrtalama

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

movingAverage fabrika yöntemi, basit bir düz hareketli ortalama filtre oluşturur. Bu, mümkün olan en basit düşük geçişli FIR filtresidir ve tek kutuplu IIR filtresiyle aynı bağlamların çoğunda kullanışlıdır. Hesaplamak biraz daha maliyetlidir, ancak genellikle biraz daha hoş bir şekilde davranır.

// Creates a new flat moving average filter
// Average will be taken over the last 5 samples
LinearFilter filter = LinearFilter.movingAverage(5);
// Creates a new flat moving average filter
// Average will be taken over the last 5 samples
frc::LinearFilter<double> filter = frc::LinearFilter<double>::MovingAverage(5);
from wpimath.filter import LinearFilter

# Creates a new flat moving average filter
# Average will be taken over the last 5 samples
filter = LinearFilter.movingAverage(5)

The “taps” parameter is the number of samples that will be included in the flat moving average. This behaves similarly to the “time constant” above - the effective time constant is the number of taps times the period at which calculate() is called.

highPass-yüksekGeçiş

A graph with two peaks except the highpass only shows the rate of change centered around 0.

highPass-yüksekGeçiş fabrika yöntemi, basit bir birinci dereceden sonsuz dürtü tepkisi yüksek geçiren filtre oluşturur. Bu, “singlePoleIIR” nin “karşılığıdır”.

// Creates a new high-pass IIR filter
// Time constant is 0.1 seconds
// Period is 0.02 seconds - this is the standard FRC main loop period
LinearFilter filter = LinearFilter.highPass(0.1, 0.02);
// Creates a new high-pass IIR filter
// Time constant is 0.1 seconds
// Period is 0.02 seconds - this is the standard FRC main loop period
frc::LinearFilter<double> filter = frc::LinearFilter<double>::HighPass(0.1_s, 0.02_s);
from wpimath.filter import LinearFilter

# Creates a new high-pass IIR filter
# Time constant is 0.1 seconds
# Period is 0.02 seconds - this is the standard FRC main loop period
filter = LinearFilter.highPass(0.1, 0.02)

“time constant-zaman sabiti” parametresi, filtrenin dürtü yanıtının “characteristic timescale-karakteristik zaman ölçeğini” belirler; filtre, bundan önemli ölçüde daha uzun zaman ölçeklerinde meydana gelen sinyal dinamiklerini iptal edecektir. Benzer şekilde, bu aynı zamanda tanıtılan yaklaşık zaman ölçeğidir: ref: “faz kurşun <docs/software/advanced-controls/filters/introduction:Phase lag>”. 2 pi ile çarpılan bu zaman ölçeğinin tersi, filtrenin ” cutoff frequency-kesme frekansı” dır.

” period - dönem” parametresi, filtrenin ``calculate() `` yönteminin çağrılacağı dönemdir. Uygulamaların büyük çoğunluğu için bu, 0,02 saniyelik standart ana robot döngüsü süresi olacaktır. -

LinearFilter kullanma

Not

Oluşturulan filtrenin belirtilen zaman ölçeği parametresine uyması için, `` calculate () ‘’ işlevinin * belirtilen sürede düzenli olarak çağrılması gerekir *. Herhangi bir nedenle `` hesapla () ‘’ çağrılarında önemli bir hata olması gerekiyorsa, filtrenin `` reset () ‘’ yöntemi daha fazla kullanılmadan önce çağrılmalıdır.

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)