mirror of https://github.com/markqvist/MMDVM.git
Add fine adjustment to the DMR/YSF thresholds.
parent
a3ea870b52
commit
17f6314f90
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
// #define WANT_DEBUG
|
||||
#define WANT_DEBUG
|
||||
|
||||
#include "Config.h"
|
||||
#include "Globals.h"
|
||||
|
@ -47,7 +47,8 @@ m_endPtr(NOENDPTR),
|
|||
m_maxCorr(0),
|
||||
m_centre(0),
|
||||
m_threshold(0),
|
||||
m_colorCode(0U)
|
||||
m_colorCode(0U),
|
||||
m_scale(SCALING_FACTOR)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -103,7 +104,7 @@ void CDMRIdleRX::processSample(q15_t sample)
|
|||
if (corr > m_maxCorr) {
|
||||
q15_t centre = (max + min) >> 1;
|
||||
|
||||
q31_t v1 = (max - centre) * SCALING_FACTOR;
|
||||
q31_t v1 = (max - centre) * m_scale;
|
||||
q15_t threshold = q15_t(v1 >> 15);
|
||||
|
||||
uint8_t sync[DMR_SYNC_BYTES_LENGTH];
|
||||
|
@ -200,3 +201,20 @@ void CDMRIdleRX::setColorCode(uint8_t colorCode)
|
|||
m_colorCode = colorCode;
|
||||
}
|
||||
|
||||
void CDMRIdleRX::setThreshold(int8_t percent)
|
||||
{
|
||||
q31_t res = SCALING_FACTOR * 1000;
|
||||
|
||||
if (percent > 0) {
|
||||
for (int8_t i = 0; i < percent; i++)
|
||||
res += SCALING_FACTOR;
|
||||
} else if (percent < 0) {
|
||||
for (int8_t i = 0; i < -percent; i++)
|
||||
res -= SCALING_FACTOR;
|
||||
}
|
||||
|
||||
m_scale = res / 1000;
|
||||
|
||||
DEBUG2("DMR, Scale", m_scale);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
|
||||
void samples(const q15_t* samples, uint8_t length);
|
||||
|
||||
void setThreshold(int8_t threshold);
|
||||
void setColorCode(uint8_t colorCode);
|
||||
|
||||
void reset();
|
||||
|
@ -42,6 +43,7 @@ private:
|
|||
q15_t m_centre;
|
||||
q15_t m_threshold;
|
||||
uint8_t m_colorCode;
|
||||
q15_t m_scale;
|
||||
|
||||
void processSample(q15_t sample);
|
||||
void samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold);
|
||||
|
|
|
@ -56,6 +56,12 @@ void CDMRRX::setColorCode(uint8_t colorCode)
|
|||
m_slot2RX.setColorCode(colorCode);
|
||||
}
|
||||
|
||||
void CDMRRX::setThreshold(int8_t threshold)
|
||||
{
|
||||
m_slot1RX.setThreshold(threshold);
|
||||
m_slot2RX.setThreshold(threshold);
|
||||
}
|
||||
|
||||
void CDMRRX::setDelay(uint8_t delay)
|
||||
{
|
||||
m_slot1RX.setDelay(delay);
|
||||
|
|
1
DMRRX.h
1
DMRRX.h
|
@ -29,6 +29,7 @@ public:
|
|||
void samples(const q15_t* samples, const uint8_t* control, uint8_t length);
|
||||
|
||||
void setColorCode(uint8_t colorCode);
|
||||
void setThreshold(int8_t threshold);
|
||||
void setDelay(uint8_t delay);
|
||||
|
||||
void reset();
|
||||
|
|
|
@ -61,7 +61,8 @@ m_colorCode(0U),
|
|||
m_delay(0U),
|
||||
m_state(DMRRXS_NONE),
|
||||
m_n(0U),
|
||||
m_type(0U)
|
||||
m_type(0U),
|
||||
m_scale(SCALING_FACTOR)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -270,7 +271,7 @@ void CDMRSlotRX::correlateSync(bool first)
|
|||
if (corr > m_maxCorr) {
|
||||
q15_t centre = (max + min) >> 1;
|
||||
|
||||
q31_t v1 = (max - centre) * SCALING_FACTOR;
|
||||
q31_t v1 = (max - centre) * m_scale;
|
||||
q15_t threshold = q15_t(v1 >> 15);
|
||||
|
||||
uint8_t sync[DMR_SYNC_BYTES_LENGTH];
|
||||
|
@ -371,3 +372,20 @@ void CDMRSlotRX::setDelay(uint8_t delay)
|
|||
m_delay = delay;
|
||||
}
|
||||
|
||||
void CDMRSlotRX::setThreshold(int8_t percent)
|
||||
{
|
||||
q31_t res = SCALING_FACTOR * 1000;
|
||||
|
||||
if (percent > 0) {
|
||||
for (int8_t i = 0; i < percent; i++)
|
||||
res += SCALING_FACTOR;
|
||||
} else if (percent < 0) {
|
||||
for (int8_t i = 0; i < -percent; i++)
|
||||
res -= SCALING_FACTOR;
|
||||
}
|
||||
|
||||
m_scale = res / 1000;
|
||||
|
||||
DEBUG2("DMR, Scale", m_scale);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
bool processSample(q15_t sample);
|
||||
|
||||
void setColorCode(uint8_t colorCode);
|
||||
void setThreshold(int8_t threshold);
|
||||
void setDelay(uint8_t delay);
|
||||
|
||||
void reset();
|
||||
|
@ -62,6 +63,7 @@ private:
|
|||
DMRRX_STATE m_state;
|
||||
uint8_t m_n;
|
||||
uint8_t m_type;
|
||||
q15_t m_scale;
|
||||
|
||||
void correlateSync(bool first);
|
||||
void samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold);
|
||||
|
|
|
@ -185,7 +185,7 @@ void CSerialPort::getVersion()
|
|||
|
||||
uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
|
||||
{
|
||||
if (length < 14U)
|
||||
if (length < 16U)
|
||||
return 4U;
|
||||
|
||||
bool rxInvert = (data[0U] & 0x01U) == 0x01U;
|
||||
|
@ -240,6 +240,9 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
|
|||
int8_t ysfLevel1 = int8_t(data[12U]) - 128;
|
||||
int8_t ysfLevel3 = int8_t(data[13U]) - 128;
|
||||
|
||||
int8_t dmrThreshold = int8_t(data[14U]) - 128;
|
||||
int8_t ysfThreshold = int8_t(data[15U]) - 128;
|
||||
|
||||
m_modemState = modemState;
|
||||
|
||||
m_dstarEnable = dstarEnable;
|
||||
|
@ -258,6 +261,10 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
|
|||
dmrTX.setLevels(dmrLevel1, dmrLevel3);
|
||||
ysfTX.setLevels(ysfLevel1, ysfLevel3);
|
||||
|
||||
dmrIdleRX.setThreshold(dmrThreshold);
|
||||
dmrRX.setThreshold(dmrThreshold);
|
||||
ysfRX.setThreshold(ysfThreshold);
|
||||
|
||||
io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, txLevel);
|
||||
|
||||
io.start();
|
||||
|
|
22
YSFRX.cpp
22
YSFRX.cpp
|
@ -55,7 +55,8 @@ m_bufferPtr(0U),
|
|||
m_symbolPtr(0U),
|
||||
m_lostCount(0U),
|
||||
m_centre(0),
|
||||
m_threshold(0)
|
||||
m_threshold(0),
|
||||
m_scale(SCALING_FACTOR)
|
||||
{
|
||||
m_buffer = m_outBuffer + 1U;
|
||||
}
|
||||
|
@ -123,7 +124,7 @@ void CYSFRX::processNone(q15_t sample)
|
|||
|
||||
q15_t centre = (max + min) >> 1;
|
||||
|
||||
q31_t v1 = (max - centre) * SCALING_FACTOR;
|
||||
q31_t v1 = (max - centre) * m_scale;
|
||||
q15_t threshold = q15_t(v1 >> 15);
|
||||
|
||||
uint16_t ptr = m_symbolPtr + 1U;
|
||||
|
@ -242,3 +243,20 @@ void CYSFRX::processData(q15_t sample)
|
|||
}
|
||||
}
|
||||
|
||||
void CYSFRX::setThreshold(int8_t percent)
|
||||
{
|
||||
q31_t res = SCALING_FACTOR * 1000;
|
||||
|
||||
if (percent > 0) {
|
||||
for (int8_t i = 0; i < percent; i++)
|
||||
res += SCALING_FACTOR;
|
||||
} else if (percent < 0) {
|
||||
for (int8_t i = 0; i < -percent; i++)
|
||||
res -= SCALING_FACTOR;
|
||||
}
|
||||
|
||||
m_scale = res / 1000;
|
||||
|
||||
DEBUG2("YSF, Scale", m_scale);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue