This makes Amplitude Modulated Pulse Train, which can be regarded as the discretized wave of the signal. Pulse Train can be defined by frequency and duty cycle, which can be temporarily changed, referring to PWM.
Dependents: Interference_Simple
Diff: DSinGenerator.h
- Revision:
- 1:19c3a52c80c3
- Parent:
- 0:6400e338266f
- Child:
- 3:5e9675a0c08c
- Child:
- 4:7d5afb2e3b79
--- a/DSinGenerator.h Wed Nov 27 23:03:42 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/** Defining Discretized Sinusoidal Wave Generator - * - * \file DSinGenerator.h - * \author Akifumi Takahashi - * \date 2019/Nov/28 ver.1 publish - * \version 1.0.2019.Nov - */ - -#ifndef DISCRETIZED_SINUSOIDAL_WAVE_GENERATOR_H -#define DISCRETIZED_SINUSOIDAL_WAVE_GENERATOR_H -#define _USE_MATH_DEFINES -#include <cmath> - -#ifndef M_PI -#define M_PI 3.141592 -#endif - -#include "mbed.h" -/** \Class DISCRETIZED SINUSOIDAL WAVE GENERATOR - * - * Generate a discretized sinusoidal wave whose value type is float, - * and the range is from (-1.0f * ampl) to (1.0f * ampl). - * - */ -class DSinGenerator -{ -private: - /// Amplitude of sinusoidal wave (mA) - float ampl; - - /// Frequency of the wave (Hz) - uint16_t freq; - - /// Pulse width fineness of dicretization (us) - /// pwth = 1000000 / freq / resolution_ofsin; - uint16_t pwth; - - float* discretized_sin; - int32_t* discretized_sin_p16m16; - - void init(); - -public: - float const ampl_max; - uint16_t const freq_max; - uint16_t const resolution_ofsin; // = arg_resolution_ofsin below - - DSinGenerator( - uint16_t const arg_resolution_ofsin = 20 - ); - DSinGenerator( - float const arg_ampl, - uint16_t const arg_freq, - uint16_t const arg_resolution_ofsin = 20 - ); - - void setParam( - float const arg_ampl, - uint16_t const arg_freq - ); - - void setAmplitude( - float const arg_ampl - ); - - void setFrequency( - uint16_t const arg_freq - ); - - float getValue(); - int32_t getValue_p16m16(); - - void getValueofSamplePoints(float[]); - - float getAmplitude(); //inline - uint16_t getFrequency(); //inline - uint16_t getPulseWidth(); //inline - -}; - - -inline float DSinGenerator::getAmplitude() -{ - return ampl; -} - -inline uint16_t DSinGenerator::getFrequency() -{ - return freq; -} - -inline uint16_t DSinGenerator::getPulseWidth() -{ - return pwth; -} -#endif \ No newline at end of file