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

Committer:
aktk
Date:
Mon Jan 06 20:26:53 2020 +0000
Revision:
1:19c3a52c80c3
Derived from DSinGenerator.lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 1:19c3a52c80c3 1 /** Defining Amplide Modulated Pulse Train Model
aktk 1:19c3a52c80c3 2 *
aktk 1:19c3a52c80c3 3 * \file AMSignal.h
aktk 1:19c3a52c80c3 4 * \author Akifumi Takahashi
aktk 1:19c3a52c80c3 5 * \date 2019/12/02 -
aktk 1:19c3a52c80c3 6 * \version 1.0.2019.Dec
aktk 1:19c3a52c80c3 7 */
aktk 1:19c3a52c80c3 8
aktk 1:19c3a52c80c3 9 #ifndef AM_SIGNAL_H
aktk 1:19c3a52c80c3 10 #define AM_SIGNAL_H
aktk 1:19c3a52c80c3 11
aktk 1:19c3a52c80c3 12
aktk 1:19c3a52c80c3 13 #include "mbed.h"
aktk 1:19c3a52c80c3 14
aktk 1:19c3a52c80c3 15 /** \Class Amplide Modulated Signal Model for AM Pulse Train Model
aktk 1:19c3a52c80c3 16 *
aktk 1:19c3a52c80c3 17 * All parameter data is dealed as unsigned 16 bit int.
aktk 1:19c3a52c80c3 18 * \version alluint16
aktk 1:19c3a52c80c3 19 */
aktk 1:19c3a52c80c3 20 class AMSignal
aktk 1:19c3a52c80c3 21 {
aktk 1:19c3a52c80c3 22 public:
aktk 1:19c3a52c80c3 23 /// Constructor
aktk 1:19c3a52c80c3 24 AMSignal(
aktk 1:19c3a52c80c3 25 uint16_t const arg_freq = 50,
aktk 1:19c3a52c80c3 26 uint16_t const arg_freq_max = 100,
aktk 1:19c3a52c80c3 27 uint16_t const arg_ampl_max_u16 = 4095
aktk 1:19c3a52c80c3 28 ):
aktk 1:19c3a52c80c3 29 FREQ_MAX(arg_freq_max),
aktk 1:19c3a52c80c3 30 AMPL_MAX_u16(arg_ampl_max_u16)
aktk 1:19c3a52c80c3 31 {
aktk 1:19c3a52c80c3 32 setFrequency(arg_freq);
aktk 1:19c3a52c80c3 33 attachAMSignalExpression(constantDC_defaltSignal);
aktk 1:19c3a52c80c3 34 }
aktk 1:19c3a52c80c3 35
aktk 1:19c3a52c80c3 36 /** Amplitude Modified Signal / Pulse Hight Writing Handler
aktk 1:19c3a52c80c3 37 *
aktk 1:19c3a52c80c3 38 * For fast processing, no float culc nor div culc is recommended
aktk 1:19c3a52c80c3 39 */
aktk 1:19c3a52c80c3 40 void attachAMSignalExpression(
aktk 1:19c3a52c80c3 41 /** Callback
aktk 1:19c3a52c80c3 42 *
aktk 1:19c3a52c80c3 43 * \arg AMSignal* contains parameters of this.
aktk 1:19c3a52c80c3 44 * \retval is dealed as a factor the argument of Callback as Pulse rising.
aktk 1:19c3a52c80c3 45 */
aktk 1:19c3a52c80c3 46 Callback<uint16_t(AMSignal*)> arg_signal
aktk 1:19c3a52c80c3 47 )
aktk 1:19c3a52c80c3 48 {
aktk 1:19c3a52c80c3 49 m_AMSignalExpression = arg_signal;
aktk 1:19c3a52c80c3 50 }
aktk 1:19c3a52c80c3 51
aktk 1:19c3a52c80c3 52 uint16_t getAMSinalValue()
aktk 1:19c3a52c80c3 53 {
aktk 1:19c3a52c80c3 54 return m_AMSignalExpression(this);
aktk 1:19c3a52c80c3 55 }
aktk 1:19c3a52c80c3 56
aktk 1:19c3a52c80c3 57
aktk 1:19c3a52c80c3 58 private:
aktk 1:19c3a52c80c3 59 uint16_t m_ampl_u16;
aktk 1:19c3a52c80c3 60 uint16_t m_freq;
aktk 1:19c3a52c80c3 61 uint16_t m_period_us;
aktk 1:19c3a52c80c3 62 template <typename T>
aktk 1:19c3a52c80c3 63 static T velidateRange(T const arg_val, T const arg_min, T const arg_max);
aktk 1:19c3a52c80c3 64
aktk 1:19c3a52c80c3 65 Callback<uint16_t(AMSignal*)> m_AMSignalExpression;
aktk 1:19c3a52c80c3 66
aktk 1:19c3a52c80c3 67 /// Default amplitude modulation signal
aktk 1:19c3a52c80c3 68 static uint16_t constantDC_defaltSignal (AMSignal* arg)
aktk 1:19c3a52c80c3 69 {
aktk 1:19c3a52c80c3 70 return 1;
aktk 1:19c3a52c80c3 71 }
aktk 1:19c3a52c80c3 72
aktk 1:19c3a52c80c3 73
aktk 1:19c3a52c80c3 74 public:
aktk 1:19c3a52c80c3 75 // constants
aktk 1:19c3a52c80c3 76 uint16_t const FREQ_MAX;
aktk 1:19c3a52c80c3 77 uint16_t const AMPL_MAX_u16;
aktk 1:19c3a52c80c3 78
aktk 1:19c3a52c80c3 79 /** Frequency could be slightly modulated because it depends on the carrier freq
aktk 1:19c3a52c80c3 80 */
aktk 1:19c3a52c80c3 81 void setFrequency(uint16_t const arg_freq);
aktk 1:19c3a52c80c3 82
aktk 1:19c3a52c80c3 83 /** Set Amplitude Paramiter
aktk 1:19c3a52c80c3 84 *
aktk 1:19c3a52c80c3 85 * - Crumping a value within [0f,1f], converted to [0, 0xFFFF]
aktk 1:19c3a52c80c3 86 * - Note that this is a parameter which affects a pulse hight,
aktk 1:19c3a52c80c3 87 * but isn't the pulse hight itself
aktk 1:19c3a52c80c3 88 * - The Pulse hight is defined in callback attached with attachAMSignalExpression()
aktk 1:19c3a52c80c3 89 */
aktk 1:19c3a52c80c3 90 void setAmplitude(float const arg_ampl);
aktk 1:19c3a52c80c3 91
aktk 1:19c3a52c80c3 92 void setAmplitude(uint16_t const arg_ampl);
aktk 1:19c3a52c80c3 93
aktk 1:19c3a52c80c3 94 /// Get a parameter which defines the size of pulse hight axis with in [0,1]
aktk 1:19c3a52c80c3 95 float getAmplitude_uf(); //inline
aktk 1:19c3a52c80c3 96
aktk 1:19c3a52c80c3 97 /// Get a parameter which defines the size of pulse hight axis with in [0, 4096]
aktk 1:19c3a52c80c3 98 uint16_t getAmplitude_u16(); //inline
aktk 1:19c3a52c80c3 99
aktk 1:19c3a52c80c3 100 uint16_t getFrequency(); //inline
aktk 1:19c3a52c80c3 101
aktk 1:19c3a52c80c3 102 uint16_t getPeriod_us(); //inline
aktk 1:19c3a52c80c3 103
aktk 1:19c3a52c80c3 104 };
aktk 1:19c3a52c80c3 105 #endif