# How to use discrete cosine and discrete sine transforms in fftw

I work on fluid-related simulations. I have used FFT for fluid simulation. I want to use discrete cosine transform (DCT) and discrete sine transform (DST) to transform my velocity field to wavenumbers.

I am using REDFT00 and RODFT00 as DCT and DST respectively (so the inverse are themselves).

I understand that the normalization is $$2(n-1)$$ and $$2(n+1)$$, respectively.

for DCT and DST, I take

$$u(x) = \cos(3x); n=64$$

But when I invert it, values after $$(n/2)+1$$ are all incorrect.

What is the right way to do?

UPDATE: I was using an old library which was heavily modified(FFT worked fine though). I used the original library and everything works fine. But now I have difficulty in using the library for my purposes(Don't know how to take care of the wavenumbers) which I have posted as a separate question. So I guess I don't need the answer. It was a defective library.

• What package are you using exactly? What do you mean with incorrect? To high, to low, NaN? – MPIchael Nov 26 '19 at 11:14
• I am using P3DFFT LIBRARY. The values of the inverted matrix after x=(n/2)+1 are exactly 2(n-1) and 2(n+1) times smaller than the original one for dct and dst respectively. – user162281 Nov 26 '19 at 11:57
• If I multiply 2(n-1) and 2(n+1) to the values of the original matrix (for x>(n/2)+1)before transforming I get what I want but it is not the original matrix – user162281 Nov 26 '19 at 12:01
• I was using a modified p3dfft library. I changed the library to the original one and it fixed it. – user162281 Nov 28 '19 at 9:34