Generating Any Levels CDF 9/7 Wavelet Transform Matrix For 1D Signal With Whole Point Symmetric Padding By Matlab

CDF 9/7 Wavelet Transform is used by JPEG2k standard.

This is the matlab code that would generate any levels CDF 9/7 Wavelet Transform Matrix for 1D Signal With Whole Point Symmetric Padding:

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
function H = cdf97td(X,nlevel)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% Generating any levels CDF 9/7 wavelet transform matrix
% for 1D signal with whole point symmetric padding by matlab
% X is of length 2^N and note that CDF 9/7 matrix is biorthogonal.
 
[xx,yy] = size(X);
 
H=X;
for i=1:nlevel
 
   for k=1:yy
      [ss,dd] = cdf971d(H(1:xx,k)'); % column transform
      H(1:xx,k) = [ss,dd]';
   end
 
   xx = xx/2;
   yy = yy;
 
end
 
 
%% 1d CDF 9/7 wavelet lifting scheme % symw_ext->...12321...
 
function [ss,dd] = cdf971d(S)
 
N = length(S);
 
fa = -1.586134342;
fb = -0.05298011854;
fc = 0.8829110762;
fd = 0.4435068522;
fz = 1.149604398;
 
s0 = S(1:2:N-1);  % S(1),S(3),S(5),S(7)...
d0 = S(2:2:N);    % S(2),S(4),S(6),S(8)...
 
d1 = d0 + fa*(s0 + [s0(2:N/2) s0(N/2)]);
s1 = s0 + fb*(d1 + [d1(1) d1(1:N/2-1)]);
 
d2 = d1 + fc*(s1 + [s1(2:N/2) s1(N/2)]);
s2 = s1 + fd*(d2 + [d2(1) d2(1:N/2-1)]);
 
ss = fz*s2;
dd = d2/fz;
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
function X = icdf97td(H,nlevel)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% Generating any levels inverse CDF 9/7 wavelet transform matrix
% for 1D signal with whole point symmetric padding by matlab
% H is of length 2^N and note that CDF 9/7 matrix is biorthogonal.
 
[x,y] = size(H);
xx = x/(2^nlevel);
yy = y/(2^nlevel);
 
X=H;
for i=1:nlevel
 
   for j=1:yy*2
      ss = X(1:xx,j);
      dd = X(xx+1:xx*2,j);
      X(1:xx*2,j) = icdf971d(ss',dd')'; % inverse column transform
   end
 
   xx = xx*2;
   yy = yy*2;
 
end
 
 
%% inverse 1d CDF 9/7 lifting scheme % symw_ext->...12321...
 
function S = icdf971d(ss,dd)
 
N = length(ss) + length(dd);
 
fa = -1.586134342;
fb = -0.05298011854;
fc = 0.8829110762;
fd = 0.4435068522;
fz = 1.149604398;
 
d2 = fz*dd;
s2 = ss/fz;
 
s1 = s2 - fd*(d2 + [d2(1) d2(1:N/2-1)]);
d1 = d2 - fc*(s1 + [s1(2:N/2) s1(N/2)]);
 
 
s0 = s1 - fb*(d1 + [d1(1) d1(1:N/2-1)]);
d0 = d1 - fa*(s0 + [s0(2:N/2) s0(N/2)]);
 
S(2:2:N) = d0;
S(1:2:N-1) = s0;
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
function outputcdf97
 
% wh = 2;
% E = eye(wh);
% nlevel = 1;
 
wh = 8;
E = eye(wh);
nlevel = 3;
 
LG = cdf97td(E,nlevel)
 
ILG = icdf97td(E,nlevel)
 
%% output transform matrix to txt file
 
fid=fopen('C:\cdf97mtx.txt','w');
 
fprintf(fid,'%%%% %g-level %g point CDF 9/7 matrix\r\n\r\n',nlevel,wh);
 
%% output CDF 9/7 wavelet transform matrix
 
fprintf(fid,'cdf97mtx_%g_%g = [',wh,nlevel);
matrix=LG;
[m,n]=size(matrix);
for i=1:1:m
   for j=1:1:n
      if j==n
         fprintf(fid,'%g\r\n',matrix(i,j));
      else
         fprintf(fid,'%g ',matrix(i,j));
      end
   end
end
fprintf(fid,'];\r\n\r\n\r\n');
%% end
 
 
%% output inverse CDF 9/7 wavelet transform matrix
 
fprintf(fid,'%%%% %g-level %g point inverse CDF 9/7 matrix\r\n\r\n',nlevel,wh);
 
fprintf(fid,'icdf97mtx_%g_%g = [',wh,nlevel);
matrix=ILG;
[m,n]=size(matrix);
for i=1:1:m
   for j=1:1:n
      if j==n
         fprintf(fid,'%g\r\n',matrix(i,j));
      else
         fprintf(fid,'%g ',matrix(i,j));
      end
   end
end
fprintf(fid,'];\r\n');
 
fclose(fid);
 
% is LG*ILG equal identity matrix:
 
isequal(round(cdf97td(E,nlevel)*icdf97td(E,nlevel)),E)

Results:

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%% 1-level 2 point CDF 9/7 matrix
 
cdf97mtx_2_1 = [0.707107 0.707107
-0.707107 0.707107
];
 
 
%% 1-level 2 point inverse CDF 9/7 matrix
 
icdf97mtx_2_1 = [0.707107 -0.707107
0.707107 0.707107
];
 
%% 2-level 4 point CDF 9/7 matrix
 
cdf97mtx_4_2 = [0.551475 0.766864 0.448525 0.233136
-0.654424 -0.300592 0.654424 0.300592
-0.418092 0.747796 -0.289015 -0.0406894
0.129078 -0.0813788 -0.836185 0.788486
];
 
 
%% 2-level 4 point inverse CDF 9/7 matrix
 
icdf97mtx_4_2 = [0.5 -0.615087 -0.754806 0.0476989
0.5 -0.0912718 0.779903 -0.0727959
0.5 0.557544 -0.329704 -0.377403
0.5 0.682544 -0.145592 0.852699
];
 
%% 2-level 8 point CDF 9/7 matrix
 
cdf97mtx_8_2 = [0.638088 0.913958 0.497818 0.190384 -0.139661 -0.0898126 0.00375549 -0.0145294
-0.0690438 0.0430209 0.237717 0.41324 0.595568 0.419906 0.235759 0.123833
-0.450164 -0.0442997 0.788868 0.194058 -0.357836 -0.141295 0.0191325 -0.00846346
0.0874354 0.0885994 0.0213012 -0.371253 -0.751644 -0.0348658 0.642907 0.317519
-0.418092 0.747796 -0.353553 -0.0406894 0.0645389 0 0 0
0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0
0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.353553 -0.0406894
0 0 0 0 0.129078 -0.0813788 -0.836185 0.788486
];
 
 
%% 2-level 8 point inverse CDF 9/7 matrix
 
icdf97mtx_8_2 = [0.587686 -0.0876857 -0.658621 0.043534 -0.754806 0.0476989 0 0
0.480104 0.0198963 -0.0185625 0.0185625 0.742074 -0.0727959 0.0378285 0
0.299232 0.200768 0.65907 -0.0439831 -0.353553 -0.377403 0.0238495 0
0.115232 0.384768 0.246335 -0.246335 -0.0727959 0.852699 -0.110624 0.0378285
-0.0438429 0.543843 -0.285777 -0.329311 0.0238495 -0.377403 -0.377403 0.0238495
-0.089631 0.589631 -0.239655 0.148383 0.0378285 -0.110624 0.890527 -0.110624
-0.0948682 0.594868 -0.0954576 0.653001 0 0.0238495 -0.353553 -0.377403
-0.102681 0.602681 -0.0791842 0.761728 0 0.0756569 -0.221249 0.852699
];
%% 3-level 8 point CDF 9/7 matrix
 
cdf97mtx_8_3 = [0.402375 0.676686 0.520102 0.426827 0.322375 0.233411 0.169363 0.0772891
-0.500017 -0.615846 -0.183919 0.157583 0.519885 0.360426 0.164052 0.0978368
-0.450164 -0.0442997 0.788868 0.194058 -0.357836 -0.141295 0.0191325 -0.00846346
0.0874354 0.0885994 0.0213012 -0.371253 -0.751644 -0.0348658 0.642907 0.317519
-0.418092 0.747796 -0.353553 -0.0406894 0.0645389 0 0 0
0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0
0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.353553 -0.0406894
0 0 0 0 0.129078 -0.0813788 -0.836185 0.788486
];
 
 
%% 3-level 8 point inverse CDF 9/7 matrix
 
icdf97mtx_8_3 = [0.353553 -0.47756 -0.658621 0.043534 -0.754806 0.0476989 0 0
0.353553 -0.325416 -0.0185625 0.0185625 0.742074 -0.0727959 0.0378285 0
0.353553 -0.0696251 0.65907 -0.0439831 -0.353553 -0.377403 0.0238495 0
0.353553 0.190591 0.246335 -0.246335 -0.0727959 0.852699 -0.110624 0.0378285
0.353553 0.415557 -0.285777 -0.329311 0.0238495 -0.377403 -0.377403 0.0238495
0.353553 0.480311 -0.239655 0.148383 0.0378285 -0.110624 0.890527 -0.110624
0.353553 0.487717 -0.0954576 0.653001 0 0.0238495 -0.353553 -0.377403
0.353553 0.498766 -0.0791842 0.761728 0 0.0756569 -0.221249 0.852699
];
 
%% 4-level 16 point CDF 9/7 matrix
 
cdf97mtx_16_4 = [0.287921 0.530555 0.472193 0.422299 0.364052 0.333546 0.305184 0.26478 0.227931 0.195537 0.163701 0.142476 0.125163 0.085677 0.0538549 0.0251299
-0.365194 -0.590764 -0.411492 -0.281742 -0.124296 -0.00765078 0.0875428 0.251469 0.38525 0.324561 0.241337 0.183207 0.112559 0.0879081 0.0742942 0.0330113
-0.349112 -0.374263 -0.0197789 0.297846 0.608505 0.38055 0.11077 -0.0772545 -0.280398 -0.193458 -0.0759926 -0.0373685 0.0190247 0.00759819 -0.0130183 -0.00365043
0.0655605 0.0968133 0.0431549 0.0461604 0.0276135 -0.116259 -0.23374 -0.423461 -0.570873 -0.30331 -0.0197338 0.23983 0.500516 0.355727 0.187503 0.1045
-0.452606 -0.0427605 0.796008 0.169701 -0.408888 -0.168162 0.0255642 0.0174329 0.0461591 0.0253276 -0.00867879 -0.00153922 0.00244141 0 0 0
0.0437177 0.0442997 0.0255642 -0.195029 -0.450164 0.150729 0.761765 0.150729 -0.452606 -0.19349 0.034243 0.0189721 0.0437177 0.0253276 -0.00623739 -0.00153922
0.00244141 -0.00153922 -0.00867879 0.0253276 0.0437177 0.0189721 0.034243 -0.19349 -0.450164 0.14919 0.754625 0.175086 -0.401554 -0.166623 0.0253699 -0.00692424
0 0 0 0 0.00488281 -0.00307844 -0.0173576 0.0506552 0.0874354 0.0379443 0.0386588 -0.368174 -0.756527 -0.0348658 0.642907 0.317519
-0.418092 0.747796 -0.353553 -0.0406894 0.0645389 0 0 0 0 0 0 0 0 0 0 0
0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0 0 0 0 0 0 0 0 0
0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0 0 0 0 0 0 0
0 0 0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0 0 0 0 0
0 0 0 0 0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0 0 0
0 0 0 0 0 0 0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.418092 -0.0406894 0.0645389 0
0 0 0 0 0 0 0 0 0 0 0.0645389 -0.0406894 -0.418092 0.788486 -0.353553 -0.0406894
0 0 0 0 0 0 0 0 0 0 0 0 0.129078 -0.0813788 -0.836185 0.788486
];

Summary of programs:

1. outputcdf97.m – main function output CDF 9/7 transform matrix
2. cdf97td.m – forward CDF 9/7 wavelet transform
3. icdf97td.m – inverse CDF 9/7 wavelet transform

download zip

Leave a Reply

Your email address will not be published. Required fields are marked *