模拟电话拨号matlab代码实现(完整code)

模拟电话拨号频率GUI实现(使用工具 matlab_2014a)
模拟界面

function varargout = myphone(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @myphone_OpeningFcn, ...
                   'gui_OutputFcn',  @myphone_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



function myphone_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

% --- Outputs from this function are returned to the command line.
function varargout = myphone_OutputFcn(hObject, eventdata, handles) 

varargout{1} = handles.output;

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'1');
set(handles.edit1,'string',n);
string=n;
toneChoice=1;toneChoice1=1;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time) 
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs) 
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);  
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end

function pushbutton2_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'2');
set(handles.edit1,'string',n);
string=n;
toneChoice=2;toneChoice1=2;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs  = 8000;       
N = 1000;          
t   = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);  
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end


function pushbutton3_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'3');
set(handles.edit1,'string',n);
string=n;
toneChoice=3;toneChoice1=3;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs  = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];  

Nt = 205;
original_f = [lfg(:);hfg(:)];
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);  
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1); 
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



function pushbutton4_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'4');
set(handles.edit1,'string',n);
string=n;
toneChoice=4;toneChoice1=4;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs  = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space]; 

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt);  
estim_f = round(k*Fs/Nt);     
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



function pushbutton5_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'5');
set(handles.edit1,'string',n);
string=n;
toneChoice=5;toneChoice1=5;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs  = 8000;       
N = 1000;          
t   = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space]; 

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);   
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end


function pushbutton6_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'6');
set(handles.edit1,'string',n);
string=n;
toneChoice=6;toneChoice1=6;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];   

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt); 
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end


function pushbutton7_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'7');
set(handles.edit1,'string',n);
string=n;

toneChoice=7;toneChoice1=7;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs = 8000;       
N = 1000;         
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
    tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
    axes(handles.axes_Time)
    plot(t*1e3,tones(:,toneChoice));
    set(handles.axes_Time)
    title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
    set(gca, 'XLim', [0 25]);
     xlabel('Time (ms)');ylabel('Amplitude');
    if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt); 
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency,'XMinorTick','on')
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end


function pushbutton8_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'8');
set(handles.edit1,'string',n);
string=n;
toneChoice=8;toneChoice1=8;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs  = 8000;       
N = 1000;          
t   = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200);
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);   
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1); % Goertzel use 1-based indexing
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



function pushbutton9_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'9');
set(handles.edit1,'string',n);
string=n;
toneChoice=9;toneChoice1=9;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt); 
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1); % Goertzel use 1-based indexing
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



function pushbutton10_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'*');
set(handles.edit1,'string',n);
string=n;
toneChoice=10;toneChoice1=10;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs  = 8000;       
N = 1000;          
t   = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)];
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);  
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1); 
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



function pushbutton11_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'0');
set(handles.edit1,'string',n);
string=n;
toneChoice=11;toneChoice1=11;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt);  
estim_f = round(k*Fs/Nt);  
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1); 
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)

global string;
n=strcat(get(handles.edit1,'string'),'#');
set(handles.edit1,'string',n);
string=n;
toneChoice=12;toneChoice1=12;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; 
hfg = [1209 1336 1477];  
f  = [];
for c=1:4,
    for r=1:3,
        f = [ f [lfg(c);hfg(r)] ];
    end
end
Fs = 8000;       
N = 1000;          
t = (0:N-1)/Fs; 
pit = 2*pi*t;
tones = zeros(N,size(f,2));
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
axes(handles.axes_Time)
plot(t*1e3,tones(:,toneChoice));
set(handles.axes_Time)
title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
xlabel('Time (ms)');ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
    
sound(tones(:,toneChoice),Fs)
global numb
space=zeros(1,200); 
tones1=tones(:,toneChoice)';
phone=[numb,tones1];
numb=[phone,space];

