Is there way to get Mathematica to do a FourierDCT that is of mixed "type"?

To clarify suppose we have some data on a 2D grid that includes the boundary,

type1grid =   Table[N[Cos[x] Cos[y]], {x, 0, Pi, Pi/10}, {y, 0, Pi, Pi/10}]

In this case we can do a "Type I" FourierDCT to recover the coefficients, i.e.

Chop@FourierDCT[type1grid, 1]

will produce a grid of zeroes, except at the (2,2) position.

Similarly, if we have a similar grid of data that avoids the boundary,

type2grid = Table[N[Cos[x] Cos[y]], {x, Pi/20, Pi, Pi/10}, {y, Pi/ 20, pi, Pi/10}],

we can do a "type II" FourierDCT to extract the coefficients, i.e.

Chop@FourierDCT[type2grid, 2]

will again produce a grid of zeroes, except at the (2,2) position.

Now suppose we have a grid that in one direction includes the boundaries and in the other avoids the boundary,

 mixedgrid = Table[N[Cos[x] Cos[y]], {x, 0, Pi, Pi/10}, {y, Pi/ 20, pi, Pi/10}].

I would like to be able to do a "mixed type I/II" FourierDCT that recovers the correct coefficients. The Mathematica documentation for FourierDCT does not mention this as an option, and naively trying

Chop@FourierDCT[mixedgrid, {1, 2}]

results in Mathematica asserting that the second argument should be 1, 2, 3, or 4.

Short of outright implementing a FastDCT from scratch, is there a way to do the mixed type FourierDCT using built in functions?


Do a mixed transformation, you can apply the transformations corresponding to the rows to the rows. Then you take the transpose to get the columns into the places of the rows and apply the transformation corresponding tp the columns to the rows. Finally you tranpose again to retsore the original order. To make the output more readable, I take fewer points:

(type3grid = 
   Table[N[Cos[x] Cos[y]], {x, Pi/10, Pi, Pi/5}, {y, 0, Pi, Pi/5}]) // TableForm

(fft1 = Chop[FourierDCT[#, 1]] & /@ type3grid)  // TableForm

Chop[FourierDCT[#, 2]] & /@ Transpose[fft1] // Transpose // TableForm


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.