Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};

lfg = [697 770 852 941]; % Low frequency group

hfg = [1209 1336 1477]; % High frequency group

f = [];

for c=1:4,

for r=1:3,

f = [ f [lfg(c);hfg(r)] ];

end

end

Fs = 8000; % Sampling frequency 8 kHz

N = 800; % Tones of 100 ms

t = (0:N-1)/Fs; % 800 samples at Fs

pit = 2*pi*t;

tones = zeros(N,size(f,2));

for toneChoice=1:12,

% Generate tone

tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';

% Plot tone

subplot(4,3,toneChoice),plot(t*1e3,tones(:,toneChoice));

title(['Symbol "', symbol{toneChoice},'": [',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])

set(gca, 'Xlim', [0 25]);

ylabel('Amplitude');

if toneChoice>9, xlabel('Time (ms)'); end

end

set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])


annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...

'EdgeColor',[1 1 1],...

'String', '\bf Time response of each tone of the telephone pad', ...

'FitBoxToText','on');

function [B] = decode(Z,A,fa,d)

% This programm analyze a frequency coded signalvector and sort the won

% frequencies its key.

% example: [B] = decode(Z,A,4000)

%Z : frequency coded signalvector

%A : dtmf key vector

% fa : sampling rate in hz

%d : time in seconds

%B : key vector

n=length(A);

for k=1:n;

% fft analyze of the frequency coded signalvector

temp=abs(fft(Z(k,:)));

% Analyze to the half sampling rate, because the frequencies after are

% not interesting for analyze. They were created by sampling the signal
x=1:(fa/2)*d;

% maximum of the array

[a,i]=max(temp(x));

% frequency 1

f1=(i/d)-1;

% set the actuall x coordinate at area +/-10 to 0

i=i-10:i+10;

temp(i)=0;

% maximum of the array

[a,i]=max(temp(x));

% frequency 2

f2=(i/d)-1;

% frequency sort

if f1>1000

var=f1;

f1=f2;

f2=var;

elseif f1<1000

end

% msgbox(num2str(f1));

% msgbox(num2str(f2));

% include frequency tolerance and sort the key frequencies (the actuall

% tolerance are at with time: >= 0.0499 s and sampling rate: 3300Hz)

if ((f1>692) && (f1<720))


f1=697;

elseif ((f1>765) && (f1<800))

f1=770;

elseif ((f1>847) && (f1<880))

f1=852;

elseif ((f1>936) && (f1<960))

f1=941;

end

if ((f2>1204) && (f2<1240))

f2=1209;

elseif ((f2>1331) && (f2<1360))

f2=1336;

elseif ((f2>1472) && (f2<1500))

f2=1477;

elseif ((f2>1628) && (f2<1660))

f2=1633;

end

% msgbox(num2str(f1))

% msgbox(num2str(f2))

% sort the evaluated frequencies to the keys

switch(f1);

case{697};

switch(f2);
case{1209};

taste='1';

case{1336};

taste='2';

case{1477};

taste='3';

case{1633};

taste='A';

end

case{770};

switch(f2);

case{1209};

taste='4';

case{1336};

taste='5';

case{1477};

taste='6';

case{1633};

taste='B';

end

case{852};

switch(f2);

case{1209};

taste='7';

case{1336};
taste='8';

case{1477};

taste='9';

case{1633};

taste='C';

end

case{941};

switch(f2);

case{1209};

taste='*';

case{1336};

taste='0';

case{1477};

taste='#';

case{1633};

taste='D';

end

end

% the evaluated key into vector

B(k)=taste;

% increase variable

k=k+1;

end
function [x,t] = encode(key,d,Ta)

% [x,t] = encode(key,d,Ta)

% This program encode the dtmf key vector.

% example: [x,t]=encode(5,0.2,0.0003)

% key: key

% d: time in seconds

% Ta; sampling time

% f1: frequency in y-coordinate in Hz(from DTMF matrix)

% f2: frequency in x-coordinate in Hz(from DTMF matrix)

if d<=0;

disp(' ');

