Skip to main content

filter

Function filter 

Source
pub fn filter(x: &[C64], h: impl IntoIterator<Item = C64>) -> Vec<C64> ⓘ
Expand description

Filter a periodic block by its frequency response: IFFT(FFT(x) · H), H one value per DFT bin in the order of fftfreq (a circular convolution).

§Panics

If h does not yield one value per sample of x (the callers build it on the frequencies of x).

§Examples

use comnum_math::{C64, fft};
// a delay of one sample: H_k = e^{-j2πk/N}
let x = vec![C64::new(1.0, 0.0), C64::new(2.0, 0.0), C64::new(3.0, 0.0), C64::new(4.0, 0.0)];
let h = (0..4).map(|k| comnum_math::cis(-std::f64::consts::TAU * k as f64 / 4.0));
let y = fft::filter(&x, h);
assert!((y[1] - x[0]).norm() < 1e-12 && (y[0] - x[3]).norm() < 1e-12);