| 
									
										
										
										
											2015-06-16 04:42:37 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * ctcssdetector.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Jun 16, 2015 | 
					
						
							|  |  |  |  *      Author: f4exb | 
					
						
							|  |  |  |  *      See: http://www.embedded.com/design/connectivity/4025660/Detecting-CTCSS-tones-with-Goertzel-s-algorithm
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef INCLUDE_GPL_DSP_CTCSSDETECTOR_H_
 | 
					
						
							|  |  |  | #define INCLUDE_GPL_DSP_CTCSSDETECTOR_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-16 04:42:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** CTCSSDetector: Continuous Tone Coded Squelch System
 | 
					
						
							|  |  |  |  * tone detector class based on the Modified Goertzel | 
					
						
							|  |  |  |  * algorithm. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class SDRBASE_API CTCSSDetector { | 
					
						
							| 
									
										
										
										
											2015-06-16 04:42:37 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     // Constructors and Destructor
 | 
					
						
							|  |  |  |     CTCSSDetector(); | 
					
						
							|  |  |  |     // allows user defined CTCSS tone set
 | 
					
						
							|  |  |  |     CTCSSDetector(int _nTones, Real *tones); | 
					
						
							|  |  |  |     virtual ~CTCSSDetector(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // setup the basic parameters and coefficients
 | 
					
						
							|  |  |  |     void setCoefficients( | 
					
						
							| 
									
										
										
										
											2016-02-28 10:53:37 +01:00
										 |  |  |     		int zN,            // the algorithm "block"  size
 | 
					
						
							| 
									
										
										
										
											2015-06-16 04:42:37 +02:00
										 |  |  | 			int SampleRate);  // input signal sample rate
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // set the detection threshold
 | 
					
						
							|  |  |  |     void setThreshold(double thold); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // analyze a sample set and optionally filter
 | 
					
						
							|  |  |  |     // the tone frequencies.
 | 
					
						
							|  |  |  |     bool analyze(Real *sample); // input signal sample
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // get the number of defined tones.
 | 
					
						
							|  |  |  |     int getNTones() const { | 
					
						
							|  |  |  |     	return nTones; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // get the tone set
 | 
					
						
							|  |  |  |     const Real *getToneSet() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     	return toneSet; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // get the currently detected tone, if any
 | 
					
						
							|  |  |  |     bool getDetectedTone(int &maxTone) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     	maxTone = maxPowerIndex; | 
					
						
							|  |  |  |     	return toneDetected; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Get the max power at the detected tone.
 | 
					
						
							|  |  |  |     Real getMaxPower() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     	return maxPower; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void reset();                       // reset the analysis algorithm
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     // Override these to change behavior of the detector
 | 
					
						
							|  |  |  |     virtual void initializePower(); | 
					
						
							|  |  |  |     virtual void evaluatePower(); | 
					
						
							|  |  |  |     void feedback(Real sample); | 
					
						
							|  |  |  |     void feedForward(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     int N; | 
					
						
							|  |  |  |     int sampleRate; | 
					
						
							|  |  |  |     int nTones; | 
					
						
							|  |  |  |     int samplesProcessed; | 
					
						
							|  |  |  |     int maxPowerIndex; | 
					
						
							|  |  |  |     bool toneDetected; | 
					
						
							|  |  |  |     Real maxPower; | 
					
						
							|  |  |  |     Real *k; | 
					
						
							|  |  |  |     Real *coef; | 
					
						
							|  |  |  |     Real *toneSet; | 
					
						
							|  |  |  |     Real *u0; | 
					
						
							|  |  |  |     Real *u1; | 
					
						
							|  |  |  |     Real *power; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* INCLUDE_GPL_DSP_CTCSSDETECTOR_H_ */
 |