1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

first skeleton for DWT

This commit is contained in:
Antonin Portelli 2022-02-17 19:24:34 +00:00
parent 47d0b3f040
commit 65a656f257
5 changed files with 694 additions and 0 deletions

View File

@ -48,6 +48,8 @@ libLatAnalyze_la_SOURCES = \
Io/XmlReader.cpp \
Io/Xml/tinyxml2.cpp \
Numerical/Derivative.cpp \
Numerical/DWT.cpp \
Numerical/DWTFilters.cpp \
Numerical/GslFFT.cpp \
Numerical/GslHybridRootFinder.cpp\
Numerical/GslMinimizer.cpp \
@ -92,6 +94,8 @@ HPPFILES = \
Io/IoObject.hpp \
Io/XmlReader.hpp \
Numerical/Derivative.hpp \
Numerical/DWT.hpp \
Numerical/DWTFilters.hpp \
Numerical/FFT.hpp \
Numerical/GslFFT.hpp \
Numerical/GslHybridRootFinder.hpp\

57
lib/Numerical/DWT.cpp Normal file
View File

@ -0,0 +1,57 @@
/*
* DWT.cpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/Numerical/DWT.hpp>
#include <LatAnalyze/includes.hpp>
using namespace std;
using namespace Latan;
/******************************************************************************
* DWT implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
DWT::DWT(const DWTFilter &filter)
: filter_(filter)
{}
// convolution primitive ///////////////////////////////////////////////////////
DVec DWT::filterConvolution(const DVec &data, const DWTFilter &filter,
const Index offset)
{
DVec res(data.size());
return res;
}
// DWT /////////////////////////////////////////////////////////////////////////
std::vector<DWT::DWTLevel>
DWT::forward(const DVec &data, const unsigned int level) const
{
std::vector<DWT::DWTLevel> dwt(level);
return dwt;
}
DVec DWT::backward(const std::vector<DWTLevel>& dwt) const
{
DVec res;
return res;
}

52
lib/Numerical/DWT.hpp Normal file
View File

@ -0,0 +1,52 @@
/*
* DWT.hpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_DWT_hpp_
#define Latan_DWT_hpp_
#include <LatAnalyze/Global.hpp>
#include <LatAnalyze/Numerical/DWTFilters.hpp>
BEGIN_LATAN_NAMESPACE
/******************************************************************************
* Discrete wavelet transform class *
******************************************************************************/
class DWT
{
public:
typedef std::pair<DVec, DVec> DWTLevel;
public:
// constructor
DWT(const DWTFilter &filter);
// destructor
virtual ~DWT(void) = default;
// convolution primitive
static DVec filterConvolution(const DVec &data, const DWTFilter &filter,
const Index offset);
// DWT
std::vector<DWTLevel> forward(const DVec &data, const unsigned int level) const;
DVec backward(const std::vector<DWTLevel>& dwt) const;
private:
DWTFilter filter_;
};
END_LATAN_NAMESPACE
#endif // Latan_DWT_hpp_

View File

