Skip to main content

FourierSeries

Struct FourierSeries 

Source
pub struct FourierSeries;
Expand description

Discrete Fourier Transform and spectral utilities.

Provides Cooley-Tukey radix-2 FFT (in-place), IFFT, power spectrum estimation, and circular convolution via the convolution theorem.

Implementations§

Source§

impl FourierSeries

Source

pub fn fft(data: &[f64]) -> Vec<(f64, f64)>

Compute the FFT of data (length must be a power of 2).

Returns a vector of complex coefficients X[k] where X[k] = Σ x[n] * exp(-2πi kn/N).

Source

pub fn ifft(spectrum: &[(f64, f64)]) -> Vec<f64>

Compute the inverse FFT.

Input is a slice of (re, im) pairs; output is the real part of the inverse transform (discards imaginary part which should be ~0 for real signals).

Source

pub fn power_spectrum(data: &[f64]) -> Vec<f64>

Compute the one-sided power spectrum of data.

Returns |X[k]|^2 / N for k = 0, …, N/2.

Source

pub fn convolve(a: &[f64], b: &[f64]) -> Vec<f64>

Circular convolution of a and b via the convolution theorem.

Both inputs must have the same length (a power of 2). Returns the circular convolution a * b.

Source

pub fn frequencies(n: usize, fs: f64) -> Vec<f64>

Compute the DFT frequency bins for sample rate fs and n points.

Returns n/2 + 1 non-negative frequencies in Hz.

Source

pub fn eval_series(coeffs: &[(f64, f64)], x: f64) -> f64

Evaluate the truncated Fourier series at points x using n_terms terms.

Coefficients (a_k, b_k) are the cosine and sine amplitudes. Returns sum_{k=0}^{n_terms-1} a_k cos(k x) + b_k sin(k x).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.