1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use num::{traits::FloatConst, Float};
use option_trait::Maybe;

use crate::quantities::{IntoList, ListOrSingle};

pub trait Meyeraux<T, L, N>: IntoList<T, L, N>
where
    T: Float,
    L: ListOrSingle<T>,
    N: Maybe<usize>
{
    fn meyeraux(self, numtaps: N) -> (L::Mapped<T>, L);
}

impl<T, L, R, N> Meyeraux<T, L, N> for R
where
    T: Float + FloatConst,
    L: ListOrSingle<T>,
    R: IntoList<T, L, N>,
    N: Maybe<usize>
{
    fn meyeraux(self, n: N) -> (L::Mapped<T>, L)
    {
        let t = self.into_list(n);

        let y = t.map_to_owned(|&x| {
            let x4 = x*x*x*x;
            x4*(T::from(35u8).unwrap() + x*(-T::from(84u8).unwrap() + x*(T::from(70u8).unwrap() - x*T::from(20u8).unwrap())))
        });

        (y, t)
    }
}

#[cfg(test)]
mod test
{
    use array_math::ArrayOps;

    use crate::{plot, gen::wavelet::Meyeraux};

    #[test]
    fn test()
    {
        const N: usize = 1024;
        let (y, t): (_, [_; N]) = (0.0..=1.0).meyeraux(());

        plot::plot_curves("y(t)", "plots/y_t_meyeraux.png", [&t.zip(y)])
            .unwrap()
    }
}