Nt = 205;
original_f = [lfg(:);hfg(:)]; 
k = round(original_f/Fs*Nt); 
estim_f = round(k*Fs/Nt);  
tones = tones(1:205,:);
tone=tones(:,toneChoice1);
ydft(:,toneChoice1) = goertzel(tone,k+1);
axes(handles.axes_Frequency)
stem(estim_f,abs(ydft(:,toneChoice1)));
set(handles.axes_Frequency)
title(['Symbol "', symbol{toneChoice1},'": [',num2str(f(1,toneChoice1)),',',num2str(f(2,toneChoice1)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'XLim', [650 1550]);
xlabel('Frequency (Hz)');ylabel('Magnitude');
if toneChoice1>9, xlabel('Frequency (Hz)'); end



function pushbutton16_Callback(hObject, eventdata, handles)
%拨号键

global string;
global number;
for nn=1:length(string)
    if string(nn)=='#'
        msgbox(' "#" 输入有误:请重新输入','MATLAB','warn');
        set(handles.edit1,'string',string)
        pause(2.0)
        set(handles.edit1,'string','')
        string='';
        set(handles.edit3,'string','')
        string='';
        axes(handles.axes_Time)
        cla reset
        axes(handles.axes_Frequency)
        cla reset
        clc,clear all;
    elseif string(nn)=='*'
        msgbox(' "*" 输入有误:请重新输入','MATLAB','warn');
        set(handles.edit1,'string',string)
        pause(1.0)
        set(handles.edit1,'string','')
        string='';
        set(handles.edit3,'string','')
        string='';
        axes(handles.axes_Time)
        cla reset
        axes(handles.axes_Frequency)
        cla reset
        clc,clear all;
    end
end
if length(string)==0
    msgbox('请输入电话号码!' ,'MATLAB','warn')
elseif  length(string)<11||length(string)>11
    msgbox('输入电话号码位数错误:请检查!' ,'MATLAB','warn')
else
    global numb     %输入为采样频率和采样长度    
    nu=numb;
    fs=8000;
    lfg = [697 770 852 941]; 
    hfg = [1209 1336 1477]; 
    h=1000*hfg/fs+1;
    l=1000*lfg/fs+1;
    
    N=length(numb)/1200;
    for i=1:N
        X=abs(fft(numb(1200*(i-1)+1:1200*(i-1)+1000)));
        Y=find(X==max(X));  %寻找频谱最大值对应的位置
      Z=find(X==max([X(1:Y(1)-1) X(Y(1)+1:Y(2)-1) X(Y(2)+1:1000)])); %寻找频谱次大值对应的位置
    if Y(1)<Z(1)  %除了0键其他键都满足此情形
        m(i)=Y(1);  %存放列频(低频)频谱位置
        n(i)=Z(1);  %存放行频(高频)频谱位置
    else
        m(i)=Z(1);   %存放列频(低频)频谱位置
        n(i)=Y(1);   %存放行频(高频)频谱位置
    end
    end
    clear X Y Z;
    %m为列频(低频),n为行频(高频)
    for i=1:N   %列频匹配
        for j=1:4
            if(abs(m(i)-l(j))<1)    %误差不超过一个点
                m(i)=lfg(j);
            end
        end
    end
    for i=1:N   %行频匹配
        for j=1:3
            if(abs(n(i)-h(j))<1)
                n(i)=hfg(j);
            end
        end
    end
    number='';
    for i=1:N
        switch m(i)
            case 697
                switch n(i)
                    case 1209 
                        number=[number '1'];
                    case 1336
                        number=[number '2'];
                    case 1477
                        number=[number '3'];
                    otherwise
                end
            case 770
                switch n(i)
                    case 1209
                        number=[number '4'];
                    case 1336
                        number=[number '5'];
                    case 1477
                        number=[number '6'];
                    otherwise
                        return
                end
            case 852
                switch n(i)
                    case 1209
                        number=[number '7'];
                    case 1336
                        number=[number '8'];
                    case 1477
                        number=[number '9'];
                    otherwise
                        return
                end
            case 941
                switch n(i)
                    case 1209
                        number=[number '*'];
                    case 1336
                        number=[number '0'];
                    case 1477
                        number=[number '#'];
                    otherwise
                        return
                end
        end
    set(handles.edit3,'string',number);
   end
    sound(nu(1:length(nu)-1200),8000)
end



% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)

%清除键
global numb
numb(:,end-1199:end)=[];
global string;
string(:,end)=[];
num=string;
set(handles.edit1,'string',num);
axes(handles.axes_Time)
cla reset
axes(handles.axes_Frequency)
cla reset

global number
number(:,end)=[];
set(handles.edit3,'string',number);

function pushbutton17_Callback(hObject, eventdata, handles)
%摘机键
global string;
set(handles.edit1,'string',''); 
set(handles.edit3,'string',''); 

axes(handles.axes_Time)
cla reset
axes(handles.axes_Frequency)
cla reset
clc,clear all;% close all;


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


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% % hObject    handle to edit1 (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



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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

源代码下载地址

以下是一个简单的 Matlab GUI 双音拨号系统的示例代码: ``` % --- Executes on button press in dialButton. function dialButton_Callback(hObject, eventdata, handles) % hObject handle to dialButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get the current value of the text box textValue = get(handles.textBox, 'String'); % Define the DTMF frequencies and durations frequencies = [697 1209; 697 1336; 697 1477; 770 1209; 770 1336; 770 1477; 852 1209; 852 1336; 852 1477; 941 1209; 941 1336; 941 1477]; durations = [0.2 0.2]; % Generate the DTMF tone for each character in the text box for i = 1:length(textValue) % Get the ASCII code for the current character charCode = double(textValue(i)); % Generate the DTMF tone for the current character if charCode >= 48 && charCode <= 57 % If the character is a digit index = charCode - 47; tone = dtmf_tone(frequencies(index,:), durations); elseif charCode >= 65 && charCode <= 90 % If the character is an uppercase letter index = charCode - 54; tone = dtmf_tone(frequencies(index,:), durations); elseif charCode >= 97 && charCode <= 122 % If the character is a lowercase letter index = charCode - 86; tone = dtmf_tone(frequencies(index,:), durations); else % If the character is not a digit or letter tone = zeros(1, round(durations(1)*44100)); end % Play the DTMF tone sound(tone, 44100); pause(durations(1)); end % --- Executes on button press in clearButton. function clearButton_Callback(hObject, eventdata, handles) % hObject handle to clearButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Clear the text box set(handles.textBox, 'String', ''); function tone = dtmf_tone(frequencies, durations) % Generate a DTMF tone with the given frequencies and durations t = 0:1/44100:durations(1); tone = sin(2*pi*frequencies(1)*t) + sin(2*pi*frequencies(2)*t); tone = tone/max(abs(tone)); % Normalize the amplitude tone = [tone zeros(1, round(durations(2)*44100))]; % Add a pause between tones end ``` 此代码包括两个回调函数,`dialButton_Callback` 和 `clearButton_Callback`,以及一个辅助函数 `dtmf_tone`。 `dialButton_Callback` 生成 DTMF 音调并将其发送到音频输出设备。 `clearButton_Callback` 用于清除文本框中的内容。 `dtmf_tone` 函数用于生成 DTMF 音调的波形。该代码需要与一个包含一个文本框和两个按钮的 Matlab GUI 配合使用,其中一个按钮用于拨打电话,另一个按钮用于清除文本框中的内容。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

奋斗羊羊

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

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

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

打赏作者

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

抵扣说明:

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

余额充值