RtMedianFilter.cpp
Go to the documentation of this file.
1 #include "RtMedianFilter.h"
2 
4 
5 
7 {
8  RtMedianFilter::RtMedianFilter(size_t windowSize)
9  {
10  dataHistory.set_capacity(windowSize);
11  medianBuffer.resize(windowSize);
12  }
13 
14  float
16  {
17  dataHistory.push_back(value);
18  std::copy(dataHistory.begin(), dataHistory.end(), medianBuffer.begin());
19  const auto n = dataHistory.size();
20  std::sort(medianBuffer.begin(), medianBuffer.begin() + static_cast<long>(n));
21  float result = n % 2 == 0 ? (medianBuffer.at(n / 2 - 1) + medianBuffer.at(n / 2)) / 2
22  : medianBuffer.at(n / 2);
23  return result;
24  }
25 
26  std::size_t
28  {
29  return medianBuffer.size();
30  }
31 } // namespace armarx::control::rt_filters
armarx::control::rt_filters
Definition: AverageFilter.cpp:3
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
copy
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: license.txt:39
RtMedianFilter.h
Logging.h
armarx::control::rt_filters::RtMedianFilter::update
float update(float value)
Definition: RtMedianFilter.cpp:15
armarx::control::rt_filters::RtMedianFilter::getWindowSize
std::size_t getWindowSize() const
Definition: RtMedianFilter.cpp:27
armarx::control::rt_filters::RtMedianFilter::RtMedianFilter
RtMedianFilter(size_t windowSize=10)
Definition: RtMedianFilter.cpp:8