Transistor Gijutsu, October 2014, Special Features Chapter 8,Software of the thermistor thermometer of 0.001 ° resolution, トランジスタ技術2014年10月号 特集第8章のソフトウェア 0.001℃分解能で気配もキャッチ「超敏感肌温度計」

Dependencies:   USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ExpAvr.h Source File

ExpAvr.h

00001 #ifndef EXPAVR_H
00002 #define EXPAVR_H
00003 
00004 #include <math.h>
00005 
00006 #define MathPi (3.1415926535897932384626433832795)
00007 /// 指数平均を計算する(実質的なローパスフィルタ)
00008 class ExpAvr {
00009 private:
00010     int order;      ///< ローパスフィルタの次数に相当
00011     double tc;      ///< 指数平均への増分、CR時定数に相当
00012     double *acc;    ///< 中間値を保存
00013     bool first;     ///< 初期化が必要かどうかのフラグ
00014 public:
00015     /// コンストラクタ
00016     /// @param order 次数(フィルタの段数)
00017     /// @param fcutoff カットオフ周波数[Hz]、fsampleより十分小さいこと。1/10以下を推奨。
00018     /// @param fsample サンプリング周波数[Hz]
00019     ExpAvr(int order, double fcutoff, double fsample){
00020         this->order = order;
00021         this->tc = exp((-2*fcutoff*MathPi)/fsample);
00022         acc = new double[order];
00023         first = true;
00024     };
00025     /// 指数平均計算
00026     /// @param d フィルタの入力値
00027     /// @return フィルタの出力値
00028     double getOutput(double d);
00029 };
00030 
00031 
00032 #endif