Code covered by the BSD License  

Highlights from
Dual Frequency, Touch-Tone

image thumbnail

Dual Frequency, Touch-Tone

by

 

Touch-Tone :Frequency analysis with FFT.

cellphone(varargin)
function varargout = cellphone(varargin)
% CELLPHONE M-file for cellphone.fig
%      CELLPHONE, by itself, creates a new CELLPHONE or raises the existing
%      singleton*.
%
%      H = CELLPHONE returns the handle to a new CELLPHONE or the handle to
%      the existing singleton*.
%
%      CELLPHONE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CELLPHONE.M with the given input arguments.
%
%      CELLPHONE('Property','Value',...) creates a new CELLPHONE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before cellphone_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to cellphone_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 cellphone

% Last Modified by GUIDE v2.5 13-May-2013 04:21:03


% (c) KHMOU Youssef,  Applied Mathematics , 2013
%
% (c) Reference :  Fourier Analysis with Cleve Moler :
%     http://www.mathworks.com/moler/fourier.pdf

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @cellphone_OpeningFcn, ...
                   'gui_OutputFcn',  @cellphone_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 cellphone is made visible.
function cellphone_OpeningFcn(hObject, eventdata, 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 cellphone (see VARARGIN)

% Choose default command line output for cellphone
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = cellphone_OutputFcn(hObject, eventdata, 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;
global t Fs fr fc one two three four five six seven eight nine zero star diez r
Fs=32768;            % Sampling rate 
t=0:1/Fs:0.25;       % time points 
fr=[697 770 852 941];%Basic frequencies 
fc=[1209 1336 1477];

% --- Executes on button press in one.
function one_Callback(hObject, eventdata, handles)
% hObject    handle to one (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs one
y1=sin(2*pi*t*fr(1));
y2=sin(2*pi*t*fc(1));
one=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),one(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title(' 1');
sound(one,Fs)
[Power,N,f]=FFT(one,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);


% --- Executes on button press in two.
function two_Callback(hObject, eventdata, handles)
% hObject    handle to two (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs two
y1=sin(2*pi*t*fr(1));
y2=sin(2*pi*t*fc(2));
two=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),two(1:500),'LineWidth',2) , xlabel(' t(seconds)'),title('2');
sound(two,Fs)
[Power,N,f]=FFT(two,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);


% --- Executes on button press in six.
function six_Callback(hObject, eventdata, handles)
% hObject    handle to six (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs six
y1=sin(2*pi*t*fr(2));
y2=sin(2*pi*t*fc(3));
six=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),six(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('6');
sound(six,Fs)
[Power,N,f]=FFT(six,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);

% --- Executes on button press in three.
function three_Callback(hObject, eventdata, handles)
% hObject    handle to three (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs three
y1=sin(2*pi*t*fr(1));
y2=sin(2*pi*t*fc(3));
three=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),three(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('3');
sound(three,Fs)
[Power,N,f]=FFT(three,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);


% --- Executes on button press in five.
function five_Callback(hObject, eventdata, handles)
% hObject    handle to five (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs five
y1=sin(2*pi*t*fr(2));
y2=sin(2*pi*t*fc(2));
five=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),five(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('5');
sound(five,Fs)
[Power,N,f]=FFT(five,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);


% --- Executes on button press in seven.
function seven_Callback(hObject, eventdata, handles)
% hObject    handle to seven (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs seven
y1=sin(2*pi*t*fr(3));
y2=sin(2*pi*t*fc(1));
seven=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),seven(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('7');
sound(seven,Fs)
[Power,N,f]=FFT(seven,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Power Spectral Density'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);


% --- Executes on button press in zero.
function zero_Callback(hObject, eventdata, handles)
% hObject    handle to zero (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs zero
y1=sin(2*pi*t*fr(4));
y2=sin(2*pi*t*fc(2));
zero=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),zero(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('0');
sound(zero,Fs)
[Power,N,f]=FFT(zero,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('Amplitude Spectrum'),axis([0 1600 0 0.5])

F=sort([fr fc]);
set(gca,'XTickLabel',F);

% --- Executes on button press in eight.
function eight_Callback(hObject, eventdata, handles)
% hObject    handle to eight (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs eight
y1=sin(2*pi*t*fr(3));
y2=sin(2*pi*t*fc(2));
eight=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),eight(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('8');

sound(eight,Fs)
[Power,N,f]=FFT(eight,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])

F=sort([fr fc]);
set(gca,'XTickLabel',F);

% --- Executes on button press in nine.
function nine_Callback(hObject, eventdata, handles)
% hObject    handle to nine (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs nine
y1=sin(2*pi*t*fr(1));
y2=sin(2*pi*t*fc(1));
nine=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),nine(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('9');

sound(nine,Fs)
[Power,N,f]=FFT(nine,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('  Amplitude Spectrum'),axis([0 1600 0 0.5])

F=sort([fr fc]);
set(gca,'XTickLabel',F);

% --- Executes on button press in four.
function four_Callback(hObject, eventdata, handles)
% hObject    handle to four (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs four
y1=sin(2*pi*t*fr(3));
y2=sin(2*pi*t*fc(3));
four=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),four(1:500),'LineWidth',2)  ,xlabel(' t(seconds)'),title('4');

sound(four,Fs)
[Power,N,f]=FFT(four,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title('Amplitude Spectrum'),axis([0 1600 0 0.5])
F=sort([fr fc]);
set(gca,'XTickLabel',F);


% --- Executes on button press in star.
function star_Callback(hObject, eventdata, handles)
% hObject    handle to star (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs star
y1=sin(2*pi*t*fr(4));
y2=sin(2*pi*t*fc(1));
star=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),star(1:500),'LineWidth',2) ,xlabel(' t(seconds)'), title('*');
sound(star,Fs)
[Power,N,f]=FFT(star,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title(' Amplitude Spectrum'),axis([0 1600 0 0.5])

F=sort([fr fc]);
set(gca,'XTickLabel',F);

% --- Executes on button press in diez.
function diez_Callback(hObject, eventdata, handles)
% hObject    handle to diez (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t fr fc Fs diez
y1=sin(2*pi*t*fr(4));
y2=sin(2*pi*t*fc(3));
diez=(y1+y2)/2;
axes(handles.axes1);
plot(t(1:500),diez(1:500),'LineWidth',2) ,xlabel(' t(seconds)'),title('#');
sound(diez,Fs)
[Power,N,f]=FFT(diez,Fs);
axes(handles.axes2);
plot(f(1:1600),sqrt(Power(1:1600)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title(' Amplitude Spectrum'),axis([0 1600 0 0.5])

F=sort([fr fc]);
set(gca,'XTickLabel',F);

function [Power,N,f]=FFT(y,Fs)
L=length(y);
N=ceil(log2(length(y)));
fy=fft(y,2^N)/(L/2);
Power=fy.*conj(fy);
f=(Fs/2^N)*(0:2^(N-1)-1);
return



% --- Executes on button press in RND_number.
function RND_number_Callback(hObject, eventdata, handles)
% hObject    handle to RND_number (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global one two three four five six seven eight nine zero Fs t r
C=cell(9);
C{1}=one;
C{2}=two;
C{3}=three;
C{4}=four;
C{5}=five;
C{6}=six;
C{7}=seven;
C{8}=eight;
C{9}=nine;
C{10}=zero;
r=mod(round(10*rand(10,1)),10)+1;
Signal=[C{1} C{2} C{3} C{4} C{5} C{6} C{7} C{8} C{9} C{10}];
[Power,N,f]=FFT(Signal,Fs);
axes(handles.axes2);
plot(f,sqrt(Power(1:end/2)),'r','LineWidth',2),  xlabel('  Frequency (Hz)'), ylabel(' Magnitude (w)');
title(' Amplitude Spectrum'),axis([0 1600 0 0.5]), grid on;
set(gca,'GridLineStyle','-');
axes(handles.axes1),
for n=1:length(r)
    SS=C{r(n)};
plot(t(1:500),SS(1:500));
title(int2str(r(n)),'FontSize',10)
sound(C{r(n)},Fs)
pause(0.6);
end
set(gca,'GridLineStyle','-');
m=int2str(r);
TITLE1=strcat(m(1),'-',m(2),'-',m(3),'-',m(4),'-',...
    m(5),'-',m(6),'-',m(7),'-',m(8),'-',m(9),'-',m(10));
set(handles.Display_number,'String',TITLE1);
% --- Executes on button press in Display_number.
function Display_number_Callback(hObject, eventdata, handles)
% hObject    handle to Display_number (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Display_number
handles.RND_number;

Contact us