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

Committer:
aktk
Date:
Wed Nov 27 23:03:42 2019 +0000
Revision:
0:6400e338266f
nyaan

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 0:6400e338266f 1 /** Defining Discretized Sinusoidal Wave Generator
aktk 0:6400e338266f 2 *
aktk 0:6400e338266f 3 * \file DSinGenerator.h
aktk 0:6400e338266f 4 * \author Akifumi Takahashi
aktk 0:6400e338266f 5 * \date 2019/Nov/28 ver.1 publish
aktk 0:6400e338266f 6 * \version 1.0.2019.Nov
aktk 0:6400e338266f 7 */
aktk 0:6400e338266f 8
aktk 0:6400e338266f 9 #ifndef DISCRETIZED_SINUSOIDAL_WAVE_GENERATOR_H
aktk 0:6400e338266f 10 #define DISCRETIZED_SINUSOIDAL_WAVE_GENERATOR_H
aktk 0:6400e338266f 11 #define _USE_MATH_DEFINES
aktk 0:6400e338266f 12 #include <cmath>
aktk 0:6400e338266f 13
aktk 0:6400e338266f 14 #ifndef M_PI
aktk 0:6400e338266f 15 #define M_PI 3.141592
aktk 0:6400e338266f 16 #endif
aktk 0:6400e338266f 17
aktk 0:6400e338266f 18 #include "mbed.h"
aktk 0:6400e338266f 19 /** \Class DISCRETIZED SINUSOIDAL WAVE GENERATOR
aktk 0:6400e338266f 20 *
aktk 0:6400e338266f 21 * Generate a discretized sinusoidal wave whose value type is float,
aktk 0:6400e338266f 22 * and the range is from (-1.0f * ampl) to (1.0f * ampl).
aktk 0:6400e338266f 23 *
aktk 0:6400e338266f 24 */
aktk 0:6400e338266f 25 class DSinGenerator
aktk 0:6400e338266f 26 {
aktk 0:6400e338266f 27 private:
aktk 0:6400e338266f 28 /// Amplitude of sinusoidal wave (mA)
aktk 0:6400e338266f 29 float ampl;
aktk 0:6400e338266f 30
aktk 0:6400e338266f 31 /// Frequency of the wave (Hz)
aktk 0:6400e338266f 32 uint16_t freq;
aktk 0:6400e338266f 33
aktk 0:6400e338266f 34 /// Pulse width fineness of dicretization (us)
aktk 0:6400e338266f 35 /// pwth = 1000000 / freq / resolution_ofsin;
aktk 0:6400e338266f 36 uint16_t pwth;
aktk 0:6400e338266f 37
aktk 0:6400e338266f 38 float* discretized_sin;
aktk 0:6400e338266f 39 int32_t* discretized_sin_p16m16;
aktk 0:6400e338266f 40
aktk 0:6400e338266f 41 void init();
aktk 0:6400e338266f 42
aktk 0:6400e338266f 43 public:
aktk 0:6400e338266f 44 float const ampl_max;
aktk 0:6400e338266f 45 uint16_t const freq_max;
aktk 0:6400e338266f 46 uint16_t const resolution_ofsin; // = arg_resolution_ofsin below
aktk 0:6400e338266f 47
aktk 0:6400e338266f 48 DSinGenerator(
aktk 0:6400e338266f 49 uint16_t const arg_resolution_ofsin = 20
aktk 0:6400e338266f 50 );
aktk 0:6400e338266f 51 DSinGenerator(
aktk 0:6400e338266f 52 float const arg_ampl,
aktk 0:6400e338266f 53 uint16_t const arg_freq,
aktk 0:6400e338266f 54 uint16_t const arg_resolution_ofsin = 20
aktk 0:6400e338266f 55 );
aktk 0:6400e338266f 56
aktk 0:6400e338266f 57 void setParam(
aktk 0:6400e338266f 58 float const arg_ampl,
aktk 0:6400e338266f 59 uint16_t const arg_freq
aktk 0:6400e338266f 60 );
aktk 0:6400e338266f 61
aktk 0:6400e338266f 62 void setAmplitude(
aktk 0:6400e338266f 63 float const arg_ampl
aktk 0:6400e338266f 64 );
aktk 0:6400e338266f 65
aktk 0:6400e338266f 66 void setFrequency(
aktk 0:6400e338266f 67 uint16_t const arg_freq
aktk 0:6400e338266f 68 );
aktk 0:6400e338266f 69
aktk 0:6400e338266f 70 float getValue();
aktk 0:6400e338266f 71 int32_t getValue_p16m16();
aktk 0:6400e338266f 72
aktk 0:6400e338266f 73 void getValueofSamplePoints(float[]);
aktk 0:6400e338266f 74
aktk 0:6400e338266f 75 float getAmplitude(); //inline
aktk 0:6400e338266f 76 uint16_t getFrequency(); //inline
aktk 0:6400e338266f 77 uint16_t getPulseWidth(); //inline
aktk 0:6400e338266f 78
aktk 0:6400e338266f 79 };
aktk 0:6400e338266f 80
aktk 0:6400e338266f 81
aktk 0:6400e338266f 82 inline float DSinGenerator::getAmplitude()
aktk 0:6400e338266f 83 {
aktk 0:6400e338266f 84 return ampl;
aktk 0:6400e338266f 85 }
aktk 0:6400e338266f 86
aktk 0:6400e338266f 87 inline uint16_t DSinGenerator::getFrequency()
aktk 0:6400e338266f 88 {
aktk 0:6400e338266f 89 return freq;
aktk 0:6400e338266f 90 }
aktk 0:6400e338266f 91
aktk 0:6400e338266f 92 inline uint16_t DSinGenerator::getPulseWidth()
aktk 0:6400e338266f 93 {
aktk 0:6400e338266f 94 return pwth;
aktk 0:6400e338266f 95 }
aktk 0:6400e338266f 96 #endif