File Exchange

## DCT and DST (+ inverse) in arbitrary dimension

version 1.5.0.0 (8.53 KB) by Damien Garcia

### Damien Garcia (view profile)

Discrete cosine/sine transforms and their inverses

Updated 25 Nov 2011

Y = DCTN(X) returns the discrete cosine transform (DCT) of X.

X = IDCTN(Y) returns the inverse discrete cosine transform (IDCT) of Y.

Y = DSTN(X) returns the discrete sine transform (DST) of X.

X = IDSTN(Y) returns the inverse discrete sine transform (IDST) of Y.

X and Y can be N-dimensional.

D = DSTMTX(k) returns the k-by-k DST transform matrix.

Faster DCT2 and IDCT2 are also included in the zip file.

Enter "help dctn", "help dstn", "help idctn", "help idstn" and "help dstmtx" in the Matlab command window for complete information.

Example
-------
I = rgb2gray(RGB);
J = dstn(I);
imshow(log(abs(J)),[]), colormap(jet), colorbar

The commands below set values less than magnitude 10 in the DST matrix to zero, then reconstruct the image using the inverse DST.

J(abs(J)<10) = 0;
K = idstn(J);
figure, imshow(I)
figure, imshow(K,[0 255])

------
http://www.biomecardio.com/matlab
-----

### Cite As

Damien Garcia (2020). DCT and DST (+ inverse) in arbitrary dimension (https://www.mathworks.com/matlabcentral/fileexchange/26040-dct-and-dst-inverse-in-arbitrary-dimension), MATLAB Central File Exchange. Retrieved .

Marjan Shayegan

### Marjan Shayegan (view profile)

Does the output need to be revered so that it corresponds to the low frequency and going up? (I am a bit confused by what would be the corresponding omega after transformation.) Can you please help?

Qi

### Qi (view profile)

Works great. But the idctn is missing?

Denis-Gabriel Caprace

### Denis-Gabriel Caprace (view profile)

According to the author and the reference in IEEE, the definition of the DCT rather corresponds to what is called REDFT10 in fftw. I guess the DST corresponds to RODFT10. Matlab dst function rather uses the same definition as RODFT00.

Léopold Cambier

### Léopold Cambier (view profile)

Would be great if you could add the exact definition. Does dstn correspond to https://www.mathworks.com/help/pde/ug/dst.html ?

Really useful otherwise :)

Gianni Schena

### Gianni Schena (view profile)

these function when used in >resize3d< allow faster volume resizing of large volumes with less memory usage