make discretized sin wave, which is stored internal array var. The iterator of which array can go ahead by calling a get function.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DSin.h Source File

DSin.h

Go to the documentation of this file.
00001 /** Defining Discretized Sinusoidal Wave Model 
00002  *
00003  *  \file   DSin.h
00004  *  \author Akifumi Takahashi
00005  *  \date   2019/Nov/28 ver.1 publish
00006  *  \version 1.0.2019.Nov
00007  *  \version 2.0.2019.Dec
00008  */
00009  
00010 #ifndef DISCRETIZED_SINUSOIDAL_WAVE_MODEL_H
00011 #define DISCRETIZED_SINUSOIDAL_WAVE_MODEL_H
00012 #define _USE_MATH_DEFINES
00013 #include <cmath>
00014 
00015 #ifndef M_PI
00016 #define M_PI 3.141592
00017 #endif
00018 
00019 #include "mbed.h"
00020 /** \Class DISCRETIZED SINUSOIDAL WAVE MODEL
00021  *
00022  *  Model of a discretized sinusoidal wave whose value type is float, 
00023  *  and the range is from (-1.0f * ampl) to (1.0f * ampl).
00024  *
00025  */
00026 class DSin
00027 {
00028 private:
00029     /// Amplitude of sinusoidal wave (mA)
00030     float m_ampl;
00031     
00032     /// Frequency of the wave (Hz)
00033     uint16_t m_freq;
00034     
00035     /// Pulse width fineness of dicretization (us) 
00036     /// pwth = 1000000 / freq / resolution_ofsin;
00037     uint16_t m_pwth;
00038     
00039     float*      m_discretized_sin;
00040     int32_t*    m_discretized_sin_p16m16;
00041     
00042     void init();
00043 
00044 public:
00045     float const ampl_max;
00046     uint16_t const freq_max;
00047     uint16_t const resolution_ofsin; // = arg_resolution_ofsin below
00048     
00049     DSin(
00050         uint16_t const arg_resolution_ofsin = 20
00051     );
00052     DSin(
00053         float const arg_ampl,
00054         uint16_t const arg_freq,
00055         uint16_t const arg_resolution_ofsin = 20
00056     );
00057     
00058     void setParam(
00059         float const arg_ampl,
00060         uint16_t const arg_freq
00061     );
00062     
00063     void setAmplitude(
00064         float const arg_ampl
00065     );
00066     
00067     void setFrequency(
00068         uint16_t const arg_freq
00069     );
00070     
00071     float getValue();
00072     int32_t getValue_p16m16();
00073     
00074     void getValueofSamplePoints(float[]);
00075     
00076     float    getAmplitude();    //inline
00077     uint16_t getFrequency();    //inline
00078     uint16_t getPulseWidth(); //inline
00079     
00080 };
00081 
00082 
00083 inline float DSin::getAmplitude()
00084 {
00085     return m_ampl;
00086 }
00087 
00088 inline uint16_t DSin::getFrequency()
00089 {
00090     return m_freq;
00091 }
00092 
00093 inline uint16_t DSin::getPulseWidth()
00094 {
00095     return m_pwth;
00096 }
00097 #endif