bundles / scipy latest / scipy / fftpack / _realtransforms / dct
function
scipy.fftpack._realtransforms:dct
Signature
def dct ( x , type = 2 , n = None , axis = -1 , norm = None , overwrite_x = False ) Summary
Return the Discrete Cosine Transform of arbitrary type sequence x.
Parameters
x: array_likeThe input array.
type: {1, 2, 3, 4}, optionalType of the DCT (see Notes). Default type is 2.
n: int, optionalLength of the transform. If
n < x.shape[axis],xis truncated. Ifn > x.shape[axis],xis zero-padded. The default results inn = x.shape[axis].axis: int, optionalAxis along which the dct is computed; the default is over the last axis (i.e.,
axis=-1).norm: {None, 'ortho'}, optionalNormalization mode (see Notes). Default is None.
overwrite_x: bool, optionalIf True, the contents of
xcan be destroyed; the default is False.
Returns
y: ndarray of realThe transformed input array.
Notes
For a single dimension array x, dct(x, norm='ortho') is equal to MATLAB dct(x).
There are, theoretically, 8 types of the DCT, only the first 4 types are implemented in scipy. 'The' DCT generally refers to DCT type 2, and 'the' Inverse DCT generally refers to DCT type 3.
Type I
There are several definitions of the DCT-I; we use the following (for norm=None)
If norm='ortho', x[0] and x[N-1] are multiplied by a scaling factor of , and y[k] is multiplied by a scaling factor f
Type II
There are several definitions of the DCT-II; we use the following (for norm=None)
If norm='ortho', y[k] is multiplied by a scaling factor f
which makes the corresponding matrix of coefficients orthonormal (O @ O.T = np.eye(N)).
Type III
There are several definitions, we use the following (for norm=None)
or, for norm='ortho'
The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up to a factor 2N. The orthonormalized DCT-III is exactly the inverse of the orthonormalized DCT-II.
Type IV
There are several definitions of the DCT-IV; we use the following (for norm=None)
If norm='ortho', y[k] is multiplied by a scaling factor f
Examples
The Type 1 DCT is equivalent to the FFT (though faster) for real, even-symmetrical inputs. The output is also real and even-symmetrical. Half of the FFT input is used to generate half of the FFT output:from scipy.fftpack import fft, dct import numpy as np✓
fft(np.array([4., 3., 5., 10., 5., 3.])).real dct(np.array([4., 3., 5., 10.]), 1)✗
See also
- idct
Inverse DCT
Aliases
-
scipy.fftpack.dct