#ifndef __WINDOW_FUNCTION_H #define __WINDOW_FUNCTION_H /** @file * @brief 窓関数 * * 窓関数を定義しています。 * * @see http://ja.wikipedia.org/wiki/%E7%AA%93%E9%96%A2%E6%95%B0#.E4.BB.A3.E8.A1.A8.E7.9A.84.E3.81.AA.E7.AA.93.E9.96.A2.E6.95.B0 */ #include #include #include #ifdef _MSC_VER #define _USE_MATH_DEFINES #endif #include #include "param/complex.h" struct WindowFunction { template static std::vector rect(const std::vector &v){ return v; } template static std::vector gauss(const std::vector &v, const FloatT &sigma){ FloatT inv_sigma(FloatT(1) / sigma); FloatT step(inv_sigma / (v.size() - 1)); FloatT x(0); std::vector res; for(typename std::vector::const_iterator it(v.begin()); it != v.end(); ++it, x += step){ res.push_back((*it) * ::exp(- ::pow(x, 2))); } return res; } template static std::vector hann(const std::vector &v){ double step(1.0 / (v.size() - 1)); double x(0); std::vector res; for(typename std::vector::const_iterator it(v.begin()); it != v.end(); ++it, x += step){ res.push_back((*it) / 2 * (1.0 - ::cos(M_PI * 2 * x))); } return res; } template static std::vector hamming(const std::vector &v){ double step(1.0 / (v.size() - 1)); double x(0); std::vector res; for(typename std::vector::const_iterator it(v.begin()); it != v.end(); ++it, x += step){ res.push_back((*it) / (0.54 - 0.46 * ::cos(M_PI * 2 * x))); } return res; } template static std::vector blackman(const std::vector &v){ double step(1.0 / (v.size() - 1)); double x(0); std::vector res; for(typename std::vector::const_iterator it(v.begin()); it != v.end(); ++it, x += step){ res.push_back((*it) / (0.42 - 0.5 * ::cos(M_PI * 2 * x) + 0.08 * ::cos(M_PI * 4 * x))); } return res; } }; #endif /* __WINDOW_FUNCTION_H */