Detect the level of a single tone
Port | Purpose |
---|---|
In 0 | Signal to analyze |
frequency(freq);
Set the frequency to detect. The default detection time will be 10 cycles of this frequency.
frequency(freq, cycles);
Set the frequency to detect, and the number of cycles. Longer detection time (more cycles) will give higher precision, but of course slower response.
available();
Returns true (non-zero) each time a detection interval (number of cycles) completed and a new level is detected.
read();
Read the detected signal level. Range is 0 to 1.0.
threshold(level);
Set a detection threshold, where the bool test operation will return true if at or above this level, or false when below.
(bool)
By testing the object as a boolean value, you can respond to detection of a tone.
File > Examples > Audio > Analysis > DialTone_Serial
File > Examples > Audio > Analysis > DialTone_7segment
Low frequency detection has trouble with numerical precision. Works really well for all 8 DTMF frequencies, but fails for detecting "sub audible tones" used in some control applications.
The (bool) test continues to return true until the next detection interval (the configured number of cycles). This behavior may change in future versions, for a single true each time the signal is detected, and then false for the remainder of that interval.