The experiment using this program is introduced on "Interface" No.3, CQ publishing Co.,Ltd, 2015. 本プログラムを使った実験は,CQ出版社のインターフェース 2015年3月号で紹介しています.

Dependencies:   DSProcessingIO mbed

TwoPhaseGenerator.hpp

Committer:
CQpub0Mikami
Date:
2014-12-27
Revision:
2:0b15cd2b79e3
Parent:
0:a5a171eda3f8

File content as of revision 2:0b15cd2b79e3:

//--------------------------------------------------------------
// Two phase sin generator class
// Copyright (c) 2014 MIKAMI, Naoki,  2014/06/23
//--------------------------------------------------------------

#ifndef TWO_PHASE_GENERATOR_HPP
#define TWO_PHASE_GENERATOR_HPP

#include "mbed.h"

namespace Mikami
{
    class TwoPhaseGenerator
    {
    public:
        // Constructor
        TwoPhaseGenerator(float f0, float fs)
            : a1_(cosf(6.283185f*f0/fs)),
              b1_(sinf(6.283185f*f0/fs)),
              xn1_(1.0f), yn1_(0.0f) {}

        // -1.0f <= x1, x2 <= 1.0f
        void Generate(float& xn, float& yn)
        {
            yn = a1_*yn1_ + b1_*xn1_;     // sin
            xn = -b1_*yn1_ + a1_*xn1_;    // cos

            float c1 = 1.5f - 0.5f*(xn*xn + yn*yn);

            xn1_ = c1*xn;
            yn1_ = c1*yn;
        }

    private:
        const float a1_, b1_;
        float xn1_, yn1_;

        TwoPhaseGenerator(const TwoPhaseGenerator&);
        TwoPhaseGenerator& operator=(const TwoPhaseGenerator&);
    };
}
#endif  // TWO_PHASE_GENERATOR_HPP