danieleb@2
|
1 function x = idcti(c,type)
|
danieleb@14
|
2 % IDCTI inverse discrete cosine transform of types I-IV
|
danieleb@2
|
3 %
|
danieleb@14
|
4 % Example
|
danieleb@14
|
5 % X = IDCTI(C,TYPE) returns the idct of the signal c of the specified type
|
danieleb@2
|
6 %
|
danieleb@14
|
7 % Input
|
danieleb@14
|
8 % - c: vector or matrix containing the dct coefficients. If matrix, the
|
danieleb@2
|
9 % function acts columnwise.
|
danieleb@14
|
10 % - type: (optional, default = 'II') string containing the idct type. Valid
|
danieleb@2
|
11 % types are 'I','II','III' and 'IV'
|
danieleb@2
|
12 %
|
danieleb@2
|
13 % OUTPUT
|
danieleb@14
|
14 % - x: vector or matrix contaning the inverse dct coefficients
|
danieleb@2
|
15 %
|
danieleb@14
|
16 % References
|
danieleb@14
|
17 % 1) S. Mallat, A wavelet tour of signal processing
|
danieleb@2
|
18 %
|
danieleb@14
|
19 % See also DCTI, DCT, FFT, IDCT, IFFT
|
danieleb@2
|
20
|
danieleb@4
|
21 % Author(s): Daniele Barchiesi
|
danieleb@14
|
22 % Copyright 2011-2011
|
danieleb@2
|
23
|
danieleb@2
|
24 %% Check inputs & defaults
|
danieleb@2
|
25 error(nargchk(1,2,nargin,'struct'));
|
danieleb@2
|
26 if nargin==1, type = 'II'; end
|
danieleb@2
|
27
|
danieleb@2
|
28 %% Compute idct
|
danieleb@2
|
29 [N M] = size(c);
|
danieleb@2
|
30 switch upper(type)
|
danieleb@9
|
31 case 'I'
|
danieleb@13
|
32 % Explicit calculation of IDCT-I. Replace with fast algorithm (todo)
|
danieleb@2
|
33 dctMat = zeros(N);
|
danieleb@9
|
34 dctMat(:,1) = 1/sqrt(N)*ones(N,1);
|
danieleb@9
|
35 for k=1:N-1
|
danieleb@9
|
36 dctMat(:,k+1) = sqrt(2/N)*cos(k*pi/N*(0.5+(0:N-1)));
|
danieleb@2
|
37 end
|
danieleb@2
|
38 x = dctMat*c;
|
danieleb@2
|
39 case 'II' % Fast calculation of DCT II. Uses method employed in idct.M
|
danieleb@2
|
40 % Compute wieghts
|
danieleb@2
|
41 w = sqrt(2*N) * exp(1i*(0:N-1)*pi/(2*N)).';
|
danieleb@2
|
42 if rem(N,2) || ~isreal(c), % odd case
|
danieleb@2
|
43 % Form intermediate even-symmetric matrix.
|
danieleb@2
|
44 w(1) = w(1) * sqrt(2);
|
danieleb@2
|
45 W = w(:,ones(1,M));
|
danieleb@2
|
46 yy = zeros(2*N,M);
|
danieleb@2
|
47 yy(1:N,:) = W.*c;
|
danieleb@2
|
48 yy(N+2:2*N,:) = -1i*W(2:N,:).*flipud(c(2:N,:));
|
danieleb@2
|
49
|
danieleb@2
|
50 y = ifft(yy);
|
danieleb@2
|
51
|
danieleb@2
|
52 % Extract inverse DCT
|
danieleb@2
|
53 x = y(1:N,:);
|
danieleb@2
|
54
|
danieleb@2
|
55 else % even case
|
danieleb@2
|
56 w(1) = w(1)/sqrt(2);
|
danieleb@2
|
57 W = w(:,ones(1,M));
|
danieleb@2
|
58 yy = W.*c;
|
danieleb@2
|
59
|
danieleb@2
|
60 % Compute x tilde using equation (5.93) in Jain
|
danieleb@2
|
61 y = ifft(yy);
|
danieleb@2
|
62
|
danieleb@2
|
63 % Re-order elements of each column according to equations (5.93) and
|
danieleb@2
|
64 % (5.94) in Jain
|
danieleb@2
|
65 x = zeros(N,M);
|
danieleb@2
|
66 x(1:2:N,:) = y(1:N/2,:);
|
danieleb@2
|
67 x(2:2:N,:) = y(N:-1:N/2+1,:);
|
danieleb@2
|
68 end
|
danieleb@13
|
69 case 'III' % Explicit calculation of IDCT III. Replace with fast algorithm (todo)
|
danieleb@2
|
70 dctMat = zeros(N);
|
danieleb@2
|
71 for k=0:N-1
|
danieleb@2
|
72 dctMat(:,k+1) = [sqrt(2)/2; cos(pi/N*(k+1/2)*(1:N-1))'];
|
danieleb@2
|
73 end
|
danieleb@2
|
74 dctMat = normcol(dctMat);
|
danieleb@2
|
75 x = dctMat*c;
|
danieleb@2
|
76 case 'IV' % Fast calculation of IDCT IV.
|
danieleb@2
|
77 y = zeros(8*N,M);
|
danieleb@2
|
78 y(2:2:2*N,:) = c;
|
danieleb@2
|
79 yy = fft(y,[],1);
|
danieleb@2
|
80 x = sqrt(2/N)*real(yy(2:2:2*N,:));
|
danieleb@2
|
81 otherwise
|
danieleb@2
|
82 error('Unsupported idct type');
|
danieleb@2
|
83 end
|
danieleb@2
|
84
|
danieleb@2
|
85 %% Postprocess
|
danieleb@2
|
86 if isreal(c), x = real(x); end
|
danieleb@2
|
87
|
danieleb@2
|
88 %EOF |