双音多频(DTMF)信号检测

文章描述了一个使用MATLAB构建的GUI界面,用户输入电话号码和信噪比,程序会生成DTMF信号声音并显示其频谱图,用于识别电话号码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GUI页面设计 

命令行输入“guide”指令,打开GUI面板,按照实验要求添加所需要的的元素(一般需要普通按钮、静态文本、普通文本、坐标图、单选按钮等)

代码:

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 && 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 && 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; %定义全局变量,用于存储可编程文本框获得的文本数据。
TN_data = get(handles.edit_input,'String'); %获得数据
TN = str2double(TN_data);%转化为数字
format long g
disp(TN);%显示获得的数字


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 && 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;%定义全局变量,用于存储可编程文本框获得的文本数据。
SNR_data = get(handles.edit_SNR,'String'); %获得数据
SNR= str2double(SNR_data);%转化为数字
format long g
disp(SNR);%显示获得的数字

% --- 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; %定义全局变量,用于存储可编程文本框获得的文本数据。
TN_data = get(handles.edit_input,'String'); %获得数据
TN = str2double(TN_data);%转化为数字
global SNR;%定义全局变量,用于存储可编程文本框获得的文本数据。
SNR_data = get(handles.edit_SNR,'String'); %获得数据
SNR= str2double(SNR_data);%转化为数字
tm=[1,2,3,65;
4,5,6,66;
7,8,9,67;
42,0,35,68]; % DTMF信号代表的16个数
N=205;%DFT的长度取205
fs=8000;%信号采样频率为8000Hz
K=[18,20,22,24,31,34,38,42];%各个频率对应的K值
f1=[697,770,852,941]; % 行频率向量
f2=[1209,1336,1477,1633]; % 列频率向量
TNr=0; %接收端电话号码初值为零
global l;
for l = 1:11 %循环11次检测数字 
    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 % 检测码相符的列号q
        end
            if tm(p,q)==abs(d); break,end % 检测码相符的行号p
      
    end
    n=0:1023; % 为了发声,加长序列
    x = sin(2*pi*n*f1(p)/fs) + sin(2*pi*n*f2(q)/fs);% 构成双频信号
    w = awgn(x,SNR);% 加入白噪声
    sound(x,8000); % 发出声音 
    pause(0.15)% 间隔0.15秒
    X=goertzel(w(1:N),K+1); % 用Goertzel算法计算八点DFT样本
    val = abs(X); % 列出八点DFT向量
    subplot(4,3,l);
    stem(K,val,'.');grid;xlabel('k');ylabel('|X(k)|') % 画出DFT(k)幅度
    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('接收端检测到的号码为:')
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 && 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

实验结果:

实验分析:

运行程序,根据提示输入11位电话号码和信噪比,回车后可以听见11位电话号码对应的DTMF信号的声音,并输出响应的频谱图,如图上所示。左上角的第一个图在k=18和k=31两点出现峰值,所以对应第一位号码数字1,依次类推,其他10幅图分别表示数字1,2,3,4,5,6,7,8,9,0,对应的DTMF信号DFT的8点采样的幅度值。最后显示检测到的电话号码11234567890。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风起晨曦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值