Remove any DC offset from before any further filtering takes place.

boxcar
Jonathan Naylor 2017-07-16 18:57:15 +01:00
parent 9d1ebc0f8f
commit 8540964097
9 changed files with 23 additions and 25 deletions

View File

@ -88,7 +88,7 @@ bool CDMRDMORX::processSample(q15_t sample, uint16_t rssi)
m_rssi[m_dataPtr] = rssi;
m_bitBuffer[m_bitPtr] <<= 1;
if (sample < m_dcLevel)
if (sample < 0)
m_bitBuffer[m_bitPtr] |= 0x01U;
if (m_state == DMORXS_NONE) {

View File

@ -104,7 +104,7 @@ bool CDMRSlotRX::processSample(q15_t sample, uint16_t rssi)
m_rssi[m_dataPtr] = rssi;
m_bitBuffer[m_bitPtr] <<= 1;
if (sample < m_dcLevel)
if (sample < 0)
m_bitBuffer[m_bitPtr] |= 0x01U;
if (m_state == DMRRXS_NONE) {

View File

@ -279,7 +279,7 @@ void CDStarRX::samples(const q15_t* samples, const uint16_t* rssi, uint8_t lengt
m_rssiAccum += rssi[i];
m_rssiCount++;
bool bit = samples[i] < m_dcLevel;
bool bit = samples[i] < 0;
if (bit != m_prev) {
if (m_pll < (PLLMAX / 2U))

View File

@ -93,8 +93,6 @@ extern bool m_duplex;
extern bool m_tx;
extern bool m_dcd;
extern q15_t m_dcLevel;
extern CSerialPort serial;
extern CIO io;

22
IO.cpp
View File

@ -33,7 +33,7 @@ static q15_t GAUSSIAN_0_5_FILTER[] = {8, 104, 760, 3158, 7421, 9866, 7421, 315
const uint16_t GAUSSIAN_0_5_FILTER_LEN = 12U;
// One symbol boxcar filter
static q15_t BOXCAR_FILTER[] = {3000, 3000, 3000, 3000, 3000, 0};
static q15_t BOXCAR_FILTER[] = {12000, 12000, 12000, 12000, 12000, 0};
const uint16_t BOXCAR_FILTER_LEN = 6U;
// Generated using [b, a] = butter(1, 0.001) in MATLAB
@ -73,7 +73,7 @@ m_dcState()
::memset(m_rrcState, 0x00U, 70U * sizeof(q15_t));
::memset(m_gaussianState, 0x00U, 40U * sizeof(q15_t));
::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t));
::memset(m_dcState, 0x00U, 4U * sizeof(q31_t));
::memset(m_dcState, 0x00U, 4U * sizeof(q31_t));
m_rrcFilter.numTaps = RRC_0_2_FILTER_LEN;
m_rrcFilter.pState = m_rrcState;
@ -88,8 +88,8 @@ m_dcState()
m_boxcarFilter.pCoeffs = BOXCAR_FILTER;
m_dcFilter.numStages = DC_FILTER_STAGES;
m_dcFilter.pState = m_dcState;
m_dcFilter.pCoeffs = DC_FILTER;
m_dcFilter.pState = m_dcState;
m_dcFilter.pCoeffs = DC_FILTER;
m_dcFilter.postShift = 0;
initInt();
@ -171,17 +171,19 @@ void CIO::process()
q31_t dcLevel = 0;
q31_t dcVals[20];
q31_t intSamp[20];
::arm_q15_to_q31((q15_t*)samples, intSamp, RX_BLOCK_SIZE);
::arm_biquad_cascade_df1_q31(&m_dcFilter, intSamp, dcVals, RX_BLOCK_SIZE);
q31_t q31Samples[20U];
::arm_q15_to_q31(samples, q31Samples, RX_BLOCK_SIZE);
::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, RX_BLOCK_SIZE);
for (uint8_t i = 0U; i < RX_BLOCK_SIZE; i++)
dcLevel += dcVals[i];
dcLevel /= RX_BLOCK_SIZE;
q15_t offset = q15_t(dcLevel >> 16);
m_dcLevel = q15_t(dcLevel >> 16);
for (uint8_t i = 0U; i < RX_BLOCK_SIZE; i++)
samples[i] -= offset;
if (m_modemState == STATE_IDLE) {
if (m_dstarEnable) {

12
IO.h
View File

@ -60,12 +60,12 @@ private:
CSampleRB m_txBuffer;
CRSSIRB m_rssiBuffer;
arm_fir_instance_q15 m_rrcFilter;
arm_fir_instance_q15 m_gaussianFilter;
arm_fir_instance_q15 m_boxcarFilter;
q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare
q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare
arm_fir_instance_q15 m_rrcFilter;
arm_fir_instance_q15 m_gaussianFilter;
arm_fir_instance_q15 m_boxcarFilter;
q15_t m_rrcState[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare
q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare
arm_biquad_casd_df1_inst_q31 m_dcFilter;
q31_t m_dcState[4];

View File

@ -36,8 +36,6 @@ bool m_duplex = true;
bool m_tx = false;
bool m_dcd = false;
q15_t m_dcLevel = 0;
CDStarRX dstarRX;
CDStarTX dstarTX;

View File

@ -95,7 +95,7 @@ void CP25RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length)
m_rssiCount++;
m_bitBuffer[m_bitPtr] <<= 1;
if (sample < m_dcLevel)
if (sample < 0)
m_bitBuffer[m_bitPtr] |= 0x01U;
m_buffer[m_dataPtr] = sample;

View File

@ -91,7 +91,7 @@ void CYSFRX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length)
m_rssiCount++;
m_bitBuffer[m_bitPtr] <<= 1;
if (sample < m_dcLevel)
if (sample < 0)
m_bitBuffer[m_bitPtr] |= 0x01U;
m_buffer[m_dataPtr] = sample;