How to perform * Fast * DCT (Discrete Cosine Transformation) in R?

Using Rprof showed that the dct in the dtt package is the main intruder in the R code snippet, which worked quite slowly. Rearranging it for fft in the statistics package (this is not the same conversion, but should take the same time to calculate), my runtime has improved significantly. In fact, 2/3 of my Rprof lines were previously dct calls, and only 3 out of 600 were fft calls after the switch was turned on.

Is the dct implementation in the dtt package not executed using the fast discrete Fourier transform? If so, is there a package that has it? (I know that you can double the data and then extract the coefficients for dct from these fft coefficients, but the direct fast dct will certainly be nicer, and there really should be somewhere).

+5
source share
1 answer

It doesn't seem to have a quick dct, but the statistics package has fft (fast Fourier transform), so here is how you could get a fast dct with fft.

. . , dct dtt. - , dct, .

: v = (1,2,3), w = (1,2,3,3,2,1). . v = (1,2,4,9), w = (1,2,4,9,9,4,2,1)

N - ( ).

N .5 * fft (w)/exp ( ( = pi/2/N) * (seq (2 * N) -1)) DCT (v) , .

. N, , dct, , dct . , N 2 ^ K, K dct , . N ( ), . - , .

: R- , , . N fft, , . . P e ^ (pi * i/2/N). . P, P ^ 2, P ^ 3 .. 2 ( ), R, dct,

, dct dtt, .

+7

All Articles