pub struct R2rSolver<T: Float> { /* private fields */ }Expand description
Real-to-Real transform solver.
Implementations§
Source§impl<T: Float> R2rSolver<T>
impl<T: Float> R2rSolver<T>
Sourcepub fn applicable(&self, n: usize) -> bool
pub fn applicable(&self, n: usize) -> bool
Check if this solver is applicable for the given size.
Sourcepub fn execute_dct2_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dct2_direct(&self, input: &[T], output: &mut [T])
Execute DCT-II (REDFT10) using direct O(n²) computation.
Formula: X[k] = sum_{n=0}^{N-1} x[n] * cos(π * (2n + 1) * k / (2N))
Sourcepub fn execute_dct2_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dct2_fast(&self, input: &[T], output: &mut [T])
Execute DCT-II using FFT-based O(n log n) algorithm.
Algorithm (2N-point FFT, even reflection): v[i] = x[i] for i = 0..N-1 v[i] = x[2N-1-i] for i = N..2N-1 Y = FFT_{2N}(v) DCT_II[k] = (c_k * Y[k].re - s_k * Y[k].im) / 2 where c_k = cos(-πk/(2N)), s_k = sin(-πk/(2N))
Sourcepub fn execute_dct2(&self, input: &[T], output: &mut [T])
pub fn execute_dct2(&self, input: &[T], output: &mut [T])
Execute DCT-II transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dct3_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dct3_direct(&self, input: &[T], output: &mut [T])
Execute DCT-III (REDFT01) using direct O(n²) computation.
Formula: x[n] = X[0]/2 + sum_{k=1}^{N-1} X[k] * cos(π * k * (2n + 1) / (2N))
Sourcepub fn execute_dct3_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dct3_fast(&self, input: &[T], output: &mut [T])
Execute DCT-III using FFT-based O(n log n) algorithm.
DCT-III is the transpose/inverse of DCT-II. We use the conj-FFT-conj trick: IFFT_{2N}(Z) = conj(FFT_{2N}(conj(Z))) / (2N)
Build Z of length 2N: Z[0] = 2X[0], Z[N] = 0 Z[k] = 2X[k]exp(iπ*k/(2N)) for k = 1..N-1 Z[2N-k] = conj(Z[k]) for k = 1..N-1
Then DCT_III[n] = Re(IFFT_{2N}(Z)[n]) = Re(conj(FFT_{2N}(conj(Z)))[n]) / (2N)
Sourcepub fn execute_dct3(&self, input: &[T], output: &mut [T])
pub fn execute_dct3(&self, input: &[T], output: &mut [T])
Execute DCT-III transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dct1_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dct1_direct(&self, input: &[T], output: &mut [T])
Execute DCT-I (REDFT00) using direct O(n²) computation.
Formula: X[k] = x[0] + (-1)^k * x[N-1] + 2 * sum_{n=1}^{N-2} x[n] * cos(π * n * k / (N-1))
Sourcepub fn execute_dct1_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dct1_fast(&self, input: &[T], output: &mut [T])
Execute DCT-I using FFT-based O(n log n) algorithm.
Even extension of length 2(N-1): v[i] = x[i] for i = 0..N-1 v[i] = x[2(N-1)-i] for i = N..2(N-1)-1
DCT_I[k] = Re(FFT_{2(N-1)}(v))[k]
Sourcepub fn execute_dct1(&self, input: &[T], output: &mut [T])
pub fn execute_dct1(&self, input: &[T], output: &mut [T])
Execute DCT-I transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dct4_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dct4_direct(&self, input: &[T], output: &mut [T])
Execute DCT-IV (REDFT11) using direct O(n²) computation.
Formula: X[k] = sum_{n=0}^{N-1} x[n] * cos(π * (2n + 1) * (2k + 1) / (4N))
Sourcepub fn execute_dct4_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dct4_fast(&self, input: &[T], output: &mut [T])
Execute DCT-IV using FFT-based O(n log n) algorithm.
Algorithm using 4N-point FFT: Pad x to length 4N (zeros for indices N..4N-1) Y = FFT_{4N}(x_padded) DCT_IV[k] = Re(exp(-iπ(2k+1)/(4N)) * Y[2k+1])
Derivation: DCT_IV[k] = Re(sum_n x[n]exp(iπ*(2n+1)(2k+1)/(4N))) = Re(exp(-iπ*(2k+1)/(4N)) * sum_n x[n]exp(-2πin*(2k+1)/(4N))) = Re(exp(-iπ(2k+1)/(4N)) * FFT_{4N}(x_padded)[2k+1])
Sourcepub fn execute_dct4(&self, input: &[T], output: &mut [T])
pub fn execute_dct4(&self, input: &[T], output: &mut [T])
Execute DCT-IV transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dst1_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dst1_direct(&self, input: &[T], output: &mut [T])
Execute DST-I (RODFT00) transform.
Formula: X[k] = sum_{n=0}^{N-1} x[n] * sin(π * (n+1) * (k+1) / (N+1))
Note: DST-I is always computed directly (no FFT fast path for all sizes). For n >= 16, we use an odd-extension FFT approach.
Sourcepub fn execute_dst1_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dst1_fast(&self, input: &[T], output: &mut [T])
Execute DST-I using FFT-based O(n log n) algorithm.
DST-I of length N via 2(N+1)-point odd extension: Build v of length 2(N+1): v[0] = 0, v[n+1] = x[n] for n=0..N-1, v[N+1] = 0, v[N+2+n] = -x[N-1-n] for n=0..N-1 Y = FFT_{2(N+1)}(v) DST_I[k] = -Im(Y[k+1]) for k=0..N-1
Sourcepub fn execute_dst1(&self, input: &[T], output: &mut [T])
pub fn execute_dst1(&self, input: &[T], output: &mut [T])
Execute DST-I transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dst2_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dst2_direct(&self, input: &[T], output: &mut [T])
Execute DST-II (RODFT10) using direct O(n²) computation.
Formula: X[k] = sum_{n=0}^{N-1} x[n] * sin(π * (2n+1) * (k+1) / (2N))
Sourcepub fn execute_dst2_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dst2_fast(&self, input: &[T], output: &mut [T])
Execute DST-II using FFT-based O(n log n) algorithm.
Relationship: DST_II(x)[k] = DCT_II(y)[N-1-k] where y[n] = (-1)^n * x[n] (sign-alternate input)
Sourcepub fn execute_dst2(&self, input: &[T], output: &mut [T])
pub fn execute_dst2(&self, input: &[T], output: &mut [T])
Execute DST-II transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dst3_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dst3_direct(&self, input: &[T], output: &mut [T])
Execute DST-III (RODFT01) using direct O(n²) computation.
Formula: X[k] = (-1)^k * x[N-1]/2 + sum_{n=0}^{N-2} x[n] * sin(π * (n+1) * (2k+1) / (2N))
Sourcepub fn execute_dst3_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dst3_fast(&self, input: &[T], output: &mut [T])
Execute DST-III using FFT-based O(n log n) algorithm.
Relationship: DST_III(f)[n] = (-1)^n * DCT_III(f_reversed)[n] where f_reversed[k] = f[N-1-k]
Sourcepub fn execute_dst3(&self, input: &[T], output: &mut [T])
pub fn execute_dst3(&self, input: &[T], output: &mut [T])
Execute DST-III transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dst4_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dst4_direct(&self, input: &[T], output: &mut [T])
Execute DST-IV (RODFT11) using direct O(n²) computation.
Formula: X[k] = sum_{n=0}^{N-1} x[n] * sin(π * (2n+1) * (2k+1) / (4N))
Sourcepub fn execute_dst4_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dst4_fast(&self, input: &[T], output: &mut [T])
Execute DST-IV using FFT-based O(n log n) algorithm.
Relationship: DST_IV(x)[k] = (-1)^k * DCT_IV(x_reversed)[k] where x_reversed[n] = x[N-1-n]
Sourcepub fn execute_dst4(&self, input: &[T], output: &mut [T])
pub fn execute_dst4(&self, input: &[T], output: &mut [T])
Execute DST-IV transform (dispatches to fast for n >= 16, direct otherwise).
Sourcepub fn execute_dht_direct(&self, input: &[T], output: &mut [T])
pub fn execute_dht_direct(&self, input: &[T], output: &mut [T])
Execute Discrete Hartley Transform (DHT) using direct O(n²) computation.
Formula: H[k] = sum_{n=0}^{N-1} x[n] * cas(2πnk/N)
where cas(θ) = cos(θ) + sin(θ)
Sourcepub fn execute_dht_fast(&self, input: &[T], output: &mut [T])
pub fn execute_dht_fast(&self, input: &[T], output: &mut [T])
Execute DHT using FFT-based O(n log n) algorithm.
For real input x: Y = FFT(x) (complex FFT with zero imaginary parts) DHT[k] = Y[k].re - Y[k].im
This works because the DFT with negative exponential gives: Y[k] = sum x[n] * exp(-2πink/N) = sum x[n] * (cos - i*sin)(2πnk/N) Y[k].re - Y[k].im = sum x[n] * (cos + sin)(2πnk/N) = DHT[k]
Sourcepub fn execute_dht(&self, input: &[T], output: &mut [T])
pub fn execute_dht(&self, input: &[T], output: &mut [T])
Execute Discrete Hartley Transform (dispatches to fast for n >= 16, direct otherwise).
The DHT is its own inverse (up to scaling by N), making it particularly elegant for real-valued signals.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for R2rSolver<T>
impl<T> RefUnwindSafe for R2rSolver<T>where
T: RefUnwindSafe,
impl<T> Send for R2rSolver<T>
impl<T> Sync for R2rSolver<T>
impl<T> Unpin for R2rSolver<T>where
T: Unpin,
impl<T> UnsafeUnpin for R2rSolver<T>
impl<T> UnwindSafe for R2rSolver<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more