-
Notifications
You must be signed in to change notification settings - Fork 227
/
compute_dct_matrix.m
68 lines (61 loc) · 1.24 KB
/
compute_dct_matrix.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function M = compute_dct_matrix(w, ndims)
% compute_dct_matrix - compute the DCT matrix for a discrete cosine transform.
%
% M = compute_dct_matrix(w,ndims);
%
% ndims==1 or 2 for 1D or 2D data.
% w is the width of the data to transform
% (so that M is a transform matrix
% of size w^ndims x w^ndims).
%
% Copyright (c) 2005 Gabriel Peyré
if nargin<2
ndims = 2;
end
if length(w)==2
ndims = 2;
end
if ndims==1
M = zeros(w,w);
k = 0;
for i=1:w
k = k+1;
y = dirac(w, i);
x = idct2(y);
M(k,:) = x(:)';
end
else
if length(w)==1
w = [w w];
end
ww = prod(w);
M = zeros(ww,ww);
Jmin = 1;
k = 0;
for i=1:w(1)
for j=1:w(2)
k = k+1;
y = dirac(w, [i,j]);
x = idct2(y);
M(k,:) = x(:)';
end
end
end
function y = dirac(s,n)
% dirac - dirac function.
%
% y = dirac(s,n);
%
% s is the size of the matrix, and
% n is the location of the dirac (default (1,...,1)).
%
% Copyright (c) 2004 Gabriel Peyré
if nargin<2
n = ones(size(s));
end
if length(s)==1
y = zeros(s,1);
else
y = zeros(s);
end
y = array_set_val( y, n, 1 );