Is there a way to compute the inverse discrete cosine transform (type-2) by leveraging either a DCT, FFT, or IFFT algorithm? I have seen ways to compute the DCT using FFTs, and I've seen ways to compute IFFT using FFT. I can't quite find a simple example with description.
Answer
Have a look at Fast DCT Algorithm (PDF Version).
It has both DCT and Inverse DCT using DFT (FFT).
They show how to do a DCT and Inverse without the reflection trick.
The standard (Less efficient then above) way doing so is:
numElements = 10;
vX = randn(1, numElements);
disp(vX); %
vDctRef = dct(vX);
% Forward DCR using FFT
vXX = [fliplr(vX), vX]; %vXDft = fft(vXX);
vGrid = [0:((2 * numElements) - 1)];
vShiftGrid = exp(-1j * 2 * pi * (numElements - 0.5) * vGrid / (2 * numElements));
vXDft2 = real(vXDft ./ vShiftGrid);
vDct = vXDft2(1:numElements) / sqrt(2 * numElements);
vDct(1) = vDct(1) / sqrt(2);
disp(vDctRef)
disp(vDct)
% Inverse DCT Using FFT
vDct(1) = vDct(1) * sqrt(2);
vDct = vDct * sqrt(2 * numElements);
vXDft = [vDct, 0, -fliplr(vDct(2:numElements))] .* vShiftGrid;
vXX = ifft(vXDft);
vX = real(fliplr(vXX(1:numElements)));
disp(vX);
A reference code for the IDCT by the more efficient method (As in reference):
numElements = 10;
% Signal (DCT Coefficients)
vXDct = randn(1, numElements);
% Reference Inverse IDCT
vXRef = idct(vXDct);
% Inverse IDCT Using FFT
vGrid = [0:(numElements - 1)];
vShiftGrid = exp((1j * pi * vGrid) / (2 * numElements));
vShiftGrid = vShiftGrid * sqrt(2 * numElements);
vShiftGrid(1) = vShiftGrid(1) / sqrt(2);
vTmp = vShiftGrid .* vXDct ;
vTmp = real(ifft(vTmp));
vX = zeros(1, numElements);
for ii = 0:((numElements / 2) - 1)
vX((2 * ii) + 1) = vTmp(ii + 1) ;
vX((2 * ii) + 2) = vTmp(numElements - ii) ;
end
disp(vXRef);
disp(vX);
Another reference is given by Lecture Notes for the Course MAT-INF2360 - Fourier Theory, Wavelet Analysis and Non Linear Optimization.
Have a look at 4.2 Efficient implementations of the DCT at page 115.
Enjoy...
Remark
When it is written DCT above it refers to DCT Type II.
No comments:
Post a Comment