2

Technically FT of a symmetric function yields all real values. It means the cos transform of the function and FT of the function should give the same values. When I test compute FT of an array (scipy.fftpack.fft(b)) and DCT (scipy.fftpack.dct(b)), I get different values. Following is one example:

b=[4,3,2,1,0,1,2,3]
In:scipy.fftpack.fft(b) 
Out:array([ 16.00000000 +0.00000000e+00j,   6.82842712 +2.22044605e-16j,
         0.00000000 -0.00000000e+00j,   1.17157288 +2.22044605e-16j,
         0.00000000 +0.00000000e+00j,   1.17157288 -2.22044605e-16j,
         0.00000000 +0.00000000e+00j,   6.82842712 -2.22044605e-16j])
In:scipy.fftpack.dct(b,1)
Out:array([ 25.        ,   4.49395921,  10.09783468,  -1.60387547,
         0.61595706,   1.10991626,   1.28620826,  -1.        ])

What could be the reason for this discrepancy ?

roadrunner66
  • 7,772
  • 4
  • 32
  • 38
PythonNoob
  • 139
  • 2
  • 7

1 Answers1

0

You are right in your expectation.

See the note on the bottom of the DCT manual page:

"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"

fft(array([4., 3., 5., 10., 5., 3.])).real
#array([ 30.,  -8.,   6.,  -2.,   6.,  -8.])
dct(array([4., 3., 5., 10.]), 1)
#array([ 30.,  -8.,   6.,  -2.]) 

Why did the writers of the function make that choice? To avoid duplication and to be faster.

The symmetry works for you the way you described in your question for the DCT. So if you have symmetric function, why calculate the symmetric part twice? Also since the spectrums imaginary part is zero (or extremely close to it as given in your example, based on finite float precision) there is no need for the 'negative frequencies' which are duplicates of the positive frequencies. In the case of the more general FFT the 'negative frequencies` can have relevant information.

roadrunner66
  • 7,772
  • 4
  • 32
  • 38