disp('ERROR: time must be greater 0 !');

disp(' ')

return;

else;

switch (key);

case {1 2 3 'a' 'A'};

f1=697;

case {4 5 6 'b' 'B'};


f1=770;

case {7 8 9 'c' 'C'};

f1=852;

case {'*' 0 '0' '#' 'D'};

f1=941;

otherwise;

disp(' ');

disp('ERROR: incorrect entry !');

disp('only entry: 1 2 3 4 5 6 7 8 9 0 a b c d # * ');

disp(' ');

return;

end;

switch (key);

case {1 4 7 '*'};

f2=1209;

case {2 5 8 0 '0'};

f2=1336;

case {3 6 9 '#'};

f2=1477;

case {'a' 'b' 'c' 'd' 'A' 'B' 'C' 'D'};

f2=1633;

end;

t = 0:Ta:d;
x = sin(2*pi*f1*t)+sin(2*pi*f2*t);

if nargout==0 sound(x,1/Ta); end;

end;

function [Z] = genfcs(A,d,fa)

% This program gives a dtmf key vector to function "encode.m", and generate

% frequency coded signalvector with the parameter from "encode.m".

% example: [Z] = genfcs(A,1,4000);

% fa : sampling rate in hz

%d : time in seconds

%A : dtmf key vector

%Z : frequency coded signalvector

% sampling time

Ta=1/fa;

n=length(A);

for k=1:n;

% elements dtmf key vector to function "encode.m" and save won

% parameter into x,t

[x,t]=encode(A(k),d,Ta);

% fft analyze frequency coded signalvector

% yabs=abs(fft(x));
% figure;

% stem(yabs);

% generate frequency coded signalvector

Z(k,:)=x;

% increase variable

k=k+1;

end

clear;

clc;

% dtmf key vector

A=[1,2,3,'A',4,5,6,'B',7,8,9,'C','*',0,'#','D'];

% function call "ausgabe.m" with X time and sampling rate of 4000Hz, because

% the highest signalfrequency is 1633Hz. With this sampling rate we are

% safe, because of Shannon (sampling rate = 2 * signalfrequency).

% The following configurations have been tested:

% | 0.0499s | 0.0500s | 0.0860s | 0.0870s | 0.1000s | 0.5000s | 1s | 2s | 50s |

% ----------------------------------------------------------------------------------------

% 3266.0341Hz| x | x | x | x | x | x | ok | ok | ok |

% ----------------------------------------------------------------------------------------

% 3267.0000Hz| x | x | x | ok | ok | ok | ok | ok | ok |

% ----------------------------------------------------------------------------------------
% 3300.0000Hz| ok | ok | ok | ok | ok | ok | ok | ok | ok |

% ----------------------------------------------------------------------------------------

% 3500.0000Hz| ok | ok | ok | ok | ok | ok | ok | ok | ok |

% ----------------------------------------------------------------------------------------

% 4000.0000Hz| ok | ok | ok | ok | ok | ok | ok | ok | ok |

% ----------------------------------------------------------------------------------------

% 8000.0000Hz| ok | ok | ok | ok | ok | ok | ok | ok | ok |

% 3267Hz border with time d=0.08636836628511967289829...

d=0.5;

fa=3267;

[Z]=genfcs(A,d,fa);

% function call analyze

[B]=decode(Z,A,fa,d);

clear; clc;

[data,Fs] = audioread('tel.wav'); % Read the audio file and store the audio in data and sampling rate into
fs

player = audioplayer(data,Fs);

play(player);

NFFT = length(data);

Y = fft(data,NFFT);

F = ((0:1/NFFT:1-1/NFFT)*Fs).';
magnitudeY = abs(Y); % Magnitude of the FFT

phaseY = unwrap(angle(Y)); % Phase of the FFT

tone= abs(data)';

figure

subplot(2,1,1)

plot(F,magnitudeY)

title('Magnitude')

line([1209 697], [0 500],'LineStyle',':'); % dotted line at DTMF?

subplot(2,1,2)

plot(F,phaseY)

title('Phase')

You might also like