scipy.fftpack.dct

Prototype: scipy.fftpack.dct (x,type=2,n=None,axis=-1,norm=None,overwrite_x=False)

Back discrete cosine transform any type of sequence x.

  • parameter:

    x: array_like

    Input sequence matrix

    type: Optional parameters

    May be {1,2,3,4}, the default is 2; the DCT type parameter (see note)

    n-: int , optional parameters

    The length of the DCT, if n <x.shape [axis], then x is truncated. If n> x.shape [axis], then x zeros. The default result is n = x.shape [axis].

    Axis: int , optional parameters

    Dct axis calculated; the default value is the last one axis (i.e., axis = -1).

    norm: {None, 'ortho'}, optional parameters

    Standardized mode (see note), no default.

    overwrite_x: BOOL , optional parameters

    If True, the content of x can be destroyed; the default value is False.

  • return:

    y: array of real numbers

    After the input sequence into an array.

  • Note

    For a one-dimensional array of x, dct(x,norm ='ortho')equal to MATLAB dct(x).

    In theory, DCT has eight types, only the first four types can be achieved. "The" DCT generally refers to a DCT type 2, and "the" Inverse DCT DCT type 3 refers generally.

    • Type 1

      Type 1 has several definitions. We use the following (for norm = None):

                                         N-2
      y[k] = x[0] + (-1)**k x[N-1] + 2 * sum x[n]*cos(pi*k*n/(N-1))
                                         n=1
      

      If the norm = 'ortho', then x [0] and x [N-1] is multiplied by sqrt (2) scale factors, and y [k] multiplied by the scaling factor f:

      f = 0.5*sqrt(1/(N-1)) if k = 0 or N-1,
      f = 0.5*sqrt(2/(N-1)) otherwise.
      

      Note: only when the input size> 1, only one type may be used.

    • Type 2

      Type 2 There are several definitions, we use the following (for norm = None):

                N-1
      y[k] = 2* sum x[n]*cos(pi*k*(2n+1)/(2*N)), 0 <= k < N.
                n=0
      

      If the norm = 'ortho', then y [k] by a scaling factor f:

      f = sqrt(1/(4*N)) if k = 0,
      f = sqrt(1/(2*N)) otherwise.
      

      This coefficient matrix so that the corresponding orthogonal.

    • Type 3

      Type 3 There are several definitions, we use the following (for norm = None):

                        N-1
      y[k] = x[0] + 2 * sum x[n]*cos(pi*(k+0.5)*n/N), 0 <= k < N.
                        n=1
      

      Alternatively, for norm = 'ortho' and 0 <= k <N:

                                          N-1
      y[k] = x[0] / sqrt(N) + sqrt(2/N) * sum x[n]*cos(pi*(k+0.5)*n/N)
                                          n=1
      

      (Not normalized) DCT-III is a (non-normalized) of the inverse of DCT-II, a maximum of 2N; normalized orthogonal DCT-III is exactly the inverse orthogonal DCT-II of standardized.

    • Type 4

      4 There are several types of definition, we use the following (for norm = None):

                N-1
      y[k] = 2* sum x[n]*cos(pi*(2k+1)*(2n+1)/(4*N)), 0 <= k < N.
                n=0
      

      If the norm = 'ortho', then y [k] by a scaling factor f:

      f = 0.5*sqrt(2/N)
      
  • For example

    For real numbers, even symmetric input, the DCT type 1 equivalent to FFT (although faster). Output is also a real number, or even symmetrical. Half of the FFT input half of the FFT output for generating:

    >>> from scipy.fftpack import fft, dct
    >>> fft(np.array([4., 3., 5., 10., 5., 3.])).real
    array([ 30.,  -8.,   6.,  -2.,   6.,  -8.])
    >>> dct(np.array([4., 3., 5., 10.]), 1)
    array([ 30.,  -8.,   6.,  -2.])
    
Released five original articles · won praise 0 · Views 85

Guess you like

Origin blog.csdn.net/a1227605575/article/details/102631032