kopia lustrzana https://github.com/vsamy/DiFipp
Licensing and renaming.
rodzic
74f52009dc
commit
83391bb797
|
@ -1,3 +1,28 @@
|
|||
# Copyright (c) 2019, Vincent SAMY
|
||||
# All rights reserved.
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the AIST nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# Version minimum
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
|
||||
|
@ -5,7 +30,7 @@ include(cmake/base.cmake)
|
|||
include(cmake/eigen.cmake)
|
||||
include(cmake/msvc-specific.cmake)
|
||||
|
||||
set(PROJECT_NAME fratio)
|
||||
set(PROJECT_NAME DiFi++)
|
||||
set(PROJECT_DESCRIPTION "Filter using rational transfer function")
|
||||
set(PROJECT_URL "...")
|
||||
SET(PROJECT_DEBUG_POSTFIX "_d")
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
Copyright (c) 2019, Vincent SAMY
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the AIST nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
README.md
35
README.md
|
@ -0,0 +1,35 @@
|
|||
DiFi++
|
||||
======
|
||||
|
||||
[License BSD 3-Clause](https://tldrlegal.com/license/bsd-3-clause-license-(revised)#fulltext)
|
||||
|
||||
DiFi++ is a small c++ header-only library for **DI**gital **FI**lters based on rational transfer functions such as the butterworth filter and the moving average filter. DiFi++ is using the Eigen library for math computations.
|
||||
|
||||
The implementation is based on well written article from Neil Robertson.
|
||||
Please check out the followings
|
||||
* https://www.dsprelated.com/showarticle/1119.php
|
||||
* https://www.dsprelated.com/showarticle/1135.php
|
||||
* https://www.dsprelated.com/showarticle/1128.php
|
||||
* https://www.dsprelated.com/showarticle/1131.php
|
||||
|
||||
The library has been tested against Matlab results.
|
||||
|
||||
A doxygen documentation is generated when compiling.
|
||||
|
||||
Installing
|
||||
-----
|
||||
|
||||
This is an header-only library so there is nothing to compile (but the documentation)
|
||||
|
||||
```bash
|
||||
git clone --recursive https://github.com/vsamy/DiFi++
|
||||
cd DiFi++
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make install
|
||||
```
|
||||
|
||||
Note
|
||||
-----
|
||||
The method used is close but somewhat different from Matlab methods and Butterworth band-reject has quite different results (precision of 1e-8).
|
|
@ -1,9 +1,34 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "type_checks.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
/*! \brief Transform an analog signal to a discrete signal and vice versa.
|
||||
*
|
||||
|
@ -71,4 +96,4 @@ void BilinearTransform<T>::ZToS(SubType fs, const vectX_t<T>& zPlanePoles, Eigen
|
|||
ZToS(fs, zPlanePoles(k), sPlanePoles(k));
|
||||
}
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
|
@ -1,3 +1,28 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DigitalFilter.h"
|
||||
|
@ -5,7 +30,7 @@
|
|||
#include <cmath>
|
||||
#include <complex>
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
/*! \brief Butterworth digital filter.
|
||||
*
|
||||
|
@ -130,6 +155,6 @@ private:
|
|||
T m_fs; /*!< Filter sampling frequency */
|
||||
};
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
||||
|
||||
#include "Butterworth.tpp"
|
||||
|
|
|
@ -1,7 +1,32 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "BilinearTransform.h"
|
||||
#include "polynome_functions.h"
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
template <typename T>
|
||||
T Butterworth<T>::PI = static_cast<T>(M_PI);
|
||||
|
@ -258,4 +283,4 @@ void Butterworth<T>::scaleAmplitude(const vectX_t<T>& aCoeff, Eigen::Ref<vectX_t
|
|||
bCoeff *= num / denum;
|
||||
}
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
|
@ -1,10 +1,39 @@
|
|||
# Copyright (c) 2019, Vincent SAMY
|
||||
# All rights reserved.
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the AIST nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set(HEADERS
|
||||
BilinearTransform.h
|
||||
Butterworth.h
|
||||
Butterworth.tpp
|
||||
difi
|
||||
DigitalFilter.h
|
||||
GenericFilter.h
|
||||
GenericFilter.tpp
|
||||
MovingAverage.h
|
||||
polynome_functions.h
|
||||
type_checks.h
|
||||
typedefs.h
|
||||
)
|
||||
|
||||
|
|
|
@ -1,9 +1,34 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GenericFilter.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
/*! \brief Basic digital filter.
|
||||
*
|
||||
|
@ -25,4 +50,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
|
@ -1,3 +1,28 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "type_checks.h"
|
||||
|
@ -5,7 +30,7 @@
|
|||
#include <stddef.h>
|
||||
#include <string>
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
/*! \brief Low-level filter.
|
||||
*
|
||||
|
@ -107,6 +132,6 @@ private:
|
|||
vectX_t<T> m_rawData; /*!< Last set of non-filtered data */
|
||||
};
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
||||
|
||||
#include "GenericFilter.tpp"
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
// Public static functions
|
||||
template <typename T>
|
||||
|
@ -148,4 +173,4 @@ bool GenericFilter<T>::checkCoeffs(const vectX_t<T>& aCoeff, const vectX_t<T>& b
|
|||
return m_status == FilterStatus::READY;
|
||||
}
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
|
@ -1,9 +1,34 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DigitalFilter.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
/*! \brief Moving average digital filter.
|
||||
*
|
||||
|
@ -36,4 +61,4 @@ public:
|
|||
int windowSize() const noexcept { return bOrder(); }
|
||||
};
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BilinearTransform.h"
|
||||
#include "Butterworth.h"
|
||||
#include "DigitalFilter.h"
|
||||
#include "GenericFilter.h"
|
||||
#include "MovingAverage.h"
|
||||
#include "polynome_functions.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace difi {
|
||||
|
||||
// Filters
|
||||
using DigitalFilterf = DigitalFilter<float>;
|
||||
using DigitalFilterd = DigitalFilter<double>;
|
||||
using MovingAveragef = MovingAverage<float>;
|
||||
using MovingAveraged = MovingAverage<double>;
|
||||
using Butterworthf = Butterworth<float>;
|
||||
using Butterworthd = Butterworth<double>;
|
||||
|
||||
// Polynome helper functions
|
||||
using VietaAlgof = VietaAlgo<float>;
|
||||
using VietaAlgod = VietaAlgo<double>;
|
||||
using VietaAlgoi = VietaAlgo<int>;
|
||||
using VietaAlgocf = VietaAlgo<std::complex<float>>;
|
||||
using VietaAlgocd = VietaAlgo<std::complex<double>>;
|
||||
using VietaAlgoci = VietaAlgo<std::complex<int>>;
|
||||
|
||||
// Bilinear transformation functions
|
||||
using BilinearTransformf = BilinearTransform<float>;
|
||||
using BilinearTransformd = BilinearTransform<double>;
|
||||
using BilinearTransformcf = BilinearTransform<std::complex<float>>;
|
||||
using BilinearTransformcd = BilinearTransform<std::complex<double>>;
|
||||
|
||||
} // namespace difi
|
|
@ -1,35 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// #include "BilinearTransform.h"
|
||||
#include "Butterworth.h"
|
||||
#include "DigitalFilter.h"
|
||||
#include "GenericFilter.h"
|
||||
#include "MovingAverage.h"
|
||||
#include "polynome_functions.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace fratio {
|
||||
|
||||
// Filters
|
||||
using DigitalFilterf = DigitalFilter<float>;
|
||||
using DigitalFilterd = DigitalFilter<double>;
|
||||
using MovingAveragef = MovingAverage<float>;
|
||||
using MovingAveraged = MovingAverage<double>;
|
||||
using Butterworthf = Butterworth<float>;
|
||||
using Butterworthd = Butterworth<double>;
|
||||
|
||||
// Polynome helper functions
|
||||
using VietaAlgof = VietaAlgo<float>;
|
||||
using VietaAlgod = VietaAlgo<double>;
|
||||
using VietaAlgoi = VietaAlgo<int>;
|
||||
using VietaAlgocf = VietaAlgo<std::complex<float>>;
|
||||
using VietaAlgocd = VietaAlgo<std::complex<double>>;
|
||||
using VietaAlgoci = VietaAlgo<std::complex<int>>;
|
||||
|
||||
// Bilinear transformation functions
|
||||
using BilinearTransformf = BilinearTransform<float>;
|
||||
using BilinearTransformd = BilinearTransform<double>;
|
||||
using BilinearTransformcf = BilinearTransform<std::complex<float>>;
|
||||
using BilinearTransformcd = BilinearTransform<std::complex<double>>;
|
||||
|
||||
} // namespace fratio
|
|
@ -1,10 +1,35 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "type_checks.h"
|
||||
#include "typedefs.h"
|
||||
#include <complex>
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
/*! \brief Compute polynome coefficients from roots.
|
||||
*
|
||||
|
@ -37,4 +62,4 @@ vectX_t<T> VietaAlgo<T>::polyCoeffFromRoot(const vectX_t<T>& roots)
|
|||
return coeffs;
|
||||
}
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
||||
|
|
|
@ -1,8 +1,33 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <complex>
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
namespace internal {
|
||||
|
||||
|
@ -29,4 +54,4 @@ namespace internal {
|
|||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
|
@ -1,8 +1,33 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
namespace fratio {
|
||||
namespace difi {
|
||||
|
||||
template <typename T>
|
||||
using vectX_t = Eigen::Matrix<T, Eigen::Dynamic, 1>; /*!< Eigen column-vector */
|
||||
|
@ -27,4 +52,4 @@ enum class FilterStatus {
|
|||
BAD_BAND_FREQUENCY /*!< Given band frequency is bad */
|
||||
};
|
||||
|
||||
} // namespace fratio
|
||||
} // namespace difi
|
|
@ -1,8 +1,33 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define BOOST_TEST_MODULE ButterworthFilterTests
|
||||
|
||||
// Note: In term of precision, LP > HP > BP ~= BR
|
||||
|
||||
#include "fratio"
|
||||
#include "difi"
|
||||
#include "test_functions.h"
|
||||
#include "warning_macro.h"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
@ -11,28 +36,28 @@ DISABLE_CONVERSION_WARNING_BEGIN
|
|||
|
||||
template <typename T>
|
||||
struct System {
|
||||
fratio::vectX_t<T> data = (fratio::vectX_t<T>(8) << 1, 2, 3, 4, 5, 6, 7, 8).finished();
|
||||
difi::vectX_t<T> data = (difi::vectX_t<T>(8) << 1, 2, 3, 4, 5, 6, 7, 8).finished();
|
||||
int order = 5;
|
||||
T fc = 10;
|
||||
T fs = 100;
|
||||
T fLower = 5;
|
||||
T fUpper = 15;
|
||||
// LP
|
||||
fratio::vectX_t<T> lpACoeffRes = (fratio::vectX_t<T>(6) << 1, -2.975422109745684, 3.806018119320413, -2.545252868330468, 0.881130075437837, -0.125430622155356).finished();
|
||||
fratio::vectX_t<T> lpBCoeffRes = (fratio::vectX_t<T>(6) << 0.001282581078961, 0.006412905394803, 0.012825810789607, 0.012825810789607, 0.006412905394803, 0.001282581078961).finished();
|
||||
fratio::vectX_t<T> lpResults = (fratio::vectX_t<T>(8) << 0.001282581078961, 0.012794287652606, 0.062686244350084, 0.203933712825708, 0.502244959135609, 1.010304217144175, 1.744652693589064, 2.678087381460197).finished();
|
||||
difi::vectX_t<T> lpACoeffRes = (difi::vectX_t<T>(6) << 1, -2.975422109745684, 3.806018119320413, -2.545252868330468, 0.881130075437837, -0.125430622155356).finished();
|
||||
difi::vectX_t<T> lpBCoeffRes = (difi::vectX_t<T>(6) << 0.001282581078961, 0.006412905394803, 0.012825810789607, 0.012825810789607, 0.006412905394803, 0.001282581078961).finished();
|
||||
difi::vectX_t<T> lpResults = (difi::vectX_t<T>(8) << 0.001282581078961, 0.012794287652606, 0.062686244350084, 0.203933712825708, 0.502244959135609, 1.010304217144175, 1.744652693589064, 2.678087381460197).finished();
|
||||
// HP
|
||||
fratio::vectX_t<T> hpACoeffRes = (fratio::vectX_t<T>(6) << 1, -2.975422109745683, 3.806018119320411, -2.545252868330467, 0.8811300754378368, -0.1254306221553557).finished();
|
||||
fratio::vectX_t<T> hpBCoeffRes = (fratio::vectX_t<T>(6) << 0.3541641810934298, -1.770820905467149, 3.541641810934299, -3.541641810934299, 1.770820905467149, -0.3541641810934298).finished();
|
||||
fratio::vectX_t<T> hpResults = (fratio::vectX_t<T>(8) << 0.3541641810934298, -0.008704608374924483, -0.3113626313910076, -0.3460321436983160, -0.1787600153274098, 0.04471440201428267, 0.2059279258827846, 0.2533941579793959).finished();
|
||||
difi::vectX_t<T> hpACoeffRes = (difi::vectX_t<T>(6) << 1, -2.975422109745683, 3.806018119320411, -2.545252868330467, 0.8811300754378368, -0.1254306221553557).finished();
|
||||
difi::vectX_t<T> hpBCoeffRes = (difi::vectX_t<T>(6) << 0.3541641810934298, -1.770820905467149, 3.541641810934299, -3.541641810934299, 1.770820905467149, -0.3541641810934298).finished();
|
||||
difi::vectX_t<T> hpResults = (difi::vectX_t<T>(8) << 0.3541641810934298, -0.008704608374924483, -0.3113626313910076, -0.3460321436983160, -0.1787600153274098, 0.04471440201428267, 0.2059279258827846, 0.2533941579793959).finished();
|
||||
// BP
|
||||
fratio::vectX_t<T> bpACoeffRes = (fratio::vectX_t<T>(11) << 1, -6.784299264603903, 21.577693329895588, -42.338550072279737, 56.729081385507655, -54.208087151300411, 37.399203252161037, -18.397491390111661, 6.180883710485754, -1.283022311577260, 0.125430622155356).finished();
|
||||
fratio::vectX_t<T> bpBCoeffRes = (fratio::vectX_t<T>(11) << 0.001282581078963, 0, -0.006412905394817, 0, 0.012825810789633, 0, -0.012825810789633, 0, 0.006412905394817, 0, -0.001282581078963).finished();
|
||||
fratio::vectX_t<T> bpResults = (fratio::vectX_t<T>(8) << 0.001282581078963, 0.011266576028733, 0.046195520115810, 0.116904647483408, 0.200574194600111, 0.232153315136604, 0.141350142008155, -0.086403129422609).finished();
|
||||
difi::vectX_t<T> bpACoeffRes = (difi::vectX_t<T>(11) << 1, -6.784299264603903, 21.577693329895588, -42.338550072279737, 56.729081385507655, -54.208087151300411, 37.399203252161037, -18.397491390111661, 6.180883710485754, -1.283022311577260, 0.125430622155356).finished();
|
||||
difi::vectX_t<T> bpBCoeffRes = (difi::vectX_t<T>(11) << 0.001282581078963, 0, -0.006412905394817, 0, 0.012825810789633, 0, -0.012825810789633, 0, 0.006412905394817, 0, -0.001282581078963).finished();
|
||||
difi::vectX_t<T> bpResults = (difi::vectX_t<T>(8) << 0.001282581078963, 0.011266576028733, 0.046195520115810, 0.116904647483408, 0.200574194600111, 0.232153315136604, 0.141350142008155, -0.086403129422609).finished();
|
||||
// BR
|
||||
fratio::vectX_t<T> brACoeffRes = (fratio::vectX_t<T>(11) << 1.000000000000000, -6.784299264603897, 21.577693329895553, -42.338550072279631, 56.729081385507484, -54.208087151300205, 37.399203252160873, -18.397491390111572, 6.180883710485723, -1.283022311577253, 0.125430622155356).finished();
|
||||
fratio::vectX_t<T> brBCoeffRes = (fratio::vectX_t<T>(11) << 0.354164181088899, -3.012700469326103, 12.021845263663774, -29.490886190815772, 49.130136704563000, -58.004276868015168, 49.130136704563000, -29.490886190815772, 12.021845263663774, -3.012700469326103, 0.354164181088899).finished();
|
||||
fratio::vectX_t<T> brResults = (fratio::vectX_t<T>(8) << 0.354164181088899, 0.098383686162154, 0.084355149987331, 0.375555141082278, 0.735622022349639, 1.008089442365644, 1.229578363722674, 1.537000959441760).finished();
|
||||
difi::vectX_t<T> brACoeffRes = (difi::vectX_t<T>(11) << 1.000000000000000, -6.784299264603897, 21.577693329895553, -42.338550072279631, 56.729081385507484, -54.208087151300205, 37.399203252160873, -18.397491390111572, 6.180883710485723, -1.283022311577253, 0.125430622155356).finished();
|
||||
difi::vectX_t<T> brBCoeffRes = (difi::vectX_t<T>(11) << 0.354164181088899, -3.012700469326103, 12.021845263663774, -29.490886190815772, 49.130136704563000, -58.004276868015168, 49.130136704563000, -29.490886190815772, 12.021845263663774, -3.012700469326103, 0.354164181088899).finished();
|
||||
difi::vectX_t<T> brResults = (difi::vectX_t<T>(8) << 0.354164181088899, 0.098383686162154, 0.084355149987331, 0.375555141082278, 0.735622022349639, 1.008089442365644, 1.229578363722674, 1.537000959441760).finished();
|
||||
};
|
||||
|
||||
DISABLE_CONVERSION_WARNING_END
|
||||
|
@ -40,12 +65,12 @@ DISABLE_CONVERSION_WARNING_END
|
|||
BOOST_AUTO_TEST_CASE(FIND_BUTTERWORTH_LP_HP_FLOAT)
|
||||
{
|
||||
// LP
|
||||
auto butterRequirement = fratio::Butterworthf::findMinimumButter(40.f / 500.f, 150.f / 500.f, 3.f, 60.f);
|
||||
auto butterRequirement = difi::Butterworthf::findMinimumButter(40.f / 500.f, 150.f / 500.f, 3.f, 60.f);
|
||||
BOOST_REQUIRE_EQUAL(5, butterRequirement.first);
|
||||
BOOST_REQUIRE_SMALL(std::abs(static_cast<float>(0.081038494957764) - butterRequirement.second), std::numeric_limits<float>::epsilon() * 10);
|
||||
|
||||
// HP
|
||||
butterRequirement = fratio::Butterworthf::findMinimumButter(150.f / 500.f, 40.f / 500.f, 3.f, 60.f);
|
||||
butterRequirement = difi::Butterworthf::findMinimumButter(150.f / 500.f, 40.f / 500.f, 3.f, 60.f);
|
||||
BOOST_REQUIRE_EQUAL(5, butterRequirement.first);
|
||||
BOOST_REQUIRE_SMALL(std::abs(static_cast<float>(0.296655824107340) - butterRequirement.second), std::numeric_limits<float>::epsilon() * 10);
|
||||
}
|
||||
|
@ -53,19 +78,19 @@ BOOST_AUTO_TEST_CASE(FIND_BUTTERWORTH_LP_HP_FLOAT)
|
|||
BOOST_AUTO_TEST_CASE(FIND_BUTTERWORTH_LP_HP_DOUBLE)
|
||||
{
|
||||
// LP
|
||||
auto butterRequirement = fratio::Butterworthd::findMinimumButter(40. / 500., 150. / 500., 3., 60.);
|
||||
auto butterRequirement = difi::Butterworthd::findMinimumButter(40. / 500., 150. / 500., 3., 60.);
|
||||
BOOST_REQUIRE_EQUAL(5, butterRequirement.first);
|
||||
BOOST_REQUIRE_SMALL(std::abs(0.081038494957764 - butterRequirement.second), std::numeric_limits<double>::epsilon() * 10);
|
||||
|
||||
// HP
|
||||
butterRequirement = fratio::Butterworthd::findMinimumButter(150. / 500., 40. / 500., 3., 60.);
|
||||
butterRequirement = difi::Butterworthd::findMinimumButter(150. / 500., 40. / 500., 3., 60.);
|
||||
BOOST_REQUIRE_EQUAL(5, butterRequirement.first);
|
||||
BOOST_REQUIRE_SMALL(std::abs(0.296655824107340 - butterRequirement.second), std::numeric_limits<double>::epsilon() * 10);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_LP_FILTER_FLOAT, System<float>)
|
||||
{
|
||||
auto bf = fratio::Butterworthf(order, fc, fs);
|
||||
auto bf = difi::Butterworthf(order, fc, fs);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(lpACoeffRes, lpBCoeffRes, bf, std::numeric_limits<float>::epsilon() * 10);
|
||||
test_results(lpResults, data, bf, std::numeric_limits<float>::epsilon() * 100);
|
||||
|
@ -73,7 +98,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_LP_FILTER_FLOAT, System<float>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_LP_FILTER_DOUBLE, System<double>)
|
||||
{
|
||||
auto bf = fratio::Butterworthd(order, fc, fs);
|
||||
auto bf = difi::Butterworthd(order, fc, fs);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(lpACoeffRes, lpBCoeffRes, bf, std::numeric_limits<double>::epsilon() * 10);
|
||||
test_results(lpResults, data, bf, std::numeric_limits<double>::epsilon() * 100);
|
||||
|
@ -81,7 +106,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_LP_FILTER_DOUBLE, System<double>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_HP_FILTER_FLOAT, System<float>)
|
||||
{
|
||||
auto bf = fratio::Butterworthf(order, fc, fs, fratio::Butterworthf::Type::HighPass);
|
||||
auto bf = difi::Butterworthf(order, fc, fs, difi::Butterworthf::Type::HighPass);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(hpACoeffRes, hpBCoeffRes, bf, std::numeric_limits<float>::epsilon() * 10);
|
||||
test_results(hpResults, data, bf, std::numeric_limits<float>::epsilon() * 1000);
|
||||
|
@ -89,7 +114,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_HP_FILTER_FLOAT, System<float>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_HP_FILTER_DOUBLE, System<double>)
|
||||
{
|
||||
auto bf = fratio::Butterworthd(order, fc, fs, fratio::Butterworthd::Type::HighPass);
|
||||
auto bf = difi::Butterworthd(order, fc, fs, difi::Butterworthd::Type::HighPass);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(hpACoeffRes, hpBCoeffRes, bf, std::numeric_limits<double>::epsilon() * 10);
|
||||
test_results(hpResults, data, bf, std::numeric_limits<double>::epsilon() * 100);
|
||||
|
@ -97,7 +122,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_HP_FILTER_DOUBLE, System<double>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BP_FILTER_FLOAT, System<float>)
|
||||
{
|
||||
auto bf = fratio::Butterworthf(order, fLower, fUpper, fs);
|
||||
auto bf = difi::Butterworthf(order, fLower, fUpper, fs);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(bpACoeffRes, bpBCoeffRes, bf, std::numeric_limits<float>::epsilon() * 1000);
|
||||
test_results(bpResults, data, bf, std::numeric_limits<float>::epsilon() * 10000);
|
||||
|
@ -105,7 +130,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BP_FILTER_FLOAT, System<float>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BP_FILTER_DOUBLE, System<double>)
|
||||
{
|
||||
auto bf = fratio::Butterworthd(order, fLower, fUpper, fs);
|
||||
auto bf = difi::Butterworthd(order, fLower, fUpper, fs);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(bpACoeffRes, bpBCoeffRes, bf, std::numeric_limits<double>::epsilon() * 1000);
|
||||
test_results(bpResults, data, bf, std::numeric_limits<double>::epsilon() * 10000);
|
||||
|
@ -113,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BP_FILTER_DOUBLE, System<double>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BR_FILTER_FLOAT, System<float>)
|
||||
{
|
||||
auto bf = fratio::Butterworthf(order, fLower, fUpper, fs, fratio::Butterworthf::Type::BandReject);
|
||||
auto bf = difi::Butterworthf(order, fLower, fUpper, fs, difi::Butterworthf::Type::BandReject);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(brACoeffRes, brBCoeffRes, bf, 1.f);
|
||||
test_results(brResults, data, bf, 1.f);
|
||||
|
@ -121,7 +146,7 @@ BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BR_FILTER_FLOAT, System<float>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(BUTTERWORTH_BR_FILTER_DOUBLE, System<double>)
|
||||
{
|
||||
auto bf = fratio::Butterworthd(order, fLower, fUpper, fs, fratio::Butterworthd::Type::BandReject);
|
||||
auto bf = difi::Butterworthd(order, fLower, fUpper, fs, difi::Butterworthd::Type::BandReject);
|
||||
BOOST_REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(brACoeffRes, brBCoeffRes, bf, 1e-8);
|
||||
test_results(brResults, data, bf, 1e-8);
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
# Copyright (c) 2019, Vincent SAMY
|
||||
# All rights reserved.
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the AIST nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/boost.cmake)
|
||||
|
||||
enable_testing()
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define BOOST_TEST_MODULE DigitalFilterTests
|
||||
|
||||
#include "fratio"
|
||||
#include "difi"
|
||||
#include "test_functions.h"
|
||||
#include "warning_macro.h"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
@ -9,24 +34,24 @@ DISABLE_CONVERSION_WARNING_BEGIN
|
|||
|
||||
template <typename T>
|
||||
struct System {
|
||||
fratio::vectX_t<T> data = (fratio::vectX_t<T>(4) << 1, 2, 3, 4).finished();
|
||||
fratio::vectX_t<T> aCoeff = (fratio::vectX_t<T>(2) << 1, -0.99993717).finished();
|
||||
fratio::vectX_t<T> bCoeff = (fratio::vectX_t<T>(2) << 0.99996859, -0.99996859).finished();
|
||||
fratio::vectX_t<T> results = (fratio::vectX_t<T>(4) << 0.99996859, 1.999874351973491, 2.999717289867956, 3.999497407630634).finished();
|
||||
difi::vectX_t<T> data = (difi::vectX_t<T>(4) << 1, 2, 3, 4).finished();
|
||||
difi::vectX_t<T> aCoeff = (difi::vectX_t<T>(2) << 1, -0.99993717).finished();
|
||||
difi::vectX_t<T> bCoeff = (difi::vectX_t<T>(2) << 0.99996859, -0.99996859).finished();
|
||||
difi::vectX_t<T> results = (difi::vectX_t<T>(4) << 0.99996859, 1.999874351973491, 2.999717289867956, 3.999497407630634).finished();
|
||||
};
|
||||
|
||||
DISABLE_CONVERSION_WARNING_END
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(DIGITAL_FILTER_FLOAT, System<float>)
|
||||
{
|
||||
auto df = fratio::DigitalFilterf(aCoeff, bCoeff);
|
||||
auto df = difi::DigitalFilterf(aCoeff, bCoeff);
|
||||
test_coeffs(aCoeff, bCoeff, df, std::numeric_limits<float>::epsilon() * 10);
|
||||
test_results(results, data, df, std::numeric_limits<float>::epsilon() * 10);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(DIGITAL_FILTER_DOUBLE, System<double>)
|
||||
{
|
||||
auto df = fratio::DigitalFilterd(aCoeff, bCoeff);
|
||||
auto df = difi::DigitalFilterd(aCoeff, bCoeff);
|
||||
test_coeffs(aCoeff, bCoeff, df, std::numeric_limits<double>::epsilon() * 10);
|
||||
test_results(results, data, df, std::numeric_limits<double>::epsilon() * 10);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,52 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define BOOST_TEST_MODULE GenericFilterTests
|
||||
|
||||
#include "fratio"
|
||||
#include "difi"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <vector>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(FILTER_FAILURES)
|
||||
{
|
||||
auto dfd = fratio::DigitalFilterd(Eigen::VectorXd(), Eigen::VectorXd::Constant(2, 0));
|
||||
BOOST_REQUIRE(dfd.status() == fratio::FilterStatus::A_COEFF_MISSING);
|
||||
dfd = fratio::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd());
|
||||
BOOST_REQUIRE(dfd.status() == fratio::FilterStatus::B_COEFF_MISSING);
|
||||
dfd = fratio::DigitalFilterd(Eigen::VectorXd(), Eigen::VectorXd());
|
||||
BOOST_REQUIRE(dfd.status() == fratio::FilterStatus::ALL_COEFF_MISSING);
|
||||
dfd = fratio::DigitalFilterd(Eigen::VectorXd::Constant(2, 0), Eigen::VectorXd::Constant(2, 0));
|
||||
BOOST_REQUIRE(dfd.status() == fratio::FilterStatus::BAD_A_COEFF);
|
||||
dfd = fratio::DigitalFilterd();
|
||||
BOOST_REQUIRE(dfd.status() == fratio::FilterStatus::NONE);
|
||||
dfd = fratio::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd::Constant(2, 0));
|
||||
BOOST_REQUIRE(dfd.status() == fratio::FilterStatus::READY);
|
||||
auto mad = fratio::MovingAveraged(0);
|
||||
BOOST_REQUIRE(mad.status() == fratio::FilterStatus::BAD_ORDER_SIZE);
|
||||
auto bfd = fratio::Butterworthd(0, 10, 100);
|
||||
BOOST_REQUIRE(bfd.status() == fratio::FilterStatus::BAD_ORDER_SIZE);
|
||||
bfd = fratio::Butterworthd(5, 6, 5, 100);
|
||||
BOOST_REQUIRE(bfd.status() == fratio::FilterStatus::BAD_BAND_FREQUENCY);
|
||||
auto dfd = difi::DigitalFilterd(Eigen::VectorXd(), Eigen::VectorXd::Constant(2, 0));
|
||||
BOOST_REQUIRE(dfd.status() == difi::FilterStatus::A_COEFF_MISSING);
|
||||
dfd = difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd());
|
||||
BOOST_REQUIRE(dfd.status() == difi::FilterStatus::B_COEFF_MISSING);
|
||||
dfd = difi::DigitalFilterd(Eigen::VectorXd(), Eigen::VectorXd());
|
||||
BOOST_REQUIRE(dfd.status() == difi::FilterStatus::ALL_COEFF_MISSING);
|
||||
dfd = difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 0), Eigen::VectorXd::Constant(2, 0));
|
||||
BOOST_REQUIRE(dfd.status() == difi::FilterStatus::BAD_A_COEFF);
|
||||
dfd = difi::DigitalFilterd();
|
||||
BOOST_REQUIRE(dfd.status() == difi::FilterStatus::NONE);
|
||||
dfd = difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd::Constant(2, 0));
|
||||
BOOST_REQUIRE(dfd.status() == difi::FilterStatus::READY);
|
||||
auto mad = difi::MovingAveraged(0);
|
||||
BOOST_REQUIRE(mad.status() == difi::FilterStatus::BAD_ORDER_SIZE);
|
||||
auto bfd = difi::Butterworthd(0, 10, 100);
|
||||
BOOST_REQUIRE(bfd.status() == difi::FilterStatus::BAD_ORDER_SIZE);
|
||||
bfd = difi::Butterworthd(5, 6, 5, 100);
|
||||
BOOST_REQUIRE(bfd.status() == difi::FilterStatus::BAD_BAND_FREQUENCY);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,49 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define BOOST_TEST_MODULE MovingAverageFilterTests
|
||||
|
||||
#include "fratio"
|
||||
#include "difi"
|
||||
#include "test_functions.h"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
template <typename T>
|
||||
struct System {
|
||||
fratio::vectX_t<T> data = (fratio::vectX_t<T>(6) << 1, 2, 3, 4, 5, 6).finished();
|
||||
difi::vectX_t<T> data = (difi::vectX_t<T>(6) << 1, 2, 3, 4, 5, 6).finished();
|
||||
int windowSize = 4;
|
||||
fratio::vectX_t<T> results = (fratio::vectX_t<T>(6) << 0.25, 0.75, 1.5, 2.5, 3.5, 4.5).finished();
|
||||
difi::vectX_t<T> results = (difi::vectX_t<T>(6) << 0.25, 0.75, 1.5, 2.5, 3.5, 4.5).finished();
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(MOVING_AVERAGE_FLOAT, System<float>)
|
||||
{
|
||||
auto maf = fratio::MovingAveragef(windowSize);
|
||||
auto maf = difi::MovingAveragef(windowSize);
|
||||
test_results(results, data, maf, std::numeric_limits<float>::epsilon() * 10);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(MOVING_AVERAGE_DOUBLE, System<double>)
|
||||
{
|
||||
auto maf = fratio::MovingAveraged(windowSize);
|
||||
auto maf = difi::MovingAveraged(windowSize);
|
||||
test_results(results, data, maf, std::numeric_limits<double>::epsilon() * 10);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define BOOST_TEST_MODULE polynome_functions_tests
|
||||
|
||||
#include "fratio"
|
||||
#include "difi"
|
||||
#include "warning_macro.h"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <limits>
|
||||
|
@ -10,34 +35,34 @@ template <typename T>
|
|||
using c_t = std::complex<T>;
|
||||
|
||||
struct SystemInt {
|
||||
fratio::vectX_t<int> data = (fratio::vectX_t<int>(4) << 1, 1, 1, 1).finished();
|
||||
fratio::vectX_t<int> results = (fratio::vectX_t<int>(5) << 1, -4, 6, -4, 1).finished();
|
||||
difi::vectX_t<int> data = (difi::vectX_t<int>(4) << 1, 1, 1, 1).finished();
|
||||
difi::vectX_t<int> results = (difi::vectX_t<int>(5) << 1, -4, 6, -4, 1).finished();
|
||||
};
|
||||
|
||||
struct SystemCInt {
|
||||
fratio::vectX_t<c_int_t> data = (fratio::vectX_t<c_int_t>(4) << c_int_t{ 1, 1 }, c_int_t{ -1, 4 }, c_int_t{ 12, -3 }, c_int_t{ 5, 2 }).finished();
|
||||
fratio::vectX_t<c_int_t> results = (fratio::vectX_t<c_int_t>(5) << c_int_t{ 1, 0 }, c_int_t{ -17, -4 }, c_int_t{ 66, 97 }, c_int_t{ 127, -386 }, c_int_t{ -357, 153 }).finished();
|
||||
difi::vectX_t<c_int_t> data = (difi::vectX_t<c_int_t>(4) << c_int_t{ 1, 1 }, c_int_t{ -1, 4 }, c_int_t{ 12, -3 }, c_int_t{ 5, 2 }).finished();
|
||||
difi::vectX_t<c_int_t> results = (difi::vectX_t<c_int_t>(5) << c_int_t{ 1, 0 }, c_int_t{ -17, -4 }, c_int_t{ 66, 97 }, c_int_t{ 127, -386 }, c_int_t{ -357, 153 }).finished();
|
||||
};
|
||||
|
||||
DISABLE_CONVERSION_WARNING_BEGIN
|
||||
|
||||
template <typename T>
|
||||
struct SystemFloat {
|
||||
fratio::vectX_t<T> data = (fratio::vectX_t<T>(4) << 0.32, -0.0518, 41.4, 0.89).finished();
|
||||
fratio::vectX_t<T> results = (fratio::vectX_t<T>(5) << 1, -42.558199999999999, 48.171601999999993, -9.181098159999999, -0.610759296).finished();
|
||||
difi::vectX_t<T> data = (difi::vectX_t<T>(4) << 0.32, -0.0518, 41.4, 0.89).finished();
|
||||
difi::vectX_t<T> results = (difi::vectX_t<T>(5) << 1, -42.558199999999999, 48.171601999999993, -9.181098159999999, -0.610759296).finished();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct SystemCFloat {
|
||||
fratio::vectX_t<c_t<T>> data = (fratio::vectX_t<c_t<T>>(4) << c_t<T>{ 1.35, 0.2 }, c_t<T>{ -1.5, 4.45 }, c_t<T>{ 12.8, -3.36 }, c_t<T>{ 5.156, 2.12 }).finished();
|
||||
fratio::vectX_t<c_t<T>> results = (fratio::vectX_t<c_t<T>>(5) << c_t<T>{ 1, 0 }, c_t<T>{ -17.806, -3.41 }, c_t<T>{ 73.2776, 99.20074 }, c_t<T>{ 101.857496, -444.634694 }, c_t<T>{ -269.1458768, 388.7308864 }).finished();
|
||||
difi::vectX_t<c_t<T>> data = (difi::vectX_t<c_t<T>>(4) << c_t<T>{ 1.35, 0.2 }, c_t<T>{ -1.5, 4.45 }, c_t<T>{ 12.8, -3.36 }, c_t<T>{ 5.156, 2.12 }).finished();
|
||||
difi::vectX_t<c_t<T>> results = (difi::vectX_t<c_t<T>>(5) << c_t<T>{ 1, 0 }, c_t<T>{ -17.806, -3.41 }, c_t<T>{ 73.2776, 99.20074 }, c_t<T>{ 101.857496, -444.634694 }, c_t<T>{ -269.1458768, 388.7308864 }).finished();
|
||||
};
|
||||
|
||||
DISABLE_CONVERSION_WARNING_END
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_INT, SystemInt)
|
||||
{
|
||||
auto res = fratio::VietaAlgoi::polyCoeffFromRoot(data);
|
||||
auto res = difi::VietaAlgoi::polyCoeffFromRoot(data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_EQUAL(res(i), results(i));
|
||||
|
@ -45,7 +70,7 @@ BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_INT, SystemInt)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_FLOAT, SystemFloat<float>)
|
||||
{
|
||||
auto res = fratio::VietaAlgof::polyCoeffFromRoot(data);
|
||||
auto res = difi::VietaAlgof::polyCoeffFromRoot(data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_SMALL(std::abs(res(i) - results(i)), std::numeric_limits<float>::epsilon() * 1000);
|
||||
|
@ -53,7 +78,7 @@ BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_FLOAT, SystemFloat<float>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_DOUBLE, SystemFloat<double>)
|
||||
{
|
||||
auto res = fratio::VietaAlgod::polyCoeffFromRoot(data);
|
||||
auto res = difi::VietaAlgod::polyCoeffFromRoot(data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_SMALL(std::abs(res(i) - results(i)), std::numeric_limits<double>::epsilon() * 1000);
|
||||
|
@ -61,7 +86,7 @@ BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_DOUBLE, SystemFloat<double>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_CINT, SystemCInt)
|
||||
{
|
||||
auto res = fratio::VietaAlgoci::polyCoeffFromRoot(data);
|
||||
auto res = difi::VietaAlgoci::polyCoeffFromRoot(data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_EQUAL(res(i), results(i));
|
||||
|
@ -69,7 +94,7 @@ BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_CINT, SystemCInt)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_CFLOAT, SystemCFloat<float>)
|
||||
{
|
||||
auto res = fratio::VietaAlgocf::polyCoeffFromRoot(data);
|
||||
auto res = difi::VietaAlgocf::polyCoeffFromRoot(data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_SMALL(std::abs(res(i) - results(i)), std::numeric_limits<float>::epsilon() * 1000);
|
||||
|
@ -77,7 +102,7 @@ BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_CFLOAT, SystemCFloat<float>)
|
|||
|
||||
BOOST_FIXTURE_TEST_CASE(POLYNOME_FUNCTION_CDOUBLE, SystemCFloat<double>)
|
||||
{
|
||||
auto res = fratio::VietaAlgocd::polyCoeffFromRoot(data);
|
||||
auto res = difi::VietaAlgocd::polyCoeffFromRoot(data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_SMALL(std::abs(res(i) - results(i)), std::numeric_limits<double>::epsilon() * 1000);
|
||||
|
|
|
@ -1,15 +1,40 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fratio"
|
||||
#include "difi"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <limits>
|
||||
|
||||
template <typename T>
|
||||
void test_coeffs(const fratio::vectX_t<T>& aCoeff, const fratio::vectX_t<T>& bCoeff, const fratio::GenericFilter<T>& filter, T prec)
|
||||
void test_coeffs(const difi::vectX_t<T>& aCoeff, const difi::vectX_t<T>& bCoeff, const difi::GenericFilter<T>& filter, T prec)
|
||||
{
|
||||
BOOST_REQUIRE_EQUAL(aCoeff.size(), filter.aOrder());
|
||||
BOOST_REQUIRE_EQUAL(bCoeff.size(), filter.bOrder());
|
||||
fratio::vectX_t<T> faCoeff, fbCoeff;
|
||||
difi::vectX_t<T> faCoeff, fbCoeff;
|
||||
filter.getCoeffs(faCoeff, fbCoeff);
|
||||
for (Eigen::Index i = 0; i < faCoeff.size(); ++i)
|
||||
BOOST_REQUIRE_SMALL(std::abs(aCoeff(i) - faCoeff(i)), prec);
|
||||
|
@ -18,9 +43,9 @@ void test_coeffs(const fratio::vectX_t<T>& aCoeff, const fratio::vectX_t<T>& bCo
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void test_results(const fratio::vectX_t<T>& results, const fratio::vectX_t<T>& data, fratio::GenericFilter<T>& filter, T prec)
|
||||
void test_results(const difi::vectX_t<T>& results, const difi::vectX_t<T>& data, difi::GenericFilter<T>& filter, T prec)
|
||||
{
|
||||
fratio::vectX_t<T> filteredData(results.size());
|
||||
difi::vectX_t<T> filteredData(results.size());
|
||||
|
||||
for (Eigen::Index i = 0; i < data.size(); ++i)
|
||||
filteredData(i) = filter.stepFilter(data(i));
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
// Copyright (c) 2019, Vincent SAMY
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the AIST nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
Ładowanie…
Reference in New Issue