You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wavelet2s.cpp 124KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447
  1. //============================================================================
  2. // Name : 1D/2D Wavelet Transform
  3. // Author : Rafat Hussain
  4. // Version :
  5. // Copyright : GNU Lesser GPL License
  6. // Description : Wavelet Library
  7. //============================================================================
  8. /*Copyright (C) 2011 Rafat Hussain
  9. * This program is free software; you can redistribute it and/or modify it under the terms of
  10. * the GNU General Public License as published by the Free Software Foundation; version 2 or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  13. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU General Public License for more details.
  15. *
  16. *You should have received a copy of the GNU General Public License
  17. *along with this program; if not, write to the Free Software
  18. *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. *
  20. */
  21. #if defined(TARGET_HAS_ThirdPartyFFTW3)
  22. #include "wavelet2s.h"
  23. #include <iostream>
  24. #include <complex>
  25. #include <utility>
  26. #include <vector>
  27. #include <string>
  28. #include <cmath>
  29. #include <algorithm>
  30. #include <cstdlib>
  31. #include "fftw3.h"
  32. // extern "C" int _get_output_format( void ){ return 0; }
  33. fftw_plan plan_forward_inp, plan_forward_filt, plan_backward;
  34. static std::size_t fftTransientSize = 0;
  35. void* per_ext2d(std::vector<std::vector<double>>& signal, std::vector<std::vector<double>>& temp2, const int a)
  36. {
  37. const std::size_t rows = signal.size();
  38. const std::size_t cols = signal[0].size();
  39. const std::size_t cols2 = (cols % 2) != 0 ? cols + 1 : cols;
  40. std::vector<std::vector<double>> tempVec(rows, std::vector<double>(cols2 + 2 * a));
  41. for (std::size_t i = 0; i < rows; ++i)
  42. {
  43. std::vector<double> sig;
  44. for (std::size_t j = 0; j < cols; ++j)
  45. {
  46. double temp = signal[i][j];
  47. sig.push_back(temp);
  48. }
  49. per_ext(sig, a);
  50. for (std::size_t j = 0; j < sig.size(); ++j) { tempVec[i][j] = sig[j]; }
  51. }
  52. for (std::size_t j = 0; j < tempVec[0].size(); ++j)
  53. {
  54. std::vector<double> sig;
  55. for (std::size_t i = 0; i < rows; ++i)
  56. {
  57. double temp = tempVec[i][j];
  58. sig.push_back(temp);
  59. }
  60. per_ext(sig, a);
  61. for (std::size_t i = 0; i < sig.size(); ++i) { temp2[i][j] = sig[i]; }
  62. }
  63. return nullptr;
  64. }
  65. void* swt_2d(std::vector<std::vector<double>>& sig, int J, const std::string& nm, std::vector<double>& swtOutput)
  66. {
  67. std::size_t m = sig.size(); // No. of rows
  68. std::size_t n = sig[0].size(); //No. of columns
  69. //std::vector<std::vector<double>> sig2 = sig;
  70. std::size_t nRows = m;
  71. std::size_t nCols = n;
  72. std::vector<double> lp1, hp1, lp2, hp2;
  73. filtcoef(nm, lp1, hp1, lp2, hp2);
  74. for (std::size_t it = 0; it < std::size_t(J); ++it)
  75. {
  76. int U = int(pow(2.0, double(it)));
  77. std::vector<double> lowPass, highPass;
  78. if (it > 0)
  79. {
  80. upsamp(lp1, U, lowPass);
  81. upsamp(hp1, U, highPass);
  82. }
  83. else
  84. {
  85. lowPass = lp1;
  86. highPass = hp1;
  87. }
  88. int lf = lowPass.size();
  89. if ((sig.size() % 2) == 0) { nRows = sig.size(); }
  90. else { nRows = sig.size() + 1; }
  91. if ((sig[0].size() % 2) == 0) { nCols = sig[0].size(); }
  92. else { nCols = sig[0].size() + 1; }
  93. std::vector<std::vector<double>> signal(nRows + lf, std::vector<double>(nCols + lf));
  94. // per_ext2d(sig,signal,lf/2); Edit per_ext if you want to use per_ext2d. Remove
  95. // the even indexing.
  96. per_ext2d(sig, signal, lf / 2);
  97. std::size_t lenX = signal.size();
  98. std::size_t lenY = signal[0].size();
  99. std::vector<std::vector<double>> sigL(nRows + lf, std::vector<double>(nCols));
  100. std::vector<std::vector<double>> sigH(nRows + lf, std::vector<double>(nCols));
  101. std::vector<std::vector<double>> cA(nRows, std::vector<double>(nCols));
  102. std::vector<std::vector<double>> cH(nRows, std::vector<double>(nCols));
  103. std::vector<std::vector<double>> cV(nRows, std::vector<double>(nCols));
  104. std::vector<std::vector<double>> cD(nRows, std::vector<double>(nCols));
  105. for (std::size_t i = 0; i < lenX; ++i)
  106. {
  107. std::vector<double> tempRow;
  108. for (std::size_t j = 0; j < lenY; ++j) { tempRow.push_back(signal[i][j]); }
  109. // ------------------Low Pass Branch--------------------------
  110. std::vector<double> oup;
  111. convfftm(tempRow, lowPass, oup);
  112. oup.erase(oup.begin(), oup.begin() + lf);
  113. oup.erase(oup.begin() + nCols, oup.end());
  114. // ------------------High Pass Branch--------------------------
  115. std::vector<double> oup2;
  116. convfftm(tempRow, highPass, oup2);
  117. oup2.erase(oup2.begin(), oup2.begin() + lf);
  118. oup2.erase(oup2.begin() + nCols, oup2.end());
  119. tempRow.clear();
  120. for (std::size_t j = 0; j < oup.size(); ++j)
  121. {
  122. sigL[i][j] = oup[j];
  123. sigH[i][j] = oup2[j];
  124. }
  125. }
  126. for (std::size_t j = 0; j < nCols; ++j)
  127. {
  128. std::vector<double> tempRow;
  129. for (std::size_t i = 0; i < lenX; ++i) { tempRow.push_back(sigL[i][j]); }
  130. // ------------------Low Pass Branch--------------------------
  131. std::vector<double> oup;
  132. convfftm(tempRow, lowPass, oup);
  133. oup.erase(oup.begin(), oup.begin() + lf);
  134. oup.erase(oup.begin() + nRows, oup.end());
  135. // ------------------High Pass Branch--------------------------
  136. std::vector<double> oup2;
  137. convfftm(tempRow, highPass, oup2);
  138. oup2.erase(oup2.begin(), oup2.begin() + lf);
  139. oup2.erase(oup2.begin() + nRows, oup2.end());
  140. tempRow.clear();
  141. for (std::size_t i = 0; i < oup.size(); ++i) { cA[i][j] = oup[i]; }
  142. for (std::size_t i = 0; i < oup2.size(); ++i) { cH[i][j] = oup2[i]; }
  143. }
  144. for (std::size_t j = 0; j < nCols; ++j)
  145. {
  146. std::vector<double> tempRow;
  147. for (std::size_t i = 0; i < lenX; ++i) { tempRow.push_back(sigH[i][j]); }
  148. // ------------------Low Pass Branch--------------------------
  149. std::vector<double> oup;
  150. convfftm(tempRow, lowPass, oup);
  151. oup.erase(oup.begin(), oup.begin() + lf);
  152. oup.erase(oup.begin() + nRows, oup.end());
  153. // ------------------High Pass Branch--------------------------
  154. std::vector<double> oup2;
  155. convfftm(tempRow, highPass, oup2);
  156. oup2.erase(oup2.begin(), oup2.begin() + lf);
  157. oup2.erase(oup2.begin() + nRows, oup2.end());
  158. tempRow.clear();
  159. for (std::size_t i = 0; i < oup.size(); ++i) { cV[i][j] = oup[i]; }
  160. for (std::size_t i = 0; i < oup2.size(); ++i) { cD[i][j] = oup2[i]; }
  161. }
  162. sig = cA;
  163. std::vector<double> tempSig2;
  164. if (it == std::size_t(J - 1)) { for (std::size_t i = 0; i < nRows; ++i) { for (std::size_t j = 0; j < nCols; ++j) { tempSig2.push_back(cA[i][j]); } } }
  165. for (std::size_t i = 0; i < nRows; ++i) { for (std::size_t j = nCols; j < nCols * 2; ++j) { tempSig2.push_back(cH[i][j - nCols]); } }
  166. for (std::size_t i = nRows; i < nRows * 2; ++i) { for (std::size_t j = 0; j < nCols; ++j) { tempSig2.push_back(cV[i - nRows][j]); } }
  167. for (std::size_t i = nRows; i < nRows * 2; ++i) { for (std::size_t j = nCols; j < nCols * 2; ++j) { tempSig2.push_back(cD[i - nRows][j - nCols]); } }
  168. swtOutput.insert(swtOutput.begin(), tempSig2.begin(), tempSig2.end());
  169. }
  170. return nullptr;
  171. }
  172. void* per_ext(std::vector<double>& sig, const int a)
  173. {
  174. std::size_t len = sig.size();
  175. if ((len % 2) != 0)
  176. {
  177. sig.push_back(sig[len - 1]);
  178. len = sig.size();
  179. }
  180. for (std::size_t i = 0; i < std::size_t(a); ++i)
  181. {
  182. double temp1 = sig[2 * i];
  183. double temp2 = sig[len - 1];
  184. sig.insert(sig.begin(), temp2);
  185. sig.insert(sig.end(), temp1);
  186. }
  187. return nullptr;
  188. }
  189. void* iswt(std::vector<double>& swtop, int J, const std::string& nm, std::vector<double>& iswtOutput)
  190. {
  191. std::size_t n = swtop.size() / (J + 1);
  192. std::vector<double> lpd, hpd, lpr, hpr;
  193. filtcoef(nm, lpd, hpd, lpr, hpr);
  194. std::vector<double> appxSig;
  195. std::vector<double> lowPass = lpr;
  196. std::vector<double> highPass = hpr;
  197. int lf = lowPass.size();
  198. for (std::size_t iter = 0; iter < std::size_t(J); ++iter)
  199. {
  200. std::vector<double> detSig;
  201. if (iter == 0)
  202. {
  203. for (std::size_t i = 0; i < n; ++i)
  204. {
  205. double temp = swtop[i];
  206. appxSig.push_back(temp);
  207. double temp1 = swtop[(iter + 1) * n + i];
  208. detSig.push_back(temp1);
  209. }
  210. }
  211. else
  212. {
  213. for (std::size_t i = 0; i < n; ++i)
  214. {
  215. double temp1 = swtop[(iter + 1) * n + i];
  216. detSig.push_back(temp1);
  217. }
  218. }
  219. std::size_t value = std::size_t(pow(2.0, double(J - 1 - iter)));
  220. iswtOutput.assign(n, 0.0);
  221. for (std::size_t count = 0; count < value; ++count)
  222. {
  223. std::vector<double> appx1, det1;
  224. for (std::size_t index = count; index < n; index += value)
  225. {
  226. double temp = appxSig[index];
  227. appx1.push_back(temp);
  228. double temp1 = detSig[index];
  229. det1.push_back(temp1);
  230. }
  231. std::size_t len = appx1.size();
  232. // Shift = 0
  233. std::vector<double> appx2, det2;
  234. for (std::size_t i = 0; i < len; i += 2)
  235. {
  236. double temp = appx1[i];
  237. appx2.push_back(temp);
  238. double temp1 = det1[i];
  239. det2.push_back(temp1);
  240. }
  241. int U = 2; // Upsampling Factor
  242. std::vector<double> cL0, cH0;
  243. upsamp(appx2, U, cL0);
  244. upsamp(det2, U, cH0);
  245. per_ext(cL0, lf / 2);
  246. per_ext(cH0, lf / 2);
  247. std::vector<double> oup00L, oup00H, oup00;
  248. convfft(cL0, lowPass, oup00L);
  249. convfft(cH0, highPass, oup00H);
  250. oup00L.erase(oup00L.begin(), oup00L.begin() + lf - 1);
  251. oup00L.erase(oup00L.begin() + len, oup00L.end());
  252. oup00H.erase(oup00H.begin(), oup00H.begin() + lf - 1);
  253. oup00H.erase(oup00H.begin() + len, oup00H.end());
  254. vecsum(oup00L, oup00H, oup00);
  255. // Shift = 1
  256. std::vector<double> appx3, det3;
  257. for (std::size_t i = 1; i < len; i += 2)
  258. {
  259. double temp = appx1[i];
  260. appx3.push_back(temp);
  261. double temp1 = det1[i];
  262. det3.push_back(temp1);
  263. }
  264. std::vector<double> cL1, cH1;
  265. upsamp(appx3, U, cL1);
  266. upsamp(det3, U, cH1);
  267. per_ext(cL1, lf / 2);
  268. per_ext(cH1, lf / 2);
  269. std::vector<double> oup01L, oup01H, oup01;
  270. convfft(cL1, lowPass, oup01L);
  271. convfft(cH1, highPass, oup01H);
  272. oup01L.erase(oup01L.begin(), oup01L.begin() + lf - 1);
  273. oup01L.erase(oup01L.begin() + len, oup01L.end());
  274. oup01H.erase(oup01H.begin(), oup01H.begin() + lf - 1);
  275. oup01H.erase(oup01H.begin() + len, oup01H.end());
  276. vecsum(oup01L, oup01H, oup01);
  277. circshift(oup01, -1);
  278. // Continue
  279. std::size_t index2 = 0;
  280. for (std::size_t index = count; index < n; index += value)
  281. {
  282. double temp = oup00[index2] + oup01[index2];
  283. iswtOutput.at(index) = temp / 2;
  284. index2++;
  285. }
  286. }
  287. appxSig = iswtOutput;
  288. }
  289. return nullptr;
  290. }
  291. void* swt(std::vector<double>& signal1, const int J, const std::string& nm, std::vector<double>& swtOutput, int& length)
  292. {
  293. std::vector<double> lpd, hpd, lpr, hpr;
  294. std::vector<double> sig = signal1;
  295. const std::size_t n = sig.size();
  296. length = int(n);
  297. filtcoef(nm, lpd, hpd, lpr, hpr);
  298. for (std::size_t iter = 0; iter < std::size_t(J); ++iter)
  299. {
  300. std::vector<double> lowPass;
  301. std::vector<double> highPass;
  302. if (iter > 0)
  303. {
  304. const int m = int(pow(2.0, iter));
  305. upsamp(lpd, m, lowPass);
  306. upsamp(hpd, m, highPass);
  307. }
  308. else
  309. {
  310. lowPass = lpd;
  311. highPass = hpd;
  312. }
  313. const std::size_t lenFilt = lowPass.size();
  314. per_ext(sig, int(lenFilt / 2));
  315. std::vector<double> cA;
  316. convfft(sig, lowPass, cA);
  317. std::vector<double> cD;
  318. convfft(sig, highPass, cD);
  319. // Resize cA and cD
  320. cA.erase(cA.begin(), cA.begin() + lenFilt);
  321. cA.erase(cA.begin() + n, cA.end());
  322. cD.erase(cD.begin(), cD.begin() + lenFilt);
  323. cD.erase(cD.begin() + n, cD.end());
  324. // Reset signal value;
  325. sig = cA;
  326. if (iter == std::size_t(J - 1))
  327. {
  328. swtOutput.insert(swtOutput.begin(), cD.begin(), cD.end());
  329. swtOutput.insert(swtOutput.begin(), cA.begin(), cA.end());
  330. }
  331. else { swtOutput.insert(swtOutput.begin(), cD.begin(), cD.end()); }
  332. }
  333. return nullptr;
  334. }
  335. void* DwtOutputDimSym(std::vector<std::size_t>& length, std::vector<std::size_t>& length2, const int J)
  336. {
  337. const std::size_t sz = length.size();
  338. std::size_t rows = length[sz - 2];
  339. std::size_t cols = length[sz - 1];
  340. for (std::size_t i = 0; i < std::size_t(J); ++i)
  341. {
  342. rows = std::size_t(ceil(double(rows) / 2.0));
  343. cols = std::size_t(ceil(double(cols) / 2.0));
  344. }
  345. for (std::size_t i = 0; i < std::size_t(J + 1); ++i)
  346. {
  347. length2.push_back(rows);
  348. length2.push_back(cols);
  349. rows = rows * 2;
  350. cols = cols * 2;
  351. }
  352. return nullptr;
  353. }
  354. void* dwt_output_dim2(std::vector<std::size_t>& length, std::vector<std::size_t>& length2, const int j)
  355. {
  356. std::size_t row = length[0];
  357. std::size_t col = length[1];
  358. for (std::size_t i = 0; i < std::size_t(j + 1); ++i)
  359. {
  360. length2.push_back(row);
  361. length2.push_back(col);
  362. row = row * 2;
  363. col = col * 2;
  364. }
  365. return nullptr;
  366. }
  367. void* dispDWT(std::vector<double>& output, std::vector<std::vector<double>>& dwtdisp, std::vector<std::size_t>& length, std::vector<std::size_t>& length2, const int J)
  368. {
  369. std::size_t sum = 0;
  370. for (std::size_t it = 0; it < std::size_t(J); ++it)
  371. {
  372. const int dRows = int(length[2 * it] - length2[2 * it]);
  373. const int dCols = int(length[2 * it + 1] - length2[2 * it + 1]);
  374. const std::size_t nRows = length[2 * it];
  375. const std::size_t nCols = length[2 * it + 1];
  376. std::vector<std::vector<double>> oDwt(2 * nRows, std::vector<double>(2 * nCols));
  377. if (it == 0)
  378. {
  379. for (std::size_t i = 0; i < nRows; ++i) { for (std::size_t j = 0; j < nCols; ++j) { oDwt[i][j] = output[i * nCols + j]; } }
  380. for (std::size_t i = 0; i < nRows; ++i)
  381. {
  382. for (std::size_t j = nCols; j < nCols * 2; ++j) { oDwt[i][j] = output[nRows * nCols + i * nCols + (j - nCols)]; }
  383. }
  384. for (std::size_t i = nRows; i < nRows * 2; ++i)
  385. {
  386. for (std::size_t j = 0; j < nCols; ++j) { oDwt[i][j] = output[2 * nRows * nCols + (i - nRows) * nCols + j]; }
  387. }
  388. for (std::size_t i = nRows; i < nRows * 2; ++i)
  389. {
  390. for (std::size_t j = nCols; j < nCols * 2; ++j) { oDwt[i][j] = output[3 * nRows * nCols + (i - nRows) * nCols + (j - nCols)]; }
  391. }
  392. }
  393. else
  394. {
  395. for (std::size_t i = 0; i < nRows; ++i) { for (std::size_t j = nCols; j < nCols * 2; ++j) { oDwt[i][j] = output[sum + i * nCols + (j - nCols)]; } }
  396. for (std::size_t i = nRows; i < nRows * 2; ++i)
  397. {
  398. for (std::size_t j = 0; j < nCols; ++j) { oDwt[i][j] = output[sum + nRows * nCols + (i - nRows) * nCols + j]; }
  399. }
  400. for (std::size_t i = nRows; i < nRows * 2; ++i)
  401. {
  402. for (std::size_t j = nCols; j < nCols * 2; ++j) { oDwt[i][j] = output[sum + 2 * nRows * nCols + (i - nRows) * nCols + (j - nCols)]; }
  403. }
  404. }
  405. const std::size_t rowsX = length2[2 * it];
  406. const std::size_t colsX = length2[2 * it + 1];
  407. const int dCols2 = int(ceil(double(dCols - 1) / 2.0));
  408. const int dRows2 = int(ceil(double(dRows - 1) / 2.0));
  409. if (it == 0)
  410. {
  411. for (std::size_t i = 0; i < rowsX; ++i)
  412. {
  413. for (std::size_t j = 0; j < colsX; ++j)
  414. {
  415. if (i + dRows - 1 < 0) { dwtdisp[i][j] = 0; }
  416. else if (j + dCols - 1 < 0) { dwtdisp[i][j] = 0; }
  417. else { dwtdisp[i][j] = oDwt[i + dRows - 1][j + dCols - 1]; }
  418. }
  419. }
  420. }
  421. for (std::size_t i = 0; i < rowsX; ++i)
  422. {
  423. for (std::size_t j = colsX; j < colsX * 2; ++j)
  424. {
  425. if (i + dRows2 < 0) { dwtdisp[i][j] = 0; }
  426. else if (int(j + 2 * (dCols - 1) + 1) > signed(oDwt[0].size()) - 1) { dwtdisp[i][j] = 0; }
  427. else { dwtdisp[i][j] = oDwt[i + dRows2][j + 2 * (dCols - 1) + 1]; }
  428. }
  429. }
  430. for (std::size_t i = rowsX; i < rowsX * 2; ++i)
  431. {
  432. for (std::size_t j = 0; j < colsX; ++j)
  433. {
  434. if (int(i + 2 * (dRows - 1) + 1) > signed(oDwt.size()) - 1) { dwtdisp[i][j] = 0; }
  435. else if (j + dCols2 < 0) { dwtdisp[i][j] = 0; }
  436. else { dwtdisp[i][j] = oDwt[i + 2 * (dRows - 1) + 1][j + dCols2]; }
  437. }
  438. }
  439. for (std::size_t i = rowsX; i < rowsX * 2; ++i)
  440. {
  441. for (std::size_t j = colsX; j < colsX * 2; ++j)
  442. {
  443. if (int(i + (dRows - 1) + 1 + dRows2) > signed(oDwt.size()) - 1) { dwtdisp[i][j] = 0; }
  444. else if (int(j + (dCols - 1) + 1 + dCols2) > signed(oDwt[0].size()) - 1) { dwtdisp[i][j] = 0; }
  445. else { dwtdisp[i][j] = oDwt[i + (dRows - 1) + 1 + dRows2][j + (dCols - 1) + 1 + dCols2]; }
  446. }
  447. }
  448. if (it == 0) { sum += 4 * nRows * nCols; }
  449. else { sum += 3 * nRows * nCols; }
  450. }
  451. return nullptr;
  452. }
  453. void symm_ext2d(std::vector<std::vector<double>>& signal, std::vector<std::vector<double>>& temp2, const int a)
  454. {
  455. const std::size_t rows = signal.size();
  456. const std::size_t cols = signal[0].size();
  457. std::vector<std::vector<double>> tempVec(rows, std::vector<double>(cols + 2 * a));
  458. for (std::size_t i = 0; i < rows; ++i)
  459. {
  460. std::vector<double> sig;
  461. for (std::size_t j = 0; j < cols; ++j)
  462. {
  463. double temp = signal[i][j];
  464. sig.push_back(temp);
  465. }
  466. symm_ext(sig, a);
  467. for (std::size_t j = 0; j < sig.size(); ++j) { tempVec[i][j] = sig[j]; }
  468. }
  469. for (std::size_t j = 0; j < tempVec[0].size(); ++j)
  470. {
  471. std::vector<double> sig;
  472. for (std::size_t i = 0; i < rows; ++i)
  473. {
  474. double temp = tempVec[i][j];
  475. sig.push_back(temp);
  476. }
  477. symm_ext(sig, a);
  478. for (std::size_t i = 0; i < sig.size(); ++i) { temp2[i][j] = sig[i]; }
  479. }
  480. }
  481. void* circshift2d(std::vector<std::vector<double>>& signal, const int x, const int y)
  482. {
  483. const std::size_t rows = signal.size();
  484. const std::size_t cols = signal[0].size();
  485. std::vector<std::vector<double>> tempVec(rows, std::vector<double>(cols));
  486. for (std::size_t i = 0; i < rows; ++i)
  487. {
  488. std::vector<double> sig;
  489. for (std::size_t j = 0; j < cols; ++j)
  490. {
  491. double temp = signal[i][j];
  492. sig.push_back(temp);
  493. }
  494. circshift(sig, x);
  495. for (std::size_t j = 0; j < cols; ++j) { tempVec[i][j] = sig[j]; }
  496. }
  497. for (std::size_t j = 0; j < cols; ++j)
  498. {
  499. std::vector<double> sig;
  500. for (std::size_t i = 0; i < rows; ++i)
  501. {
  502. double temp = tempVec[i][j];
  503. sig.push_back(temp);
  504. }
  505. circshift(sig, y);
  506. for (std::size_t i = 0; i < rows; ++i) { signal[i][j] = sig[i]; }
  507. }
  508. return nullptr;
  509. }
  510. void* idwt_2d_sym(std::vector<double>& dwtop, std::vector<double>& flag, const std::string& nm, std::vector<std::vector<double>>& idwtOutput, std::vector<std::size_t>& length)
  511. {
  512. int J = int(flag[0]);
  513. std::size_t rows = length[0];
  514. std::size_t cols = length[1];
  515. std::size_t sumCoef = 0;
  516. std::vector<double> lp1, hp1, lp2, hp2;
  517. filtcoef(nm, lp1, hp1, lp2, hp2);
  518. std::size_t lf = lp1.size();
  519. std::vector<std::vector<double>> cLL(rows, std::vector<double>(cols));
  520. for (std::size_t it = 0; it < std::size_t(J); ++it)
  521. {
  522. std::size_t nRows = length[2 * it];
  523. std::size_t nCols = length[2 * it + 1];
  524. std::vector<std::vector<double>> cLH(nRows, std::vector<double>(nCols));
  525. std::vector<std::vector<double>> cHL(nRows, std::vector<double>(nCols));
  526. std::vector<std::vector<double>> cHH(nRows, std::vector<double>(nCols));
  527. for (std::size_t i = 0; i < nRows; ++i)
  528. {
  529. for (std::size_t j = 0; j < nCols; ++j)
  530. {
  531. if (it == 0)
  532. {
  533. cLL[i][j] = dwtop[sumCoef + i * nCols + j];
  534. cLH[i][j] = dwtop[sumCoef + nRows * nCols + i * nCols + j];
  535. cHL[i][j] = dwtop[sumCoef + 2 * nRows * nCols + i * nCols + j];
  536. cHH[i][j] = dwtop[sumCoef + 3 * nRows * nCols + i * nCols + j];
  537. }
  538. else
  539. {
  540. cLH[i][j] = dwtop[sumCoef + i * nCols + j];
  541. cHL[i][j] = dwtop[sumCoef + nRows * nCols + i * nCols + j];
  542. cHH[i][j] = dwtop[sumCoef + 2 * nRows * nCols + i * nCols + j];
  543. }
  544. }
  545. }
  546. // temp_A = cLL;
  547. // idwt2_sym(nm,idwtOutput2, cA, cH,cV,cD);
  548. std::size_t lenX = cLH.size();
  549. std::size_t lenY = cLH[0].size();
  550. // Row Upsampling and Column Filtering at the first LP Stage
  551. std::vector<std::vector<double>> cL(2 * lenX - lf + 2, std::vector<double>(lenY));
  552. std::vector<std::vector<double>> cH(2 * lenX - lf + 2, std::vector<double>(lenY));
  553. if (it == 0)
  554. {
  555. for (std::size_t j = 0; j < lenY; ++j)
  556. {
  557. std::vector<double> sigLL, sigLH, oup;
  558. for (std::size_t i = 0; i < lenX; ++i)
  559. {
  560. double temp1 = cLL[i][j];
  561. double temp2 = cLH[i][j];
  562. sigLL.push_back(temp1);
  563. sigLH.push_back(temp2);
  564. }
  565. idwt1_sym_m(nm, oup, sigLL, sigLH);
  566. for (std::size_t i = 0; i < oup.size(); ++i) { cL[i][j] = oup[i]; }
  567. }
  568. }
  569. else
  570. {
  571. std::size_t rows1 = cLH.size();
  572. std::size_t cols1 = cLH[0].size();
  573. for (std::size_t j = 0; j < cols1; ++j)
  574. {
  575. std::vector<double> tempL1, tempL2, oup;
  576. for (std::size_t i = 0; i < rows1; ++i)
  577. {
  578. double temp = cLL[i][j];
  579. tempL1.push_back(temp);
  580. double temp2 = cLH[i][j];
  581. tempL2.push_back(temp2);
  582. }
  583. idwt1_sym_m(nm, oup, tempL1, tempL2);
  584. for (std::size_t i = 0; i < oup.size(); ++i) { cL[i][j] = oup[i]; }
  585. }
  586. }
  587. for (std::size_t j = 0; j < lenY; ++j)
  588. {
  589. std::vector<double> sigHL, sigHH, oup2;
  590. for (std::size_t i = 0; i < lenX; ++i)
  591. {
  592. double temp3 = cHL[i][j];
  593. double temp4 = cHH[i][j];
  594. sigHL.push_back(temp3);
  595. sigHH.push_back(temp4);
  596. }
  597. idwt1_sym_m(nm, oup2, sigHL, sigHH);
  598. for (std::size_t i = 0; i < oup2.size(); ++i) { cH[i][j] = oup2[i]; }
  599. }
  600. std::vector<std::vector<double>> signal(2 * lenX - lf + 2, std::vector<double>(2 * lenY - lf + 2));
  601. for (std::size_t i = 0; i < 2 * lenX - lf + 2; ++i)
  602. {
  603. std::vector<double> sigL, sigH, oup;
  604. for (std::size_t j = 0; j < lenY; ++j)
  605. {
  606. double temp5 = cL[i][j];
  607. double temp6 = cH[i][j];
  608. sigL.push_back(temp5);
  609. sigH.push_back(temp6);
  610. }
  611. idwt1_sym_m(nm, oup, sigL, sigH);
  612. for (std::size_t j = 0; j < oup.size(); ++j) { signal[i][j] = oup[j]; }
  613. }
  614. idwtOutput = signal;
  615. if (it == 0) { sumCoef += 4 * nRows * nCols; }
  616. else { sumCoef += 3 * nRows * nCols; }
  617. cLL = signal;
  618. }
  619. return nullptr;
  620. }
  621. void* dwt2_sym(const std::string& name, std::vector<std::vector<double>>& signal, std::vector<std::vector<double>>& cLL, std::vector<std::vector<double>>& cLH,
  622. std::vector<std::vector<double>>& cHL, std::vector<std::vector<double>>& cHH)
  623. {
  624. //Analysis
  625. const std::size_t rows = signal.size();
  626. std::size_t cols = signal[0].size();
  627. const std::size_t colsLp1 = cLL[0].size();
  628. const std::size_t colsHp1 = cLL[0].size();
  629. std::vector<double> lp1, hp1, lp2, hp2;
  630. filtcoef(name, lp1, hp1, lp2, hp2);
  631. std::vector<std::vector<double>> lpDn1(rows, std::vector<double>(colsLp1));
  632. std::vector<std::vector<double>> hpDn1(rows, std::vector<double>(colsHp1));
  633. // Implementing row filtering and column downsampling in each branch.
  634. for (std::size_t i = 0; i < rows; ++i)
  635. {
  636. std::vector<double> tempRow, oupLp, oupHp;
  637. for (std::size_t j = 0; j < cols; ++j)
  638. {
  639. double temp = signal[i][j];
  640. tempRow.push_back(temp);
  641. }
  642. dwt1_sym_m(name, tempRow, oupLp, oupHp);
  643. for (std::size_t j = 0; j < oupLp.size(); ++j)
  644. {
  645. lpDn1[i][j] = oupLp[j];
  646. hpDn1[i][j] = oupHp[j];
  647. }
  648. }
  649. cols = colsLp1;
  650. // Implementing column filtering and row downsampling in Low Pass branch.
  651. for (std::size_t j = 0; j < cols; ++j)
  652. {
  653. std::vector<double> tempRow3, oupLp, oupHp;
  654. for (std::size_t i = 0; i < rows; ++i)
  655. {
  656. double temp = lpDn1[i][j];
  657. tempRow3.push_back(temp);
  658. }
  659. dwt1_sym_m(name, tempRow3, oupLp, oupHp);
  660. for (std::size_t i = 0; i < oupLp.size(); ++i)
  661. {
  662. cLL[i][j] = oupLp[i];
  663. cLH[i][j] = oupHp[i];
  664. }
  665. }
  666. // Implementing column filtering and row downsampling in High Pass branch.
  667. for (std::size_t j = 0; j < cols; ++j)
  668. {
  669. std::vector<double> tempRow5, oupLp, oupHp;
  670. for (std::size_t i = 0; i < rows; ++i)
  671. {
  672. double temp = hpDn1[i][j];
  673. tempRow5.push_back(temp);
  674. }
  675. dwt1_sym_m(name, tempRow5, oupLp, oupHp);
  676. for (std::size_t i = 0; i < oupLp.size(); ++i)
  677. {
  678. cHL[i][j] = oupLp[i];
  679. cHH[i][j] = oupHp[i];
  680. }
  681. }
  682. return nullptr;
  683. }
  684. void* dwt_2d_sym(std::vector<std::vector<double>>& origsig, const int J, const std::string& nm, std::vector<double>& dwtOutput, std::vector<double>& flag, std::vector<std::size_t>& length)
  685. {
  686. // flag will contain
  687. std::vector<std::vector<double>> sig = origsig;
  688. std::size_t nRows = sig.size(); // No. of rows
  689. std::size_t nCols = sig[0].size(); //No. of columns
  690. std::vector<std::vector<double>> originalCopy = sig;
  691. const int maxIter = std::min(int(ceil(log(double(sig.size())) / log(2.0))), int(ceil(log(double(sig[0].size())) / log(2.0))));
  692. if (maxIter < J)
  693. {
  694. std::cout << J << " Iterations are not possible with signals of this dimension " << std::endl;
  695. exit(1);
  696. }
  697. std::vector<double> lp1, hp1, lp2, hp2;
  698. flag.push_back(double(J));
  699. length.insert(length.begin(), nCols);
  700. length.insert(length.begin(), nRows);
  701. // Flag Values
  702. /*
  703. double temp = (double) (sig2.size() - sig.size()); // Number of zeropad rows
  704. flag.push_back(temp);
  705. double temp2 = (double) (sig2[0].size() - sig[0].size());// Number of zpad cols
  706. flag.push_back(temp2);
  707. flag.push_back((double) J); // Number of Iterations
  708. */
  709. std::size_t sumCoef = 0;
  710. for (std::size_t iter = 0; iter < std::size_t(J); ++iter)
  711. {
  712. filtcoef(nm, lp1, hp1, lp2, hp2);
  713. const std::size_t lf = lp1.size();
  714. nRows = std::size_t(floor(double(nRows + lf - 1) / 2));
  715. nCols = std::size_t(floor(double(nCols + lf - 1) / 2));
  716. length.insert(length.begin(), nCols);
  717. length.insert(length.begin(), nRows);
  718. std::vector<std::vector<double>> cA(nRows, std::vector<double>(nCols));
  719. std::vector<std::vector<double>> cH(nRows, std::vector<double>(nCols));
  720. std::vector<std::vector<double>> cV(nRows, std::vector<double>(nCols));
  721. std::vector<std::vector<double>> cD(nRows, std::vector<double>(nCols));
  722. if (iter == 0) { dwt2_sym(nm, originalCopy, cA, cH, cV, cD); }
  723. else { dwt2_sym(nm, originalCopy, cA, cH, cV, cD); }
  724. std::vector<double> tempSig2;
  725. originalCopy = cA;
  726. if (iter == std::size_t(J - 1))
  727. {
  728. for (std::size_t i = 0; i < nRows; ++i)
  729. {
  730. for (std::size_t j = 0; j < nCols; ++j)
  731. {
  732. double temp = cA[i][j];
  733. tempSig2.push_back(temp);
  734. }
  735. }
  736. }
  737. for (std::size_t i = 0; i < nRows; ++i)
  738. {
  739. for (std::size_t j = nCols; j < nCols * 2; ++j)
  740. {
  741. double temp = cH[i][j - nCols];
  742. tempSig2.push_back(temp);
  743. }
  744. }
  745. for (std::size_t i = nRows; i < nRows * 2; ++i)
  746. {
  747. for (std::size_t j = 0; j < nCols; ++j)
  748. {
  749. double temp = cV[i - nRows][j];
  750. tempSig2.push_back(temp);
  751. }
  752. }
  753. for (std::size_t i = nRows; i < nRows * 2; ++i)
  754. {
  755. for (std::size_t j = nCols; j < nCols * 2; ++j)
  756. {
  757. double temp = cD[i - nRows][j - nCols];
  758. tempSig2.push_back(temp);
  759. }
  760. }
  761. dwtOutput.insert(dwtOutput.begin(), tempSig2.begin(), tempSig2.end());
  762. sumCoef += 4 * nRows * nCols;
  763. }
  764. /*
  765. ofstream dwt2out("dwt2out.dat");
  766. for (std::size_t i= 0; i < dwtOutput.size(); ++i){ dwt2out << dwtOutput[i] <<endl; }
  767. */
  768. return nullptr;
  769. }
  770. void* idwt1_sym(const std::string& wname, std::vector<double>& x, std::vector<double>& app, std::vector<double>& detail)
  771. {
  772. std::vector<double> flag;
  773. std::vector<double> idwtOutput;
  774. std::vector<std::size_t> length;
  775. length[0] = app.size();
  776. length[1] = detail.size();
  777. std::vector<double> dwtop = app;
  778. dwtop.insert(dwtop.end(), detail.begin(), detail.end());
  779. flag.push_back(1);
  780. flag.push_back(0);
  781. idwt_sym(dwtop, flag, wname, idwtOutput, length);
  782. x = idwtOutput;
  783. return nullptr;
  784. }
  785. void* idwt1_sym_m(const std::string& wname, std::vector<double>& x, std::vector<double>& app, std::vector<double>& detail)
  786. {
  787. const int U = 2; // Upsampling Factor
  788. std::vector<double> lpd1, hpd1, lpr1, hpr1;
  789. filtcoef(wname, lpd1, hpd1, lpr1, hpr1);
  790. const std::size_t lf = lpr1.size();
  791. // Operations in the Low Frequency branch of the Synthesis Filter Bank
  792. std::vector<double> xLp, cAUp;
  793. upsamp(app, U, cAUp);
  794. cAUp.pop_back();
  795. convfftm(cAUp, lpr1, xLp);
  796. // Operations in the High Frequency branch of the Synthesis Filter Bank
  797. std::vector<double> xHp, cDUp;
  798. upsamp(detail, U, cDUp);
  799. cDUp.pop_back();
  800. convfftm(cDUp, hpr1, xHp);
  801. vecsum(xLp, xHp, x);
  802. x.erase(x.begin(), x.begin() + lf - 2);
  803. x.erase(x.end() - (lf - 2), x.end());
  804. return nullptr;
  805. }
  806. void* symm_ext(std::vector<double>& sig, const int a)
  807. {
  808. const std::size_t len = sig.size();
  809. for (std::size_t i = 0; i < std::size_t(a); ++i)
  810. {
  811. double temp1 = sig[i * 2];
  812. double temp2 = sig[len - 1];
  813. sig.insert(sig.begin(), temp1);
  814. sig.insert(sig.end(), temp2);
  815. }
  816. return nullptr;
  817. }
  818. void* idwt_sym(std::vector<double>& dwtop, std::vector<double>& flag, const std::string& nm, std::vector<double>& idwtOutput, std::vector<std::size_t>& length)
  819. {
  820. const int J = int(flag[1]);
  821. std::vector<double> app, detail;
  822. std::size_t appLen = length[0], detLen = length[1];
  823. const auto dwt = dwtop.begin();
  824. app.assign(dwt, dwtop.begin() + appLen);
  825. detail.assign(dwtop.begin() + appLen, dwtop.begin() + 2 * appLen);
  826. for (std::size_t i = 0; i < std::size_t(J); ++i)
  827. {
  828. const int U = 2; // Upsampling Factor
  829. std::vector<double> lpd1, hpd1, lpr1, hpr1;
  830. filtcoef(nm, lpd1, hpd1, lpr1, hpr1);
  831. const std::size_t lf = lpr1.size();
  832. // Operations in the Low Frequency branch of the Synthesis Filter Bank
  833. std::vector<double> xLp, cAUp;
  834. upsamp(app, U, cAUp);
  835. cAUp.pop_back();
  836. convfft(cAUp, lpr1, xLp);
  837. // Operations in the High Frequency branch of the Synthesis Filter Bank
  838. std::vector<double> xHp;
  839. std::vector<double> cDUp;
  840. upsamp(detail, U, cDUp);
  841. cDUp.pop_back();
  842. convfft(cDUp, hpr1, xHp);
  843. appLen += detLen;
  844. vecsum(xLp, xHp, idwtOutput);
  845. idwtOutput.erase(idwtOutput.begin(), idwtOutput.begin() + lf - 2);
  846. idwtOutput.erase(idwtOutput.end() - (lf - 2), idwtOutput.end());
  847. app.clear();
  848. detail.clear();
  849. if (i < std::size_t(J - 1))
  850. {
  851. detLen = length[i + 2];
  852. // detail.assign(dwtop.begin()+app_len, dwtop.begin()+ det_len);
  853. for (std::size_t l = 0; l < detLen; ++l)
  854. {
  855. double temp = dwtop[appLen + l];
  856. detail.push_back(temp);
  857. }
  858. }
  859. app = idwtOutput;
  860. for (std::size_t iter1 = 0; iter1 < app.size() - detLen; iter1++) { app.pop_back(); }
  861. }
  862. // Remove ZeroPadding
  863. const int zerop = int(flag[0]);
  864. idwtOutput.erase(idwtOutput.end() - zerop, idwtOutput.end());
  865. return nullptr;
  866. }
  867. void* dwt1_sym(const std::string& wname, std::vector<double>& signal, std::vector<double>& cA, std::vector<double>& cD)
  868. {
  869. std::vector<double> lp1, hp1, lp2, hp2;
  870. filtcoef(wname, lp1, hp1, lp2, hp2);
  871. const int d = 2; // Downsampling Factor is 2
  872. const int lf = int(lp1.size());
  873. symm_ext(signal, lf - 1);
  874. std::vector<double> cAUndec;
  875. //sig value
  876. convfft(signal, lp1, cAUndec);
  877. cAUndec.erase(cAUndec.begin(), cAUndec.begin() + lf);
  878. cAUndec.erase(cAUndec.end() - lf + 1, cAUndec.end());
  879. downsamp(cAUndec, d, cA);
  880. // cA.erase(cA.begin(),cA.begin()+(int) ceil(((double)lf-1.0)/2.0));
  881. // cA.erase(cA.end()-(int) ceil(((double)lf-1.0)/2.0),cA.end());
  882. //High Pass Branch Computation
  883. std::vector<double> cDUndec;
  884. convfft(signal, hp1, cDUndec);
  885. cDUndec.erase(cDUndec.begin(), cDUndec.begin() + lf);
  886. cDUndec.erase(cDUndec.end() - lf + 1, cDUndec.end());
  887. downsamp(cDUndec, d, cD);
  888. // cD.erase(cD.begin(),cD.begin()+(int) ceil(((double)lf-1.0)/2.0));
  889. // cD.erase(cD.end()-(int) ceil(((double)lf-1.0)/2.0),cD.end());
  890. filtcoef(wname, lp1, hp1, lp2, hp2);
  891. return nullptr;
  892. }
  893. void* dwt1_sym_m(const std::string& wname, std::vector<double>& signal, std::vector<double>& cA, std::vector<double>& cD)
  894. {
  895. std::vector<double> lp1, hp1, lp2, hp2;
  896. filtcoef(wname, lp1, hp1, lp2, hp2);
  897. const int d = 2; // Downsampling Factor is 2
  898. const int lf = int(lp1.size());
  899. symm_ext(signal, lf - 1);
  900. std::vector<double> cAUndec;
  901. //sig value
  902. convfftm(signal, lp1, cAUndec);
  903. cAUndec.erase(cAUndec.begin(), cAUndec.begin() + lf);
  904. cAUndec.erase(cAUndec.end() - lf + 1, cAUndec.end());
  905. downsamp(cAUndec, d, cA);
  906. // cA.erase(cA.begin(),cA.begin()+(int) ceil(((double)lf-1.0)/2.0));
  907. // cA.erase(cA.end()-(int) ceil(((double)lf-1.0)/2.0),cA.end());
  908. //High Pass Branch Computation
  909. std::vector<double> cDUndec;
  910. convfftm(signal, hp1, cDUndec);
  911. cDUndec.erase(cDUndec.begin(), cDUndec.begin() + lf);
  912. cDUndec.erase(cDUndec.end() - lf + 1, cDUndec.end());
  913. downsamp(cDUndec, d, cD);
  914. // cD.erase(cD.begin(),cD.begin()+(int) ceil(((double)lf-1.0)/2.0));
  915. // cD.erase(cD.end()-(int) ceil(((double)lf-1.0)/2.0),cD.end());
  916. filtcoef(wname, lp1, hp1, lp2, hp2);
  917. return nullptr;
  918. }
  919. void* dwt_sym(std::vector<double>& signal, const int J, const std::string& nm, std::vector<double>& dwtOutput, std::vector<double>& flag, std::vector<std::size_t>& length)
  920. {
  921. std::size_t tempLen = signal.size();
  922. if ((tempLen % 2) != 0)
  923. {
  924. const double temp = signal[tempLen - 1];
  925. signal.push_back(temp);
  926. flag.push_back(1);
  927. tempLen++;
  928. }
  929. else { flag.push_back(0); }
  930. length.push_back(tempLen);
  931. flag.push_back(double(J));
  932. // flag[2] contains symmetric extension length
  933. std::vector<double> appxSig, detSig;
  934. const std::vector<double> originalCopy = signal;
  935. // Storing Filter Values for GnuPlot
  936. std::vector<double> lp1, hp1, lp2, hp2;
  937. filtcoef(nm, lp1, hp1, lp2, hp2);
  938. for (std::size_t iter = 0; iter < std::size_t(J); ++iter)
  939. {
  940. dwt1_sym(nm, signal, appxSig, detSig);
  941. dwtOutput.insert(dwtOutput.begin(), detSig.begin(), detSig.end());
  942. std::size_t temp = detSig.size();
  943. length.insert(length.begin(), temp);
  944. if (iter == std::size_t(J - 1))
  945. {
  946. dwtOutput.insert(dwtOutput.begin(), appxSig.begin(), appxSig.end());
  947. length.insert(length.begin(), appxSig.size());
  948. }
  949. signal.clear();
  950. signal = appxSig;
  951. appxSig.clear();
  952. detSig.clear();
  953. }
  954. signal = originalCopy;
  955. return nullptr;
  956. }
  957. void* freq(std::vector<double>& sig, std::vector<double>& freqResp)
  958. {
  959. const std::size_t k = sig.size();
  960. const std::size_t n = std::size_t(pow(2.0, ceil(log10(double(k)) / log10(2.0))));
  961. std::vector<std::complex<double>> fftOup;
  962. for (std::size_t i = 0; i < sig.size(); ++i)
  963. {
  964. double temp = sig[i];
  965. fftOup.push_back(std::complex<double>(temp, 0));
  966. }
  967. fft(fftOup, 1, n);
  968. for (std::size_t i = 0; i < n; ++i)
  969. {
  970. double temp = abs(fftOup[i]);
  971. freqResp.push_back(temp);
  972. }
  973. circshift(freqResp, int(n) / 2);
  974. return nullptr;
  975. }
  976. double convfft(std::vector<double>& a, std::vector<double>& b, std::vector<double>& c)
  977. {
  978. const std::size_t sz = a.size() + b.size() - 1;
  979. fftw_complex* inpData = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  980. fftw_complex* filtData = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  981. fftw_complex* inpFFT = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  982. fftw_complex* filtFFT = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  983. fftw_complex* tempData = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  984. fftw_complex* tempIfft = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  985. fftw_plan plan_forward_inp = fftw_plan_dft_1d(int(sz), inpData, inpFFT, FFTW_FORWARD, FFTW_ESTIMATE);
  986. fftw_plan plan_forward_filt = fftw_plan_dft_1d(int(sz), filtData, filtFFT, FFTW_FORWARD, FFTW_ESTIMATE);
  987. fftw_plan plan_backward = fftw_plan_dft_1d(int(sz), tempData, tempIfft, FFTW_BACKWARD, FFTW_ESTIMATE);
  988. for (std::size_t i = 0; i < sz; ++i)
  989. {
  990. if (i < a.size()) { inpData[i][0] = a[i]; }
  991. else { inpData[i][0] = 0.0; }
  992. inpData[i][1] = 0.0;
  993. if (i < b.size()) { filtData[i][0] = b[i]; }
  994. else { filtData[i][0] = 0.0; }
  995. filtData[i][1] = 0.0;
  996. }
  997. fftw_execute(plan_forward_inp);
  998. fftw_execute(plan_forward_filt);
  999. for (std::size_t i = 0; i < sz; ++i)
  1000. {
  1001. tempData[i][0] = inpFFT[i][0] * filtFFT[i][0] - inpFFT[i][1] * filtFFT[i][1];
  1002. tempData[i][1] = inpFFT[i][0] * filtFFT[i][1] + inpFFT[i][1] * filtFFT[i][0];
  1003. }
  1004. fftw_execute(plan_backward);
  1005. for (std::size_t i = 0; i < sz; ++i)
  1006. {
  1007. double temp1;
  1008. temp1 = tempIfft[i][0] / double(sz);
  1009. c.push_back(temp1);
  1010. }
  1011. fftw_free(inpData);
  1012. fftw_free(filtData);
  1013. fftw_free(inpFFT);
  1014. fftw_free(filtFFT);
  1015. fftw_free(tempData);
  1016. fftw_free(tempIfft);
  1017. fftw_destroy_plan(plan_forward_inp);
  1018. fftw_destroy_plan(plan_forward_filt);
  1019. fftw_destroy_plan(plan_backward);
  1020. return 0;
  1021. }
  1022. double convfftm(std::vector<double>& a, std::vector<double>& b, std::vector<double>& c)
  1023. {
  1024. const std::size_t sz = a.size() + b.size() - 1;
  1025. fftw_complex* inpData = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  1026. fftw_complex* filtData = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  1027. fftw_complex* inpFFT = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  1028. fftw_complex* filtFFT = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  1029. fftw_complex* tempData = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  1030. fftw_complex* tempIfft = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * sz));
  1031. if (sz != fftTransientSize)
  1032. {
  1033. if (fftTransientSize != 0)
  1034. {
  1035. fftw_destroy_plan(plan_forward_inp);
  1036. fftw_destroy_plan(plan_forward_filt);
  1037. fftw_destroy_plan(plan_backward);
  1038. }
  1039. plan_forward_inp = fftw_plan_dft_1d(int(sz), inpData, inpFFT, FFTW_FORWARD, FFTW_MEASURE);
  1040. plan_forward_filt = fftw_plan_dft_1d(int(sz), filtData, filtFFT, FFTW_FORWARD, FFTW_MEASURE);
  1041. plan_backward = fftw_plan_dft_1d(int(sz), tempData, tempIfft, FFTW_BACKWARD, FFTW_MEASURE);
  1042. fftTransientSize = sz;
  1043. }
  1044. for (std::size_t i = 0; i < sz; ++i)
  1045. {
  1046. if (i < a.size()) { inpData[i][0] = a[i]; }
  1047. else { inpData[i][0] = 0.0; }
  1048. inpData[i][1] = 0.0;
  1049. if (i < b.size()) { filtData[i][0] = b[i]; }
  1050. else { filtData[i][0] = 0.0; }
  1051. filtData[i][1] = 0.0;
  1052. }
  1053. fftw_execute_dft(plan_forward_inp, inpData, inpFFT);
  1054. fftw_execute_dft(plan_forward_filt, filtData, filtFFT);
  1055. for (std::size_t i = 0; i < sz; ++i)
  1056. {
  1057. tempData[i][0] = inpFFT[i][0] * filtFFT[i][0] - inpFFT[i][1] * filtFFT[i][1];
  1058. tempData[i][1] = inpFFT[i][0] * filtFFT[i][1] + inpFFT[i][1] * filtFFT[i][0];
  1059. }
  1060. fftw_execute_dft(plan_backward, tempData, tempIfft);
  1061. for (std::size_t i = 0; i < sz; ++i)
  1062. {
  1063. double temp1;
  1064. temp1 = tempIfft[i][0] / double(sz);
  1065. c.push_back(temp1);
  1066. }
  1067. fftw_free(inpData);
  1068. fftw_free(filtData);
  1069. fftw_free(inpFFT);
  1070. fftw_free(filtFFT);
  1071. fftw_free(tempData);
  1072. fftw_free(tempIfft);
  1073. return 0;
  1074. }
  1075. void* fft(std::vector<std::complex<double>>& data, const int sign, std::size_t n)
  1076. {
  1077. double pi = - 3.14159265358979;
  1078. if (sign == 1 || sign == -1) { pi = sign * pi; }
  1079. else
  1080. {
  1081. std::cout << "Format fft(data, num), num = +1(fft) and num = -1 (Ifft)" << std::endl;
  1082. exit(1);
  1083. }
  1084. const std::size_t len = data.size();
  1085. const auto it = data.end();
  1086. if (len != n)
  1087. {
  1088. const std::size_t al = n - len;
  1089. data.insert(it, al, std::complex<double>(0, 0));
  1090. }
  1091. const std::size_t k = std::size_t(pow(2.0, ceil(log10(double(n)) / log10(2.0))));
  1092. const auto it1 = data.end();
  1093. if (n < k)
  1094. {
  1095. const std::size_t al = k - n;
  1096. data.insert(it1, al, std::complex<double>(0, 0));
  1097. n = k;
  1098. }
  1099. bitreverse(data);
  1100. // radix2(data);
  1101. for (std::size_t iter = 1; iter < n; iter <<= 1)
  1102. {
  1103. const std::size_t step = iter << 1;
  1104. const double theta = pi / double(iter);
  1105. double wtemp = sin(theta * .5);
  1106. // Multipliers
  1107. const double wreal = -2 * wtemp * wtemp;
  1108. const double wimag = sin(theta);
  1109. // Factors
  1110. double wr = 1.0;
  1111. double wi = 0.0;
  1112. // Iteration through two loops
  1113. for (std::size_t m = 0; m < iter; ++m)
  1114. {
  1115. // Iteration within m
  1116. for (std::size_t i = m; i < n; i += step)
  1117. {
  1118. // jth position
  1119. const std::size_t j = i + iter;
  1120. double tempr = wr * std::real(data[j]) - wi * std::imag(data[j]);
  1121. double tempi = wr * std::imag(data[j]) + wi * std::real(data[j]);
  1122. std::complex<double> temp(tempr, tempi);
  1123. data[j] = data[i] - temp;
  1124. data[i] += temp;
  1125. }
  1126. // Twiddle Factors updated
  1127. wtemp = wr;
  1128. wr += wr * wreal - wi * wimag;
  1129. wi += wi * wreal + wtemp * wimag;
  1130. }
  1131. }
  1132. if (sign == -1)
  1133. {
  1134. const double scale = 1.0 / double(n);
  1135. for (std::size_t i = 0; i < n; ++i) { data[i] *= scale; }
  1136. }
  1137. // Place holder
  1138. return nullptr;
  1139. }
  1140. void* bitreverse(std::vector<std::complex<double>>& sig)
  1141. {
  1142. const std::size_t len = sig.size();
  1143. const std::size_t n = std::size_t(pow(2.0, ceil(log10(double(len)) / log10(2.0))));
  1144. std::size_t rev = 0;
  1145. // Processing Input Data
  1146. for (std::size_t iter = 0; iter < n; ++iter)
  1147. {
  1148. if (rev > iter)
  1149. {
  1150. // Replacing current values with reversed values
  1151. double tempr = std::real(sig[rev]);
  1152. double tempi = std::imag(sig[rev]);
  1153. const std::complex<double> temp(tempr, tempi);
  1154. sig[rev] = sig[iter];
  1155. sig[iter] = temp;
  1156. }
  1157. // Using filter "filt" such that the value of reverse changes with each iteration
  1158. std::size_t filt = n;
  1159. while (rev & (filt >>= 1)) { rev &= ~filt; }
  1160. rev |= filt;
  1161. }
  1162. return nullptr;
  1163. }
  1164. void* dwt(std::vector<double>& sig, int j, const std::string& nm, std::vector<double>& dwtOutput, std::vector<double>& flag, std::vector<std::size_t>& length)
  1165. {
  1166. const int maxIter = int(ceil(log(double(sig.size())) / log(2.0))) - 2;
  1167. if (maxIter < j) { j = maxIter; }
  1168. std::vector<double> appxSig, detSig;
  1169. const std::vector<double> originalCopy = sig;
  1170. // Zero Pad the Signal to nearest 2^ M value ,where M is an integer.
  1171. std::size_t tempLen = sig.size();
  1172. if ((tempLen % 2) != 0)
  1173. {
  1174. const double temp = sig[tempLen - 1];
  1175. sig.push_back(temp);
  1176. flag.push_back(1);
  1177. tempLen++;
  1178. }
  1179. else { flag.push_back(0); }
  1180. length.push_back(tempLen);
  1181. flag.push_back(double(j));
  1182. std::vector<double> orig = sig;
  1183. // Storing Filter Values for GnuPlot
  1184. std::vector<double> lp1, hp1, lp2, hp2;
  1185. filtcoef(nm, lp1, hp1, lp2, hp2);
  1186. for (std::size_t iter = 0; iter < std::size_t(j); ++iter)
  1187. {
  1188. dwt1(nm, orig, appxSig, detSig);
  1189. dwtOutput.insert(dwtOutput.begin(), detSig.begin(), detSig.end());
  1190. const int temp = detSig.size();
  1191. length.insert(length.begin(), temp);
  1192. if (iter == std::size_t(j - 1))
  1193. {
  1194. dwtOutput.insert(dwtOutput.begin(), appxSig.begin(), appxSig.end());
  1195. std::size_t temp2 = appxSig.size();
  1196. length.insert(length.begin(), temp2);
  1197. }
  1198. orig = appxSig;
  1199. appxSig.clear();
  1200. detSig.clear();
  1201. }
  1202. sig = originalCopy;
  1203. return nullptr;
  1204. }
  1205. void circshift(std::vector<double>& sigCir, int l)
  1206. {
  1207. if (abs(l) > int(sigCir.size())) { l = sign(l) * int(abs(l) % sigCir.size()); }
  1208. if (l < 0)
  1209. {
  1210. l = int((sigCir.size() + l) % sigCir.size());
  1211. // std::cout << "L" << L << std::endl;
  1212. }
  1213. for (std::size_t i = 0; i < std::size_t(l); ++i)
  1214. {
  1215. sigCir.push_back(sigCir[0]);
  1216. sigCir.erase(sigCir.begin());
  1217. }
  1218. }
  1219. double convol(std::vector<double>& a1, std::vector<double>& b1, std::vector<double>& c)
  1220. {
  1221. const std::size_t lenC = a1.size() + b1.size() - 1;
  1222. std::vector<double> a = a1;
  1223. std::vector<double> b = b1;
  1224. std::vector<double> oup(lenC);
  1225. const auto itA = a.end();
  1226. const double al = double(lenC - a.size());
  1227. a.insert(itA, al, 0);
  1228. const auto itB = b.end();
  1229. const double bl = double(lenC - b.size());
  1230. b.insert(itB, bl, 0);
  1231. for (std::size_t ini = 0; ini < lenC; ++ini)
  1232. {
  1233. oup[ini] = 0;
  1234. double temp = 0;
  1235. for (std::size_t jni = 0; jni <= ini; ++jni)
  1236. {
  1237. const double ou1 = a[jni] * b[ini - jni];
  1238. oup[ini] += ou1;
  1239. }
  1240. temp = oup[ini];
  1241. c.push_back(temp);
  1242. }
  1243. oup.clear();
  1244. return 0;
  1245. }
  1246. void downsamp(std::vector<double>& sig, const int m, std::vector<double>& sigD)
  1247. {
  1248. const std::size_t len = sig.size();
  1249. const std::size_t n = std::size_t(ceil(double(len) / double(m)));
  1250. for (std::size_t i = 0; i < n; ++i)
  1251. {
  1252. double temp = sig[i * m];
  1253. sigD.push_back(temp);
  1254. }
  1255. }
  1256. void* dwt1(const std::string& wname, std::vector<double>& signal, std::vector<double>& cA, std::vector<double>& cD)
  1257. {
  1258. std::vector<double> lpd, hpd, lpr, hpr;
  1259. filtcoef(wname, lpd, hpd, lpr, hpr);
  1260. const std::size_t lenLpfilt = lpd.size();
  1261. const std::size_t lenHpfilt = hpd.size();
  1262. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1263. const std::size_t lenSig = 2 * std::size_t(ceil(double(signal.size()) / 2.0));
  1264. // std::cout << lenLpfilt << "Filter" << std::endl;
  1265. per_ext(signal, int(lenAvg / 2)); // Periodic Extension
  1266. // computations designed to deal with boundary distortions
  1267. // Low Pass Filtering Operations in the Analysis Filter Bank Section
  1268. // int len_cA =(int) floor(double (len_sig + lenLpfilt -1) / double (2));
  1269. std::vector<double> cAUndec;
  1270. // convolving signal with lpd, Low Pass Filter, and O/P is stored in cA_undec
  1271. convfft(signal, lpd, cAUndec);
  1272. const int d = 2; // Downsampling Factor is 2
  1273. cAUndec.erase(cAUndec.begin(), cAUndec.begin() + lenAvg - 1);
  1274. cAUndec.erase(cAUndec.end() - lenAvg + 1, cAUndec.end());
  1275. cAUndec.erase(cAUndec.begin() + lenSig, cAUndec.end());
  1276. cAUndec.erase(cAUndec.begin());
  1277. // Downsampling by 2 gives cA
  1278. downsamp(cAUndec, d, cA);
  1279. // cA.erase(cA.begin(),cA.begin()+len_avg/2);
  1280. // cA.erase(cA.end()-len_avg/2,cA.end());
  1281. // High Pass Filtering Operations in the Analysis Filter Bank Section
  1282. // int len_cA =(int) floor(double (len_sig + lenLpfilt -1) / double (2));
  1283. std::vector<double> cDUndec;
  1284. // convolving signal with lpd, Low Pass Filter, and O/P is stored in cA_undec
  1285. convfft(signal, hpd, cDUndec);
  1286. cDUndec.erase(cDUndec.begin(), cDUndec.begin() + lenAvg - 1);
  1287. cDUndec.erase(cDUndec.end() - lenAvg + 1, cDUndec.end());
  1288. cDUndec.erase(cDUndec.begin() + lenSig, cDUndec.end());
  1289. cDUndec.erase(cDUndec.begin());
  1290. // Downsampling Factor is 2
  1291. // Downsampling by 2 gives cA
  1292. downsamp(cDUndec, d, cD);
  1293. // cD.erase(cD.begin(),cD.begin()+len_avg/2);
  1294. // cD.erase(cD.end()-len_avg/2,cD.end());
  1295. filtcoef(wname, lpd, hpd, lpr, hpr);
  1296. return nullptr;
  1297. }
  1298. void* dwt1_m(const std::string& wname, std::vector<double>& signal, std::vector<double>& cA, std::vector<double>& cD)
  1299. {
  1300. std::vector<double> lpd, hpd, lpr, hpr;
  1301. filtcoef(wname, lpd, hpd, lpr, hpr);
  1302. const std::size_t lenLpfilt = lpd.size();
  1303. const std::size_t lenHpfilt = hpd.size();
  1304. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1305. const std::size_t lenSig = 2 * std::size_t(ceil(double(signal.size()) / 2.0));
  1306. // std::cout << lenLpfilt << "Filter" << std::endl;
  1307. per_ext(signal, int(lenAvg / 2)); // Periodic Extension
  1308. // computations designed to deal with boundary distortions
  1309. // Low Pass Filtering Operations in the Analysis Filter Bank Section
  1310. // int len_cA =(int) floor(double (len_sig + lenLpfilt -1) / double (2));
  1311. std::vector<double> cAUndec;
  1312. // convolving signal with lpd, Low Pass Filter, and O/P is stored in cA_undec
  1313. convfftm(signal, lpd, cAUndec);
  1314. const int d = 2; // Downsampling Factor is 2
  1315. cAUndec.erase(cAUndec.begin(), cAUndec.begin() + lenAvg - 1);
  1316. cAUndec.erase(cAUndec.end() - lenAvg + 1, cAUndec.end());
  1317. cAUndec.erase(cAUndec.begin() + lenSig, cAUndec.end());
  1318. cAUndec.erase(cAUndec.begin());
  1319. // Downsampling by 2 gives cA
  1320. downsamp(cAUndec, d, cA);
  1321. // cA.erase(cA.begin(),cA.begin()+len_avg/2);
  1322. // cA.erase(cA.end()-len_avg/2,cA.end());
  1323. // High Pass Filtering Operations in the Analysis Filter Bank Section
  1324. // int len_cA =(int) floor(double (len_sig + lenLpfilt -1) / double (2));
  1325. std::vector<double> cDUndec;
  1326. // convolving signal with lpd, Low Pass Filter, and O/P is stored in cA_undec
  1327. convfftm(signal, hpd, cDUndec);
  1328. cDUndec.erase(cDUndec.begin(), cDUndec.begin() + lenAvg - 1);
  1329. cDUndec.erase(cDUndec.end() - lenAvg + 1, cDUndec.end());
  1330. cDUndec.erase(cDUndec.begin() + lenSig, cDUndec.end());
  1331. cDUndec.erase(cDUndec.begin());
  1332. // Downsampling Factor is 2
  1333. // Downsampling by 2 gives cA
  1334. downsamp(cDUndec, d, cD);
  1335. // cD.erase(cD.begin(),cD.begin()+len_avg/2);
  1336. // cD.erase(cD.end()-len_avg/2,cD.end());
  1337. filtcoef(wname, lpd, hpd, lpr, hpr);
  1338. return nullptr;
  1339. }
  1340. void* dyadic_zpad_1d(std::vector<double>& signal)
  1341. {
  1342. const std::size_t n = signal.size();
  1343. const double m = log10(double(n)) / log10(2.0);
  1344. const int d = int(ceil(m));
  1345. const double intVal = pow(2.0, double(d)) - pow(2.0, m);
  1346. const int z = int(intVal);
  1347. const auto itA = signal.end();
  1348. const double val = signal[n - 1];
  1349. // double val = 0;
  1350. signal.insert(itA, z, val);
  1351. return nullptr;
  1352. }
  1353. void* idwt(std::vector<double>& dwtop, std::vector<double>& flag, const std::string& nm, std::vector<double>& idwtOutput, std::vector<std::size_t>& length)
  1354. {
  1355. const std::size_t j = std::size_t(flag[1]);
  1356. // int zpad =(int) flag[0];
  1357. std::vector<double> app;
  1358. std::vector<double> detail;
  1359. std::size_t appLen = length[0];
  1360. std::size_t detLen = length[1];
  1361. const auto dwt = dwtop.begin();
  1362. app.assign(dwt, dwtop.begin() + appLen);
  1363. detail.assign(dwtop.begin() + appLen, dwtop.begin() + 2 * appLen);
  1364. for (std::size_t i = 0; i < j; ++i)
  1365. {
  1366. idwt1(nm, idwtOutput, app, detail);
  1367. appLen += detLen;
  1368. app.clear();
  1369. detail.clear();
  1370. if (i < j - 1)
  1371. {
  1372. detLen = length[i + 2];
  1373. for (std::size_t l = 0; l < detLen; ++l)
  1374. {
  1375. double temp = dwtop[appLen + l];
  1376. detail.push_back(temp);
  1377. }
  1378. app = idwtOutput;
  1379. if (app.size() >= detail.size())
  1380. {
  1381. const std::size_t t = app.size() - detail.size();
  1382. const std::size_t lent = std::size_t(floor(double(t) / 2.0));
  1383. app.erase(app.begin() + detail.size() + lent, app.end());
  1384. app.erase(app.begin(), app.begin() + lent);
  1385. }
  1386. }
  1387. //int value1 = (int) ceil(double(app.size() - det_len)/2.0);
  1388. //int value2 = (int) floor(double(app.size() - det_len)/2.0);
  1389. //app.erase(app.end() -value2,app.end());
  1390. //app.erase(app.begin(),app.begin()+value1);
  1391. }
  1392. // Remove ZeroPadding
  1393. const int zerop = int(flag[0]);
  1394. idwtOutput.erase(idwtOutput.end() - zerop, idwtOutput.end());
  1395. return nullptr;
  1396. }
  1397. void* idwt1_m(const std::string& wname, std::vector<double>& x, std::vector<double>& cA, std::vector<double>& cD)
  1398. {
  1399. std::vector<double> lpd1, hpd1, lpr1, hpr1;
  1400. filtcoef(wname, lpd1, hpd1, lpr1, hpr1);
  1401. const std::size_t lenLpfilt = lpr1.size();
  1402. const std::size_t lenHpfilt = hpr1.size();
  1403. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1404. const std::size_t n = 2 * cD.size();
  1405. const int U = 2; // Upsampling Factor
  1406. // Operations in the Low Frequency branch of the Synthesis Filter Bank
  1407. std::vector<double> cAUp;
  1408. std::vector<double> xLp;
  1409. // int len1 = cAUp.size();
  1410. upsamp(cA, U, cAUp);
  1411. per_ext(cAUp, int(lenAvg / 2));
  1412. convfftm(cAUp, lpr1, xLp);
  1413. // Operations in the High Frequency branch of the Synthesis Filter Bank
  1414. std::vector<double> cDUp, xHp;
  1415. upsamp(cD, U, cDUp);
  1416. per_ext(cDUp, int(lenAvg / 2));
  1417. convfftm(cDUp, hpr1, xHp);
  1418. // Remove periodic extension
  1419. // X.erase(X.begin(),X.begin()+len_avg+len_avg/2-1);
  1420. // X.erase(X.end()-len_avg-len_avg/2,X.end());
  1421. xLp.erase(xLp.begin() + n + lenAvg - 1, xLp.end());
  1422. xLp.erase(xLp.begin(), xLp.begin() + lenAvg - 1);
  1423. xHp.erase(xHp.begin() + n + lenAvg - 1, xHp.end());
  1424. xHp.erase(xHp.begin(), xHp.begin() + lenAvg - 1);
  1425. vecsum(xLp, xHp, x);
  1426. return nullptr;
  1427. }
  1428. void* idwt1(const std::string& wname, std::vector<double>& X, std::vector<double>& cA, std::vector<double>& cD)
  1429. {
  1430. std::vector<double> lpd1, hpd1, lpr1, hpr1;
  1431. filtcoef(wname, lpd1, hpd1, lpr1, hpr1);
  1432. const std::size_t lenLpfilt = lpr1.size();
  1433. const std::size_t lenHpfilt = hpr1.size();
  1434. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1435. const std::size_t n = 2 * cD.size();
  1436. const int U = 2; // Upsampling Factor
  1437. // Operations in the Low Frequency branch of the Synthesis Filter Bank
  1438. std::vector<double> cAUp, xLp;
  1439. // int len1 = cAUp.size();
  1440. upsamp(cA, U, cAUp);
  1441. per_ext(cAUp, int(lenAvg / 2));
  1442. convfft(cAUp, lpr1, xLp);
  1443. // Operations in the High Frequency branch of the Synthesis Filter Bank
  1444. std::vector<double> cDUp, xHp;
  1445. upsamp(cD, U, cDUp);
  1446. per_ext(cDUp, int(lenAvg / 2));
  1447. convfft(cDUp, hpr1, xHp);
  1448. // Remove periodic extension
  1449. // X.erase(X.begin(),X.begin()+len_avg+len_avg/2-1);
  1450. // X.erase(X.end()-len_avg-len_avg/2,X.end());
  1451. xLp.erase(xLp.begin() + n + lenAvg - 1, xLp.end());
  1452. xLp.erase(xLp.begin(), xLp.begin() + lenAvg - 1);
  1453. xHp.erase(xHp.begin() + n + lenAvg - 1, xHp.end());
  1454. xHp.erase(xHp.begin(), xHp.begin() + lenAvg - 1);
  1455. vecsum(xLp, xHp, X);
  1456. return nullptr;
  1457. }
  1458. int sign(const int x)
  1459. {
  1460. if (x >= 0) { return 1; }
  1461. return -1;
  1462. }
  1463. void upsamp(std::vector<double>& sig, const int m, std::vector<double>& sigU)
  1464. {
  1465. const std::size_t len = sig.size();
  1466. const std::size_t n = std::size_t(ceil(double(len) * double(m)));
  1467. for (std::size_t i = 0; i < n; ++i)
  1468. {
  1469. if (i % m == 0)
  1470. {
  1471. double temp = sig[i / m];
  1472. sigU.push_back(temp);
  1473. }
  1474. else { sigU.push_back(0); }
  1475. }
  1476. }
  1477. double OPSum(const double i, const double j) { return (i + j); }
  1478. int vecsum(std::vector<double>& a, std::vector<double>& b, std::vector<double>& c)
  1479. {
  1480. c.resize(a.size());
  1481. transform(a.begin(), a.end(), b.begin(), b.begin(), OPSum);
  1482. c = b;
  1483. return 0;
  1484. }
  1485. void* getcoeff2d(std::vector<std::vector<double>>& dwtoutput, std::vector<std::vector<double>>& cH, std::vector<std::vector<double>>& cV,
  1486. std::vector<std::vector<double>>& cD, std::vector<double>& flag, int& n)
  1487. {
  1488. if (n > flag[2])
  1489. {
  1490. std::cout << "Signal is decimated only up to " << flag[2] << " levels" << std::endl;
  1491. exit(1);
  1492. }
  1493. const std::size_t rows = dwtoutput.size();
  1494. const std::size_t cols = dwtoutput[0].size();
  1495. // Getting Horizontal Coefficients
  1496. const std::size_t r = std::size_t(ceil(double(rows) / pow(2.0, n)));
  1497. const std::size_t c = std::size_t(ceil(double(cols) / pow(2.0, n)));
  1498. for (std::size_t i = 0; i < std::size_t(ceil(double(rows) / pow(2.0, n))); ++i)
  1499. {
  1500. for (std::size_t j = 0; j < std::size_t(ceil(double(cols) / pow(2.0, n))); ++j) { cH[i][j] = dwtoutput[i][c + j]; }
  1501. }
  1502. for (std::size_t i = 0; i < std::size_t(ceil(double(rows) / pow(2.0, n))); ++i)
  1503. {
  1504. for (std::size_t j = 0; j < std::size_t(ceil(double(cols) / pow(2.0, n))); ++j) { cV[i][j] = dwtoutput[i + r][j]; }
  1505. }
  1506. for (std::size_t i = 0; i < std::size_t(ceil(double(rows) / pow(2.0, n))); ++i)
  1507. {
  1508. for (std::size_t j = 0; j < std::size_t(ceil(double(cols) / pow(2.0, n))); ++j) { cD[i][j] = dwtoutput[i + r][c + j]; }
  1509. }
  1510. return nullptr;
  1511. }
  1512. void* zero_remove(std::vector<std::vector<double>>& input, std::vector<std::vector<double>>& output)
  1513. {
  1514. const int zeroRows = int(output.size() - input.size());
  1515. const int zeroCols = int(output[0].size() - input[0].size());
  1516. auto row = output.end() - zeroRows;
  1517. const std::size_t ousize = output.size();
  1518. for (std::size_t i = input.size(); i < ousize; ++i)
  1519. {
  1520. output.erase(row);
  1521. ++row;
  1522. }
  1523. // std::size_t ousize2 = output[0].size();
  1524. for (std::size_t i = 0; i < ousize; ++i)
  1525. {
  1526. const auto col = output[i].end() - zeroCols;
  1527. output[i].erase(col, output[i].end());
  1528. }
  1529. return nullptr;
  1530. }
  1531. void* dwt_output_dim(std::vector<std::vector<double>>& signal, int& r, int& c)
  1532. {
  1533. const std::size_t rows = signal.size();
  1534. const std::size_t cols = signal[0].size();
  1535. const double mr = log10(double(rows)) / log10(2.0);
  1536. const int dr = int(ceil(mr));
  1537. const double intValRow = pow(2.0, double(dr));
  1538. const int r1 = int(intValRow);
  1539. const double mc = log10(double(cols)) / log10(2.0);
  1540. const int dc = int(ceil(mc));
  1541. const double intValCols = pow(2.0, double(dc));
  1542. const int c1 = int(intValCols);
  1543. r = std::max(r1, c1);
  1544. c = std::max(r1, c1);
  1545. return nullptr;
  1546. }
  1547. void* dyadic_zpad_2d(std::vector<std::vector<double>>& signal, std::vector<std::vector<double>>& mod)
  1548. {
  1549. const std::size_t rows = signal.size();
  1550. const std::size_t cols = signal[0].size();
  1551. for (std::size_t i = 0; i < rows; ++i) { for (std::size_t j = 0; j < cols; ++j) { mod[i][j] = signal[i][j]; } }
  1552. // Zeropadding the columns
  1553. const double mr = log10(double(rows)) / log10(2.0);
  1554. const int dr = int(ceil(mr));
  1555. const double intValRow = pow(2.0, double(dr)) - pow(2.0, mr);
  1556. const int zerosRow = int(intValRow);
  1557. const double mc = log10(double(cols)) / log10(2.0);
  1558. const int dc = int(ceil(mc));
  1559. const double intValCols = pow(2.0, double(dc)) - pow(2.0, mc);
  1560. const int zerosCols = int(intValCols);
  1561. for (std::size_t i = 0; i < rows + zerosRow; ++i) { for (std::size_t j = cols; j < cols + zerosCols; ++j) { mod[i][j] = 0; } }
  1562. for (std::size_t i = rows; i < rows + zerosRow; ++i) { for (std::size_t j = 0; j < cols + zerosCols; ++j) { mod[i][j] = 0; } }
  1563. return nullptr;
  1564. }
  1565. void* idwt_2d(std::vector<double>& dwtop, std::vector<double>& flag, const std::string& nm, std::vector<std::vector<double>>& idwtOutput, std::vector<std::size_t>& length)
  1566. {
  1567. std::size_t J = std::size_t(flag[0]);
  1568. std::size_t rows = length[0];
  1569. std::size_t cols = length[1];
  1570. std::size_t sumCoef = 0;
  1571. std::vector<double> lp1, hp1, lp2, hp2;
  1572. filtcoef(nm, lp1, hp1, lp2, hp2);
  1573. std::vector<std::vector<double>> cLL(rows, std::vector<double>(cols));
  1574. for (std::size_t iter = 0; iter < J; ++iter)
  1575. {
  1576. std::size_t nRows = length[2 * iter];
  1577. std::size_t nCols = length[2 * iter + 1];
  1578. std::vector<std::vector<double>> cLH(nRows, std::vector<double>(nCols));
  1579. std::vector<std::vector<double>> cHL(nRows, std::vector<double>(nCols));
  1580. std::vector<std::vector<double>> cHH(nRows, std::vector<double>(nCols));
  1581. for (std::size_t i = 0; i < nRows; ++i)
  1582. {
  1583. for (std::size_t j = 0; j < nCols; ++j)
  1584. {
  1585. if (iter == 0)
  1586. {
  1587. cLL[i][j] = dwtop[sumCoef + i * nCols + j];
  1588. cLH[i][j] = dwtop[sumCoef + nRows * nCols + i * nCols + j];
  1589. cHL[i][j] = dwtop[sumCoef + 2 * nRows * nCols + i * nCols + j];
  1590. cHH[i][j] = dwtop[sumCoef + 3 * nRows * nCols + i * nCols + j];
  1591. }
  1592. else
  1593. {
  1594. cLH[i][j] = dwtop[sumCoef + i * nCols + j];
  1595. cHL[i][j] = dwtop[sumCoef + nRows * nCols + i * nCols + j];
  1596. cHH[i][j] = dwtop[sumCoef + 2 * nRows * nCols + i * nCols + j];
  1597. }
  1598. }
  1599. }
  1600. // temp_A = cLL;
  1601. // idwt2_sym(nm,idwtOutput2, cA, cH,cV,cD);
  1602. std::size_t lenX = cLH.size();
  1603. std::size_t lenY = cLH[0].size();
  1604. // Row Upsampling and Column Filtering at the first LP Stage
  1605. std::vector<std::vector<double>> cL(2 * lenX, std::vector<double>(lenY));
  1606. std::vector<std::vector<double>> cH(2 * lenX, std::vector<double>(lenY));
  1607. if (iter == 0)
  1608. {
  1609. for (std::size_t j = 0; j < lenY; ++j)
  1610. {
  1611. std::vector<double> sigLL, sigLH, oup;
  1612. for (std::size_t i = 0; i < lenX; ++i)
  1613. {
  1614. double temp1 = cLL[i][j];
  1615. double temp2 = cLH[i][j];
  1616. sigLL.push_back(temp1);
  1617. sigLH.push_back(temp2);
  1618. }
  1619. idwt1_m(nm, oup, sigLL, sigLH);
  1620. for (std::size_t i = 0; i < oup.size(); ++i) { cL[i][j] = oup[i]; }
  1621. }
  1622. }
  1623. else
  1624. {
  1625. std::size_t rows1 = cLH.size();
  1626. std::size_t cols1 = cLH[0].size();
  1627. for (std::size_t j = 0; j < cols1; ++j)
  1628. {
  1629. std::vector<double> tempL1, tempL2, oup;
  1630. for (std::size_t i = 0; i < rows1; ++i)
  1631. {
  1632. double temp = cLL[i][j];
  1633. tempL1.push_back(temp);
  1634. double temp2 = cLH[i][j];
  1635. tempL2.push_back(temp2);
  1636. }
  1637. idwt1_m(nm, oup, tempL1, tempL2);
  1638. for (std::size_t i = 0; i < oup.size(); ++i) { cL[i][j] = oup[i]; }
  1639. }
  1640. }
  1641. for (std::size_t j = 0; j < lenY; ++j)
  1642. {
  1643. std::vector<double> sigHL, sigHH, oup2;
  1644. for (std::size_t i = 0; i < lenX; ++i)
  1645. {
  1646. double temp3 = cHL[i][j];
  1647. double temp4 = cHH[i][j];
  1648. sigHL.push_back(temp3);
  1649. sigHH.push_back(temp4);
  1650. }
  1651. idwt1_m(nm, oup2, sigHL, sigHH);
  1652. for (std::size_t i = 0; i < oup2.size(); ++i) { cH[i][j] = oup2[i]; }
  1653. }
  1654. std::vector<std::vector<double>> signal(2 * lenX, std::vector<double>(2 * lenY));
  1655. for (std::size_t i = 0; i < 2 * lenX; ++i)
  1656. {
  1657. std::vector<double> sigL, sigH, oup;
  1658. for (std::size_t j = 0; j < lenY; ++j)
  1659. {
  1660. double temp5 = cL[i][j];
  1661. double temp6 = cH[i][j];
  1662. sigL.push_back(temp5);
  1663. sigH.push_back(temp6);
  1664. }
  1665. idwt1_m(nm, oup, sigL, sigH);
  1666. for (std::size_t j = 0; j < oup.size(); ++j) { signal[i][j] = oup[j]; }
  1667. }
  1668. idwtOutput = signal;
  1669. if (iter == 0) { sumCoef += 4 * nRows * nCols; }
  1670. else { sumCoef += 3 * nRows * nCols; }
  1671. cLL = signal;
  1672. }
  1673. return nullptr;
  1674. }
  1675. void* dwt_2d(std::vector<std::vector<double>>& origsig, const int J, const std::string& nm, std::vector<double>& dwtOutput, std::vector<double>& flag, std::vector<std::size_t>& length)
  1676. {
  1677. // flag will contain
  1678. std::vector<std::vector<double>> sig = origsig;
  1679. std::size_t nRows = sig.size(); // No. of rows
  1680. std::size_t nCols = sig[0].size(); //No. of columns
  1681. std::vector<std::vector<double>> originalCopy = sig;
  1682. const int maxIter = std::min(int(ceil(log(double(sig.size())) / log(2.0))), int(ceil(log(double(sig[0].size())) / log(2.0))));
  1683. if (maxIter < J)
  1684. {
  1685. std::cout << J << " Iterations are not possible with signals of this dimension " << std::endl;
  1686. exit(1);
  1687. }
  1688. std::vector<double> lp1, hp1, lp2, hp2;
  1689. flag.push_back(double(J));
  1690. flag.push_back(0);
  1691. length.insert(length.begin(), nCols);
  1692. length.insert(length.begin(), nRows);
  1693. std::size_t sumCoef = 0;
  1694. for (std::size_t iter = 0; iter < std::size_t(J); ++iter)
  1695. {
  1696. filtcoef(nm, lp1, hp1, lp2, hp2);
  1697. nRows = int(ceil(double(nRows) / 2.0));
  1698. nCols = int(ceil(double(nCols) / 2.0));
  1699. length.insert(length.begin(), nCols);
  1700. length.insert(length.begin(), nRows);
  1701. std::vector<std::vector<double>> cA(nRows, std::vector<double>(nCols));
  1702. std::vector<std::vector<double>> cH(nRows, std::vector<double>(nCols));
  1703. std::vector<std::vector<double>> cV(nRows, std::vector<double>(nCols));
  1704. std::vector<std::vector<double>> cD(nRows, std::vector<double>(nCols));
  1705. if (iter == 0) { dwt2(nm, originalCopy, cA, cH, cV, cD); }
  1706. else { dwt2(nm, originalCopy, cA, cH, cV, cD); }
  1707. std::vector<double> tempSig2;
  1708. originalCopy = cA;
  1709. if (iter == std::size_t(J - 1))
  1710. {
  1711. for (std::size_t i = 0; i < nRows; ++i)
  1712. {
  1713. for (std::size_t j = 0; j < nCols; ++j)
  1714. {
  1715. double temp = cA[i][j];
  1716. tempSig2.push_back(temp);
  1717. }
  1718. }
  1719. }
  1720. for (std::size_t i = 0; i < nRows; ++i)
  1721. {
  1722. for (std::size_t j = nCols; j < nCols * 2; ++j)
  1723. {
  1724. double temp = cH[i][j - nCols];
  1725. tempSig2.push_back(temp);
  1726. }
  1727. }
  1728. for (std::size_t i = nRows; i < nRows * 2; ++i)
  1729. {
  1730. for (std::size_t j = 0; j < nCols; ++j)
  1731. {
  1732. double temp = cV[i - nRows][j];
  1733. tempSig2.push_back(temp);
  1734. }
  1735. }
  1736. for (std::size_t i = nRows; i < nRows * 2; ++i)
  1737. {
  1738. for (std::size_t j = nCols; j < nCols * 2; ++j)
  1739. {
  1740. double temp = cD[i - nRows][j - nCols];
  1741. tempSig2.push_back(temp);
  1742. }
  1743. }
  1744. dwtOutput.insert(dwtOutput.begin(), tempSig2.begin(), tempSig2.end());
  1745. sumCoef += 4 * nRows * nCols;
  1746. }
  1747. /*
  1748. ofstream dwt2out("dwt2out.dat");
  1749. for (std::size_t i= 0; i < dwtOutput.size(); ++i){ dwt2out << dwtOutput[i] <<endl; }
  1750. */
  1751. return nullptr;
  1752. }
  1753. void* branch_lp_hp_up(const std::string& wname, std::vector<double>& cA, std::vector<double>& cD, std::vector<double>& x)
  1754. {
  1755. std::vector<double> lpd1, hpd1, lpr1, hpr1;
  1756. filtcoef(wname, lpd1, hpd1, lpr1, hpr1);
  1757. const std::size_t lenLpfilt = lpr1.size();
  1758. const std::size_t lenHpfilt = hpr1.size();
  1759. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1760. //std::size_t N = 2 * cA.size();
  1761. const int U = 2; // Upsampling Factor
  1762. // Operations in the Low Frequency branch of the Synthesis Filter Bank
  1763. std::vector<double> cAUp;
  1764. std::vector<double> xLp;
  1765. per_ext(cA, int(lenAvg / 2));
  1766. upsamp(cA, U, cAUp);
  1767. convfftm(cAUp, lpr1, xLp);
  1768. // Operations in the High Frequency branch of the Synthesis Filter Bank
  1769. std::vector<double> cDUp;
  1770. std::vector<double> xHp;
  1771. per_ext(cD, int(lenAvg / 2));
  1772. upsamp(cD, U, cDUp);
  1773. convfftm(cDUp, hpr1, xHp);
  1774. vecsum(xLp, xHp, x);
  1775. // Remove periodic extension
  1776. x.erase(x.begin(), x.begin() + lenAvg + lenAvg / 2 - 1);
  1777. x.erase(x.end() - lenAvg - lenAvg / 2, x.end());
  1778. return nullptr;
  1779. }
  1780. void* branch_hp_dn(const std::string& wname, std::vector<double>& signal, std::vector<double>& sigop)
  1781. {
  1782. std::vector<double> lpd, hpd, lpr, hpr;
  1783. filtcoef(wname, lpd, hpd, lpr, hpr);
  1784. //for (std::size_t i = 0; i < signal.size(); ++i) {
  1785. // std::cout << signal[i] << std::endl;
  1786. // out2 << signal[i] << std::endl;
  1787. //}
  1788. const std::size_t tempLen = signal.size();
  1789. if ((tempLen % 2) != 0)
  1790. {
  1791. const double temp = signal[tempLen - 1];
  1792. signal.push_back(temp);
  1793. }
  1794. const std::size_t lenLpfilt = lpd.size();
  1795. const std::size_t lenHpfilt = hpd.size();
  1796. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1797. // std::cout << lenLpfilt << "Filter" << std::endl;
  1798. per_ext(signal, int(lenAvg / 2)); // Periodic Extension
  1799. // computations designed to deal with boundary distortions
  1800. // Low Pass Filtering Operations in the Analysis Filter Bank Section
  1801. // int len_cA =(int) floor(double (len_sig + lenLpfilt -1) / double (2));
  1802. std::vector<double> cAUndec;
  1803. // convolving signal with lpd, Low Pass Filter, and O/P is stored in cA_undec
  1804. convfftm(signal, hpd, cAUndec);
  1805. const int d = 2; // Downsampling Factor is 2
  1806. // Downsampling by 2 gives cA
  1807. downsamp(cAUndec, d, sigop);
  1808. sigop.erase(sigop.begin(), sigop.begin() + lenAvg / 2);
  1809. sigop.erase(sigop.end() - lenAvg / 2, sigop.end());
  1810. return nullptr;
  1811. }
  1812. void* branch_lp_dn(const std::string& wname, std::vector<double>& signal, std::vector<double>& sigop)
  1813. {
  1814. std::vector<double> lpd, hpd, lpr, hpr;
  1815. filtcoef(wname, lpd, hpd, lpr, hpr);
  1816. // for (std::size_t i = 0; i < signal.size(); ++i) {
  1817. // std::cout << signal[i] << endl;
  1818. // out2 << signal[i] <<endl;
  1819. // }
  1820. const std::size_t tempLen = signal.size();
  1821. if ((tempLen % 2) != 0)
  1822. {
  1823. const double temp = signal[tempLen - 1];
  1824. signal.push_back(temp);
  1825. }
  1826. const std::size_t lenLpfilt = lpd.size();
  1827. const std::size_t lenHpfilt = hpd.size();
  1828. const std::size_t lenAvg = (lenLpfilt + lenHpfilt) / 2;
  1829. // std::cout << lenLpfilt << "Filter" << std::endl;
  1830. per_ext(signal, int(lenAvg / 2)); // Periodic Extension
  1831. // computations designed to deal with boundary distortions
  1832. // Low Pass Filtering Operations in the Analysis Filter Bank Section
  1833. // int len_cA =(int) floor(double (len_sig + lenLpfilt -1) / double (2));
  1834. std::vector<double> cAUndec;
  1835. // convolving signal with lpd, Low Pass Filter, and O/P is stored in cA_undec
  1836. convfftm(signal, lpd, cAUndec);
  1837. const int d = 2; // Downsampling Factor is 2
  1838. // Downsampling by 2 gives cA
  1839. downsamp(cAUndec, d, sigop);
  1840. sigop.erase(sigop.begin(), sigop.begin() + lenAvg / 2);
  1841. sigop.erase(sigop.end() - lenAvg / 2, sigop.end());
  1842. return nullptr;
  1843. }
  1844. void* idwt2(const std::string& name, std::vector<std::vector<double>>& signal, std::vector<std::vector<double>>& cLL, std::vector<std::vector<double>>& cLH,
  1845. std::vector<std::vector<double>>& cHL, std::vector<std::vector<double>>& cHH)
  1846. {
  1847. // Synthesis
  1848. const std::size_t rows = cLL.size();
  1849. const std::size_t cols = cLL[0].size();
  1850. const std::size_t nRows = 2 * rows;
  1851. // Row Upsampling and Column Filtering at the first LP Stage
  1852. std::vector<std::vector<double>> cL(nRows, std::vector<double>(cols));
  1853. std::vector<std::vector<double>> cH(nRows, std::vector<double>(cols));
  1854. for (std::size_t j = 0; j < cols; ++j)
  1855. {
  1856. std::vector<double> sigLL;
  1857. std::vector<double> sigLH;
  1858. for (std::size_t i = 0; i < rows; ++i)
  1859. {
  1860. double temp1 = cLL[i][j];
  1861. double temp2 = cLH[i][j];
  1862. sigLL.push_back(temp1);
  1863. sigLH.push_back(temp2);
  1864. }
  1865. std::vector<double> oup;
  1866. branch_lp_hp_up(name, sigLL, sigLH, oup);
  1867. sigLL.clear();
  1868. sigLH.clear();
  1869. for (std::size_t i = 0; i < oup.size(); ++i) { cL[i][j] = oup[i]; }
  1870. }
  1871. for (std::size_t j = 0; j < cols; ++j)
  1872. {
  1873. std::vector<double> sigHL;
  1874. std::vector<double> sigHH;
  1875. for (std::size_t i = 0; i < rows; ++i)
  1876. {
  1877. double temp3 = cHL[i][j];
  1878. double temp4 = cHH[i][j];
  1879. sigHL.push_back(temp3);
  1880. sigHH.push_back(temp4);
  1881. }
  1882. std::vector<double> oup2;
  1883. branch_lp_hp_up(name, sigHL, sigHH, oup2);
  1884. sigHL.clear();
  1885. sigHH.clear();
  1886. for (std::size_t i = 0; i < oup2.size(); ++i) { cH[i][j] = oup2[i]; }
  1887. }
  1888. for (std::size_t i = 0; i < nRows; ++i)
  1889. {
  1890. std::vector<double> sigL;
  1891. std::vector<double> sigH;
  1892. for (std::size_t j = 0; j < cols; ++j)
  1893. {
  1894. double temp5 = cL[i][j];
  1895. double temp6 = cH[i][j];
  1896. sigL.push_back(temp5);
  1897. sigH.push_back(temp6);
  1898. }
  1899. std::vector<double> oup3;
  1900. branch_lp_hp_up(name, sigL, sigH, oup3);
  1901. sigL.clear();
  1902. sigH.clear();
  1903. for (std::size_t j = 0; j < oup3.size(); ++j) { signal[i][j] = oup3[j]; }
  1904. }
  1905. return nullptr;
  1906. }
  1907. void* dwt2(const std::string& name, std::vector<std::vector<double>>& signal, std::vector<std::vector<double>>& cLL, std::vector<std::vector<double>>& cLH,
  1908. std::vector<std::vector<double>>& cHL, std::vector<std::vector<double>>& cHH)
  1909. {
  1910. //Analysis
  1911. const std::size_t rows = signal.size();
  1912. std::size_t cols = signal[0].size();
  1913. const std::size_t colsLp1 = cLL[0].size();
  1914. const std::size_t colsHp1 = cLL[0].size();
  1915. std::vector<double> lp1, hp1, lp2, hp2;
  1916. filtcoef(name, lp1, hp1, lp2, hp2);
  1917. std::vector<std::vector<double>> lpDn1(rows, std::vector<double>(colsLp1));
  1918. std::vector<std::vector<double>> hpDn1(rows, std::vector<double>(colsHp1));
  1919. // Implementing row filtering and column downsampling in each branch.
  1920. for (std::size_t i = 0; i < rows; ++i)
  1921. {
  1922. std::vector<double> tempRow, oupLp, oupHp;
  1923. for (std::size_t j = 0; j < cols; ++j)
  1924. {
  1925. double temp = signal[i][j];
  1926. tempRow.push_back(temp);
  1927. }
  1928. dwt1_m(name, tempRow, oupLp, oupHp);
  1929. for (std::size_t j = 0; j < oupLp.size(); ++j)
  1930. {
  1931. lpDn1[i][j] = oupLp[j];
  1932. hpDn1[i][j] = oupHp[j];
  1933. }
  1934. }
  1935. cols = colsLp1;
  1936. // Implementing column filtering and row downsampling in Low Pass branch.
  1937. for (std::size_t j = 0; j < cols; ++j)
  1938. {
  1939. std::vector<double> tempRow3, oupLp, oupHp;
  1940. for (std::size_t i = 0; i < rows; ++i)
  1941. {
  1942. double temp = lpDn1[i][j];
  1943. tempRow3.push_back(temp);
  1944. }
  1945. dwt1_m(name, tempRow3, oupLp, oupHp);
  1946. for (std::size_t i = 0; i < oupLp.size(); ++i)
  1947. {
  1948. cLL[i][j] = oupLp[i];
  1949. cLH[i][j] = oupHp[i];
  1950. }
  1951. }
  1952. // Implementing column filtering and row downsampling in High Pass branch.
  1953. for (std::size_t j = 0; j < cols; ++j)
  1954. {
  1955. std::vector<double> tempRow5, oupLp, oupHp;
  1956. for (std::size_t i = 0; i < rows; ++i)
  1957. {
  1958. double temp = hpDn1[i][j];
  1959. tempRow5.push_back(temp);
  1960. }
  1961. dwt1_m(name, tempRow5, oupLp, oupHp);
  1962. for (std::size_t i = 0; i < oupLp.size(); ++i)
  1963. {
  1964. cHL[i][j] = oupLp[i];
  1965. cHH[i][j] = oupHp[i];
  1966. }
  1967. }
  1968. return nullptr;
  1969. }
  1970. void* downsamp2(std::vector<std::vector<double>>& vec1, std::vector<std::vector<double>>& vec2, const int rowsDn, const int colsDn)
  1971. {
  1972. const std::size_t rows = vec1.size();
  1973. const std::size_t cols = vec1[0].size();
  1974. const std::size_t nRows = std::size_t(ceil(double(rows) / double(rowsDn)));
  1975. const std::size_t nCols = std::size_t(ceil(double(cols) / double(colsDn)));
  1976. for (std::size_t i = 0; i < nRows; ++i) { for (std::size_t j = 0; j < nCols; ++j) { vec2[i][j] = vec1[i * rowsDn][j * colsDn]; } }
  1977. return nullptr;
  1978. }
  1979. void* upsamp2(std::vector<std::vector<double>>& vec1, std::vector<std::vector<double>>& vec2, const int rowsUp, const int colsUp)
  1980. {
  1981. const std::size_t rows = vec1.size();
  1982. const std::size_t cols = vec1[0].size();
  1983. const std::size_t nRows = rows * rowsUp;
  1984. const std::size_t nCols = cols * colsUp;
  1985. for (std::size_t i = 0; i < nRows; ++i)
  1986. {
  1987. for (std::size_t j = 0; j < nCols; ++j)
  1988. {
  1989. if (i % rowsUp == 0 && j % colsUp == 0) { vec2[i][j] = vec1[i / rowsUp][j / colsUp]; }
  1990. else { vec2[i][j] = 0; }
  1991. }
  1992. }
  1993. return nullptr;
  1994. }
  1995. int filtcoef(const std::string& name, std::vector<double>& lp1, std::vector<double>& hp1, std::vector<double>& lp2, std::vector<double>& hp2)
  1996. {
  1997. if (name == "haar" || name == "db1")
  1998. {
  1999. lp1.push_back(0.7071);
  2000. lp1.push_back(0.7071);
  2001. hp1.push_back(-0.7071);
  2002. hp1.push_back(0.7071);
  2003. lp2.push_back(0.7071);
  2004. lp2.push_back(0.7071);
  2005. hp2.push_back(0.7071);
  2006. hp2.push_back(-0.7071);
  2007. // std::cout << lp2[1] << std::endl;
  2008. // hpd = {-0.7071, 0.7071};
  2009. // lpr = {0.7071, 0.7071};
  2010. // hpr = {0.7071, -0.7071};
  2011. return 0;
  2012. }
  2013. if (name == "db2")
  2014. {
  2015. lp1 = { -0.12940952255092145, 0.22414386804185735, 0.83651630373746899, 0.48296291314469025 };
  2016. hp1 = { -0.48296291314469025, 0.83651630373746899, -0.22414386804185735, -0.12940952255092145 };
  2017. lp2 = { 0.48296291314469025, 0.83651630373746899, 0.22414386804185735, -0.12940952255092145 };
  2018. hp2 = { -0.12940952255092145, -0.22414386804185735, 0.83651630373746899, -0.48296291314469025 };
  2019. return 0;
  2020. }
  2021. if (name == "db3")
  2022. {
  2023. lp1 = { 0.035226291882100656, -0.085441273882241486, -0.13501102001039084, 0.45987750211933132, 0.80689150931333875, 0.33267055295095688 };
  2024. hp1 = { -0.33267055295095688, 0.80689150931333875, -0.45987750211933132, -0.13501102001039084, 0.085441273882241486, 0.035226291882100656 };
  2025. lp2 = { 0.33267055295095688, 0.80689150931333875, 0.45987750211933132, -0.13501102001039084, -0.085441273882241486, 0.035226291882100656 };
  2026. hp2 = { 0.035226291882100656, 0.085441273882241486, -0.13501102001039084, -0.45987750211933132, 0.80689150931333875, -0.33267055295095688 };
  2027. return 0;
  2028. }
  2029. if (name == "db4")
  2030. {
  2031. lp1 = {
  2032. -0.010597401784997278, 0.032883011666982945, 0.030841381835986965, -0.18703481171888114, -0.027983769416983849, 0.63088076792959036,
  2033. 0.71484657055254153, 0.23037781330885523
  2034. };
  2035. hp1 = {
  2036. -0.23037781330885523, 0.71484657055254153, -0.63088076792959036, -0.027983769416983849, 0.18703481171888114, 0.030841381835986965,
  2037. -0.032883011666982945, -0.010597401784997278
  2038. };
  2039. lp2 = {
  2040. 0.23037781330885523, 0.71484657055254153, 0.63088076792959036, -0.027983769416983849, -0.18703481171888114, 0.030841381835986965,
  2041. 0.032883011666982945, -0.010597401784997278
  2042. };
  2043. hp2 = {
  2044. -0.010597401784997278, -0.032883011666982945, 0.030841381835986965, 0.18703481171888114, -0.027983769416983849, -0.63088076792959036,
  2045. 0.71484657055254153, -0.23037781330885523
  2046. };
  2047. return 0;
  2048. }
  2049. if (name == "db5")
  2050. {
  2051. lp1 = {
  2052. 0.0033357252850015492, -0.012580751999015526, -0.0062414902130117052, 0.077571493840065148, -0.03224486958502952, -0.24229488706619015,
  2053. 0.13842814590110342, 0.72430852843857441, 0.60382926979747287, 0.16010239797412501
  2054. };
  2055. hp1 = {
  2056. -0.16010239797412501, 0.60382926979747287, -0.72430852843857441, 0.13842814590110342, 0.24229488706619015, -0.03224486958502952,
  2057. -0.077571493840065148, -0.0062414902130117052, 0.012580751999015526, 0.0033357252850015492
  2058. };
  2059. lp2 = {
  2060. 0.16010239797412501, 0.60382926979747287, 0.72430852843857441, 0.13842814590110342, -0.24229488706619015, -0.03224486958502952,
  2061. 0.077571493840065148, -0.0062414902130117052, -0.012580751999015526, 0.0033357252850015492
  2062. };
  2063. hp2 = {
  2064. 0.0033357252850015492, 0.012580751999015526, -0.0062414902130117052, -0.077571493840065148, -0.03224486958502952, 0.24229488706619015,
  2065. 0.13842814590110342, -0.72430852843857441, 0.60382926979747287, -0.16010239797412501
  2066. };
  2067. return 0;
  2068. }
  2069. if (name == "db6")
  2070. {
  2071. lp1 = {
  2072. -0.0010773010849955799, 0.0047772575110106514, 0.0005538422009938016, -0.031582039318031156, 0.027522865530016288, 0.097501605587079362,
  2073. -0.12976686756709563, -0.22626469396516913, 0.3152503517092432, 0.75113390802157753, 0.49462389039838539, 0.11154074335008017
  2074. };
  2075. hp1 = {
  2076. -0.11154074335008017, 0.49462389039838539, -0.75113390802157753, 0.3152503517092432, 0.22626469396516913, -0.12976686756709563,
  2077. -0.097501605587079362, 0.027522865530016288, 0.031582039318031156, 0.0005538422009938016, -0.0047772575110106514, -0.0010773010849955799
  2078. };
  2079. lp2 = {
  2080. 0.11154074335008017, 0.49462389039838539, 0.75113390802157753, 0.3152503517092432, -0.22626469396516913, -0.12976686756709563, 0.097501605587079362,
  2081. 0.027522865530016288, -0.031582039318031156, 0.0005538422009938016, 0.0047772575110106514, -0.0010773010849955799
  2082. };
  2083. hp2 = {
  2084. -0.0010773010849955799, -0.0047772575110106514, 0.0005538422009938016, 0.031582039318031156, 0.027522865530016288, -0.097501605587079362,
  2085. -0.12976686756709563, 0.22626469396516913, 0.3152503517092432, -0.75113390802157753, 0.49462389039838539, -0.11154074335008017
  2086. };
  2087. return 0;
  2088. }
  2089. if (name == "db7")
  2090. {
  2091. lp1 = {
  2092. 0.00035371380000103988, -0.0018016407039998328, 0.00042957797300470274, 0.012550998556013784, -0.01657454163101562, -0.038029936935034633,
  2093. 0.080612609151065898, 0.071309219267050042, -0.22403618499416572, -0.14390600392910627, 0.4697822874053586, 0.72913209084655506,
  2094. 0.39653931948230575, 0.077852054085062364
  2095. };
  2096. hp1 = {
  2097. -0.077852054085062364, 0.39653931948230575, -0.72913209084655506, 0.4697822874053586, 0.14390600392910627, -0.22403618499416572,
  2098. -0.071309219267050042, 0.080612609151065898, 0.038029936935034633, -0.01657454163101562, -0.012550998556013784, 0.0004295779730047027,
  2099. 0.0018016407039998328, 0.00035371380000103988
  2100. };
  2101. lp2 = {
  2102. 0.077852054085062364, 0.39653931948230575, 0.72913209084655506, 0.4697822874053586, -0.14390600392910627, -0.22403618499416572,
  2103. 0.071309219267050042, 0.080612609151065898, -0.038029936935034633, -0.01657454163101562, 0.012550998556013784, 0.00042957797300470274,
  2104. -0.0018016407039998328, 0.00035371380000103988
  2105. };
  2106. hp2 = {
  2107. 0.00035371380000103988, 0.0018016407039998328, 0.00042957797300470274, -0.01255099855601378, -0.01657454163101562, 0.038029936935034633,
  2108. 0.080612609151065898, -0.071309219267050042, -0.22403618499416572, 0.14390600392910627, 0.4697822874053586, -0.72913209084655506,
  2109. 0.39653931948230575, -0.077852054085062364
  2110. };
  2111. return 0;
  2112. }
  2113. if (name == "db8")
  2114. {
  2115. lp1 = {
  2116. -0.00011747678400228192, 0.00067544940599855677, -0.00039174037299597711, -0.0048703529930106603, 0.0087460940470156547, 0.013981027917015516,
  2117. -0.044088253931064719, -0.017369301002022108, 0.12874742662018601, 0.00047248457399797254, -0.28401554296242809, -0.015829105256023893,
  2118. 0.58535468365486909, 0.67563073629801285, 0.31287159091446592, 0.054415842243081609
  2119. };
  2120. hp1 = {
  2121. -0.054415842243081609, 0.31287159091446592, -0.67563073629801285, 0.58535468365486909, 0.015829105256023893, -0.28401554296242809,
  2122. -0.00047248457399797254, 0.12874742662018601, 0.017369301002022108, -0.044088253931064719, -0.013981027917015516, 0.0087460940470156547,
  2123. 0.0048703529930106603, -0.00039174037299597711, -0.00067544940599855677, -0.00011747678400228192
  2124. };
  2125. lp2 = {
  2126. 0.054415842243081609, 0.31287159091446592, 0.67563073629801285, 0.58535468365486909, -0.015829105256023893, -0.28401554296242809,
  2127. 0.00047248457399797254, 0.12874742662018601, -0.017369301002022108, -0.044088253931064719, 0.013981027917015516, 0.0087460940470156547,
  2128. -0.0048703529930106603, -0.00039174037299597711, 0.00067544940599855677, -0.00011747678400228192
  2129. };
  2130. hp2 = {
  2131. -0.00011747678400228192, -0.00067544940599855677, -0.00039174037299597711, 0.0048703529930106603, 0.0087460940470156547, -0.013981027917015516,
  2132. -0.044088253931064719, 0.017369301002022108, 0.12874742662018601, -0.00047248457399797254, -0.28401554296242809, 0.015829105256023893,
  2133. 0.58535468365486909, -0.67563073629801285, 0.31287159091446592, -0.054415842243081609
  2134. };
  2135. return 0;
  2136. }
  2137. if (name == "db9")
  2138. {
  2139. lp1 = {
  2140. 3.9347319995026124e-05, -0.00025196318899817888, 0.00023038576399541288, 0.0018476468829611268, -0.0042815036819047227, -0.004723204757894831,
  2141. 0.022361662123515244, 0.00025094711499193845, -0.067632829059523988, 0.030725681478322865, 0.14854074933476008, -0.096840783220879037,
  2142. -0.29327378327258685, 0.13319738582208895, 0.65728807803663891, 0.6048231236767786, 0.24383467463766728, 0.038077947363167282
  2143. };
  2144. hp1 = {
  2145. -0.038077947363167282, 0.24383467463766728, -0.6048231236767786, 0.65728807803663891, -0.13319738582208895, -0.29327378327258685,
  2146. 0.096840783220879037, 0.14854074933476008, -0.030725681478322865, -0.067632829059523988, -0.00025094711499193845, 0.022361662123515244,
  2147. 0.004723204757894831, -0.0042815036819047227, -0.0018476468829611268, 0.00023038576399541288, 0.00025196318899817888, 3.9347319995026124e-05
  2148. };
  2149. lp2 = {
  2150. 0.038077947363167282, 0.24383467463766728, 0.6048231236767786, 0.65728807803663891, 0.13319738582208895, -0.29327378327258685,
  2151. -0.096840783220879037, 0.14854074933476008, 0.030725681478322865, -0.067632829059523988, 0.00025094711499193845, 0.022361662123515244,
  2152. -0.004723204757894831, -0.0042815036819047227, 0.0018476468829611268, 0.00023038576399541288, -0.00025196318899817888, 3.9347319995026124e-05
  2153. };
  2154. hp2 = {
  2155. 3.9347319995026124e-05, 0.00025196318899817888, 0.00023038576399541288, -0.0018476468829611268, -0.0042815036819047227, 0.004723204757894831,
  2156. 0.022361662123515244, -0.00025094711499193845, -0.067632829059523988, -0.030725681478322865, 0.14854074933476008, 0.096840783220879037,
  2157. -0.29327378327258685, -0.13319738582208895, 0.65728807803663891, -0.6048231236767786, 0.24383467463766728, -0.038077947363167282
  2158. };
  2159. return 0;
  2160. }
  2161. if (name == "db10")
  2162. {
  2163. lp1 = {
  2164. -1.3264203002354869e-05, 9.3588670001089845e-05, -0.0001164668549943862, -0.00068585669500468248, 0.0019924052949908499, 0.0013953517469940798,
  2165. -0.010733175482979604, 0.0036065535669883944, 0.033212674058933238, -0.029457536821945671, -0.071394147165860775, 0.093057364603806592,
  2166. 0.12736934033574265, -0.19594627437659665, -0.24984642432648865, 0.28117234366042648, 0.68845903945259213, 0.52720118893091983, 0.18817680007762133,
  2167. 0.026670057900950818
  2168. };
  2169. hp1 = {
  2170. -0.026670057900950818, 0.18817680007762133, -0.52720118893091983, 0.68845903945259213, -0.28117234366042648, -0.24984642432648865,
  2171. 0.19594627437659665, 0.12736934033574265, -0.093057364603806592, -0.071394147165860775, 0.029457536821945671, 0.033212674058933238,
  2172. -0.0036065535669883944, -0.010733175482979604, -0.0013953517469940798, 0.0019924052949908499, 0.00068585669500468248, -0.0001164668549943862,
  2173. -9.3588670001089845e-05, -1.3264203002354869e-05
  2174. };
  2175. lp2 = {
  2176. 0.026670057900950818, 0.18817680007762133, 0.52720118893091983, 0.68845903945259213, 0.28117234366042648, -0.24984642432648865,
  2177. -0.19594627437659665, 0.12736934033574265, 0.093057364603806592, -0.071394147165860775, -0.029457536821945671, 0.033212674058933238,
  2178. 0.0036065535669883944, -0.010733175482979604, 0.0013953517469940798, 0.0019924052949908499, -0.00068585669500468248, -0.0001164668549943862,
  2179. 9.3588670001089845e-05, -1.3264203002354869e-05
  2180. };
  2181. hp2 = {
  2182. -1.3264203002354869e-05, -9.3588670001089845e-05, -0.0001164668549943862, 0.00068585669500468248, 0.0019924052949908499, -0.0013953517469940798,
  2183. -0.010733175482979604, -0.0036065535669883944, 0.033212674058933238, 0.029457536821945671, -0.071394147165860775, -0.093057364603806592,
  2184. 0.12736934033574265, 0.19594627437659665, -0.24984642432648865, -0.28117234366042648, 0.68845903945259213, -0.52720118893091983,
  2185. 0.18817680007762133, -0.026670057900950818
  2186. };
  2187. return 0;
  2188. }
  2189. if (name == "db12")
  2190. {
  2191. lp1 = {
  2192. -1.5290717580684923e-06, 1.2776952219379579e-05, -2.4241545757030318e-05, -8.8504109208203182e-05, 0.00038865306282092672, 6.5451282125215034e-06,
  2193. -0.0021795036186277044, 0.0022486072409952287, 0.0067114990087955486, -0.012840825198299882, -0.01221864906974642, 0.041546277495087637,
  2194. 0.010849130255828966, -0.09643212009649671, 0.0053595696743599965, 0.18247860592758275, -0.023779257256064865, -0.31617845375277914,
  2195. -0.044763885653777619, 0.51588647842780067, 0.65719872257929113, 0.37735513521420411, 0.10956627282118277, 0.013112257957229239
  2196. };
  2197. hp1 = {
  2198. -0.013112257957229239, 0.10956627282118277, -0.37735513521420411, 0.65719872257929113, -0.51588647842780067, -0.044763885653777619,
  2199. 0.31617845375277914, -0.023779257256064865, -0.18247860592758275, 0.0053595696743599965, 0.09643212009649671, 0.010849130255828966,
  2200. -0.041546277495087637, -0.01221864906974642, 0.012840825198299882, 0.0067114990087955486, -0.0022486072409952287, -0.0021795036186277044,
  2201. -6.5451282125215034e-06, 0.00038865306282092672, 8.8504109208203182e-05, -2.4241545757030318e-05, -1.2776952219379579e-05, -1.5290717580684923e-06
  2202. };
  2203. lp2 = {
  2204. 0.013112257957229239, 0.10956627282118277, 0.37735513521420411, 0.65719872257929113, 0.51588647842780067, -0.044763885653777619,
  2205. -0.31617845375277914, -0.023779257256064865, 0.18247860592758275, 0.0053595696743599965, -0.09643212009649671, 0.010849130255828966,
  2206. 0.041546277495087637, -0.01221864906974642, -0.012840825198299882, 0.0067114990087955486, 0.0022486072409952287, -0.0021795036186277044,
  2207. 6.5451282125215034e-06, 0.00038865306282092672, -8.8504109208203182e-05, -2.4241545757030318e-05, 1.2776952219379579e-05, -1.5290717580684923e-06
  2208. };
  2209. hp2 = {
  2210. -1.5290717580684923e-06, -1.2776952219379579e-05, -2.4241545757030318e-05, 8.8504109208203182e-05, 0.00038865306282092672, -6.5451282125215034e-06,
  2211. -0.0021795036186277044, -0.0022486072409952287, 0.0067114990087955486, 0.012840825198299882, -0.01221864906974642, -0.041546277495087637,
  2212. 0.010849130255828966, 0.09643212009649671, 0.0053595696743599965, -0.18247860592758275, -0.023779257256064865, 0.31617845375277914,
  2213. -0.044763885653777619, -0.51588647842780067, 0.65719872257929113, -0.37735513521420411, 0.10956627282118277, -0.013112257957229239
  2214. };
  2215. return 0;
  2216. }
  2217. if (name == "db13")
  2218. {
  2219. lp1 = {
  2220. 5.2200350984547998e-07, -4.7004164793608082e-06, 1.0441930571407941e-05, 3.0678537579324358e-05, -0.00016512898855650571, 4.9251525126285676e-05,
  2221. 0.00093232613086724904, -0.0013156739118922766, -0.002761911234656831, 0.0072555894016171187, 0.0039239414487955773, -0.023831420710327809,
  2222. 0.0023799722540522269, 0.056139477100276156, -0.026488406475345658, -0.10580761818792761, 0.072948933656788742, 0.17947607942935084,
  2223. -0.12457673075080665, -0.31497290771138414, 0.086985726179645007, 0.58888957043121193, 0.61105585115878114, 0.31199632216043488,
  2224. 0.082861243872901946, 0.0092021335389622788
  2225. };
  2226. hp1 = {
  2227. -0.0092021335389622788, 0.082861243872901946, -0.31199632216043488, 0.61105585115878114, -0.58888957043121193, 0.086985726179645007,
  2228. 0.31497290771138414, -0.12457673075080665, -0.17947607942935084, 0.072948933656788742, 0.10580761818792761, -0.026488406475345658,
  2229. -0.056139477100276156, 0.0023799722540522269, 0.023831420710327809, 0.0039239414487955773, -0.0072555894016171187, -0.002761911234656831,
  2230. 0.0013156739118922766, 0.00093232613086724904, -4.9251525126285676e-05, -0.00016512898855650571, -3.0678537579324358e-05, 1.0441930571407941e-05,
  2231. 4.7004164793608082e-06, 5.2200350984547998e-07
  2232. };
  2233. lp2 = {
  2234. 0.0092021335389622788, 0.082861243872901946, 0.31199632216043488, 0.61105585115878114, 0.58888957043121193, 0.086985726179645007,
  2235. -0.31497290771138414, -0.12457673075080665, 0.17947607942935084, 0.072948933656788742, -0.10580761818792761, -0.026488406475345658,
  2236. 0.056139477100276156, 0.0023799722540522269, -0.023831420710327809, 0.0039239414487955773, 0.0072555894016171187, -0.002761911234656831,
  2237. -0.0013156739118922766, 0.00093232613086724904, 4.9251525126285676e-05, -0.00016512898855650571, 3.0678537579324358e-05, 1.0441930571407941e-05,
  2238. -4.7004164793608082e-06, 5.2200350984547998e-07
  2239. };
  2240. hp2 = {
  2241. 5.2200350984547998e-07, 4.7004164793608082e-06, 1.0441930571407941e-05, -3.0678537579324358e-05, -0.00016512898855650571, -4.9251525126285676e-05,
  2242. 0.00093232613086724904, 0.0013156739118922766, -0.002761911234656831, -0.0072555894016171187, 0.0039239414487955773, 0.023831420710327809,
  2243. 0.0023799722540522269, -0.056139477100276156, -0.026488406475345658, 0.10580761818792761, 0.072948933656788742, -0.17947607942935084,
  2244. -0.12457673075080665, 0.31497290771138414, 0.086985726179645007, -0.58888957043121193, 0.61105585115878114, -0.31199632216043488,
  2245. 0.082861243872901946, -0.0092021335389622788
  2246. };
  2247. return 0;
  2248. }
  2249. if (name == "db11")
  2250. {
  2251. lp1 = {
  2252. 4.4942742772363519e-06, -3.4634984186983789e-05, 5.4439074699366381e-05, 0.00024915252355281426, -0.00089302325066623663, -0.00030859285881515924,
  2253. 0.0049284176560587777, -0.0033408588730145018, -0.015364820906201324, 0.020840904360180039, 0.031335090219045313, -0.066438785695020222,
  2254. -0.04647995511667613, 0.14981201246638268, 0.066043588196690886, -0.27423084681792875, -0.16227524502747828, 0.41196436894789695,
  2255. 0.68568677491617847, 0.44989976435603013, 0.14406702115061959, 0.018694297761470441
  2256. };
  2257. hp1 = {
  2258. -0.018694297761470441, 0.14406702115061959, -0.44989976435603013, 0.68568677491617847, -0.41196436894789695, -0.16227524502747828,
  2259. 0.27423084681792875, 0.066043588196690886, -0.14981201246638268, -0.04647995511667613, 0.066438785695020222, 0.031335090219045313,
  2260. -0.020840904360180039, -0.015364820906201324, 0.0033408588730145018, 0.0049284176560587777, 0.00030859285881515924, -0.00089302325066623663,
  2261. -0.00024915252355281426, 5.4439074699366381e-05, 3.4634984186983789e-05, 4.4942742772363519e-06
  2262. };
  2263. lp2 = {
  2264. 0.018694297761470441, 0.14406702115061959, 0.44989976435603013, 0.68568677491617847, 0.41196436894789695, -0.16227524502747828,
  2265. -0.27423084681792875, 0.066043588196690886, 0.14981201246638268, -0.04647995511667613, -0.066438785695020222, 0.031335090219045313,
  2266. 0.020840904360180039, -0.015364820906201324, -0.0033408588730145018, 0.0049284176560587777, -0.00030859285881515924, -0.00089302325066623663,
  2267. 0.00024915252355281426, 5.4439074699366381e-05, -3.4634984186983789e-05, 4.4942742772363519e-06
  2268. };
  2269. hp2 = {
  2270. 4.4942742772363519e-06, 3.4634984186983789e-05, 5.4439074699366381e-05, -0.00024915252355281426, -0.00089302325066623663, 0.00030859285881515924,
  2271. 0.0049284176560587777, 0.0033408588730145018, -0.015364820906201324, -0.020840904360180039, 0.031335090219045313, 0.066438785695020222,
  2272. -0.04647995511667613, -0.14981201246638268, 0.066043588196690886, 0.27423084681792875, -0.16227524502747828, -0.41196436894789695,
  2273. 0.68568677491617847, -0.44989976435603013, 0.14406702115061959, -0.018694297761470441
  2274. };
  2275. return 0;
  2276. }
  2277. if (name == "db14")
  2278. {
  2279. lp1 = {
  2280. -1.7871399683109222e-07, 1.7249946753674012e-06, -4.3897049017804176e-06, -1.0337209184568496e-05, 6.875504252695734e-05, -4.1777245770370672e-05,
  2281. -0.00038683194731287514, 0.00070802115423540481, 0.001061691085606874, -0.003849638868019787, -0.00074621898926387534, 0.012789493266340071,
  2282. -0.0056150495303375755, -0.030185351540353976, 0.026981408307947971, 0.05523712625925082, -0.071548955503983505, -0.086748411568110598,
  2283. 0.13998901658445695, 0.13839521386479153, -0.21803352999321651, -0.27168855227867705, 0.21867068775886594, 0.63118784910471981, 0.55430561794077093,
  2284. 0.25485026779256437, 0.062364758849384874, 0.0064611534600864905
  2285. };
  2286. hp1 = {
  2287. -0.0064611534600864905, 0.062364758849384874, -0.25485026779256437, 0.55430561794077093, -0.63118784910471981, 0.21867068775886594,
  2288. 0.27168855227867705, -0.21803352999321651, -0.13839521386479153, 0.13998901658445695, 0.086748411568110598, -0.071548955503983505,
  2289. -0.05523712625925082, 0.026981408307947971, 0.030185351540353976, -0.0056150495303375755, -0.012789493266340071, -0.00074621898926387534,
  2290. 0.003849638868019787, 0.001061691085606874, -0.00070802115423540481, -0.00038683194731287514, 4.1777245770370672e-05, 6.875504252695734e-05,
  2291. 1.0337209184568496e-05, -4.3897049017804176e-06, -1.7249946753674012e-06, -1.7871399683109222e-07
  2292. };
  2293. lp2 = {
  2294. 0.0064611534600864905, 0.062364758849384874, 0.25485026779256437, 0.55430561794077093, 0.63118784910471981, 0.21867068775886594,
  2295. -0.27168855227867705, -0.21803352999321651, 0.13839521386479153, 0.13998901658445695, -0.086748411568110598, -0.071548955503983505,
  2296. 0.05523712625925082, 0.026981408307947971, -0.030185351540353976, -0.0056150495303375755, 0.012789493266340071, -0.00074621898926387534,
  2297. -0.003849638868019787, 0.001061691085606874, 0.00070802115423540481, -0.00038683194731287514, -4.1777245770370672e-05, 6.875504252695734e-05,
  2298. -1.0337209184568496e-05, -4.3897049017804176e-06, 1.7249946753674012e-06, -1.7871399683109222e-07
  2299. };
  2300. hp2 = {
  2301. -1.7871399683109222e-07, -1.7249946753674012e-06, -4.3897049017804176e-06, 1.0337209184568496e-05, 6.875504252695734e-05, 4.1777245770370672e-05,
  2302. -0.00038683194731287514, -0.00070802115423540481, 0.001061691085606874, 0.003849638868019787, -0.00074621898926387534, -0.012789493266340071,
  2303. -0.0056150495303375755, 0.030185351540353976, 0.026981408307947971, -0.05523712625925082, -0.071548955503983505, 0.086748411568110598,
  2304. 0.13998901658445695, -0.13839521386479153, -0.21803352999321651, 0.27168855227867705, 0.21867068775886594, -0.63118784910471981,
  2305. 0.55430561794077093, -0.25485026779256437, 0.062364758849384874, -0.0064611534600864905
  2306. };
  2307. return 0;
  2308. }
  2309. if (name == "db15")
  2310. {
  2311. lp1 = {
  2312. 6.1333599133037138e-08, -6.3168823258794506e-07, 1.8112704079399406e-06, 3.3629871817363823e-06, -2.8133296266037558e-05, 2.579269915531323e-05,
  2313. 0.00015589648992055726, -0.00035956524436229364, -0.00037348235413726472, 0.0019433239803823459, -0.00024175649075894543, -0.0064877345603061454,
  2314. 0.0051010003604228726, 0.015083918027862582, -0.020810050169636805, -0.025767007328366939, 0.054780550584559995, 0.033877143923563204,
  2315. -0.11112093603713753, -0.039666176555733602, 0.19014671400708816, 0.065282952848765688, -0.28888259656686216, -0.19320413960907623,
  2316. 0.33900253545462167, 0.64581314035721027, 0.49263177170797529, 0.20602386398692688, 0.046743394892750617, 0.0045385373615773762
  2317. };
  2318. hp1 = {
  2319. -0.0045385373615773762, 0.046743394892750617, -0.20602386398692688, 0.49263177170797529, -0.64581314035721027, 0.33900253545462167,
  2320. 0.19320413960907623, -0.28888259656686216, -0.065282952848765688, 0.19014671400708816, 0.039666176555733602, -0.11112093603713753,
  2321. -0.033877143923563204, 0.054780550584559995, 0.025767007328366939, -0.020810050169636805, -0.015083918027862582, 0.0051010003604228726,
  2322. 0.0064877345603061454, -0.00024175649075894543, -0.0019433239803823459, -0.00037348235413726472, 0.00035956524436229364, 0.00015589648992055726,
  2323. -2.579269915531323e-05, -2.8133296266037558e-05, -3.3629871817363823e-06, 1.8112704079399406e-06, 6.3168823258794506e-07, 6.1333599133037138e-08
  2324. };
  2325. lp2 = {
  2326. 0.0045385373615773762, 0.046743394892750617, 0.20602386398692688, 0.49263177170797529, 0.64581314035721027, 0.33900253545462167,
  2327. -0.19320413960907623, -0.28888259656686216, 0.065282952848765688, 0.19014671400708816, -0.039666176555733602, -0.11112093603713753,
  2328. 0.033877143923563204, 0.054780550584559995, -0.025767007328366939, -0.020810050169636805, 0.015083918027862582, 0.0051010003604228726,
  2329. -0.0064877345603061454, -0.00024175649075894543, 0.0019433239803823459, -0.00037348235413726472, -0.00035956524436229364, 0.00015589648992055726,
  2330. 2.579269915531323e-05, -2.8133296266037558e-05, 3.3629871817363823e-06, 1.8112704079399406e-06, -6.3168823258794506e-07, 6.1333599133037138e-08
  2331. };
  2332. hp2 = {
  2333. 6.1333599133037138e-08, 6.3168823258794506e-07, 1.8112704079399406e-06, -3.3629871817363823e-06, -2.8133296266037558e-05, -2.579269915531323e-05,
  2334. 0.00015589648992055726, 0.00035956524436229364, -0.00037348235413726472, -0.0019433239803823459, -0.00024175649075894543, 0.0064877345603061454,
  2335. 0.0051010003604228726, -0.015083918027862582, -0.020810050169636805, 0.025767007328366939, 0.054780550584559995, -0.033877143923563204,
  2336. -0.11112093603713753, 0.039666176555733602, 0.19014671400708816, -0.065282952848765688, -0.28888259656686216, 0.19320413960907623,
  2337. 0.33900253545462167, -0.64581314035721027, 0.49263177170797529, -0.20602386398692688, 0.046743394892750617, -0.0045385373615773762
  2338. };
  2339. return 0;
  2340. }
  2341. if (name == "bior1.1")
  2342. {
  2343. lp1 = { 0.70710678118654757, 0.70710678118654757 };
  2344. hp1 = { -0.70710678118654757, 0.70710678118654757 };
  2345. lp2 = { 0.70710678118654757, 0.70710678118654757 };
  2346. hp2 = { 0.70710678118654757, -0.70710678118654757 };
  2347. return 0;
  2348. }
  2349. if (name == "bior1.3")
  2350. {
  2351. lp1 = { -0.088388347648318447, 0.088388347648318447, 0.70710678118654757, 0.70710678118654757, 0.088388347648318447, -0.088388347648318447, };
  2352. hp1 = { 0.0, 0.0, -0.70710678118654757, 0.70710678118654757, 0.0, 0.0 };
  2353. lp2 = { 0.0, 0.0, 0.70710678118654757, 0.70710678118654757, 0.0, 0.0 };
  2354. hp2 = { -0.088388347648318447, -0.088388347648318447, 0.70710678118654757, -0.70710678118654757, 0.088388347648318447, 0.088388347648318447 };
  2355. return 0;
  2356. }
  2357. if (name == "bior1.5")
  2358. {
  2359. lp1 = {
  2360. 0.01657281518405971, -0.01657281518405971, -0.12153397801643787, 0.12153397801643787, 0.70710678118654757, 0.70710678118654757, 0.12153397801643787,
  2361. -0.12153397801643787, -0.01657281518405971, 0.01657281518405971
  2362. };
  2363. hp1 = { 0.0, 0.0, 0.0, 0.0, -0.70710678118654757, 0.70710678118654757, 0.0, 0.0, 0.0, 0.0 };
  2364. lp2 = { 0.0, 0.0, 0.0, 0.0, 0.70710678118654757, 0.70710678118654757, 0.0, 0.0, 0.0, 0.0 };
  2365. hp2 = {
  2366. 0.01657281518405971, 0.01657281518405971, -0.12153397801643787, -0.12153397801643787, 0.70710678118654757, -0.70710678118654757,
  2367. 0.12153397801643787, 0.12153397801643787, -0.01657281518405971, -0.01657281518405971
  2368. };
  2369. return 0;
  2370. }
  2371. if (name == "bior2.2")
  2372. {
  2373. lp1 = { 0.0, -0.17677669529663689, 0.35355339059327379, 1.0606601717798214, 0.35355339059327379, -0.17677669529663689 };
  2374. hp1 = { 0.0, 0.35355339059327379, -0.70710678118654757, 0.35355339059327379, 0.0, 0.0 };
  2375. lp2 = { 0.0, 0.35355339059327379, 0.70710678118654757, 0.35355339059327379, 0.0, 0.0 };
  2376. hp2 = { 0.0, 0.17677669529663689, 0.35355339059327379, -1.0606601717798214, 0.35355339059327379, 0.17677669529663689 };
  2377. return 0;
  2378. }
  2379. if (name == "bior2.4")
  2380. {
  2381. lp1 = {
  2382. 0.0, 0.033145630368119419, -0.066291260736238838, -0.17677669529663689, 0.4198446513295126, 0.99436891104358249, 0.4198446513295126,
  2383. -0.17677669529663689, -0.066291260736238838, 0.033145630368119419
  2384. };
  2385. hp1 = { 0.0, 0.0, 0.0, 0.35355339059327379, -0.70710678118654757, 0.35355339059327379, 0.0, 0.0, 0.0, 0.0 };
  2386. lp2 = { 0.0, 0.0, 0.0, 0.35355339059327379, 0.70710678118654757, 0.35355339059327379, 0.0, 0.0, 0.0, 0.0 };
  2387. hp2 = {
  2388. 0.0, -0.033145630368119419, -0.066291260736238838, 0.17677669529663689, 0.4198446513295126, -0.99436891104358249, 0.4198446513295126,
  2389. 0.17677669529663689, -0.066291260736238838, -0.033145630368119419
  2390. };
  2391. return 0;
  2392. }
  2393. if (name == "bior2.6")
  2394. {
  2395. lp1 = {
  2396. 0.0, -0.0069053396600248784, 0.013810679320049757, 0.046956309688169176, -0.10772329869638811, -0.16987135563661201, 0.44746600996961211,
  2397. 0.96674755240348298, 0.44746600996961211, -0.16987135563661201, -0.10772329869638811, 0.046956309688169176, 0.013810679320049757,
  2398. -0.0069053396600248784
  2399. };
  2400. hp1 = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.35355339059327379, -0.70710678118654757, 0.35355339059327379, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  2401. lp2 = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.35355339059327379, 0.70710678118654757, 0.35355339059327379, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  2402. hp2 = {
  2403. 0.0, 0.0069053396600248784, 0.013810679320049757, -0.046956309688169176, -0.10772329869638811, 0.16987135563661201, 0.44746600996961211,
  2404. -0.96674755240348298, 0.44746600996961211, 0.16987135563661201, -0.10772329869638811, -0.046956309688169176, 0.013810679320049757,
  2405. 0.0069053396600248784
  2406. };
  2407. return 0;
  2408. }
  2409. if (name == "bior2.8")
  2410. {
  2411. lp1 = {
  2412. 0.0, 0.0015105430506304422, -0.0030210861012608843, -0.012947511862546647, 0.028916109826354178, 0.052998481890690945, -0.13491307360773608,
  2413. -0.16382918343409025, 0.46257144047591658, 0.95164212189717856, 0.46257144047591658, -0.16382918343409025, -0.13491307360773608,
  2414. 0.052998481890690945, 0.028916109826354178, -0.012947511862546647, -0.0030210861012608843, 0.0015105430506304422
  2415. };
  2416. hp1 = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.35355339059327379, -0.70710678118654757, 0.35355339059327379, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  2417. lp2 = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.35355339059327379, 0.70710678118654757, 0.35355339059327379, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  2418. hp2 = {
  2419. 0.0, -0.0015105430506304422, -0.0030210861012608843, 0.012947511862546647, 0.028916109826354178, -0.052998481890690945, -0.13491307360773608,
  2420. 0.16382918343409025, 0.46257144047591658, -0.95164212189717856, 0.46257144047591658, 0.16382918343409025, -0.13491307360773608,
  2421. -0.052998481890690945, 0.028916109826354178, 0.012947511862546647, -0.0030210861012608843, -0.0015105430506304422
  2422. };
  2423. return 0;
  2424. }
  2425. if (name == "bior3.1")
  2426. {
  2427. lp1 = { -0.35355339059327379, 1.0606601717798214, 1.0606601717798214, -0.35355339059327379 };
  2428. hp1 = { -0.17677669529663689, 0.53033008588991071, -0.53033008588991071, 0.17677669529663689 };
  2429. lp2 = { 0.17677669529663689, 0.53033008588991071, 0.53033008588991071, 0.17677669529663689 };
  2430. hp2 = { -0.35355339059327379, -1.0606601717798214, 1.0606601717798214, 0.35355339059327379 };
  2431. return 0;
  2432. }
  2433. if (name == "bior3.3")
  2434. {
  2435. lp1 = {
  2436. 0.066291260736238838, -0.19887378220871652, -0.15467960838455727, 0.99436891104358249, 0.99436891104358249, -0.15467960838455727,
  2437. -0.19887378220871652, 0.066291260736238838
  2438. };
  2439. hp1 = { 0.0, 0.0, -0.17677669529663689, 0.53033008588991071, -0.53033008588991071, 0.17677669529663689, 0.0, 0.0 };
  2440. lp2 = { 0.0, 0.0, 0.17677669529663689, 0.53033008588991071, 0.53033008588991071, 0.17677669529663689, 0.0, 0.0 };
  2441. hp2 = {
  2442. 0.066291260736238838, 0.19887378220871652, -0.15467960838455727, -0.99436891104358249, 0.99436891104358249, 0.15467960838455727,
  2443. -0.19887378220871652, -0.066291260736238838
  2444. };
  2445. return 0;
  2446. }
  2447. if (name == "bior3.5")
  2448. {
  2449. lp1 = {
  2450. -0.013810679320049757, 0.041432037960149271, 0.052480581416189075, -0.26792717880896527, -0.071815532464258744, 0.96674755240348298,
  2451. 0.96674755240348298, -0.071815532464258744, -0.26792717880896527, 0.052480581416189075, 0.041432037960149271, -0.013810679320049757
  2452. };
  2453. hp1 = { 0.0, 0.0, 0.0, 0.0, -0.17677669529663689, 0.53033008588991071, -0.53033008588991071, 0.17677669529663689, 0.0, 0.0, 0.0, 0.0 };
  2454. lp2 = { 0.0, 0.0, 0.0, 0.0, 0.17677669529663689, 0.53033008588991071, 0.53033008588991071, 0.17677669529663689, 0.0, 0.0, 0.0, 0.0 };
  2455. hp2 = {
  2456. -0.013810679320049757, -0.041432037960149271, 0.052480581416189075, 0.26792717880896527, -0.071815532464258744, -0.96674755240348298,
  2457. 0.96674755240348298, 0.071815532464258744, -0.26792717880896527, -0.052480581416189075, 0.041432037960149271, 0.013810679320049757
  2458. };
  2459. return 0;
  2460. }
  2461. if (name == "bior3.7")
  2462. {
  2463. lp1 = {
  2464. 0.0030210861012608843, -0.0090632583037826529, -0.016831765421310641, 0.074663985074019001, 0.031332978707362888, -0.301159125922835,
  2465. -0.026499240945345472, 0.95164212189717856, 0.95164212189717856, -0.026499240945345472, -0.301159125922835, 0.031332978707362888,
  2466. 0.074663985074019001, -0.016831765421310641, -0.0090632583037826529, 0.0030210861012608843
  2467. };
  2468. hp1 = {
  2469. 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.17677669529663689, 0.53033008588991071, -0.53033008588991071, 0.17677669529663689, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
  2470. };
  2471. lp2 = {
  2472. 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.17677669529663689, 0.53033008588991071, 0.53033008588991071, 0.17677669529663689, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
  2473. };
  2474. hp2 = {
  2475. 0.0030210861012608843, 0.0090632583037826529, -0.016831765421310641, -0.074663985074019001, 0.031332978707362888, 0.301159125922835,
  2476. -0.026499240945345472, -0.95164212189717856, 0.95164212189717856, 0.026499240945345472, -0.301159125922835, -0.031332978707362888,
  2477. 0.074663985074019001, 0.016831765421310641, -0.0090632583037826529, -0.0030210861012608843
  2478. };
  2479. return 0;
  2480. }
  2481. if (name == "bior3.9")
  2482. {
  2483. lp1 = {
  2484. -0.00067974437278369901, 0.0020392331183510968, 0.0050603192196119811, -0.020618912641105536, -0.014112787930175846, 0.09913478249423216,
  2485. 0.012300136269419315, -0.32019196836077857, 0.0020500227115698858, 0.94212570067820678, 0.94212570067820678, 0.0020500227115698858,
  2486. -0.32019196836077857, 0.012300136269419315, 0.09913478249423216, -0.014112787930175846, -0.020618912641105536, 0.0050603192196119811,
  2487. 0.0020392331183510968, -0.00067974437278369901
  2488. };
  2489. hp1 = {
  2490. 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.17677669529663689, 0.53033008588991071, -0.53033008588991071, 0.17677669529663689, 0.0, 0.0, 0.0, 0.0,
  2491. 0.0, 0.0, 0.0, 0.0
  2492. };
  2493. lp2 = {
  2494. 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.17677669529663689, 0.53033008588991071, 0.53033008588991071, 0.17677669529663689, 0.0, 0.0, 0.0, 0.0, 0.0,
  2495. 0.0, 0.0, 0.0
  2496. };
  2497. hp2 = {
  2498. -0.00067974437278369901, -0.0020392331183510968, 0.0050603192196119811, 0.020618912641105536, -0.014112787930175846, -0.09913478249423216,
  2499. 0.012300136269419315, 0.32019196836077857, 0.0020500227115698858, -0.94212570067820678, 0.94212570067820678, -0.0020500227115698858,
  2500. -0.32019196836077857, -0.012300136269419315, 0.09913478249423216, 0.014112787930175846, -0.020618912641105536, -0.0050603192196119811,
  2501. 0.0020392331183510968, 0.00067974437278369901
  2502. };
  2503. return 0;
  2504. }
  2505. if (name == "bior4.4")
  2506. {
  2507. lp1 = {
  2508. 0.0, 0.03782845550726404, -0.023849465019556843, -0.11062440441843718, 0.37740285561283066, 0.85269867900889385, 0.37740285561283066,
  2509. -0.11062440441843718, -0.023849465019556843, 0.03782845550726404
  2510. };
  2511. hp1 = {
  2512. 0.0, -0.064538882628697058, 0.040689417609164058, 0.41809227322161724, -0.7884856164055829, 0.41809227322161724, 0.040689417609164058,
  2513. -0.064538882628697058, 0.0, 0.0
  2514. };
  2515. lp2 = {
  2516. 0.0, -0.064538882628697058, -0.040689417609164058, 0.41809227322161724, 0.7884856164055829, 0.41809227322161724, -0.040689417609164058,
  2517. -0.064538882628697058, 0.0, 0.0
  2518. };
  2519. hp2 = {
  2520. 0.0, -0.03782845550726404, -0.023849465019556843, 0.11062440441843718, 0.37740285561283066, -0.85269867900889385, 0.37740285561283066,
  2521. 0.11062440441843718, -0.023849465019556843, -0.03782845550726404
  2522. };
  2523. return 0;
  2524. }
  2525. if (name == "bior5.5")
  2526. {
  2527. lp1 = {
  2528. 0.0, 0.0, 0.03968708834740544, 0.0079481086372403219, -0.054463788468236907, 0.34560528195603346, 0.73666018142821055, 0.34560528195603346,
  2529. -0.054463788468236907, 0.0079481086372403219, 0.03968708834740544, 0.0
  2530. };
  2531. hp1 = {
  2532. -0.013456709459118716, -0.0026949668801115071, 0.13670658466432914, -0.093504697400938863, -0.47680326579848425, 0.89950610974864842,
  2533. -0.47680326579848425, -0.093504697400938863, 0.13670658466432914, -0.0026949668801115071, -0.013456709459118716, 0.0
  2534. };
  2535. lp2 = {
  2536. 0.013456709459118716, -0.0026949668801115071, -0.13670658466432914, -0.093504697400938863, 0.47680326579848425, 0.89950610974864842,
  2537. 0.47680326579848425, -0.093504697400938863, -0.13670658466432914, -0.0026949668801115071, 0.013456709459118716, 0.0
  2538. };
  2539. hp2 = {
  2540. 0.0, 0.0, 0.03968708834740544, -0.0079481086372403219, -0.054463788468236907, -0.34560528195603346, 0.73666018142821055, -0.34560528195603346,
  2541. -0.054463788468236907, -0.0079481086372403219, 0.03968708834740544, 0.0
  2542. };
  2543. return 0;
  2544. }
  2545. if (name == "bior6.8")
  2546. {
  2547. lp1 = {
  2548. 0.0, 0.0019088317364812906, -0.0019142861290887667, -0.016990639867602342, 0.01193456527972926, 0.04973290349094079, -0.077263173167204144,
  2549. -0.09405920349573646, 0.42079628460982682, 0.82592299745840225, 0.42079628460982682, -0.09405920349573646, -0.077263173167204144,
  2550. 0.04973290349094079, 0.01193456527972926, -0.016990639867602342, -0.0019142861290887667, 0.0019088317364812906
  2551. };
  2552. hp1 = {
  2553. 0.0, 0.0, 0.0, 0.014426282505624435, -0.014467504896790148, -0.078722001062628819, 0.040367979030339923, 0.41784910915027457, -0.75890772945365415,
  2554. 0.41784910915027457, 0.040367979030339923, -0.078722001062628819, -0.014467504896790148, 0.014426282505624435, 0.0, 0.0, 0.0, 0.0
  2555. };
  2556. lp2 = {
  2557. 0.0, 0.0, 0.0, 0.014426282505624435, 0.014467504896790148, -0.078722001062628819, -0.040367979030339923, 0.41784910915027457, 0.75890772945365415,
  2558. 0.41784910915027457, -0.040367979030339923, -0.078722001062628819, 0.014467504896790148, 0.014426282505624435, 0.0, 0.0, 0.0, 0.0
  2559. };
  2560. hp2 = {
  2561. 0.0, -0.0019088317364812906, -0.0019142861290887667, 0.016990639867602342, 0.01193456527972926, -0.04973290349094079, -0.077263173167204144,
  2562. 0.09405920349573646, 0.42079628460982682, -0.82592299745840225, 0.42079628460982682, 0.09405920349573646, -0.077263173167204144,
  2563. -0.04973290349094079, 0.01193456527972926, 0.016990639867602342, -0.0019142861290887667, -0.0019088317364812906
  2564. };
  2565. return 0;
  2566. }
  2567. if (name == "coif1")
  2568. {
  2569. lp1 = { -0.01565572813546454, -0.072732619512853897, 0.38486484686420286, 0.85257202021225542, 0.33789766245780922, -0.072732619512853897 };
  2570. hp1 = { 0.072732619512853897, 0.33789766245780922, -0.85257202021225542, 0.38486484686420286, 0.072732619512853897, -0.01565572813546454 };
  2571. lp2 = { -0.072732619512853897, 0.33789766245780922, 0.85257202021225542, 0.38486484686420286, -0.072732619512853897, -0.01565572813546454 };
  2572. hp2 = { -0.01565572813546454, 0.072732619512853897, 0.38486484686420286, -0.85257202021225542, 0.33789766245780922, 0.072732619512853897 };
  2573. return 0;
  2574. }
  2575. if (name == "coif2")
  2576. {
  2577. lp1 = {
  2578. -0.00072054944536451221, -0.0018232088707029932, 0.0056114348193944995, 0.023680171946334084, -0.059434418646456898, -0.076488599078306393,
  2579. 0.41700518442169254, 0.81272363544554227, 0.38611006682116222, -0.067372554721963018, -0.041464936781759151, 0.016387336463522112
  2580. };
  2581. hp1 = {
  2582. -0.016387336463522112, -0.041464936781759151, 0.067372554721963018, 0.38611006682116222, -0.81272363544554227, 0.41700518442169254,
  2583. 0.076488599078306393, -0.059434418646456898, -0.023680171946334084, 0.0056114348193944995, 0.0018232088707029932, -0.00072054944536451221
  2584. };
  2585. lp2 = {
  2586. 0.016387336463522112, -0.041464936781759151, -0.067372554721963018, 0.38611006682116222, 0.81272363544554227, 0.41700518442169254,
  2587. -0.076488599078306393, -0.059434418646456898, 0.023680171946334084, 0.0056114348193944995, -0.0018232088707029932, -0.00072054944536451221
  2588. };
  2589. hp2 = {
  2590. -0.00072054944536451221, 0.0018232088707029932, 0.0056114348193944995, -0.023680171946334084, -0.059434418646456898, 0.076488599078306393,
  2591. 0.41700518442169254, -0.81272363544554227, 0.38611006682116222, 0.067372554721963018, -0.041464936781759151, -0.016387336463522112
  2592. };
  2593. return 0;
  2594. }
  2595. if (name == "coif3")
  2596. {
  2597. lp1 = {
  2598. -3.4599772836212559e-05, -7.0983303138141252e-05, 0.00046621696011288631, 0.0011175187708906016, -0.0025745176887502236, -0.0090079761366615805,
  2599. 0.015880544863615904, 0.034555027573061628, -0.082301927106885983, -0.071799821619312018, 0.42848347637761874, 0.79377722262562056,
  2600. 0.4051769024096169, -0.061123390002672869, -0.0657719112818555, 0.023452696141836267, 0.0077825964273254182, -0.0037935128644910141
  2601. };
  2602. hp1 = {
  2603. 0.0037935128644910141, 0.0077825964273254182, -0.023452696141836267, -0.0657719112818555, 0.061123390002672869, 0.4051769024096169,
  2604. -0.79377722262562056, 0.42848347637761874, 0.071799821619312018, -0.082301927106885983, -0.034555027573061628, 0.015880544863615904,
  2605. 0.0090079761366615805, -0.0025745176887502236, -0.0011175187708906016, 0.00046621696011288631, 7.0983303138141252e-05, -3.4599772836212559e-05
  2606. };
  2607. lp2 = {
  2608. -0.0037935128644910141, 0.0077825964273254182, 0.023452696141836267, -0.0657719112818555, -0.061123390002672869, 0.4051769024096169,
  2609. 0.79377722262562056, 0.42848347637761874, -0.071799821619312018, -0.082301927106885983, 0.034555027573061628, 0.015880544863615904,
  2610. -0.0090079761366615805, -0.0025745176887502236, 0.0011175187708906016, 0.00046621696011288631, -7.0983303138141252e-05, -3.4599772836212559e-05
  2611. };
  2612. hp2 = {
  2613. -3.4599772836212559e-05, 7.0983303138141252e-05, 0.00046621696011288631, -0.0011175187708906016, -0.0025745176887502236, 0.0090079761366615805,
  2614. 0.015880544863615904, -0.034555027573061628, -0.082301927106885983, 0.071799821619312018, 0.42848347637761874, -0.79377722262562056,
  2615. 0.4051769024096169, 0.061123390002672869, -0.0657719112818555, -0.023452696141836267, 0.0077825964273254182, 0.0037935128644910141
  2616. };
  2617. return 0;
  2618. }
  2619. if (name == "coif4")
  2620. {
  2621. lp1 = {
  2622. -1.7849850030882614e-06, -3.2596802368833675e-06, 3.1229875865345646e-05, 6.2339034461007128e-05, -0.00025997455248771324, -0.00058902075624433831,
  2623. 0.0012665619292989445, 0.0037514361572784571, -0.0056582866866107199, -0.015211731527946259, 0.025082261844864097, 0.039334427123337491,
  2624. -0.096220442033987982, -0.066627474263425038, 0.4343860564914685, 0.78223893092049901, 0.41530840703043026, -0.056077313316754807,
  2625. -0.081266699680878754, 0.026682300156053072, 0.016068943964776348, -0.0073461663276420935, -0.0016294920126017326, 0.00089231366858231456
  2626. };
  2627. hp1 = {
  2628. -0.00089231366858231456, -0.0016294920126017326, 0.0073461663276420935, 0.016068943964776348, -0.026682300156053072, -0.081266699680878754,
  2629. 0.056077313316754807, 0.41530840703043026, -0.78223893092049901, 0.4343860564914685, 0.066627474263425038, -0.096220442033987982,
  2630. -0.039334427123337491, 0.025082261844864097, 0.015211731527946259, -0.0056582866866107199, -0.0037514361572784571, 0.0012665619292989445,
  2631. 0.00058902075624433831, -0.00025997455248771324, -6.2339034461007128e-05, 3.1229875865345646e-05, 3.2596802368833675e-06, -1.7849850030882614e-06
  2632. };
  2633. lp2 = {
  2634. 0.00089231366858231456, -0.0016294920126017326, -0.0073461663276420935, 0.016068943964776348, 0.026682300156053072, -0.081266699680878754,
  2635. -0.056077313316754807, 0.41530840703043026, 0.78223893092049901, 0.4343860564914685, -0.066627474263425038, -0.096220442033987982,
  2636. 0.039334427123337491, 0.025082261844864097, -0.015211731527946259, -0.0056582866866107199, 0.0037514361572784571, 0.0012665619292989445,
  2637. -0.00058902075624433831, -0.00025997455248771324, 6.2339034461007128e-05, 3.1229875865345646e-05, -3.2596802368833675e-06, -1.7849850030882614e-06
  2638. };
  2639. hp2 = {
  2640. -1.7849850030882614e-06, 3.2596802368833675e-06, 3.1229875865345646e-05, -6.2339034461007128e-05, -0.00025997455248771324, 0.00058902075624433831,
  2641. 0.0012665619292989445, -0.0037514361572784571, -0.0056582866866107199, 0.015211731527946259, 0.025082261844864097, -0.039334427123337491,
  2642. -0.096220442033987982, 0.066627474263425038, 0.4343860564914685, -0.78223893092049901, 0.41530840703043026, 0.056077313316754807,
  2643. -0.081266699680878754, -0.026682300156053072, 0.016068943964776348, 0.0073461663276420935, -0.0016294920126017326, -0.00089231366858231456
  2644. };
  2645. return 0;
  2646. }
  2647. if (name == "coif5")
  2648. {
  2649. lp1 = {
  2650. -9.517657273819165e-08, -1.6744288576823017e-07, 2.0637618513646814e-06, 3.7346551751414047e-06, -2.1315026809955787e-05, -4.1340432272512511e-05,
  2651. 0.00014054114970203437, 0.00030225958181306315, -0.00063813134304511142, -0.0016628637020130838, 0.0024333732126576722, 0.0067641854480530832,
  2652. -0.0091642311624818458, -0.019761778942572639, 0.032683574267111833, 0.041289208750181702, -0.10557420870333893, -0.062035963962903569,
  2653. 0.43799162617183712, 0.77428960365295618, 0.42156620669085149, -0.052043163176243773, -0.091920010559696244, 0.02816802897093635,
  2654. 0.023408156785839195, -0.010131117519849788, -0.004159358781386048, 0.0021782363581090178, 0.00035858968789573785, -0.00021208083980379827
  2655. };
  2656. hp1 = {
  2657. 0.00021208083980379827, 0.00035858968789573785, -0.0021782363581090178, -0.004159358781386048, 0.010131117519849788, 0.023408156785839195,
  2658. -0.02816802897093635, -0.091920010559696244, 0.052043163176243773, 0.42156620669085149, -0.77428960365295618, 0.43799162617183712,
  2659. 0.062035963962903569, -0.10557420870333893, -0.041289208750181702, 0.032683574267111833, 0.019761778942572639, -0.0091642311624818458,
  2660. -0.0067641854480530832, 0.0024333732126576722, 0.0016628637020130838, -0.00063813134304511142, -0.00030225958181306315, 0.00014054114970203437,
  2661. 4.1340432272512511e-05, -2.1315026809955787e-05, -3.7346551751414047e-06, 2.0637618513646814e-06, 1.6744288576823017e-07, -9.517657273819165e-08
  2662. };
  2663. lp2 = {
  2664. -0.00021208083980379827, 0.00035858968789573785, 0.0021782363581090178, -0.004159358781386048, -0.010131117519849788, 0.023408156785839195,
  2665. 0.02816802897093635, -0.091920010559696244, -0.052043163176243773, 0.42156620669085149, 0.77428960365295618, 0.43799162617183712,
  2666. -0.062035963962903569, -0.10557420870333893, 0.041289208750181702, 0.032683574267111833, -0.019761778942572639, -0.0091642311624818458,
  2667. 0.0067641854480530832, 0.0024333732126576722, -0.0016628637020130838, -0.00063813134304511142, 0.00030225958181306315, 0.00014054114970203437,
  2668. -4.1340432272512511e-05, -2.1315026809955787e-05, 3.7346551751414047e-06, 2.0637618513646814e-06, -1.6744288576823017e-07, -9.517657273819165e-08
  2669. };
  2670. hp2 = {
  2671. -9.517657273819165e-08, 1.6744288576823017e-07, 2.0637618513646814e-06, -3.7346551751414047e-06, -2.1315026809955787e-05, 4.1340432272512511e-05,
  2672. 0.00014054114970203437, -0.00030225958181306315, -0.00063813134304511142, 0.0016628637020130838, 0.0024333732126576722, -0.0067641854480530832,
  2673. -0.0091642311624818458, 0.019761778942572639, 0.032683574267111833, -0.041289208750181702, -0.10557420870333893, 0.062035963962903569,
  2674. 0.43799162617183712, -0.77428960365295618, 0.42156620669085149, 0.052043163176243773, -0.091920010559696244, -0.02816802897093635,
  2675. 0.023408156785839195, 0.010131117519849788, -0.004159358781386048, -0.0021782363581090178, 0.00035858968789573785, 0.00021208083980379827
  2676. };
  2677. return 0;
  2678. }
  2679. if (name == "sym2")
  2680. {
  2681. lp1 = { -0.12940952255092145, 0.22414386804185735, 0.83651630373746899, 0.48296291314469025 };
  2682. hp1 = { -0.48296291314469025, 0.83651630373746899, -0.22414386804185735, -0.12940952255092145 };
  2683. lp2 = { 0.48296291314469025, 0.83651630373746899, 0.22414386804185735, -0.12940952255092145 };
  2684. hp2 = { -0.12940952255092145, -0.22414386804185735, 0.83651630373746899, -0.48296291314469025 };
  2685. return 0;
  2686. }
  2687. if (name == "sym3")
  2688. {
  2689. lp1 = { 0.035226291882100656, -0.085441273882241486, -0.13501102001039084, 0.45987750211933132, 0.80689150931333875, 0.33267055295095688 };
  2690. hp1 = { -0.33267055295095688, 0.80689150931333875, -0.45987750211933132, -0.13501102001039084, 0.085441273882241486, 0.035226291882100656 };
  2691. lp2 = { 0.33267055295095688, 0.80689150931333875, 0.45987750211933132, -0.13501102001039084, -0.085441273882241486, 0.035226291882100656 };
  2692. hp2 = { 0.035226291882100656, 0.085441273882241486, -0.13501102001039084, -0.45987750211933132, 0.80689150931333875, -0.33267055295095688 };
  2693. return 0;
  2694. }
  2695. if (name == "sym4")
  2696. {
  2697. lp1 = {
  2698. -0.075765714789273325, -0.02963552764599851, 0.49761866763201545, 0.80373875180591614, 0.29785779560527736, -0.099219543576847216,
  2699. -0.012603967262037833, 0.032223100604042702
  2700. };
  2701. hp1 = {
  2702. -0.032223100604042702, -0.012603967262037833, 0.099219543576847216, 0.29785779560527736, -0.80373875180591614, 0.49761866763201545,
  2703. 0.02963552764599851, -0.075765714789273325
  2704. };
  2705. lp2 = {
  2706. 0.032223100604042702, -0.012603967262037833, -0.099219543576847216, 0.29785779560527736, 0.80373875180591614, 0.49761866763201545,
  2707. -0.02963552764599851, -0.075765714789273325
  2708. };
  2709. hp2 = {
  2710. -0.075765714789273325, 0.02963552764599851, 0.49761866763201545, -0.80373875180591614, 0.29785779560527736, 0.099219543576847216,
  2711. -0.012603967262037833, -0.032223100604042702
  2712. };
  2713. return 0;
  2714. }
  2715. if (name == "sym5")
  2716. {
  2717. lp1 = {
  2718. 0.027333068345077982, 0.029519490925774643, -0.039134249302383094, 0.1993975339773936, 0.72340769040242059, 0.63397896345821192,
  2719. 0.016602105764522319, -0.17532808990845047, -0.021101834024758855, 0.019538882735286728
  2720. };
  2721. hp1 = {
  2722. -0.019538882735286728, -0.021101834024758855, 0.17532808990845047, 0.016602105764522319, -0.63397896345821192, 0.72340769040242059,
  2723. -0.1993975339773936, -0.039134249302383094, -0.029519490925774643, 0.027333068345077982
  2724. };
  2725. lp2 = {
  2726. 0.019538882735286728, -0.021101834024758855, -0.17532808990845047, 0.016602105764522319, 0.63397896345821192, 0.72340769040242059,
  2727. 0.1993975339773936, -0.039134249302383094, 0.029519490925774643, 0.027333068345077982
  2728. };
  2729. hp2 = {
  2730. 0.027333068345077982, -0.029519490925774643, -0.039134249302383094, -0.1993975339773936, 0.72340769040242059, -0.63397896345821192,
  2731. 0.016602105764522319, 0.17532808990845047, -0.021101834024758855, -0.019538882735286728
  2732. };
  2733. return 0;
  2734. }
  2735. if (name == "sym6")
  2736. {
  2737. lp1 = {
  2738. 0.015404109327027373, 0.0034907120842174702, -0.11799011114819057, -0.048311742585632998, 0.49105594192674662, 0.787641141030194,
  2739. 0.3379294217276218, -0.072637522786462516, -0.021060292512300564, 0.044724901770665779, 0.0017677118642428036, -0.007800708325034148
  2740. };
  2741. hp1 = {
  2742. 0.007800708325034148, 0.0017677118642428036, -0.044724901770665779, -0.021060292512300564, 0.072637522786462516, 0.3379294217276218,
  2743. -0.787641141030194, 0.49105594192674662, 0.048311742585632998, -0.11799011114819057, -0.0034907120842174702, 0.015404109327027373
  2744. };
  2745. lp2 = {
  2746. -0.007800708325034148, 0.0017677118642428036, 0.044724901770665779, -0.021060292512300564, -0.072637522786462516, 0.3379294217276218,
  2747. 0.787641141030194, 0.49105594192674662, -0.048311742585632998, -0.11799011114819057, 0.0034907120842174702, 0.015404109327027373
  2748. };
  2749. hp2 = {
  2750. 0.015404109327027373, -0.0034907120842174702, -0.11799011114819057, 0.048311742585632998, 0.49105594192674662, -0.787641141030194,
  2751. 0.3379294217276218, 0.072637522786462516, -0.021060292512300564, -0.044724901770665779, 0.0017677118642428036, 0.007800708325034148
  2752. };
  2753. return 0;
  2754. }
  2755. if (name == "sym7")
  2756. {
  2757. lp1 = {
  2758. 0.0026818145682578781, -0.0010473848886829163, -0.01263630340325193, 0.03051551316596357, 0.067892693501372697, -0.049552834937127255,
  2759. 0.017441255086855827, 0.5361019170917628, 0.76776431700316405, 0.28862963175151463, -0.14004724044296152, -0.10780823770381774,
  2760. 0.0040102448715336634, 0.010268176708511255
  2761. };
  2762. hp1 = {
  2763. -0.010268176708511255, 0.0040102448715336634, 0.10780823770381774, -0.14004724044296152, -0.28862963175151463, 0.76776431700316405,
  2764. -0.5361019170917628, 0.017441255086855827, 0.049552834937127255, 0.067892693501372697, -0.03051551316596357, -0.01263630340325193,
  2765. 0.0010473848886829163, 0.0026818145682578781
  2766. };
  2767. lp2 = {
  2768. 0.010268176708511255, 0.0040102448715336634, -0.10780823770381774, -0.14004724044296152, 0.28862963175151463, 0.76776431700316405,
  2769. 0.5361019170917628, 0.017441255086855827, -0.049552834937127255, 0.067892693501372697, 0.03051551316596357, -0.01263630340325193,
  2770. -0.0010473848886829163, 0.0026818145682578781
  2771. };
  2772. hp2 = {
  2773. 0.0026818145682578781, 0.0010473848886829163, -0.01263630340325193, -0.03051551316596357, 0.067892693501372697, 0.049552834937127255,
  2774. 0.017441255086855827, -0.5361019170917628, 0.76776431700316405, -0.28862963175151463, -0.14004724044296152, 0.10780823770381774,
  2775. 0.0040102448715336634, -0.010268176708511255
  2776. };
  2777. return 0;
  2778. }
  2779. if (name == "sym8")
  2780. {
  2781. lp1 = {
  2782. -0.0033824159510061256, -0.00054213233179114812, 0.031695087811492981, 0.0076074873249176054, -0.14329423835080971, -0.061273359067658524,
  2783. 0.48135965125837221, 0.77718575170052351, 0.3644418948353314, -0.051945838107709037, -0.027219029917056003, 0.049137179673607506,
  2784. 0.0038087520138906151, -0.014952258337048231, -0.0003029205147213668, 0.0018899503327594609
  2785. };
  2786. hp1 = {
  2787. -0.0018899503327594609, -0.0003029205147213668, 0.014952258337048231, 0.0038087520138906151, -0.049137179673607506, -0.027219029917056003,
  2788. 0.051945838107709037, 0.3644418948353314, -0.77718575170052351, 0.48135965125837221, 0.061273359067658524, -0.14329423835080971,
  2789. -0.0076074873249176054, 0.031695087811492981, 0.00054213233179114812, -0.0033824159510061256
  2790. };
  2791. lp2 = {
  2792. 0.0018899503327594609, -0.0003029205147213668, -0.014952258337048231, 0.0038087520138906151, 0.049137179673607506, -0.027219029917056003,
  2793. -0.051945838107709037, 0.3644418948353314, 0.77718575170052351, 0.48135965125837221, -0.061273359067658524, -0.14329423835080971,
  2794. 0.0076074873249176054, 0.031695087811492981, -0.00054213233179114812, -0.0033824159510061256
  2795. };
  2796. hp2 = {
  2797. -0.0033824159510061256, 0.00054213233179114812, 0.031695087811492981, -0.0076074873249176054, -0.14329423835080971, 0.061273359067658524,
  2798. 0.48135965125837221, -0.77718575170052351, 0.3644418948353314, 0.051945838107709037, -0.027219029917056003, -0.049137179673607506,
  2799. 0.0038087520138906151, 0.014952258337048231, -0.0003029205147213668, -0.0018899503327594609
  2800. };
  2801. return 0;
  2802. }
  2803. if (name == "sym9")
  2804. {
  2805. lp1 = {
  2806. 0.0014009155259146807, 0.00061978088898558676, -0.013271967781817119, -0.01152821020767923, 0.03022487885827568, 0.00058346274612580684,
  2807. -0.054568958430834071, 0.238760914607303, 0.717897082764412, 0.61733844914093583, 0.035272488035271894, -0.19155083129728512, -0.018233770779395985,
  2808. 0.06207778930288603, 0.0088592674934004842, -0.010264064027633142, -0.00047315449868008311, 0.0010694900329086053
  2809. };
  2810. hp1 = {
  2811. -0.0010694900329086053, -0.00047315449868008311, 0.010264064027633142, 0.0088592674934004842, -0.06207778930288603, -0.018233770779395985,
  2812. 0.19155083129728512, 0.035272488035271894, -0.61733844914093583, 0.717897082764412, -0.238760914607303, -0.054568958430834071,
  2813. -0.00058346274612580684, 0.03022487885827568, 0.01152821020767923, -0.013271967781817119, -0.00061978088898558676, 0.0014009155259146807
  2814. };
  2815. lp2 = {
  2816. 0.0010694900329086053, -0.00047315449868008311, -0.010264064027633142, 0.0088592674934004842, 0.06207778930288603, -0.018233770779395985,
  2817. -0.19155083129728512, 0.035272488035271894, 0.61733844914093583, 0.717897082764412, 0.238760914607303, -0.054568958430834071,
  2818. 0.00058346274612580684, 0.03022487885827568, -0.01152821020767923, -0.013271967781817119, 0.00061978088898558676, 0.0014009155259146807
  2819. };
  2820. hp2 = {
  2821. 0.0014009155259146807, -0.00061978088898558676, -0.013271967781817119, 0.01152821020767923, 0.03022487885827568, -0.00058346274612580684,
  2822. -0.054568958430834071, -0.238760914607303, 0.717897082764412, -0.61733844914093583, 0.035272488035271894, 0.19155083129728512,
  2823. -0.018233770779395985, -0.06207778930288603, 0.0088592674934004842, 0.010264064027633142, -0.00047315449868008311, -0.0010694900329086053
  2824. };
  2825. return 0;
  2826. }
  2827. if (name == "sym10")
  2828. {
  2829. lp1 = {
  2830. 0.00077015980911449011, 9.5632670722894754e-05, -0.0086412992770224222, -0.0014653825813050513, 0.045927239231092203, 0.011609893903711381,
  2831. -0.15949427888491757, -0.070880535783243853, 0.47169066693843925, 0.7695100370211071, 0.38382676106708546, -0.035536740473817552,
  2832. -0.0319900568824278, 0.049994972077376687, 0.0057649120335819086, -0.02035493981231129, -0.00080435893201654491, 0.0045931735853118284,
  2833. 5.7036083618494284e-05, -0.00045932942100465878
  2834. };
  2835. hp1 = {
  2836. 0.00045932942100465878, 5.7036083618494284e-05, -0.0045931735853118284, -0.00080435893201654491, 0.02035493981231129, 0.0057649120335819086,
  2837. -0.049994972077376687, -0.0319900568824278, 0.035536740473817552, 0.38382676106708546, -0.7695100370211071, 0.47169066693843925,
  2838. 0.070880535783243853, -0.15949427888491757, -0.011609893903711381, 0.045927239231092203, 0.0014653825813050513, -0.0086412992770224222,
  2839. -9.5632670722894754e-05, 0.00077015980911449011
  2840. };
  2841. lp2 = {
  2842. -0.00045932942100465878, 5.7036083618494284e-05, 0.0045931735853118284, -0.00080435893201654491, -0.02035493981231129, 0.0057649120335819086,
  2843. 0.049994972077376687, -0.0319900568824278, -0.035536740473817552, 0.38382676106708546, 0.7695100370211071, 0.47169066693843925,
  2844. -0.070880535783243853, -0.15949427888491757, 0.011609893903711381, 0.045927239231092203, -0.0014653825813050513, -0.0086412992770224222,
  2845. 9.5632670722894754e-05, 0.00077015980911449011
  2846. };
  2847. hp2 = {
  2848. 0.00077015980911449011, -9.5632670722894754e-05, -0.0086412992770224222, 0.0014653825813050513, 0.045927239231092203, -0.011609893903711381,
  2849. -0.15949427888491757, 0.070880535783243853, 0.47169066693843925, -0.7695100370211071, 0.38382676106708546, 0.035536740473817552,
  2850. -0.0319900568824278, -0.049994972077376687, 0.0057649120335819086, 0.02035493981231129, -0.00080435893201654491, -0.0045931735853118284,
  2851. 5.7036083618494284e-05, 0.00045932942100465878
  2852. };
  2853. return 0;
  2854. }
  2855. std::cout << "Filter Not in Database" << std::endl;
  2856. return -1;
  2857. }
  2858. #endif