@ -0,0 +1,528 @@
/*
* DWTFilters.cpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/Numerical/DWTFilters.hpp>
#include <LatAnalyze/includes.hpp>
// cf. http://wavelets.pybytes.com
// *here we implement the reverse filters more convenient for convolutions*
using namespace std;
using namespace Latan;
#define FILTDICT(x) {#x, &DWTFilters::x}
std::map<std::string, const DWTFilter *> DWTFilters::fromName = {
FILTDICT(haar),
FILTDICT(db2),
FILTDICT(db3),
FILTDICT(db4),
FILTDICT(db5),
FILTDICT(db6),
FILTDICT(bior13),
FILTDICT(bior15),
FILTDICT(bior22),
FILTDICT(bior24),
FILTDICT(bior31),
FILTDICT(bior33),
FILTDICT(bior35)
};
DWTFilter DWTFilters::haar = {
// fwdL
{0.7071067811865476,
0.7071067811865476},
// fwdH
{0.7071067811865476,
-0.7071067811865476},
// bwdL
{0.7071067811865476,
0.7071067811865476},
// bwdH
{-0.7071067811865476,
0.7071067811865476}
};
DWTFilter DWTFilters::db2 = {
// fwdL
{0.48296291314469025,
0.836516303737469,
0.22414386804185735,
-0.12940952255092145},
// fwdH
{-0.12940952255092145,
-0.22414386804185735,
0.836516303737469,
-0.48296291314469025},
// bwdL
{-0.12940952255092145,
0.22414386804185735,
0.836516303737469,
0.48296291314469025},
// bwdH
{-0.48296291314469025,
0.836516303737469,
-0.22414386804185735,
-0.12940952255092145}
};
DWTFilter DWTFilters::db3 = {
// fwdL
{0.3326705529509569,
0.8068915093133388,
0.4598775021193313,
-0.13501102001039084,
-0.08544127388224149,
0.035226291882100656},
// fwdH
{0.035226291882100656,
0.08544127388224149,
-0.13501102001039084,
-0.4598775021193313,
0.8068915093133388,
-0.3326705529509569},
// bwdL
{0.035226291882100656,
-0.08544127388224149,
-0.13501102001039084,
0.4598775021193313,
0.8068915093133388,
0.3326705529509569},
// bwdH
{-0.3326705529509569,
0.8068915093133388,
-0.4598775021193313,
-0.13501102001039084,
0.08544127388224149,
0.035226291882100656}
};
DWTFilter DWTFilters::db4 = {
// fwdL
{0.23037781330885523,
0.7148465705525415,
0.6308807679295904,
-0.02798376941698385,
-0.18703481171888114,
0.030841381835986965,
0.032883011666982945,
-0.010597401784997278},
// fwdH
{-0.010597401784997278,
-0.032883011666982945,
0.030841381835986965,
0.18703481171888114,
-0.02798376941698385,
-0.6308807679295904,
0.7148465705525415,
-0.23037781330885523},
// bwdL
{-0.010597401784997278,
0.032883011666982945,
0.030841381835986965,
-0.18703481171888114,
-0.02798376941698385,
0.6308807679295904,
0.7148465705525415,
0.23037781330885523},
// bwdH
{-0.23037781330885523,
0.7148465705525415,
-0.6308807679295904,
-0.02798376941698385,
0.18703481171888114,
0.030841381835986965,
-0.032883011666982945,
-0.010597401784997278}
};
DWTFilter DWTFilters::db5 = {
// fwdL
{0.160102397974125,
0.6038292697974729,
0.7243085284385744,
0.13842814590110342,
-0.24229488706619015,
-0.03224486958502952,
0.07757149384006515,
-0.006241490213011705,
-0.012580751999015526,
0.003335725285001549},
// fwdH
{0.003335725285001549,
0.012580751999015526,
-0.006241490213011705,
-0.07757149384006515,
-0.03224486958502952,
0.24229488706619015,
0.13842814590110342,
-0.7243085284385744,
0.6038292697974729,
-0.160102397974125},
// bwdL
{0.003335725285001549,
-0.012580751999015526,
-0.006241490213011705,
0.07757149384006515,
-0.03224486958502952,
-0.24229488706619015,
0.13842814590110342,
0.7243085284385744,
0.6038292697974729,
0.160102397974125},
// bwdH
{-0.160102397974125,
0.6038292697974729,
-0.7243085284385744,
0.13842814590110342,
0.24229488706619015,
-0.03224486958502952,
-0.07757149384006515,
-0.006241490213011705,
0.012580751999015526,
0.003335725285001549}
};
DWTFilter DWTFilters::db6 = {
// fwdL
{0.11154074335008017,
0.4946238903983854,
0.7511339080215775,
0.3152503517092432,
-0.22626469396516913,
-0.12976686756709563,
0.09750160558707936,
0.02752286553001629,
-0.031582039318031156,
0.0005538422009938016,
0.004777257511010651,
-0.00107730108499558},
// fwdH
{-0.00107730108499558,
-0.004777257511010651,
0.0005538422009938016,
0.031582039318031156,
0.02752286553001629,
-0.09750160558707936,
-0.12976686756709563,
0.22626469396516913,
0.3152503517092432,
-0.7511339080215775,
0.4946238903983854,
-0.11154074335008017},
// bwdL
{-0.00107730108499558,
0.004777257511010651,
0.0005538422009938016,
-0.031582039318031156,
0.02752286553001629,
0.09750160558707936,
-0.12976686756709563,
-0.22626469396516913,
0.3152503517092432,
0.7511339080215775,
0.4946238903983854,
0.11154074335008017},
// bwdH
{-0.11154074335008017,
0.4946238903983854,
-0.7511339080215775,
0.3152503517092432,
0.22626469396516913,
-0.12976686756709563,
-0.09750160558707936,
0.02752286553001629,
0.031582039318031156,
0.0005538422009938016,
-0.004777257511010651,
-0.00107730108499558}
};
DWTFilter DWTFilters::bior13 = {
// fwdL
{-0.08838834764831845,
0.08838834764831845,
0.7071067811865476,
0.7071067811865476,
0.08838834764831845,
-0.08838834764831845},
// fwdH
{0.0,
0.0,
0.7071067811865476,
-0.7071067811865476,
0.0,
0.0},
// bwdL
{0.0,
0.0,
0.7071067811865476,
0.7071067811865476,
0.0,
0.0},
// bwdH
{0.08838834764831845,
0.08838834764831845,
-0.7071067811865476,
0.7071067811865476,
-0.08838834764831845,
-0.08838834764831845}
};
DWTFilter DWTFilters::bior15 = {
// fwdL
{0.01657281518405971,
-0.01657281518405971,
-0.12153397801643787,
0.12153397801643787,
0.7071067811865476,
0.7071067811865476,
0.12153397801643787,
-0.12153397801643787,
-0.01657281518405971,
0.01657281518405971},
// fwdH
{0.0,
0.0,
0.0,
0.0,
0.7071067811865476,
-0.7071067811865476,
0.0,
0.0,
0.0,
0.0},
// bwdL
{0.0,
0.0,
0.0,
0.0,
0.7071067811865476,
0.7071067811865476,
0.0,
0.0,
0.0,
0.0},
// bwdH
{-0.01657281518405971,
-0.01657281518405971,
0.12153397801643787,
0.12153397801643787,
-0.7071067811865476,
0.7071067811865476,
-0.12153397801643787,
-0.12153397801643787,
0.01657281518405971,
0.01657281518405971}
};
DWTFilter DWTFilters::bior22 = {
// fwdL
{-0.1767766952966369,
0.3535533905932738,
1.0606601717798214,
0.3535533905932738,
-0.1767766952966369,
0.0},
// fwdH
{0.0,
0.0,
0.3535533905932738,
-0.7071067811865476,
0.3535533905932738,
0.0},
// bwdL
{0.0,
0.0,
0.3535533905932738,
0.7071067811865476,
0.3535533905932738,
0.0},
// bwdH
{0.1767766952966369,
0.3535533905932738,
-1.0606601717798214,
0.3535533905932738,
0.1767766952966369,
0.0}
};
DWTFilter DWTFilters::bior24 = {
// fwdL
{0.03314563036811942,
-0.06629126073623884,
-0.1767766952966369,
0.4198446513295126,
0.9943689110435825,
0.4198446513295126,
-0.1767766952966369,
-0.06629126073623884,
0.03314563036811942,
0.0},
// fwdH
{0.0,
0.0,
0.0,
0.0,
0.3535533905932738,
-0.7071067811865476,
0.3535533905932738,
0.0,
0.0,
0.0},
// bwdL
{0.0,
0.0,
0.0,
0.0,
0.3535533905932738,
0.7071067811865476,
0.3535533905932738,
0.0,
0.0,
0.0},
// bwdH
{-0.03314563036811942,
-0.06629126073623884,
0.1767766952966369,
0.4198446513295126,
-0.9943689110435825,
0.4198446513295126,
0.1767766952966369,
-0.06629126073623884,
-0.03314563036811942,
0.0}
};
DWTFilter DWTFilters::bior31 = {
// fwdL
{-0.3535533905932738,
1.0606601717798214,
1.0606601717798214,
-0.3535533905932738},
// fwdH
{0.1767766952966369,
-0.5303300858899107,
0.5303300858899107,
-0.1767766952966369},
// bwdL
{0.1767766952966369,
0.5303300858899107,
0.5303300858899107,
0.1767766952966369},
// bwdH
{0.3535533905932738,
1.0606601717798214,
-1.0606601717798214,
-0.3535533905932738}
};
DWTFilter DWTFilters::bior33 = {
// fwdL
{0.06629126073623884,
-0.19887378220871652,
-0.15467960838455727,
0.9943689110435825,
0.9943689110435825,
-0.15467960838455727,
-0.19887378220871652,
0.06629126073623884},
// fwdH
{0.0,
0.0,
0.1767766952966369,
-0.5303300858899107,
0.5303300858899107,
-0.1767766952966369,
0.0,
0.0},
// bwdL
{0.0,
0.0,
0.1767766952966369,
0.5303300858899107,
0.5303300858899107,
0.1767766952966369,
0.0,
0.0},
// bwdH
{-0.06629126073623884,
-0.19887378220871652,
0.15467960838455727,
0.9943689110435825,
-0.9943689110435825,
-0.15467960838455727,
0.19887378220871652,
0.06629126073623884}
};
DWTFilter DWTFilters::bior35 = {
// fwdL
{-0.013810679320049757,
0.04143203796014927,
0.052480581416189075,
-0.26792717880896527,
-0.07181553246425874,
0.966747552403483,
0.966747552403483,
-0.07181553246425874,
-0.26792717880896527,
0.052480581416189075,
0.04143203796014927,
-0.013810679320049757},
// fwdH
{0.0,
0.0,
0.0,
0.0,
0.1767766952966369,
-0.5303300858899107,
0.5303300858899107,
-0.1767766952966369,
0.0,
0.0,
0.0,
0.0},
// bwdL
{0.0,
0.0,
0.0,
0.0,
0.1767766952966369,
0.5303300858899107,
0.5303300858899107,
0.1767766952966369,
0.0,
0.0,
0.0,
0.0},
// bwdH
{0.013810679320049757,
0.04143203796014927,
-0.052480581416189075,
-0.26792717880896527,
0.07181553246425874,
0.966747552403483,
-0.966747552403483,
-0.07181553246425874,
0.26792717880896527,
0.052480581416189075,
-0.04143203796014927,
-0.013810679320049757}
};

View File

@ -0,0 +1,53 @@
/*
* DWTFilters.hpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_DWTFilters_hpp_
#define Latan_DWTFilters_hpp_
#include <LatAnalyze/Global.hpp>
BEGIN_LATAN_NAMESPACE
struct DWTFilter
{
const std::vector<double> fwdL, fwdH, bwdL, bwdH;
};
namespace DWTFilters
{
extern DWTFilter haar;
extern DWTFilter db2;
extern DWTFilter db3;
extern DWTFilter db4;
extern DWTFilter db5;
extern DWTFilter db6;
extern DWTFilter bior13;
extern DWTFilter bior15;
extern DWTFilter bior22;
extern DWTFilter bior24;
extern DWTFilter bior31;
extern DWTFilter bior33;
extern DWTFilter bior35;
extern std::map<std::string, const DWTFilter *> fromName;
}
END_LATAN_NAMESPACE
#endif // Latan_DWTFilters_hpp_