Last active
February 12, 2019 00:29
-
-
Save hiyuh/875d06e046643c6dd7681dee61d45d84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cmp_sym() | |
N = 20; % NOTE: sym2 to sym20. | |
M = 2; | |
b2 = zeros(N, M); | |
for n = 2:N; | |
for m = 1:M; | |
[n, m] | |
switch (m) | |
case 1 | |
g = coe_sym(n, 1); % NOTE: LUT from PyWavelets. | |
case 2 | |
g = coe_sym(n, 0); % NOTE: Runtime by LTFAT. | |
end; | |
[b2(n, m), ~] = bb(g); | |
end; | |
end; | |
b2eps = -log2(eps); | |
plot( | |
2:N, b2(2:N, 1), '+', | |
2:N, b2(2:N, 2), 'x', | |
[2 N], [b2eps b2eps], '-' | |
); | |
legend( | |
'PyWavelets', | |
'LTFAT', | |
'IEEE 754 binary64', | |
"location", 'southwest' | |
); | |
grid on; | |
title('estimated bit accuracy of filter coefficents for symlets'); | |
xlabel('N'); | |
ylabel('estimated bit accuracy [bit]'); | |
endfunction; | |
function y = mirror(x) | |
y = -((-1).^(1:length(x))) .* x; | |
endfunction; | |
function [c2, c0] = cc(g) % NOTE: Convolution and Convolution that evaluate perfect reconstruction quality. | |
sl = g ; | |
al = flip(g) ; | |
sh = mirror(flip(g)) ; | |
ah = flip(mirror(flip(g))); | |
c2 = conv(sl, al ) + conv(sh, ah ); | |
c0 = conv(sl, flip(al)) + conv(sh, flip(ah)); | |
endfunction; | |
function [c2, c0] = ccref(g) % NOTE: Reference CC. | |
l = length(g); | |
c2 = zeros(1, 2 * l - 1); c2(l) = 2.0; | |
c0 = zeros(1, 2 * l - 1); % FIXME: Implement real c0. | |
endfunction; | |
function [b2, b0] = bb(g) % NOTE: Estimated bit accuracy. | |
[c2, c0] = cc (g); | |
[c2ref, ~ ] = ccref(g); | |
e2 = c2 - c2ref; | |
b2 = -log2(max(abs(e2))); | |
% FIXME: Implement b0. | |
l = length(g); | |
e0 = mirror(c0(1:(l - 1))) - flip(c0((l + 1):(2 * l - 1))); | |
e0(l) = c0(l); | |
b0 = -log2(max(abs(e0))); | |
endfunction; | |
function g = coe_sym(n, kind = 1) | |
switch (kind) | |
case 0 | |
% NOTE: Runtime calculation by LTFAT. | |
% FIXME: LTFAT wfilt_sym() returns column major if n > 1. | |
% FIXME: LTFAT wfilt_sym() errors like "ceros(4):out of bound 3" | |
% if called from inside dn.m::gen() loop, dunno why... | |
% FIXME: LTFAT wfilt_sym() errors like "modulos(14): out of bound 13" if n > 28. | |
% FIXME: LTFAT wfilt_sym() looks being incorrect if n > 20. | |
g = flip(wfilt_sym(n){1}.h)(:)'; | |
case 1 | |
% NOTE: Pre-calculated filter coefficients from PyWavelets. | |
% NOTE: PyWavelets has no sym1. | |
% NOTE: PyWavelets has sym2, is not equals to db2. | |
switch (n) | |
case 2 | |
g = [ | |
4.8296291314469025e-01 ... | |
8.3651630373746899e-01 ... | |
2.2414386804185735e-01 ... | |
-1.2940952255092145e-01 | |
]; | |
case 3 | |
g = [ | |
3.3267055295095688e-01 ... | |
8.0689150931333875e-01 ... | |
4.5987750211933132e-01 ... | |
-1.3501102001039084e-01 ... | |
-8.5441273882241486e-02 ... | |
3.5226291882100656e-02 | |
]; | |
case 4 | |
g = [ | |
3.2223100604042702e-02 ... | |
-1.2603967262037833e-02 ... | |
-9.9219543576847216e-02 ... | |
2.9785779560527736e-01 ... | |
8.0373875180591614e-01 ... | |
4.9761866763201545e-01 ... | |
-2.9635527645998510e-02 ... | |
-7.5765714789273325e-02 | |
]; | |
case 5 | |
g = [ | |
1.9538882735286728e-02 ... | |
-2.1101834024758855e-02 ... | |
-1.7532808990845047e-01 ... | |
1.6602105764522319e-02 ... | |
6.3397896345821192e-01 ... | |
7.2340769040242059e-01 ... | |
1.9939753397739360e-01 ... | |
-3.9134249302383094e-02 ... | |
2.9519490925774643e-02 ... | |
2.7333068345077982e-02 | |
]; | |
case 6 | |
g = [ | |
-7.8007083250341480e-03 ... | |
1.7677118642428036e-03 ... | |
4.4724901770665779e-02 ... | |
-2.1060292512300564e-02 ... | |
-7.2637522786462516e-02 ... | |
3.3792942172762180e-01 ... | |
7.8764114103019400e-01 ... | |
4.9105594192674662e-01 ... | |
-4.8311742585632998e-02 ... | |
-1.1799011114819057e-01 ... | |
3.4907120842174702e-03 ... | |
1.5404109327027373e-02 | |
]; | |
case 7 | |
g = [ | |
1.0268176708511255e-02 ... | |
4.0102448715336634e-03 ... | |
-1.0780823770381774e-01 ... | |
-1.4004724044296152e-01 ... | |
2.8862963175151463e-01 ... | |
7.6776431700316405e-01 ... | |
5.3610191709176280e-01 ... | |
1.7441255086855827e-02 ... | |
-4.9552834937127255e-02 ... | |
6.7892693501372697e-02 ... | |
3.0515513165963570e-02 ... | |
-1.2636303403251930e-02 ... | |
-1.0473848886829163e-03 ... | |
2.6818145682578781e-03 | |
]; | |
case 8 | |
g = [ | |
1.8899503327594609e-03 ... | |
-3.0292051472136680e-04 ... | |
-1.4952258337048231e-02 ... | |
3.8087520138906151e-03 ... | |
4.9137179673607506e-02 ... | |
-2.7219029917056003e-02 ... | |
-5.1945838107709037e-02 ... | |
3.6444189483533140e-01 ... | |
7.7718575170052351e-01 ... | |
4.8135965125837221e-01 ... | |
-6.1273359067658524e-02 ... | |
-1.4329423835080971e-01 ... | |
7.6074873249176054e-03 ... | |
3.1695087811492981e-02 ... | |
-5.4213233179114812e-04 ... | |
-3.3824159510061256e-03 | |
]; | |
case 9 | |
g = [ | |
1.0694900329086053e-03 ... | |
-4.7315449868008311e-04 ... | |
-1.0264064027633142e-02 ... | |
8.8592674934004842e-03 ... | |
6.2077789302886030e-02 ... | |
-1.8233770779395985e-02 ... | |
-1.9155083129728512e-01 ... | |
3.5272488035271894e-02 ... | |
6.1733844914093583e-01 ... | |
7.1789708276441200e-01 ... | |
2.3876091460730300e-01 ... | |
-5.4568958430834071e-02 ... | |
5.8346274612580684e-04 ... | |
3.0224878858275680e-02 ... | |
-1.1528210207679230e-02 ... | |
-1.3271967781817119e-02 ... | |
6.1978088898558676e-04 ... | |
1.4009155259146807e-03 | |
]; | |
case 10 | |
g = [ | |
-4.5932942100465878e-04 ... | |
5.7036083618494284e-05 ... | |
4.5931735853118284e-03 ... | |
-8.0435893201654491e-04 ... | |
-2.0354939812311290e-02 ... | |
5.7649120335819086e-03 ... | |
4.9994972077376687e-02 ... | |
-3.1990056882427800e-02 ... | |
-3.5536740473817552e-02 ... | |
3.8382676106708546e-01 ... | |
7.6951003702110710e-01 ... | |
4.7169066693843925e-01 ... | |
-7.0880535783243853e-02 ... | |
-1.5949427888491757e-01 ... | |
1.1609893903711381e-02 ... | |
4.5927239231092203e-02 ... | |
-1.4653825813050513e-03 ... | |
-8.6412992770224222e-03 ... | |
9.5632670722894754e-05 ... | |
7.7015980911449011e-04 | |
]; | |
case 11 | |
g = [ | |
4.8926361026192387e-04 ... | |
1.1053509764272153e-04 ... | |
-6.3896036664548919e-03 ... | |
-2.0034719001093887e-03 ... | |
4.3000190681552281e-02 ... | |
3.5266759564466552e-02 ... | |
-1.4460234370531561e-01 ... | |
-2.0465479449580060e-01 ... | |
2.3768990904924897e-01 ... | |
7.3034354908839572e-01 ... | |
5.7202297801008706e-01 ... | |
9.7198394458909473e-02 ... | |
-2.2832651022562687e-02 ... | |
6.9976799610734136e-02 ... | |
3.7037415978859400e-02 ... | |
-2.4080841595864003e-02 ... | |
-9.8579348287897942e-03 ... | |
6.5124956747714497e-03 ... | |
5.8835273539699145e-04 ... | |
-1.7343662672978692e-03 ... | |
-3.8795655736158566e-05 ... | |
1.7172195069934854e-04 | |
]; | |
case 12 | |
g = [ | |
-1.7906658697508691e-04 ... | |
-1.8158078862617515e-05 ... | |
2.3502976141834648e-03 ... | |
3.0764779631059454e-04 ... | |
-1.4589836449234145e-02 ... | |
-2.6043910313322326e-03 ... | |
5.7804179445505657e-02 ... | |
1.5301740622478840e-02 ... | |
-1.7037069723886492e-01 ... | |
-7.8332622316343220e-02 ... | |
4.6274103121927235e-01 ... | |
7.6347909778365719e-01 ... | |
3.9888597239022000e-01 ... | |
-2.2162306170337816e-02 ... | |
-3.5848830736954392e-02 ... | |
4.9179318299660837e-02 ... | |
7.5537806116804775e-03 ... | |
-2.4220722675013445e-02 ... | |
-1.4089092443297553e-03 ... | |
7.4149655176542510e-03 ... | |
1.8021409008538188e-04 ... | |
-1.3497557555715387e-03 ... | |
-1.1353928041541452e-05 ... | |
1.1196719424656033e-04 | |
]; | |
case 13 | |
g = [ | |
7.0429866906944016e-05 ... | |
3.6905373423196241e-05 ... | |
-7.2136438513622830e-04 ... | |
4.1326119884196064e-04 ... | |
5.6748537601224395e-03 ... | |
-1.4924472742598532e-03 ... | |
-2.0749686325515677e-02 ... | |
1.7618296880653084e-02 ... | |
9.2926030899137119e-02 ... | |
8.8197576704205465e-03 ... | |
-1.4049009311363403e-01 ... | |
1.1023022302137217e-01 ... | |
6.4456438390118564e-01 ... | |
6.9573915056149638e-01 ... | |
1.9770481877117801e-01 ... | |
-1.2436246075153011e-01 ... | |
-5.9750627717943698e-02 ... | |
1.3862497435849205e-02 ... | |
-1.7211642726299048e-02 ... | |
-2.0216768133389830e-02 ... | |
5.2963597387250252e-03 ... | |
7.5262253899680996e-03 ... | |
-1.7094285853022211e-04 ... | |
-1.1360634389281183e-03 ... | |
-3.5738623648689009e-05 ... | |
6.8203252630753188e-05 | |
]; | |
case 14 | |
g = [ | |
4.4618977991475265e-05 ... | |
1.9329016965523917e-05 ... | |
-6.0576018246643346e-04 ... | |
-7.3214213567023991e-05 ... | |
4.5326774719456481e-03 ... | |
1.0131419871842082e-03 ... | |
-1.9439314263626713e-02 ... | |
-2.3650488367403851e-03 ... | |
6.9827616361807551e-02 ... | |
2.5898587531046669e-02 ... | |
-1.5999741114652205e-01 ... | |
-5.8111823317717831e-02 ... | |
4.7533576263420663e-01 ... | |
7.5997624196109093e-01 ... | |
3.9320152196208885e-01 ... | |
-3.5318112114979733e-02 ... | |
-5.7634498351326995e-02 ... | |
3.7433088362853452e-02 ... | |
4.2805204990193782e-03 ... | |
-2.9196217764038187e-02 ... | |
-2.7537747912240711e-03 ... | |
1.0037693717672269e-02 ... | |
3.6647657366011829e-04 ... | |
-2.5794417259330780e-03 ... | |
-6.2865424814776362e-05 ... | |
3.9843567297594335e-04 ... | |
1.1210865808890361e-05 ... | |
-2.5879090265397886e-05 | |
]; | |
case 15 | |
g = [ | |
2.8660708525318081e-05 ... | |
2.1717890150778919e-05 ... | |
-4.0216853760293483e-04 ... | |
-1.0815440168545525e-04 ... | |
3.4810287370648950e-03 ... | |
1.5261382781819983e-03 ... | |
-1.7171252781638731e-02 ... | |
-8.7447888864779517e-03 ... | |
6.7969829044879179e-02 ... | |
6.8393310060480245e-02 ... | |
-1.3405629845625389e-01 ... | |
-1.9662635876623730e-01 ... | |
2.4396270543216630e-01 ... | |
7.2184302963618119e-01 ... | |
5.7864041521503451e-01 ... | |
1.1153369514261872e-01 ... | |
-4.1082666635382480e-02 ... | |
4.0735479696810677e-02 ... | |
2.1937642719753955e-02 ... | |
-3.8876716876833493e-02 ... | |
-1.9405011430934468e-02 ... | |
1.0079977087905669e-02 ... | |
3.4234507363512410e-03 ... | |
-3.5901654473726417e-03 ... | |
-2.6731644647180568e-04 ... | |
1.0705672194623959e-03 ... | |
5.5122547855586653e-05 ... | |
-1.6066186637495343e-04 ... | |
-7.3596667989194696e-06 ... | |
9.7124197379633478e-06 | |
]; | |
case 16 | |
g = [ | |
-1.0797982104319795e-05 ... | |
-5.3964831793152419e-06 ... | |
1.6545679579108483e-04 ... | |
3.6565924833482230e-05 ... | |
-1.3387206066921965e-03 ... | |
-2.2211647621176323e-04 ... | |
6.9377611308027096e-03 ... | |
1.3598447424841720e-03 ... | |
-2.4952758046290123e-02 ... | |
-3.5102750683740089e-03 ... | |
7.8037852903419913e-02 ... | |
3.0721139063301560e-02 ... | |
-1.5959219218520598e-01 ... | |
-5.4040601387606135e-02 ... | |
4.7534280601152273e-01 ... | |
7.5652498787569711e-01 ... | |
3.9712293362064416e-01 ... | |
-3.4574228416972504e-02 ... | |
-6.6983049070217779e-02 ... | |
3.2333091610663785e-02 ... | |
4.8692744049046071e-03 ... | |
-3.1051202843553064e-02 ... | |
-3.1265171722710075e-03 ... | |
1.2666731659857348e-02 ... | |
7.1821197883178923e-04 ... | |
-3.8809122526038786e-03 ... | |
-1.0844562230896880e-04 ... | |
8.5235471080470952e-04 ... | |
2.8078582128442894e-05 ... | |
-1.0943147929529757e-04 ... | |
-3.1135564076219692e-06 ... | |
6.2300067012207606e-06 | |
]; | |
case 17 | |
g = [ | |
3.7912531943321266e-06 ... | |
-2.4527163425832999e-06 ... | |
-7.6071244056051285e-05 ... | |
2.5207933140828779e-05 ... | |
7.1982706421489710e-04 ... | |
5.8400428694052584e-05 ... | |
-3.9323252797979023e-03 ... | |
-1.9054076898526659e-03 ... | |
1.2396988366648726e-02 ... | |
9.9529825235095976e-03 ... | |
-1.8038897241919240e-02 ... | |
-7.2616347509287674e-03 ... | |
1.6158808725919346e-02 ... | |
-8.6070874720733381e-02 ... | |
-1.5507600534974825e-01 ... | |
1.8053958458111286e-01 ... | |
6.8148899534492502e-01 ... | |
6.5071662920454565e-01 ... | |
1.4239835041467819e-01 ... | |
-1.1856693261143636e-01 ... | |
1.7271178210518500e-02 ... | |
1.0475461484223211e-01 ... | |
1.7903952214341119e-02 ... | |
-3.3291383492359328e-02 ... | |
-4.8192128031761478e-03 ... | |
1.0482366933031529e-02 ... | |
8.5677007019157410e-04 ... | |
-2.7416759756816018e-03 ... | |
-1.3864230268045499e-04 ... | |
4.7599638026386690e-04 ... | |
-1.3506383399901165e-05 ... | |
-6.2937025975541919e-05 ... | |
2.7801266938414138e-06 ... | |
4.2973433273459830e-06 | |
]; | |
case 18 | |
g = [ | |
-1.5131530692371587e-06 ... | |
7.8472980558317646e-07 ... | |
2.9557437620930811e-05 ... | |
-9.8588160301400580e-06 ... | |
-2.6583011024241041e-04 ... | |
4.7416145183736671e-05 ... | |
1.4280863270832796e-03 ... | |
-1.8877623940755607e-04 ... | |
-5.2397896830266083e-03 ... | |
1.0877847895956929e-03 ... | |
1.5012356344250213e-02 ... | |
-3.2607442000749834e-03 ... | |
-3.1712684731814537e-02 ... | |
6.2779445543116943e-03 ... | |
2.8529597039037808e-02 ... | |
-7.3799207290607169e-02 ... | |
-3.2480573290138676e-02 ... | |
4.0148386057061813e-01 ... | |
7.5362914010179283e-01 ... | |
4.7396905989393956e-01 ... | |
-5.2029158983952786e-02 ... | |
-1.5993814866932407e-01 ... | |
3.3995667103947358e-02 ... | |
8.4219929970386548e-02 ... | |
-5.0770851607570529e-03 ... | |
-3.0325091089369604e-02 ... | |
1.6429863972782159e-03 ... | |
9.5021643909623654e-03 ... | |
-4.1152110923597756e-04 ... | |
-2.3138718145060992e-03 ... | |
7.0212734590362685e-05 ... | |
3.9616840638254753e-04 ... | |
-1.4020992577726755e-05 ... | |
-4.5246757874949856e-05 ... | |
1.3549157618321140e-06 ... | |
2.6126125564836423e-06 | |
]; | |
case 19 | |
g = [ | |
1.7509367995348687e-06 ... | |
2.0623170632395688e-06 ... | |
-2.8151138661550245e-05 ... | |
-1.6821387029373716e-05 ... | |
2.7621877685734072e-04 ... | |
1.2930767650701415e-04 ... | |
-1.7049602611649971e-03 ... | |
-6.1792232779831076e-04 ... | |
8.2622369555282547e-03 ... | |
4.3193518748949689e-03 ... | |
-2.7709896931311252e-02 ... | |
-1.6908234861345205e-02 ... | |
8.4072676279245043e-02 ... | |
9.3630843415897141e-02 ... | |
-1.1624173010739675e-01 ... | |
-1.7659686625203097e-01 ... | |
2.5826616923728363e-01 ... | |
7.1955552571639425e-01 ... | |
5.7814494533860505e-01 ... | |
1.0902582508127781e-01 ... | |
-6.7525058040294086e-02 ... | |
8.9545911730436242e-03 ... | |
7.0155738571741596e-03 ... | |
-4.6635983534938946e-02 ... | |
-2.2651993378245951e-02 ... | |
1.5797439295674631e-02 ... | |
7.9684383206133063e-03 ... | |
-5.1222050025830140e-03 ... | |
-1.1607032572062486e-03 ... | |
2.1214250281823303e-03 ... | |
1.5915804768084938e-04 ... | |
-6.3576451500433403e-04 ... | |
-4.6120396002105868e-05 ... | |
1.1553923333578790e-04 ... | |
8.8733121737292863e-06 ... | |
-1.1880518269823984e-05 ... | |
-6.4636513033459633e-07 ... | |
5.4877327682158382e-07 | |
]; | |
case 20 | |
g = [ | |
-6.3291290447763946e-07 ... | |
-3.2567026420174407e-07 ... | |
1.2287252777961200e-05 ... | |
4.5254222091516362e-06 ... | |
-1.1739133516291466e-04 ... | |
-2.6615550335516086e-05 ... | |
7.4761085978205719e-04 ... | |
1.2544091723067259e-04 ... | |
-3.4716478028440734e-03 ... | |
-6.1112638579920880e-04 ... | |
1.2157040948785737e-02 ... | |
1.9385970672402002e-03 ... | |
-3.5373336756604236e-02 ... | |
-6.8437019650692274e-03 ... | |
8.8919668028199561e-02 ... | |
3.6250951653933078e-02 ... | |
-1.6057829841525254e-01 ... | |
-5.1088342921067398e-02 ... | |
4.7199147510148703e-01 ... | |
7.5116272842273002e-01 ... | |
4.0583144434845059e-01 ... | |
-2.9819368880333728e-02 ... | |
-7.8994344928398158e-02 ... | |
2.5579349509413946e-02 ... | |
8.1232283560096815e-03 ... | |
-3.1629437144957966e-02 ... | |
-3.3138573836233591e-03 ... | |
1.7004049023390339e-02 ... | |
1.4230873594621453e-03 ... | |
-6.6065857990888609e-03 ... | |
-3.0526283179572810e-04 ... | |
2.0889947081901982e-03 ... | |
7.2159911880740349e-05 ... | |
-4.9473109156726548e-04 ... | |
-1.9284123006452040e-05 ... | |
7.9929678357724810e-05 ... | |
3.0256660627369661e-06 ... | |
-7.9193614119769990e-06 ... | |
-1.9015675890554106e-07 ... | |
3.6955374748352210e-07 | |
]; | |
end; | |
end; | |
endfunction; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment