SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
CTCSSDetector Class Reference

#include <ctcssdetector.h>

Public Member Functions

 CTCSSDetector ()
 
 CTCSSDetector (int _nTones, Real *tones)
 
virtual ~CTCSSDetector ()
 
void setCoefficients (int zN, int SampleRate)
 
void setThreshold (double thold)
 
bool analyze (Real *sample)
 
int getNTones () const
 
const RealgetToneSet () const
 
bool getDetectedTone (int &maxTone) const
 
Real getMaxPower () const
 
void reset ()
 

Protected Member Functions

virtual void initializePower ()
 
virtual void evaluatePower ()
 
void feedback (Real sample)
 
void feedForward ()
 

Private Attributes

int N
 
int sampleRate
 
int nTones
 
int samplesProcessed
 
int maxPowerIndex
 
bool toneDetected
 
Real maxPower
 
Realk
 
Realcoef
 
RealtoneSet
 
Realu0
 
Realu1
 
Realpower
 

Detailed Description

CTCSSDetector: Continuous Tone Coded Squelch System tone detector class based on the Modified Goertzel algorithm.

Definition at line 19 of file ctcssdetector.h.

Constructor & Destructor Documentation

◆ CTCSSDetector() [1/2]

CTCSSDetector::CTCSSDetector ( )

Definition at line 13 of file ctcssdetector.cpp.

References coef, k, nTones, power, toneSet, u0, and u1.

13  :
14  N(0),
15  sampleRate(0),
17  maxPowerIndex(0),
18  toneDetected(false),
19  maxPower(0.0)
20 {
21  nTones = 32;
22  k = new Real[nTones];
23  coef = new Real[nTones];
24  toneSet = new Real[nTones];
25  u0 = new Real[nTones];
26  u1 = new Real[nTones];
27  power = new Real[nTones];
28 
29  // The 32 EIA standard tones
30  toneSet[0] = 67.0;
31  toneSet[1] = 71.9;
32  toneSet[2] = 74.4;
33  toneSet[3] = 77.0;
34  toneSet[4] = 79.7;
35  toneSet[5] = 82.5;
36  toneSet[6] = 85.4;
37  toneSet[7] = 88.5;
38  toneSet[8] = 91.5;
39  toneSet[9] = 94.8;
40  toneSet[10] = 97.4;
41  toneSet[11] = 100.0;
42  toneSet[12] = 103.5;
43  toneSet[13] = 107.2;
44  toneSet[14] = 110.9;
45  toneSet[15] = 114.8;
46  toneSet[16] = 118.8;
47  toneSet[17] = 123.0;
48  toneSet[18] = 127.3;
49  toneSet[19] = 131.8;
50  toneSet[20] = 136.5;
51  toneSet[21] = 141.3;
52  toneSet[22] = 146.2;
53  toneSet[23] = 151.4;
54  toneSet[24] = 156.7;
55  toneSet[25] = 162.2;
56  toneSet[26] = 167.9;
57  toneSet[27] = 173.8;
58  toneSet[28] = 179.9;
59  toneSet[29] = 186.2;
60  toneSet[30] = 192.8;
61  toneSet[31] = 203.5;
62 }
float Real
Definition: dsptypes.h:42

◆ CTCSSDetector() [2/2]

CTCSSDetector::CTCSSDetector ( int  _nTones,
Real tones 
)

Definition at line 64 of file ctcssdetector.cpp.

References coef, k, nTones, power, toneSet, u0, and u1.

64  :
65  N(0),
66  sampleRate(0),
68  maxPowerIndex(0),
69  toneDetected(false),
70  maxPower(0.0)
71 {
72  nTones = _nTones;
73  k = new Real[nTones];
74  coef = new Real[nTones];
75  toneSet = new Real[nTones];
76  u0 = new Real[nTones];
77  u1 = new Real[nTones];
78  power = new Real[nTones];
79 
80  for (int j = 0; j < nTones; ++j)
81  {
82  toneSet[j] = tones[j];
83  }
84 }
float Real
Definition: dsptypes.h:42

◆ ~CTCSSDetector()

CTCSSDetector::~CTCSSDetector ( )
virtual

Definition at line 87 of file ctcssdetector.cpp.

References coef, k, power, toneSet, u0, and u1.

88 {
89  delete[] k;
90  delete[] coef;
91  delete[] toneSet;
92  delete[] u0;
93  delete[] u1;
94  delete[] power;
95 }

Member Function Documentation

◆ analyze()

bool CTCSSDetector::analyze ( Real sample)

Definition at line 119 of file ctcssdetector.cpp.

References feedback(), feedForward(), N, and samplesProcessed.

Referenced by NFMDemod::processOneSample().

120 {
121 
122  feedback(*sample); // Goertzel feedback
123  samplesProcessed += 1;
124 
125  if (samplesProcessed == N) // completed a block of N
126  {
127  feedForward(); // calculate the power at each tone
128  samplesProcessed = 0;
129  return true; // have a result
130  }
131  else
132  {
133  return false;
134  }
135 }
void feedback(Real sample)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ evaluatePower()

void CTCSSDetector::evaluatePower ( )
protectedvirtual

Definition at line 189 of file ctcssdetector.cpp.

References maxPower, maxPowerIndex, nTones, power, and toneDetected.

Referenced by feedForward().

190 {
191  Real sumPower = 0.0;
192  Real aboveAvg = 2.0; // Arbitrary max power above average threshold
193  maxPower = 0.0;
194 
195  for (int j = 0; j < nTones; ++j)
196  {
197  sumPower += power[j];
198 
199  if (power[j] > maxPower)
200  {
201  maxPower = power[j];
202  maxPowerIndex = j;
203  }
204  }
205 
206  toneDetected = (maxPower > (sumPower/nTones) + aboveAvg);
207 }
float Real
Definition: dsptypes.h:42
+ Here is the caller graph for this function:

◆ feedback()

void CTCSSDetector::feedback ( Real  sample)
protected

Definition at line 138 of file ctcssdetector.cpp.

References coef, nTones, u0, and u1.

Referenced by analyze().

139 {
140  Real t;
141 
142  // feedback for each tone
143  for (int j = 0; j < nTones; ++j)
144  {
145  t = u0[j];
146  u0[j] = in + (coef[j] * u0[j]) - u1[j];
147  u1[j] = t;
148  }
149 }
float Real
Definition: dsptypes.h:42
+ Here is the caller graph for this function:

◆ feedForward()

void CTCSSDetector::feedForward ( )
protected

Definition at line 152 of file ctcssdetector.cpp.

References coef, evaluatePower(), initializePower(), nTones, power, u0, and u1.

Referenced by analyze().

153 {
154  initializePower();
155 
156  for (int j = 0; j < nTones; ++j)
157  {
158  power[j] = (u0[j] * u0[j]) + (u1[j] * u1[j]) - (coef[j] * u0[j] * u1[j]);
159  u0[j] = u1[j] = 0.0; // reset for next block.
160  }
161 
162  evaluatePower();
163 }
virtual void initializePower()
virtual void evaluatePower()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDetectedTone()

bool CTCSSDetector::getDetectedTone ( int &  maxTone) const
inline

Definition at line 51 of file ctcssdetector.h.

Referenced by NFMDemod::processOneSample().

52  {
53  maxTone = maxPowerIndex;
54  return toneDetected;
55  }
+ Here is the caller graph for this function:

◆ getMaxPower()

Real CTCSSDetector::getMaxPower ( ) const
inline

Definition at line 58 of file ctcssdetector.h.

59  {
60  return maxPower;
61  }

◆ getNTones()

int CTCSSDetector::getNTones ( ) const
inline

Definition at line 40 of file ctcssdetector.h.

Referenced by NFMDemod::getCtcssToneSet().

40  {
41  return nTones;
42  }
+ Here is the caller graph for this function:

◆ getToneSet()

const Real* CTCSSDetector::getToneSet ( ) const
inline

Definition at line 45 of file ctcssdetector.h.

Referenced by NFMDemod::getCtcssToneSet(), NFMDemod::processOneSample(), and NFMDemod::webapiFormatChannelReport().

46  {
47  return toneSet;
48  }
+ Here is the caller graph for this function:

◆ initializePower()

void CTCSSDetector::initializePower ( )
protectedvirtual

Definition at line 180 of file ctcssdetector.cpp.

References nTones, and power.

Referenced by feedForward().

181 {
182  for (int j = 0; j < nTones; ++j)
183  {
184  power[j] = 0.0; // reset
185  }
186 }
+ Here is the caller graph for this function:

◆ reset()

void CTCSSDetector::reset ( )

Definition at line 166 of file ctcssdetector.cpp.

References maxPower, maxPowerIndex, nTones, power, samplesProcessed, toneDetected, u0, and u1.

167 {
168  for (int j = 0; j < nTones; ++j)
169  {
170  power[j] = u0[j] = u1[j] = 0.0; // reset
171  }
172 
173  samplesProcessed = 0;
174  maxPower = 0.0;
175  maxPowerIndex = 0;
176  toneDetected = false;
177 }

◆ setCoefficients()

void CTCSSDetector::setCoefficients ( int  zN,
int  SampleRate 
)

Definition at line 98 of file ctcssdetector.cpp.

References coef, cos(), k, M_PI, N, nTones, sampleRate, and toneSet.

Referenced by NFMDemod::applyAudioSampleRate(), and NFMDemod::NFMDemod().

99 {
100  N = zN; // save the basic parameters for use during analysis
101  sampleRate = _samplerate;
102 
103  // for each of the frequencies (tones) of interest calculate
104  // k and the associated filter coefficient as per the Goertzel
105  // algorithm. Note: we are using a real value (as apposed to
106  // an integer as described in some references. k is retained
107  // for later display. The tone set is specified in the
108  // constructor. Notice that the resulting coefficients are
109  // independent of N.
110  for (int j = 0; j < nTones; ++j)
111  {
112  k[j] = ((double)N * toneSet[j]) / (double)sampleRate;
113  coef[j] = 2.0 * cos((2.0 * M_PI * toneSet[j])/(double)sampleRate);
114  }
115 }
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
#define M_PI
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setThreshold()

void CTCSSDetector::setThreshold ( double  thold)

Member Data Documentation

◆ coef

Real* CTCSSDetector::coef
private

Definition at line 81 of file ctcssdetector.h.

Referenced by CTCSSDetector(), feedback(), feedForward(), setCoefficients(), and ~CTCSSDetector().

◆ k

Real* CTCSSDetector::k
private

Definition at line 80 of file ctcssdetector.h.

Referenced by CTCSSDetector(), setCoefficients(), and ~CTCSSDetector().

◆ maxPower

Real CTCSSDetector::maxPower
private

Definition at line 79 of file ctcssdetector.h.

Referenced by evaluatePower(), and reset().

◆ maxPowerIndex

int CTCSSDetector::maxPowerIndex
private

Definition at line 77 of file ctcssdetector.h.

Referenced by evaluatePower(), and reset().

◆ N

int CTCSSDetector::N
private

Definition at line 73 of file ctcssdetector.h.

Referenced by analyze(), and setCoefficients().

◆ nTones

int CTCSSDetector::nTones
private

◆ power

Real* CTCSSDetector::power
private

◆ sampleRate

int CTCSSDetector::sampleRate
private

Definition at line 74 of file ctcssdetector.h.

Referenced by setCoefficients().

◆ samplesProcessed

int CTCSSDetector::samplesProcessed
private

Definition at line 76 of file ctcssdetector.h.

Referenced by analyze(), and reset().

◆ toneDetected

bool CTCSSDetector::toneDetected
private

Definition at line 78 of file ctcssdetector.h.

Referenced by evaluatePower(), and reset().

◆ toneSet

Real* CTCSSDetector::toneSet
private

Definition at line 82 of file ctcssdetector.h.

Referenced by CTCSSDetector(), setCoefficients(), and ~CTCSSDetector().

◆ u0

Real* CTCSSDetector::u0
private

Definition at line 83 of file ctcssdetector.h.

Referenced by CTCSSDetector(), feedback(), feedForward(), reset(), and ~CTCSSDetector().

◆ u1

Real* CTCSSDetector::u1
private

Definition at line 84 of file ctcssdetector.h.

Referenced by CTCSSDetector(), feedback(), feedForward(), reset(), and ~CTCSSDetector().


The documentation for this class was generated from the following files: