packages

signal::fft::dct

Cosine and sine transforms of types II and III by one complex FFT of the same length (Makhoul 1980, "A fast cosine transform in one and two dimensions"): the even samples, then the odd ones reversed, then a quarter-sample twiddle. The sine transforms are cosine transforms of the sign-alternated or reversed signal. O(n log n), error about eps log2(n). Unscaled forms and Norm::Ortho match SciPy's dct / dst.

Functions

dctSource

pub fn dct(x: some RealSamples, kind: u8 = 2, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<f64>

The discrete cosine transform of kind 2 (the default, "the DCT") or 3 (its inverse up to scale). Unscaled (Norm::Backward): DCT-II y_k = 2 sum_n x_n cos(pi k (2n + 1) / 2N), DCT-III y_k = x_0 + 2 sum_(n>=1) x_n cos(pi n (2k + 1) / 2N); Norm::Ortho makes both orthonormal. As SciPy's dct.

nabi
use signal::fft::{dct, Norm};
use core::array::Vector;

let x: Vector<f64> = [1, 1, 1, 1];
println(try dct(x)); // [8.0, 0.0, 0.0, 0.0] (to rounding)
println(try dct(x, norm: Norm::Ortho)); // [2.0, 0.0, 0.0, 0.0]

idctSource

pub fn idct(x: some RealSamples, kind: u8 = 2, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<f64>

The inverse of dct with the same kind and norm: idct(dct(x)) is x.

nabi
use signal::fft::{dct, idct};
use core::array::Vector;

let x: Vector<f64> = [4, 3, 5, 10];
println(try idct(try dct(x))); // [4.0, 3.0, 5.0, 10.0] (to rounding)

dstSource

pub fn dst(x: some RealSamples, kind: u8 = 2, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<f64>

The discrete sine transform of kind 2 or 3. Unscaled DST-II: y_k = 2 sum_n x_n sin(pi (k + 1) (2n + 1) / 2N). As SciPy's dst.

nabi
use signal::fft::dst;
use core::array::Vector;

let x: Vector<f64> = [1, 0];
println(try dst(x)); // [1.414.., 2.0]

idstSource

pub fn idst(x: some RealSamples, kind: u8 = 2, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<f64>

The inverse of dst with the same kind and norm.

nabi
use signal::fft::{dst, idst};
use core::array::Vector;

let x: Vector<f64> = [1, 2, 3];
println(try idst(try dst(x))); // [1.0, 2.0, 3.0] (to rounding)