Dual-tone multi-frequency (DTMF) signal detection

GUI page design

Enter the “guide” command on the command line, open the GUI panel, and add the required elements according to the experimental requirements (usually ordinary buttons, static text, ordinary text, coordinate charts, radio buttons, etc.)

Code:

function varargout = EXP1(varargin)
% EXP1 MATLAB code for EXP1.fig
% EXP1, by itself, creates a new EXP1 or raises the existing
% singleton*.
%
% H = EXP1 returns the handle to a new EXP1 or the handle to
% the existing singleton*.
%
% EXP1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EXP1.M with the given input arguments.
%
% EXP1('Property','Value',...) creates a new EXP1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before EXP1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to EXP1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help EXP1

% Last Modified by GUIDE v2.5 09-Nov-2023 16:30:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
                   'gui_Singleton', gui_Singleton, ...
                   'gui_OpeningFcn', @EXP1_OpeningFcn, ...
                   'gui_OutputFcn', @EXP1_OutputFcn, ...
                   'gui_LayoutFcn', [] , ...
                   'gui_Callback', []);
if nargin & amp; & amp; ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before EXP1 is made visible.
function EXP1_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to EXP1 (see VARARGIN)

% Choose default command line output for EXP1
handles.output = hObject;
set(handles.axes_check,'visible','off');
axes(handles.axes_check);
image = imread('check.png');
imshow(image);
axis off
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes EXP1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = EXP1_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit_input_Callback(~, ~, ~)
% hObject handle to edit_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_input as text
% str2double(get(hObject,'String')) returns contents of edit_input as a double


% --- Executes during object creation, after setting all properties.
function edit_input_CreateFcn(hObject, ~, ~)
% hObject handle to edit_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc & amp; & amp; isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(~, ~, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global TN; % defines global variables, used to store text data obtained by programmable text boxes.
TN_data = get(handles.edit_input,'String'); %Get data
TN = str2double(TN_data);% converted to numbers
format long g
disp(TN);% displays the obtained number


function edit_SNR_Callback(~, ~, ~)
% hObject handle to edit_SNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_SNR as text
% str2double(get(hObject,'String')) returns contents of edit_SNR as a double


% --- Executes during object creation, after setting all properties.
function edit_SNR_CreateFcn(hObject, ~, ~)
% hObject handle to edit_SNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc & amp; & amp; isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SNR;% defines global variables used to store text data obtained by programmable text boxes.
SNR_data = get(handles.edit_SNR,'String'); %Get data
SNR= str2double(SNR_data);% converted into numbers
format long g
disp(SNR);% displays the obtained number

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(~, ~, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.text2,'visible','off');
set(handles.edit_detected,'visible','off');
set(handles.edit_input,'visible','off');
set(handles.edit_SNR,'visible','off');
set(handles.pushbutton1,'visible','off');
set(handles.pushbutton2,'visible','off');
set(handles.pushbutton3,'visible','off');
set(handles.uipanel2,'visible','off');
global TN; % defines global variables, used to store text data obtained by programmable text boxes.
TN_data = get(handles.edit_input,'String'); %Get data
TN = str2double(TN_data);% converted to numbers
global SNR;% defines global variables used to store text data obtained by programmable text boxes.
SNR_data = get(handles.edit_SNR,'String'); %Get data
SNR= str2double(SNR_data);% converted into numbers
tm=[1,2,3,65;
4,5,6,66;
7,8,9,67;
42,0,35,68]; % 16 numbers represented by DTMF signal
N=205; The length of ?T is 205
fs=8000;% signal sampling frequency is 8000Hz
K=[18,20,22,24,31,34,38,42];%K value corresponding to each frequency
f1=[697,770,852,941]; % row frequency vector
f2=[1209,1336,1477,1633]; % column frequency vector
TNr=0; %The initial value of the receiving end phone number is zero
globall;
for l = 1:11 % loop 11 times to detect numbers
    d=fix(TN/10^(11-l));
    TN=TN-d*10^(11-l);
    for p=1:4
        for q=1:4
            if tm(p,q)==abs(d);break,end % Check the column number q whose code matches
        end
            if tm(p,q)==abs(d); break,end % line number p whose detection code matches
      
    end
    n=0:1023; % To make sounds, lengthen the sequence
    x = sin(2*pi*n*f1(p)/fs) + sin(2*pi*n*f2(q)/fs);% constitutes a dual-frequency signal
    w = awgn(x,SNR);% add white noise
    sound(x,8000); % make a sound
    pause(0.15)% interval 0.15 seconds
    X=goertzel(w(1:N),K + 1); % Calculate eight-point DFT samples using Goertzel algorithm
    val = abs(X); % List eight-point DFT vectors
    subplot(4,3,l);
    stem(K,val,'.');grid;xlabel('k');ylabel('|X(k)|') % Draw the DFT(k) amplitude
    axis([10 50 0 120])
    limit = 80; %
    for s=5:8
        if val(s)>limit,break,end
    end
    for r=1:4
        if val(r)>limit,break,end
    end
    TNr=TNr + tm(r,s-4)*10^(8-l);
end
disp('The number detected by the receiving end is:')
TNr=TNr*10^3;
format long g
disp(TNr)
function edit_detected_Callback(~, ~, ~)
% hObject handle to edit_detected (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_detected as text
% str2double(get(hObject,'String')) returns contents of edit_detected as a double


% --- Executes during object creation, after setting all properties.
function edit_detected_CreateFcn(hObject, ~, ~)
% hObject handle to edit_detected (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc & amp; & amp; isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes during object creation, after setting all properties.
function pushbutton1_CreateFcn(~, ~, ~)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

Experimental results:

experiment analysis:

Run the program and enter the 11-digit phone number and signal-to-noise ratio according to the prompts. After pressing Enter, you can hear the sound of the DTMF signal corresponding to the 11-digit phone number and output the response spectrum, as shown in the figure. The first picture in the upper left corner has peak values at k=18 and k=31, so it corresponds to the first number 1, and so on. The other 10 pictures represent the numbers 1, 2, 3, 4, 5, and 6 respectively. ,7,8,9,0, corresponds to the amplitude value of the 8-point sample of the DTMF signal DFT. Finally the detected phone number 11234567890 is displayed.