Professional Documents
Culture Documents
22
22
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
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));
ylabel('Amplitude');
end
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone pad', ...
'FitBoxToText','on');
% This programm analyze a frequency coded signalvector and sort the won
% fa : sampling rate in hz
%d : time in seconds
%B : key vector
n=length(A);
for k=1:n;
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;
[a,i]=max(temp(x));
% frequency 1
f1=(i/d)-1;
i=i-10:i+10;
temp(i)=0;
[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)
f1=770;
f1=852;
f1=941;
end
f2=1209;
f2=1336;
f2=1477;
f2=1633;
end
% msgbox(num2str(f1))
% msgbox(num2str(f2))
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
B(k)=taste;
% increase variable
k=k+1;
end
function [x,t] = encode(key,d,Ta)
% [x,t] = encode(key,d,Ta)
% example: [x,t]=encode(5,0.2,0.0003)
% key: key
% d: time in seconds
if d<=0;
disp(' ');
disp(' ')
return;
else;
switch (key);
f1=697;
f1=852;
f1=941;
otherwise;
disp(' ');
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;
f2=1633;
end;
t = 0:Ta:d;
x = sin(2*pi*f1*t)+sin(2*pi*f2*t);
end;
% This program gives a dtmf key vector to function "encode.m", and generate
% fa : sampling rate in hz
%d : time in seconds
% sampling time
Ta=1/fa;
n=length(A);
for k=1:n;
[x,t]=encode(A(k),d,Ta);
% yabs=abs(fft(x));
% figure;
% stem(yabs);
Z(k,:)=x;
% increase variable
k=k+1;
end
clear;
clc;
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
% ----------------------------------------------------------------------------------------
% 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 |
d=0.5;
fa=3267;
[Z]=genfcs(A,d,fa);
[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
tone= abs(data)';
figure
subplot(2,1,1)
plot(F,magnitudeY)
title('Magnitude')
subplot(2,1,2)
plot(F,phaseY)
title('Phase')