Skip to main content

RealFft

Struct RealFft 

Source
pub struct RealFft { /* private fields */ }
Expand description

A planned FFT for real input of length n. The spectrum of a real signal is conjugate symmetric, so only the n/2 + 1 non-negative-frequency bins are returned.

For even n the signal is packed into a complex sequence of half the length (even samples as real parts, odd samples as imaginary parts), transformed, and untangled with one twiddle per bin. For n of a few thousand or more this takes a quarter to a third less time than a complex FFT of the real data; for n up to about a thousand the O(n) packing and untangling cost as much as the shorter FFT saves (and more for very short signals). Odd lengths use a full complex transform. The forward transform is unscaled; RealFft::inverse divides by n, so it exactly inverts RealFft::forward.

Implementations§

Source§

impl RealFft

Source

pub fn new(n: usize) -> Result<Self, ErrorsJSL>

Source

pub fn len(&self) -> usize

The signal length.

Source

pub fn is_empty(&self) -> bool

Source

pub fn spectrum_len(&self) -> usize

The number of spectrum bins, n/2 + 1.

Source

pub fn forward(&mut self, x: &[f64]) -> Result<Vec<Complex<f64>>, ErrorsJSL>

The bins X_0 ..= X_{n/2} of the unscaled DFT X_k = Σ x_m e^{-2πi km/n}.

Source

pub fn inverse( &mut self, spectrum: &[Complex<f64>], ) -> Result<Vec<f64>, ErrorsJSL>

The real signal whose spectrum bins are spectrum (n/2 + 1 values; the imaginary parts of X_0, and of X_{n/2} for even n, are ignored as they must vanish).

Trait Implementations§

Source§

impl Debug for RealFft

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.