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 21:37:20 2020 +0000
Branch:
35e9675a
Revision:
5:77ac0df7c3a1
Parent:
1:19c3a52c80c3
Complicated branch revision :'(

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 1:19c3a52c80c3 1 #include "AMSignal.h"
aktk 1:19c3a52c80c3 2
aktk 1:19c3a52c80c3 3 void AMSignal::setFrequency(uint16_t const arg_freq)
aktk 1:19c3a52c80c3 4 {
aktk 1:19c3a52c80c3 5 m_freq = velidateRange<uint16_t>(arg_freq, 1, FREQ_MAX);
aktk 1:19c3a52c80c3 6 m_period_us = 1000000 / m_freq;
aktk 1:19c3a52c80c3 7 if(1000000 % m_freq >= (m_freq/2)) m_period_us += 1;
aktk 1:19c3a52c80c3 8 }
aktk 1:19c3a52c80c3 9
aktk 1:19c3a52c80c3 10 void AMSignal::setAmplitude(float const arg_ampl)
aktk 1:19c3a52c80c3 11 {
aktk 1:19c3a52c80c3 12 m_ampl_u16 = AMPL_MAX_u16 * velidateRange<float>(arg_ampl, 0.0, 1.0);
aktk 1:19c3a52c80c3 13 }
aktk 1:19c3a52c80c3 14
aktk 1:19c3a52c80c3 15 void AMSignal::setAmplitude(uint16_t const arg_ampl)
aktk 1:19c3a52c80c3 16 {
aktk 1:19c3a52c80c3 17 m_ampl_u16 = arg_ampl;
aktk 1:19c3a52c80c3 18 }
aktk 1:19c3a52c80c3 19
aktk 1:19c3a52c80c3 20 /// Get a parameter which defines the size of pulse hight axis with in [0,1]
aktk 1:19c3a52c80c3 21 float AMSignal::getAmplitude_uf()
aktk 1:19c3a52c80c3 22 {
aktk 1:19c3a52c80c3 23 return (float) m_ampl_u16 / (float) AMPL_MAX_u16;
aktk 1:19c3a52c80c3 24 }
aktk 1:19c3a52c80c3 25
aktk 1:19c3a52c80c3 26 uint16_t AMSignal::getAmplitude_u16()
aktk 1:19c3a52c80c3 27 {
aktk 1:19c3a52c80c3 28 return m_ampl_u16;
aktk 1:19c3a52c80c3 29 }
aktk 1:19c3a52c80c3 30
aktk 1:19c3a52c80c3 31 uint16_t AMSignal::getFrequency()
aktk 1:19c3a52c80c3 32 {
aktk 1:19c3a52c80c3 33 return m_freq;
aktk 1:19c3a52c80c3 34 }
aktk 1:19c3a52c80c3 35
aktk 1:19c3a52c80c3 36 uint16_t AMSignal::getPeriod_us()
aktk 1:19c3a52c80c3 37 {
aktk 1:19c3a52c80c3 38 return m_period_us;
aktk 1:19c3a52c80c3 39 }
aktk 1:19c3a52c80c3 40
aktk 1:19c3a52c80c3 41
aktk 1:19c3a52c80c3 42 template <typename T>
aktk 1:19c3a52c80c3 43 T AMSignal::velidateRange(T const arg_val, T const arg_min, T const arg_max)
aktk 1:19c3a52c80c3 44 {
aktk 1:19c3a52c80c3 45 if(arg_val < arg_min) return arg_min;
aktk 1:19c3a52c80c3 46 else if (arg_val <= arg_max) return arg_val;
aktk 1:19c3a52c80c3 47 else return arg_max;
aktk 1:19c3a52c80c3 48 }