pub struct SuperSmoother { /* private fields */ }Expand description
Ehlers’ 2-pole Butterworth-style “SuperSmoother” lowpass filter.
From John Ehlers’ Cycle Analytics for Traders (2013, ch. 3). For a given
critical period period, the filter coefficients are:
a1 = exp(-sqrt(2) * pi / period)
b1 = 2 * a1 * cos(sqrt(2) * pi / period)
c2 = b1
c3 = -a1 * a1
c1 = 1 - c2 - c3
y[t] = c1 * (x[t] + x[t-1]) / 2 + c2 * y[t-1] + c3 * y[t-2]The implementation needs two prior inputs and two prior outputs to begin running; until then it returns the input itself (a common Ehlers initial condition), which lets downstream filters warm up without long delays.
§Example
use wickra_core::{Indicator, SuperSmoother};
let mut ss = SuperSmoother::new(10).unwrap();
let mut last = None;
for i in 0..40 {
last = ss.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl SuperSmoother
impl SuperSmoother
Trait Implementations§
Source§impl Clone for SuperSmoother
impl Clone for SuperSmoother
Source§fn clone(&self) -> SuperSmoother
fn clone(&self) -> SuperSmoother
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SuperSmoother
impl Debug for SuperSmoother
Source§impl Indicator for SuperSmoother
impl Indicator for SuperSmoother
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for SuperSmoother
impl RefUnwindSafe for SuperSmoother
impl Send for SuperSmoother
impl Sync for SuperSmoother
impl Unpin for SuperSmoother
impl UnsafeUnpin for SuperSmoother
impl UnwindSafe for SuperSmoother
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
Run the indicator over a slice of inputs in order, returning one output (or
None during warmup) per input.Source§impl<T> BatchNanExt for T
impl<T> BatchNanExt for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more