foreword
The purpose of the experiment: use Matlab to simulate the realization of dual-tone multi-frequency dialing system
Input: a string of digital analog phone numbers
Output: Detected phone numbers
Matlab version: 2021b
System: MacOS
Experimental method: look-up table method + Goerzel function
The main idea of the experiment
Any number can be expressed as the addition of two cosine signals, so we need to convert the received phone number into such a time domain sequence first. The conversion rules are as follows
The time domain sequence x[n] is used as the input of the goertzel function, and the return value is the discrete Fourier transform corresponding to the discrete time domain sequence.
It can be seen from the table that we have a total of 8 frequencies, so we define the array k as the sampling point corresponding to each frequency when the number of sampling points is N=205. We detect these 8 sampling points and observe their amplitudes. The frequency corresponding to the two sampling points with the largest amplitude is the frequency in the table corresponding to the number currently input. In this way, we can detect what number is currently received. Since the typical sampling frequency of the telephone signal is 8kHz, here Ts (sampling period) is 1/8000s.
Two key questions:
- Why choose 8000Hz as the sampling frequency, why this sampling frequency is feasible
- Why the number of sampling points is 205
1. The frequency range of the signal to be detected is 697 ~ 1633Hz, but considering the existence of voice interference, in addition to detecting these 8 frequencies, it is also necessary to detect the amplitude of their secondary frequency multiplication, the sine wave with normal waveform and little interference The second multiplier is very small. If the second harmonic is found to be large, it cannot be sure that it is a DTMF signal. In this way, the frequency range of spectrum analysis is 697 ~ 3266Hz. According to the sampling theorem, the sampling frequency should be greater than twice the maximum frequency, which is 6532Hz. Therefore, 8000Hz is selected as the sampling frequency here, which meets the requirements.
2. The sampling frequency of DFT is
The sampling point frequency of the corresponding analog domain is
We hope to choose an appropriate N, the frequency calculated by using this formula can be close to the frequency to be detected, or when any one of the 8 frequencies is substituted into the formula, the k value obtained is closest to the integer value, so that although the point with the largest amplitude There is an error in the detected frequency, but the corresponding DTMF frequency can still be accurately judged, and then the corresponding number or symbol can be accurately judged. After testing with different values N, it is concluded that when N=205, the result is the best.
MATLAB implementation code
% Low Frequency
f1 = 697;
f2 = 770;
f3 = 852;
f4 = 941;
% High Frequency
F1 = 1209;
F2 = 1336;
F3 = 1477;
F4 = 1633;
N = 205; % The quantity of sampling points
Fs = 8000; % Sampling Frequency
T = 1/Fs; % Sampling Period
t = [0:N-1]*T; % t = n*T
% The table for look up
k1 = cos(2*pi*f1*t) + cos(2*pi*F1*t);
k2 = cos(2*pi*f1*t) + cos(2*pi*F2*t);
k3 = cos(2*pi*f1*t) + cos(2*pi*F3*t);
ka = cos(2*pi*f1*t) + cos(2*pi*F4*t);
k4 = cos(2*pi*f2*t) + cos(2*pi*F1*t);
k5 = cos(2*pi*f2*t) + cos(2*pi*F2*t);
k6 = cos(2*pi*f2*t) + cos(2*pi*F3*t);
kb = cos(2*pi*f2*t) + cos(2*pi*F4*t);
k7 = cos(2*pi*f3*t) + cos(2*pi*F1*t);
k8 = cos(2*pi*f3*t) + cos(2*pi*F2*t);
k9 = cos(2*pi*f3*t) + cos(2*pi*F3*t);
kc = cos(2*pi*f3*t) + cos(2*pi*F4*t);
km = cos(2*pi*f4*t) + cos(2*pi*F1*t); % *
k0 = cos(2*pi*f4*t) + cos(2*pi*F2*t);
kj = cos(2*pi*f4*t) + cos(2*pi*F3*t); % #
kd = cos(2*pi*f4*t) + cos(2*pi*F4*t);
% 4*4 matrix monitoring the table
key=['1','2','3','a';
'4','5','6','b';
'7','8','9','c';
'*','0','#','d'];
k=[18,20,22,24,31,34,38,42]; % the points corrsponding 8 frequencies
%-----------------------pre process----------------------------------------
num = input('please enter the key:','s'); % input as a string
num = num - '0'; % minus the offset (ascii)
len = length(num); % the length of the input telephone number
disp('The number of the key is: ');
disp(len); % display the length
number = zeros(len, length(t)); % len * length(t) zero matrix
for i = 1:len % for every number in input
switch num(i) % Look-up table method
case 1
number(i,1:N) = k1;
case 2
number(i,1:N) = k2;
case 3
number(i,1:N) = k3;
case 4
number(i,1:N) = k4;
case 5
number(i,1:N) = k5;
case 6
number(i,1:N) = k6;
case 7
number(i,1:N) = k7;
case 8
number(i,1:N) = k8;
case 9
number(i,1:N) = k9;
case 0
number(i,1:N) = k0;
case 49
number(i,1:N) = ka;
case 50
number(i,1:N) = kb;
case 51
number(i,1:N) = kc;
case 52
number(i,1:N) = kd;
case -6 % number is *
number(i,1:N) = km;
case -13 % number is #
number(i,1:N) = kj;
otherwise
error('The key is not right!');
end
end
disp('The key is: ');
for i = 1:len
dft = goertzel(number(i,1:N), k+1); % return Discrete Fourier Transform
figure;
x = [697, 770, 852, 941, 1209, 1336, 1477, 1633]; % The 8 frequency magnitude
stem(x, abs(dft), '.');
xlabel('Hz');
title('Frequency Spectrum');
idx = find(abs(dft) > 50); % find the frequency where dft is not zero
disp(key(idx(1), idx(2) - 4));
end