A MATLAB implementation of a Dual-Tone Multi-Frequency (DTMF) receiver with synthetic signal generation, microphone acquisition, frame-based frequency analysis, temporal decoding, and controlled noise evaluation.
The decoder supports the standard 16-key DTMF keypad and processes both generated signals and real acoustic input captured through a computer microphone.
The example below shows frame-energy detection for the generated sequence 1*048596 with additive white Gaussian noise at 20 dB SNR.
Target SNR: 20.00 dB
Measured SNR: 20.09 dB
Selected sequence: 1*048596
Decoded sequence: 1*048596
Result: all keys decoded correctly.
- Standard 16-key DTMF tone generation
- Microphone-based DTMF acquisition
- Configurable sampling rate, tone duration, and inter-key spacing
- Short-time frame analysis with overlapping windows
- Adaptive frame-energy thresholding
- Goertzel analysis of the eight standard DTMF frequencies
- Relative low- and high-frequency evidence estimation
- Two-tone model fitting for frame-quality estimation
- Temporal evidence validation across consecutive frames
- Active-key locking to reduce duplicate detections from tone decay
- Multi-digit sequence decoding
- Controlled additive white Gaussian noise (AWGN) injection
- Monte Carlo noise-robustness evaluation
- Automatic saving of microphone recordings for debugging and later analysis
Each DTMF symbol is represented by one low-frequency tone and one high-frequency tone.
| 1209 Hz | 1336 Hz | 1477 Hz | 1633 Hz | |
|---|---|---|---|---|
| 697 Hz | 1 | 2 | 3 | A |
| 770 Hz | 4 | 5 | 6 | B |
| 852 Hz | 7 | 8 | 9 | C |
| 941 Hz | * | 0 | # | D |
The generated-signal and microphone paths use the same decoder.
Audio signal
│
▼
Overlapping short-time frames
│
▼
Adaptive frame-energy gate
│
▼
Goertzel analysis at the 8 DTMF frequencies
│
├── low-frequency evidence
├── high-frequency evidence
└── frame quality
│
▼
Temporal evidence validation
│
▼
Active-key / release state machine
│
▼
Decoded DTMF sequence
The frame classifier produces frequency evidence rather than immediately committing to a digit. The temporal decoder then requires consistent support across multiple frames before accepting a key.
This separation improves tolerance to weak acoustic tones while reducing duplicate detections caused by amplitude decay at the end of a key press.
matlab-dtmf-decoder/
├── assets/
│ ├── decoder-example.png
│ └── noise-robustness.png
├── src/
│ ├── calculateGoertzelPower.m
│ ├── classifyDtmfFrame.m
│ ├── decodeDtmfFrameSequence.m
│ ├── detectDtmfFrames.m
│ ├── generateDtmfSequence.m
│ ├── getDtmfDefinitions.m
│ └── recordDtmfAudio.m
├── evaluateNoiseRobustness.m
├── main.m
├── README.md
└── .gitignore
- MATLAB
- Audio input device for microphone mode
The implementation uses standard MATLAB numerical and audio functionality.
Open the repository in MATLAB and run:
mainSet:
inputMode = "generated";
Define the sequence:
selectedKeys = ["1", "*", "0", "4", "8", "5", "9", "6"];
Tone and pause durations can be configured independently:
toneDurationSeconds = 0.5; pauseDurationSeconds = 0.1;
Controlled Gaussian noise can be added using:
snrDb = 20;
Set:
inputMode = "microphone";
Configure the audio input device:
computerAudioInputID = 3;
The device ID depends on the system.
The microphone path records for the configured duration and writes the captured signal to:
debugRecording.wav
This preserves difficult recordings for later inspection and analysis.
The current frame-based detector uses:
Fs = 8000; frameDurationSeconds = 0.025; frameHopSeconds = 0.005;
The 25 ms frame provides short-time frequency information, while the 5 ms hop gives substantial overlap between adjacent frames.
The detector estimates the background signal level from low-energy frames and performs spectral analysis only on frames with sufficient energy.
For each active frame, the decoder evaluates all four low-group and all four high-group DTMF frequencies using the Goertzel algorithm.
The resulting powers are converted into relative frequency evidence:
Low group:
697, 770, 852, 941 Hz
High group:
1209, 1336, 1477, 1633 Hz
The strongest low/high pair forms the current DTMF candidate.
The frame is also fitted against a two-sinusoid model. The fit contributes to a frame-quality score used by the temporal decoder.
A single frame is not enough to create a digit.
The sequence decoder accumulates evidence across neighbouring frames and supports two confirmation paths:
- strong evidence over a shorter interval;
- weaker but consistent evidence over a longer interval.
Once a digit is accepted, an active-key state prevents the decaying tail of the same tone from being interpreted as additional digits.
A new key can only be accepted after the receiver observes a sufficient release period.
Run:
evaluateNoiseRobustnessThe evaluation script uses the full 16-symbol DTMF sequence and a fixed random seed. For each tested SNR level, it:
- generates the reference DTMF sequence;
- adds controlled AWGN;
- decodes the noisy signal;
- repeats the process over 100 Monte Carlo trials;
- reports complete-sequence decoding accuracy.
This provides a repeatable measure of decoder behaviour under controlled noise conditions.
In the current 100-trial evaluation, the decoder maintained 99–100% complete-sequence accuracy from 5 dB through -2 dB, before performance degraded sharply at lower SNRs.
DTMF decoding robustness under AWGN
These results describe the current synthetic AWGN benchmark and are not intended as a universal real-world performance guarantee.
The microphone path is intended for acoustic DTMF signals played from devices such as phones or virtual dial pads.
Real recordings are more difficult than generated signals because the received waveform can be affected by:
- speaker frequency response;
- microphone frequency response;
- room reflections;
- automatic gain control;
- different key-press durations;
- short inter-key gaps;
- environmental noise;
- tone decay.
The receiver therefore combines frequency-domain evidence with temporal validation rather than relying on a single-frame spectral decision or a single energy threshold.
The implementation is divided into independent processing stages:
generateDtmfSequencecreates controlled DTMF signals.recordDtmfAudiohandles microphone acquisition.calculateGoertzelPowermeasures signal power at a target frequency.classifyDtmfFrameconverts one frame into DTMF frequency evidence and a quality score.detectDtmfFramesperforms short-time analysis and adaptive frame-energy gating.decodeDtmfFrameSequenceconverts frame-level evidence into a stable multi-digit sequence.getDtmfDefinitionsprovides the standard frequency groups and keypad mapping.
Keeping acquisition, frequency analysis, frame detection, and temporal decoding separate makes the receiver easier to analyse and modify while keeping each processing stage focused on a single responsibility.
Acoustic decoding can still degrade when:
- tones are extremely short;
- inter-key spacing is very small;
- the received signal is heavily distorted;
- the microphone level is very low;
- strong non-DTMF acoustic content overlaps the DTMF frequency range.
The controlled generated-signal path remains useful for separating algorithmic behaviour from microphone and acoustic-channel effects.