From 69e39e36b05482ca10e7c9e66877182bedb0e86e Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Thu, 30 Apr 2020 10:26:04 +0200 Subject: [PATCH 1/5] =?UTF-8?q?Change=20emphasis=20time=20constant=20to=20?= =?UTF-8?q?750=C2=B5S?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FM.cpp | 4 ++-- Tools/emphasis.txt | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/FM.cpp b/FM.cpp index f6da336..6c1043c 100644 --- a/FM.cpp +++ b/FM.cpp @@ -39,8 +39,8 @@ m_hangTimer(), m_filterStage1( 724, 1448, 724, 32768, -37895, 21352),//3rd order Cheby Filter 300 to 2700Hz, 0.2dB passband ripple, sampling rate 24kHz m_filterStage2(32768, 0,-32768, 32768, -50339, 19052), m_filterStage3(32768, -65536, 32768, 32768, -64075, 31460), -m_preemphasis(32768, 13967, 0, 32768, -18801, 0),//75µS 24kHz sampling rate -m_deemphasis (32768, -18801, 0, 32768, 13967, 0),//75µS 24kHz sampling rate +m_preemphasis(32768, 1771, 0, 32768, -30997, 0),//750µS 24kHz sampling rate +m_deemphasis (32768, -30997, 0, 32768, 1771, 0),//750µS 24kHz sampling rate m_blanking(), m_useCOS(true), m_rfAudioBoost(1U), diff --git a/Tools/emphasis.txt b/Tools/emphasis.txt index 39660d1..0c929ef 100644 --- a/Tools/emphasis.txt +++ b/Tools/emphasis.txt @@ -9,21 +9,24 @@ clear all; clc; fs = 24000; +timeConstant = 0.00075; %750µS + + samplingtime = 1/fs; % analog prototype A2 = [1]; -B2 = [0.000075 1]; +B2 = [timeConstant 1]; % Pre -Ds = tf(B2, A2); +%Ds = tf(B2, A2); % De -% Ds = tf(A2, B2); +Ds = tf(A2, B2); Ds = Ds/dcgain(Ds); % MZT -T1 = 0.000075; % 75us +T1 = timeConstant; z1 = -exp(-1.0/(fs*T1)); p1 = 1+z1; @@ -37,12 +40,12 @@ b2 = 0; % swap between a1, b1 to select pre- or de-emphasis -# Pre -Bmzt = [b0 a1 b2] -Amzt = [a0 b1 a2] +% Pre +%Bmzt = [b0 a1 b2] +%Amzt = [a0 b1 a2] % De -% Bmzt = [b0 b1 b2] -% Amzt = [a0 a1 a2] +Bmzt = [b0 b1 b2] +Amzt = [a0 a1 a2] DzMZT = tf(Amzt, Bmzt, samplingtime); DzMZT = DzMZT/dcgain(DzMZT); From cc785e32256e22b38ded25907e514c9279c8739b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 30 Apr 2020 11:23:19 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Revert=20"Change=20emphasis=20time=20consta?= =?UTF-8?q?nt=20to=20750=C2=B5S"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FM.cpp | 4 ++-- Tools/emphasis.txt | 21 +++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/FM.cpp b/FM.cpp index 6c1043c..f6da336 100644 --- a/FM.cpp +++ b/FM.cpp @@ -39,8 +39,8 @@ m_hangTimer(), m_filterStage1( 724, 1448, 724, 32768, -37895, 21352),//3rd order Cheby Filter 300 to 2700Hz, 0.2dB passband ripple, sampling rate 24kHz m_filterStage2(32768, 0,-32768, 32768, -50339, 19052), m_filterStage3(32768, -65536, 32768, 32768, -64075, 31460), -m_preemphasis(32768, 1771, 0, 32768, -30997, 0),//750µS 24kHz sampling rate -m_deemphasis (32768, -30997, 0, 32768, 1771, 0),//750µS 24kHz sampling rate +m_preemphasis(32768, 13967, 0, 32768, -18801, 0),//75µS 24kHz sampling rate +m_deemphasis (32768, -18801, 0, 32768, 13967, 0),//75µS 24kHz sampling rate m_blanking(), m_useCOS(true), m_rfAudioBoost(1U), diff --git a/Tools/emphasis.txt b/Tools/emphasis.txt index 0c929ef..39660d1 100644 --- a/Tools/emphasis.txt +++ b/Tools/emphasis.txt @@ -9,24 +9,21 @@ clear all; clc; fs = 24000; -timeConstant = 0.00075; %750µS - - samplingtime = 1/fs; % analog prototype A2 = [1]; -B2 = [timeConstant 1]; +B2 = [0.000075 1]; % Pre -%Ds = tf(B2, A2); +Ds = tf(B2, A2); % De -Ds = tf(A2, B2); +% Ds = tf(A2, B2); Ds = Ds/dcgain(Ds); % MZT -T1 = timeConstant; +T1 = 0.000075; % 75us z1 = -exp(-1.0/(fs*T1)); p1 = 1+z1; @@ -40,12 +37,12 @@ b2 = 0; % swap between a1, b1 to select pre- or de-emphasis -% Pre -%Bmzt = [b0 a1 b2] -%Amzt = [a0 b1 a2] +# Pre +Bmzt = [b0 a1 b2] +Amzt = [a0 b1 a2] % De -Bmzt = [b0 b1 b2] -Amzt = [a0 a1 a2] +% Bmzt = [b0 b1 b2] +% Amzt = [a0 a1 a2] DzMZT = tf(Amzt, Bmzt, samplingtime); DzMZT = DzMZT/dcgain(DzMZT); From 5b32fecc0afea0e01e0e27dcd2e699f63d0d4631 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 30 Apr 2020 11:39:04 +0100 Subject: [PATCH 3/5] Remove the pre- and de-emphasis and the downsampler. --- FM.cpp | 6 +++--- SerialPort.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FM.cpp b/FM.cpp index f6da336..1aaf0be 100644 --- a/FM.cpp +++ b/FM.cpp @@ -83,8 +83,8 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) // Only let audio through when relaying audio if (m_state == FS_RELAYING || m_state == FS_KERCHUNK) { - currentSample = m_deemphasis.filter(currentSample); - m_downsampler.addSample(currentSample); + // currentSample = m_deemphasis.filter(currentSample); + // m_downsampler.addSample(currentSample); currentSample = m_blanking.process(currentSample); currentSample *= m_rfAudioBoost; } else { @@ -106,7 +106,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) currentSample = m_filterStage3.filter(m_filterStage2.filter(m_filterStage1.filter(currentSample))); - currentSample = m_preemphasis.filter(currentSample); + // currentSample = m_preemphasis.filter(currentSample); currentSample += m_ctcssTX.getAudio(); diff --git a/SerialPort.cpp b/SerialPort.cpp index 0964273..897a7d8 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200429 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20200430 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c "" From 0a5c496a3aec65da14a83d6ac223a7f2dc0b798b Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 1 May 2020 17:56:45 +0200 Subject: [PATCH 4/5] Fix CTCSS value is different when using RXLevel 50 to 99 --- FMCTCSSRX.cpp | 16 +++++++++++++++- FMCTCSSRX.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/FMCTCSSRX.cpp b/FMCTCSSRX.cpp index 9e81d3c..f3f9047 100644 --- a/FMCTCSSRX.cpp +++ b/FMCTCSSRX.cpp @@ -93,7 +93,7 @@ m_rxLevelInverse(1) uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t level) { - m_rxLevelInverse = 511 / q15_t(level); + m_rxLevelInverse = q15Division(65535, q15_t(level * 128)); m_coeffDivTwo = 0; @@ -179,3 +179,17 @@ void CFMCTCSSRX::reset() m_result = CTS_NONE; m_count = 0U; } + +//Taken from https://en.wikipedia.org/wiki/Q_(number_format)#Division +q15_t CFMCTCSSRX::q15Division(q15_t a, q15_t divisor) +{ + q31_t a31 = q31_t(a) << 16; + + if (((a >> 31) & 1) == ((divisor >> 15) & 1)) + a31 += divisor >> 1; + else + a31 -= divisor >> 1; + + return a31 / divisor; +} + diff --git a/FMCTCSSRX.h b/FMCTCSSRX.h index 4c1dfc3..b5fea60 100644 --- a/FMCTCSSRX.h +++ b/FMCTCSSRX.h @@ -62,6 +62,8 @@ public: void reset(); private: + q15_t q15Division(q15_t a, q15_t divisor); + q63_t m_coeffDivTwo; q31_t m_threshold; uint16_t m_count; From de3c257f79949771a77a418e25a37190ae43f0d5 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 1 May 2020 18:47:15 +0100 Subject: [PATCH 5/5] Bump the version date. --- SerialPort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPort.cpp b/SerialPort.cpp index 897a7d8..32ab0e9 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200430 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20200501 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c ""