DCT julia equivalent to scipy.fftpack.dct

123 views Asked by At

I wonder how I could compute the following in Julia

import scipy.fftpack
scipy.fftpack.dct([1,2,3], axis=0)
array([ 1.20000000e+01, -3.46410162e+00, -4.44089210e-16]) 

I have seen that FFTW.jl seems to have the equivalent of

import scipy.fftpack
scipy.fftpack.dct([1,2,3], norm='ortho')
array([ 3.46410162, -1.41421356,  0.        ])

which in julia FFTW would be

using FFTW
dct([1,2,3])
3-element Vector{Float64}:
  3.4641016151377544
 -1.414213562373095
  9.064933036736789e-17
1

There are 1 answers

1
Soeren On

I don't think there is an equivalent for that, but you can certainly build your own normalization:

import FFTW: dct
function dct(x, dims = 1; norm = nothing)
    res = dct(x, dims)
    if norm == "ortho"
        res[1] = res[1] * 2 * sqrt(size(x, dims))
        res[2:end] = res[2:end] * sqrt(2 * size(x, dims))
    end
    res
end
julia> dct([1,2,3], norm = "ortho")
3-element Vector{Float64}:
 11.999999999999998
 -3.464101615137754
  2.2204460492503128e-16