Skip to main content

fourier_row

Function fourier_row 

Source
pub fn fourier_row(
    period: f64,
    k: usize,
    t: u64,
    row: &mut [f64],
) -> Result<(), FourierError>
Expand description

Writes the Fourier regressors of k harmonics at period for time t into row.

row gets sin(2 pi i t / period), cos(2 pi i t / period) for i = 1, ..., k, without the Nyquist sine (see fourier_columns). t is the sample index; R’s fourier() starts at t = 1, statsmodels’ Fourier at t = 0. The function needs no heap, so a device can build the regressor row of each new value as it arrives.

§Errors

§Examples

use backshift::fourier_row;

// A weekly pattern on daily data with two harmonics.
let mut row = [0.0; 4];
fourier_row(7.0, 2, 3, &mut row).unwrap();
let angle = core::f64::consts::TAU * 3.0 / 7.0;
assert!((row[0] - angle.sin()).abs() < 1e-15);
assert!((row[3] - (2.0 * angle).cos()).abs() < 1e-15);