DiFipp/include/GenericFilter.h

100 wiersze
3.5 KiB
C
Czysty Zwykły widok Historia

2019-01-04 08:45:22 +00:00
// 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:
2019-10-10 02:31:00 +00:00
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. 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.
2019-01-04 08:45:22 +00:00
// 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
2019-10-10 02:31:00 +00:00
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2019-01-04 08:45:22 +00:00
// (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.
2019-10-10 02:31:00 +00:00
// The views and conclusions contained in the software and documentation are those
// of the authors and should not be interpreted as representing official policies,
// either expressed or implied, of the FreeBSD Project.
2018-10-23 01:16:10 +00:00
#pragma once
2019-10-29 04:27:48 +00:00
#include "BaseFilter.h"
2018-10-23 01:16:10 +00:00
2019-01-04 08:45:22 +00:00
namespace difi {
2018-10-23 10:22:57 +00:00
template <typename T>
2019-10-29 06:03:13 +00:00
class GenericFilter : public BaseFilter<T, GenericFilter<T>> {
2018-12-14 10:04:41 +00:00
public:
2019-01-04 08:15:03 +00:00
/*! \brief Filter a new data.
*
* This function is practical for online application that does not know the whole signal in advance.
* \param data New data to filter.
* \return Filtered data.
*/
2018-12-17 05:48:44 +00:00
T stepFilter(const T& data);
2019-01-04 08:15:03 +00:00
/*! \brief Filter a signal.
*
* Filter all data given by the signal.
* \param data Signal.
* \return Filtered signal.
*/
2018-12-17 08:16:01 +00:00
vectX_t<T> filter(const vectX_t<T>& data);
2019-10-28 08:23:25 +00:00
2019-10-29 06:03:13 +00:00
void resetFilter() noexcept;
2018-10-23 10:22:57 +00:00
protected:
GenericFilter() = default;
2019-10-29 06:58:37 +00:00
GenericFilter(const vectX_t<T>& aCoeff, const vectX_t<T>& bCoeff, FilterType type = FilterType::Backward)
2019-10-29 04:27:48 +00:00
: BaseFilter(aCoeff, bCoeff, type)
{}
};
2019-10-29 04:27:48 +00:00
template <typename T>
2019-11-08 06:52:27 +00:00
class TVGenericFilter : public BaseFilter<T, TVGenericFilter<T>> {
2019-10-29 04:27:48 +00:00
public:
/*! \brief Filter a new data.
2019-10-28 08:23:25 +00:00
*
2019-10-29 04:27:48 +00:00
* This function is practical for online application that does not know the whole signal in advance.
* \param data New data to filter.
* \return Filtered data.
2019-01-04 08:15:03 +00:00
*/
2019-11-08 06:52:27 +00:00
T stepFilter(const T& time, const T& data);
2019-10-29 04:27:48 +00:00
/*! \brief Filter a signal.
2019-01-04 08:15:03 +00:00
*
2019-10-29 04:27:48 +00:00
* Filter all data given by the signal.
* \param data Signal.
* \return Filtered signal.
2019-01-04 08:15:03 +00:00
*/
2019-10-29 04:27:48 +00:00
vectX_t<T> filter(const vectX_t<T>& data, const vectX_t<T>& time);
2019-10-29 06:03:13 +00:00
void resetFilter() noexcept;
2019-10-29 04:27:48 +00:00
protected:
2019-10-29 06:03:13 +00:00
TVGenericFilter() = default;
2019-11-08 06:52:27 +00:00
TVGenericFilter(size_t differentialOrder, const vectX_t<T>& aCoeff, const vectX_t<T>& bCoeff, FilterType type = FilterType::Backward)
2019-10-29 04:27:48 +00:00
: BaseFilter(aCoeff, bCoeff, type)
2019-11-08 06:52:27 +00:00
, m_diffOrder(differentialOrder)
2019-10-29 04:27:48 +00:00
{
2019-11-08 06:52:27 +00:00
Expects(differentialOrder >= 1);
m_timers.resize(m_bCoeff.size());
m_timeDiffs.resize(m_bCoeff.size());
2019-10-29 04:27:48 +00:00
}
2018-10-23 10:22:57 +00:00
private:
2019-11-08 06:52:27 +00:00
size_t m_diffOrder = 1;
2019-10-29 04:27:48 +00:00
vectX_t<T> m_timers;
vectX_t<T> m_timeDiffs;
2018-10-23 10:22:57 +00:00
};
2019-01-04 08:45:22 +00:00
} // namespace difi
2019-10-29 04:27:48 +00:00
#include "GenericFilter.tpp"