Spectral Transforms¶
DST and DCT transforms (types I–IV) with optional orthonormal normalization. See the theory page for mathematical definitions.
1-D Transforms¶
dct(x, type=2, norm=None)
¶
Discrete Cosine Transform of a 1-D vector.
Computes the DCT of x using an FFT-based O(N log N) algorithm. The default type is DCT-II:
Y[k] = 2 Sigma_{n=0}^{N-1} x[n] cos(pi k(2n+1) / (2N)), k = 0, ..., N-1
All four types (I-IV) follow the scipy convention.
Parameters¶
x : Float[Array, " N"]
Input 1-D array of length N.
type : {1, 2, 3, 4}
DCT variant. Default: 2.
norm : {None, "ortho"}
Normalization mode. None (default) gives the unnormalized
transform (scipy.fft.dct(x, type, norm=None)). "ortho"
scales the output so the transform matrix is orthogonal.
Returns¶
Float[Array, " N"] DCT of x, same shape as input.
Raises¶
ValueError If x is not 1-D, type is invalid, or norm is unrecognised.
Source code in spectraldiffx/_src/fourier/transforms.py
dst(x, type=1, norm=None)
¶
Discrete Sine Transform of a 1-D vector.
Computes the DST of x using an FFT-based O(N log N) algorithm. The default type is DST-I:
Y[k] = 2 Sigma_{n=0}^{N-1} x[n] sin(pi(n+1)(k+1) / (N+1)), k = 0, ..., N-1
All four types (I-IV) follow the scipy convention.
Parameters¶
x : Float[Array, " N"]
Input 1-D array of length N.
type : {1, 2, 3, 4}
DST variant. Default: 1.
norm : {None, "ortho"}
Normalization mode. None (default) gives the unnormalized
transform. "ortho" scales the output so the transform matrix
is orthogonal.
Returns¶
Float[Array, " N"] DST of x, same shape as input.
Raises¶
ValueError If x is not 1-D, type is invalid, or norm is unrecognised.
Source code in spectraldiffx/_src/fourier/transforms.py
idct(x, type=2, norm=None)
¶
Inverse Discrete Cosine Transform of a 1-D vector.
Satisfies idct(dct(x, t, norm=m), t, norm=m) == x for all types
t in {1, 2, 3, 4} and normalization modes m in {None, "ortho"}.
Parameters¶
x : Float[Array, " N"] DCT-transformed 1-D array of length N. type : {1, 2, 3, 4} DCT variant of the forward transform to invert. norm : {None, "ortho"} Normalization mode — must match the mode used in the forward transform.
Returns¶
Float[Array, " N"] Reconstructed signal, same shape as x.
Raises¶
ValueError If x is not 1-D, type is invalid, or norm is unrecognised.
Source code in spectraldiffx/_src/fourier/transforms.py
idst(x, type=1, norm=None)
¶
Inverse Discrete Sine Transform of a 1-D vector.
Satisfies idst(dst(x, t, norm=m), t, norm=m) == x for all types
t in {1, 2, 3, 4} and normalization modes m in {None, "ortho"}.
Parameters¶
x : Float[Array, " N"] DST-transformed 1-D array of length N. type : {1, 2, 3, 4} DST variant of the forward transform to invert. norm : {None, "ortho"} Normalization mode — must match the mode used in the forward transform.
Returns¶
Float[Array, " N"] Reconstructed signal, same shape as x.
Raises¶
ValueError If x is not 1-D, type is invalid, or norm is unrecognised.
Source code in spectraldiffx/_src/fourier/transforms.py
N-D Transforms¶
dctn(x, type=2, axes=None, norm=None)
¶
N-dimensional DCT: apply DCT sequentially along each axis.
For a 2-D array with axes=[0, 1], this computes the separable
transform DCT_y(DCT_x(x)). The result is identical to applying the
1-D DCT independently along each axis in sequence.
Parameters¶
x : Float[Array, "..."]
Input array of any dimensionality.
type : {1, 2, 3, 4}
DCT variant. Default: 2.
axes : sequence of int or None
Axes to transform. None transforms all axes.
norm : {None, "ortho"}
Normalization mode.
Returns¶
Float[Array, "..."] N-D DCT of x, same shape as input.
Source code in spectraldiffx/_src/fourier/transforms.py
dstn(x, type=1, axes=None, norm=None)
¶
N-dimensional DST: apply DST sequentially along each axis.
For a 2-D array with axes=[0, 1], this computes the separable
transform DST_y(DST_x(x)). The result is identical to applying the
1-D DST independently along each axis in sequence.
Parameters¶
x : Float[Array, "..."]
Input array of any dimensionality.
type : {1, 2, 3, 4}
DST variant. Default: 1.
axes : sequence of int or None
Axes to transform. None transforms all axes.
norm : {None, "ortho"}
Normalization mode.
Returns¶
Float[Array, "..."] N-D DST of x, same shape as input.
Source code in spectraldiffx/_src/fourier/transforms.py
idctn(x, type=2, axes=None, norm=None)
¶
N-dimensional inverse DCT: apply IDCT sequentially along each axis.
Satisfies idctn(dctn(x, t, axes, norm=m), t, axes, norm=m) == x.
The inverse is separable — each axis is inverted independently.
Parameters¶
x : Float[Array, "..."]
DCT-transformed array.
type : {1, 2, 3, 4}
DCT variant of the forward transform to invert.
axes : sequence of int or None
Axes to inverse-transform. None transforms all axes.
norm : {None, "ortho"}
Normalization mode — must match the forward transform.
Returns¶
Float[Array, "..."] Reconstructed N-D array, same shape as input.
Source code in spectraldiffx/_src/fourier/transforms.py
idstn(x, type=1, axes=None, norm=None)
¶
N-dimensional inverse DST: apply IDST sequentially along each axis.
Satisfies idstn(dstn(x, t, axes, norm=m), t, axes, norm=m) == x.
The inverse is separable — each axis is inverted independently.
Parameters¶
x : Float[Array, "..."]
DST-transformed array.
type : {1, 2, 3, 4}
DST variant of the forward transform to invert.
axes : sequence of int or None
Axes to inverse-transform. None transforms all axes.
norm : {None, "ortho"}
Normalization mode — must match the forward transform.
Returns¶
Float[Array, "..."] Reconstructed N-D array, same shape as input.