D
DT
TM
MF
F
C
Co
od
d
er
e
r
/
/
D
De
ec
co
od
de
er
r
D
De
es
si
ig
g
n
n
u
u
si
s
in
ng
g
F
FI
IR
R
B
Ba
an
nk
ks
s
b
b
y
y
S
S
.S
.
Si
ir
rc
ca
ar
r
I
In
nt
tr
ro
od
du
uc
ct
ti
io
on
n
Analog DTMF telephone signaling is based on encoding standard telephone
Keypad digits and symbols in two audible sinusoidal signals of frequencies FL and
FH. Thus the scheme gets its name as dual tone multi frequency (DTMF).
Hz 1209 1336 1477 1633
697 1
2
3
A
770 4
5
6
B
852 7
8
9
C
941 *
0
#
D
Figure 1
Each digit or symbol represented in figure 1 has 2 distinct high and low
frequency components. Thus each high-low frequency pair uniquely identifies the
corresponding telephone keypad digit or symbol. Each key pressed can be
represented as a discrete time signal of form
Where N is defined as number of samples taken. Typically in the sampling
frequency used is 8khz. Thus if the two individual frequency components of the
signal can be identified then the number dialed can be decoded.
N
No
ot
te
e
:
:-
- In this report I have used (dual tone and digit/symbols) interchangeably
but both mean the same. Dual tone means the encoded samples of the
corresponding DTMF digits/symbols.
I
Im
mp
pl
le
em
me
en
nt
ta
at
ti
io
on
n
o
of
f
D
DT
TM
MF
F
E
En
nc
co
od
de
er
r
The DTMF encoder is implemented in MATLAB function dtmfe.m. The
implementation is based on a digital oscillator, that will generate sinusoidal tones
at frequencies F
oin response to an input signal x[n] = δ[n].
x[n]
H[n]
y[n]
{y[n]
=
x[n]*H[n]
dt[n] = sin[ωLn] + sin[ωLn] , 0 ≤ n ≤ N-1 (1)
Consider a causal filter with
y(n) - 2*cos(2*pi * f *Ts)y(n-1) + y(n-2) =0*x(n) sin(f)x(n-1) + 0*x(n-2).
The impulse response of this system tells us that this indeed is a digital oscillator.
The H[n] is plotted and is sinusoidal and hence any input to this system will
oscillate as governed by the system function.
The impulse response of the system is shown in the figure above. This is
generated by using the MATLAB dimpulse() function for 100 points.
The encoder is coded so that it inserts silence samples in between each
digits/symbols so that they are separated from each other.
Starting position = (total number of digits be encoded-1)*(length of each dual
tone + number of silence samples to be inserted) + 1.
This information is used at the decoding step to get each dual tone sample
length and how many samples to skip for the next digit/symbol. The resulting
waveform after encoding is shown in figure 2 below. The waveform shows an
encoded sequence of my phone number 7262527. There are 7 digits in the
dialed string and hence the waveform shows 7 distinct sub samples of the
resulting DTMF encoded waveform.
The frequency spectrum is shown in the figure below of the dialed dtmf digits.
The plot shows both sided frequency spectrum and is simply a mirror of the base
band.
I
Im
mp
pl
le
em
me
en
nt
ta
at
ti
io
on
n
o
of
f
D
DT
TM
MF
F
d
de
ec
co
od
de
er
r
The input to the decoder is a vector containing DTMF tones that are encoded by
the encoder. A FIR (Finite Impulse Response) band pass filter is implemented
which is centered at the frequencies of interest for decoding each key pressed.
The decoding process takes place in iterative form. Starting from row 1 to row
4,in each iteration a FIR band pass filter centered at each F
His implemented and
the signal strength around the band is compared against a threshold. If the
mean amplitude of the filter output is more than a set threshold, the frequency
component tested is considered to be strong. To prevent cancellation of the
sinusoids while calculating the mean, the values are squared.
Similar approach is taken in order to find the F
Lpresent in the signal. Once a
row-column pair has been detected the digit encoded is uniquely identified. This
approach has been taken in order to suppress the effects of noise in the encoded
signal. This approach has a significant advantage that is the band pass filter
coefficients can be manipulated individually to produce a narrower filter and
detection process can be enhanced in presence of noise.
In order to decode a string of dialed symbols/digits the decoding step assumes
that the encoder has inserted silence between each dual tone. Each dual tone
length is tracked and silence lengths are calculated. The decoding step loops
over for the number of digits to be decoded that is easily calculated from the
total length of the signal divided by the sum of individual dual tone length and
silence length. Thus after decoding the first digit certain number of samples are
skipped and the next set of samples are decoded. This means sampling and
decoding a small part of the resulting waveform in each iteration, where one
iteration relates to one key pressed.
C
Co
on
nc
cl
lu
us
si
io
on
n
No attempt has been made to test the system performance in a noisy
environment. However, since I have used a band pass filter in order to decode
every DTMF tone the band pass filter length can be manipulated in order to get
good results in noisy environment. A filter of length L (L=128 currently used) can
be used to increase the immunity of noise (type of noise). However a higher
value of L would detect tones even of lower amplitude better, but also increases
the chance of error in detection. This matched filter approach definitely
reduces the mean square error between two bands of detection. The system has
been tested and works according to specification in a noise free environment.
A
An
na
al
ly
ys
si
is
s
R
Re
e
su
s
ul
lt
ts
s
Consider Detecting digit 4 of DTMF which comprise of Fl = 770, Fh = 1209.
Filter coefficients and frequency response of 770 hz center frequency band pass
FIR filter.
Frequency response of the 770 hz band pass filter is shown in the plot below.
Filter coefficients and frequency response of 1209 hz center frequency band pass
FIR filter.
Frequency response of the 770 hz band pass filter is shown in the plot below.
Suppose the frequency we are looking for is 770hz and 1209 hz in order to
detect dialed digit 4. The decoding takes place by implementing a band pass
filter at every iteration step looking for a particular Fl and Fh. The decoded digit
in the following diagram is 4. Take a look at how 770hz and 1209 hz are allowed
to pass from the band pass filter.
Source Code for DTMF Encoder/Decoder
Source Code for DTMF Encoder/Decoder
g glloobbaall ddttmmff__rrffrreeqq g glloobbaall ddttmmff__ccffrreeqq g glloobbaall ddttmmff__kkeeyy g glloobbaall ddttmmff__ffss g glloobbaall ddttmmff__ssiilleenncceelleenn g glloobbaall ddttmmff__ttoonneelleenn % % EExxeeccuuttee tthhiiss SSccrriipptt aatt tthhee bbeeggiinniinngg ooff eennccooddiinngg aanndd ddeeccooddiinngg % % TThhiiss ssccrriipptt sseettss aallll tthhee gglloobbaall ppaarraammnneetteerr ffoorr eennccooddiinngg aanndd ddeeccooddiinngg % % DDeeffiinnee tthhee ffrreeqquueenncciieess uusseedd iinn ssyynntthheessiizziinngg aanndd ddeeccooddiinngg tthhee DDTTMMFF ssiiggnnaall % % EEaacchh ffrreeqquueennccyy ccoorrrreessppoonnddss ttoo aa rrooww oorr ccoolluummnn ooff kkeeyyss oonn tthhee kkeeyyppaadd,, % % eegg.. pprreessssiinngg ''44'' mmeeaannss tthhaatt tthhee ffrreeqquueenncciieess ffoorr rrooww 22 aanndd ccoolluummnn 11 sshhoouulldd % % bbee uusseedd.. TThhee rreessuullttiinngg DDTTMMFF ttoonnee iiss tthhee ttwwoo wwaavveeffoorrmmss ssuummmmeedd ttooggeetthheerr d dttmmff__rrffrreeqq == [[ 669977 777700 885522 994411]];; %% ffrreeqquueennccyy ccoommppoonneennttss ffoorr eeaacchh rrooww d dttmmff__ccffrreeqq == [[11220099 11333366 11447777 11663333]];; %% ffrreeqquueennccyy ccoommppoonneennttss ffoorr eeaacchh ccoolluummnn d dttmmff__kkeeyy == [[ ''11'' ''22'' ''33'' ''AA'';; ''44'' ''55'' ''66'' ''BB'';; ''77'' ''88'' ''99'' ''CC'';; ''**'' ''00'' ''##'' ''DD'']];; %% SSaammpplliinngg FFrreeqquueennccyy ddttmmff__ffss == 88000000;; ddiisspp(([[''DDTTMMFF ssaammpplleerraattee sseett ttoo '' nnuumm22ssttrr((ddttmmff__ffss)) '' HHzz'']]));; %%DDuurraattiioonn ooff tthhee TToonnee ttoo ggeenneerraattee ddttmmff__ttoonneelleenn == rroouunndd((ddttmmff__ffss ** 00..5500));; %% CCoonnvveerrtt lleennggtthh ffrroomm sseeccoonnddss ttoo ssaammpplleess ddiisspp(([[''DDTTMMFF ttoonnee lleennggtthh sseett ttoo '' nnuumm22ssttrr((ddttmmff__ttoonneelleenn)) '' ssaammpplleess'']]));; %%IInnsseerrtt SSiilleennccee lleennggtthhss bbeettwweeeenn ttoonneess ffoorr ddeetteeccttiioonn ddttmmff__ssiilleenncceelleenn == rroouunndd((ddttmmff__ffss ** 00..2200));; %% CCoonnvveerrtt lleennggtthh ffrroomm sseeccoonnddss ttoo ssaammpplleess ddiisspp(([[''DDTTMMFF bbrreeaakk lleennggtthh sseett ttoo '' nnuumm22ssttrr((ddttmmff__ssiilleenncceelleenn)) '' ssaammpplleess'']]));;
Code for Digital Oscillator to generate the sinusoids
Code for Digital Oscillator to generate the sinusoids
% % GGeenneerraatteess aa ssiinnoossooiiddaall oouuttppuutt aatt aa ssppeecciiffiieedd ffrreeqquueennccyy % % TThhiiss iiss ggeneneerraatteedd bbyy iimmpplleemmeennttiinngg aa ddiiggiittaall oosscciillllaattoorr uussiinngg tthhee ffoolllloowwiinngg ddiiffffeerreennccee eeqquuaattiioonn % % yy((nn)) -- 22**ccooss((22**ppii ** ff **TTss))yy((nn--11)) ++ yy((nn--22)) ==00**xx((nn)) ssiinn((ff))xx((nn--11)) ++ 00**xx((nn--22)) % % TThhee ffoolllloowwiinngg ccoo--eeffffiicciieenntt aarree aass ffoolllloowwss % % AA == [[11 --22**ccooss((22**ppii ** ff **TTss)) 11]];; % % BB == [[00 ssiinn((22**ppii ** ff **TTss)) 00 ]];; % % % % SShhiillaaddiittyyaa SSiirrccaarr 22000022 % % DDSSPP CCoouurrssee PPrroojjeecctt % % % % UUssaaggee --:: % % nn -- mmuusstt bbee aa vveeccttoorr % % TTss == 11//ddttmmff__ffss;; % % nn == 00::ddttmmff__ttoonneelleenn--11;; % % ff == ssoommee ffrreeqquueennccyy ffoorr tthhee ttoonnee ttoo bbee ggeenneerraatteedd % % YY == ggeennssiinnoo((ff,,nn,,TTss));; f fuunnccttiioonn YY == ggeennssiinnoo((ff,,nn,,TTss)) X X == zzeerrooss((11,,lleennggtthh((nn))));;XX((11)) == 11;; %% ggeenneerraattee tthhee iimmppuullsseess A A == [[11 --22**ccooss((22**ppii ** ff **TTss)) 11]];; B B == [[00 ssiinn((22**ppii ** ff **TTss)) 00 ]];; Y Y == ffiilltteerr((BB,,AA,,XX));;Code for DTMF Encoder
Code for DTMF Encoder
f fuunnccttiioonn eennccooddeeddTToonneess == ddttmmffee((nnuumm)) % % TThhiiss ffuunnccttiioonn ttrraannssllaatteess kkeeyy pprreesssseedd iinn ddiiggiittaall tteelleepphhoonnee kkeeyyppaadd ttoo ccoorrrreessppoonnddiinngg % % dduuaall ttoonnee ffrreeqquueenncciieess % % EExxaammppllee eennccooddeeddTToonneess == ddttmmffee((''55667700553311'')) % % 556677003311 iiss ssttrriinngg ooff nnuummbbeerrss pprreesssseedd.. TThhee ffuunnccttiioonn ccoonnvveerrttss tthheemm ttoo tthheeiirr % % ccoorrrreessppoonnddiinngg dduuaall ttoonneess aass ppeerr ddeeffiinneedd iinn ddttmmff mmaaiinn ((FFHH,,FFLL)) % % % % SShhiillaaddiittyyaa SSiirrccaarr 22000022 % % DDSSPP CCoouurrssee PPrroojjeecctt % %BBrriinngg tthhee gglloobbaall vvaarriiaabblleess ddeeffiinneedd iinn ddttmmffmmaaiinn ttoo tthhee ssccooppee ooff tthhiiss ffuunnccttiioonn g glloobbaall ddttmmff__rrffrreeqq g glloobbaall ddttmmff__ccffrreeqq g glloobbaall ddttmmff__kkeeyy g glloobbaall ddttmmff__ffss g glloobbaall ddttmmff__ssiilleenncceelleenn g glloobbaall ddttmmff__ttoonneelleenn % % CCaann uussee tthhee sseettppaarraammeetteerr ffuunnccttiioonn iinn oorrddeerr ttoo jjuusstt eevvaalluuaattee tthhiiss ffuunnccttiioonn % % ttoo ddoo tthhiiss jjuusstt uunn--ccoommmmeenntt tthhee sseettppaarraammeetteerr.. TThhiiss ssccrriipptt wwiillll sseett uupp tthhee gglloobbaall % %vvaarriiaabbllee rreeqquuiirreedd ttoo eexxeeccuuttee ddttmmff eennccooddiinngg.. % %sseettppaarraammeetteerr;; n nuumm == sspprriinnttff((''%%ss'',,nnuumm));; T Tss == 11//ddttmmff__ffss;; %% SSaammppllee lleennggtthh n n == 00::ddttmmff__ttoonneelleenn--11;; %% VVeeccttoorr ttoo ssaammppllee ffrroomm 00 << nn <<==NN--11 % %TToottaall NNuummbbeerr ooff EElleemmeennttss rreeqquuiirreedd iinn tthhee eeccooddeedd vveeccttoorr ssppaaccee n nuummccoouunntt == lleennggtthh((nnuumm));; t tlleenn == nnuummccoouunntt**((ddttmmff__ttoonneelleenn ++ ddttmmff__ssiilleenncceelleenn));; % %GGeenneerraattee tthhee vveeccttoorr ffiirrsstt tthhaatt ccoonnttaaiinnss tthhee ttoonneess e ennccooddeeddTToonneess == zzeerrooss((11,,ttlleenn));; % % lloooopp tthhrroouugghh tthhee iinnddiivviidduuaall kkeeyyss iinn tthhee iinnppuutt vveeccttoorr f foorr ii == 11::nnuummccoouunntt %% FFiinndd oouutt wwhhiicchh ccoolluummnn aanndd rrooww tthhiiss kkeeyy bbeelloonnggss ttoo [[rrooww,,ccooll]] == ffiinndd(( ddttmmff__kkeeyy ==== uuppppeerr((nnuumm((ii))))));; iiff (( iisseemmppttyy((rrooww)) )) ddiisspp((''OOnnee ooff tthhee KKeeyy PPrreesssseedd iiss nnoott aa vvaalliidd DDTTMMFF KKeeyy''));; eenndd %% ccaallccuullaattee tthhee ssttaarrtt aanndd eenndd ppoossiittiioonn ooff tthhee ccuurrrreenntt ttoonnee ssttaarrttppooss == ((ii--11))**((ddttmmff__ttoonneelleenn ++ ddttmmff__ssiilleenncceelleenn)) ++ 11;; eennddppooss == ssttaarrttppooss ++ ddttmmff__ttoonneelleenn -- 11;; eennccooddeeddTToonneess((ssttaarrttppooss::eennddppooss)) == ggeennssiinnoo((ddttmmff__ccffrreeqq((ccooll)) ,, nn ,, TTss )) ++ ggeennssiinnoo((ddttmmff__rrffrreeqq((rrooww)) ,, nn ,, TTss ) );; e enndd
8
Code for DTMF Decoder
Code for DTMF Decoder
f fuunnccttiioonn ddiiggiittssttrr == ddttmmffdd((eennccssttrr)) % % TThhiiss ffuunnccttiioonn ttrraannssllaatteess tthhee eennccooddeedd ttoonneess ttoo ccoorrrreessppoonnddiinngg % % kkeeyyss//kkeeyy tthhaatt aarree pprreesssseedd.. % % EExxaammppllee ddiiggititssttrr == ddttmmffdd((vveecc)) % % WWhheerree vveecc iiss tthhee vveeccttoorr tthhaatt ccoonnttaaiinnss tthhee eennccooddeedd ttoonneess % % % % SShhiillaaddiittyyaa SSiirrccaarr 22000022 % % DDSSPP CCoouurrssee PPrroojjeecctt g glloobbaall ddttmmff__rrffrreeqq g glloobbaall ddttmmff__ccffrreeqq g glloobbaall ddttmmff__ffss g glloobbaall ddttmmff__ssiilleenncceelleenn g glloobbaall ddttmmff__ttoonneelleenn g glloobbaall ddttmmff__kkeeyy % % CCaann uussee tthhee sseettppaarraammeetteerr ffuunnccttiioonn iinn oorrddeerr ttoo jjuusstt eevvaalluuaattee tthhiiss ffuunnccttiioonn % % ttoo ddoo tthhiiss jjuusstt uunn--ccoommmmeenntt tthhee sseettppaarraammeetteerr.. TThhiiss ssccrriipptt wwiillll sseett uupp tthhee gglloobbaall % %vvaarriiaabbllee rreeqquuiirreedd ttoo eexxeeccuuttee ddttmmff eennccooddiinngg.. % %sseettppaarraammeetteerr;; % % LLeennggtthh ooff BBaanndd PPaassss FFiilltteerr % % IIff tthhee bbaannddppaassss iiss ttoooo wwiiddee,, tthhiiss ccaann bbee iinnccrreeaasseedd ttoo pprroodduuccee aa mmoorree nnaarrrrooww ffiilltteerr % % ffoorr ffiinneerr pprreecciissiioonn.. HHoowweevveerr ccoommppuuttaattiioonn ttiimmee iinnccrreeaasseess aa vvaalluuee LL == 6644 ggiivveess % % ssaattiissffaaccttoorryy rreessuullttss ffoorr nnoo nnooiissee eennvviirroonnmmeenntt L L == 6644;; f fiilltt__nn == 00::LL--11;; d dttmmff__ddiiggiilleenn == lleennggtthh((eennccssttrr))//((ddttmmff__ttoonneelleenn++ddttmmff__ssiilleenncceelleenn));; f foorr ddeeccoo__sseeqq == 11::ddttmmff__ddiiggiilleenn %% LLoooopp tthhrroouugghh eeaacchh rrooww aanndd CChheecckk iiff tthhee rrooww--ii ffrreeqquueennccyy eexxiisstt iinn tthhee ssiiggnnaall %% DDeeffiinnee tthhee ppooiinntteerr aatt ssttaarrtt ooff tthhee sseeqquueennccee ssttaarrttppooss == ((ddeeccoo__sseeqq -- 11))**((ddttmmff__ttoonneelleenn ++ ddttmmff__ssiilleenncceelleenn)) ++ 11;; eennddppooss == ssttaarrttppooss ++ ddttmmff__ttoonneelleenn -- 11;; eennccssttrr__ffrraagg == eennccssttrr((ssttaarrttppooss::eennddppooss));; ffoorr ii == 11::44 %% CCaallccuullaattee ffiilltteerr ccooeeffffiicciieennttss ffoorr tthhee bbaannddppaassss ffiilltteerr ffoorr rrooww ffrreeqquueenncciieess %% ggiivveenn tthhee cceenntteerr ffrreeqquueennccyy hhhh == 22//LL**ccooss((22**ppii**ddttmmff__rrffrreeqq((ii))**ffiilltt__nn//ddttmmff__ffss));; ssss == mmeeaann((ccoonnvv((eennccssttrr__ffrraagg,,hhhh))..^^22)) >> mmeeaann((eennccssttrr__ffrraagg..^^22))//55;;%% ccoommppaarree mmeeaann aammpplliittuuddee aanndd iiff %% mmoorree tthhaann 2200%% (( //55 )),, tthhee ffrreeqquueennccyy %% ccoommppoonneenntt iiss ccoonnssiiddeerreedd ttoo bbee ssttrroonngg iiff ((ssss)) rrooww == ii;; bbrreeaakk %% wwee aallrreeaaddyy hhaavvee oouurr rrooww -- nnoo nneeeedd ttoo cchheecckk tthhee rreesstt eenndd eenndd %% LLoooopp tthhrroouugghh eeaacchh ccoolluummnn aanndd cchheecckk iiff tthhee ccoolluummnn--ii ffrreeqquueennccyy eexxiisstt iinn tthhee ssiiggnnaall ffoorr ii == 11::44 %% CCaallccuullaattee ffiilltteerr ccooeeffffiicciieennttss ffoorr tthhee bbaannddppaassss ffiilltteerr ffoorr ccoolluummnn ffrreeqquueenncciieess %% ggiivveenn tthhee cceenntteerr ffrreeqquueennccyy hhhh == 22//LL**ccooss((22**ppii**ddttmmff__ccffrreeqq((ii))**ffiilltt__nn//ddttmmff__ffss));; ssss == mmeeaann((ccoonnvv((eennccssttrr__ffrraagg,,hhhh))..^^22)) >> mmeeaann((eennccssttrr__ffrraagg..^^22))//55;; iiff ((ssss)) ccooll == ii;;
bbrreeaakk %% wwee aallrreeaaddyy hhaavvee oouurr ccoolluummnn -- nnoo nneeeedd ttoo cchheecckk tthhee rreesstt eenndd eenndd nnuummssttrr((11,,ddeeccoo__sseeqq)) == ddttmmff__kkeeyy((rrooww,,ccooll));; e enndd d diiggiittssttrr == nnuummssttrr;;
Code for DTMF main
Code for DTMF main
f fuunnccttiioonn rreettuurrnn__ddiiggiittss == ddttmmffmmaaiinn((nnuumm22eennccooddee)) % % TThhiiss pprrooggrraamm ssiimmuullaatteess tthhee tteelleepphhoonnee DDTTMMFF DDiiaalliinngg SScchheemmee % % PPlleeaassee SSeeee ddttmmffee..mm ffoorr hhooww eennccooddiinngg iiss ddoonnee % % PPlleeaassee SSeeee ddttmmffdd..mm ffoorr hhooww ddeeccooddiinngg iiss ddoonnee % % UUssaaggee EExxaammpplleess % % rreettuurrnn__ddiiggiittss == ddttmmffmmaaiinn((''112233AA##**'')) % % % % SShhiillaaddiittyyaa SSiirrccaarr 22000022 % % DDSSPP CCoouurrssee PPrroojjeecctt % %DDeeffiinnee GGlloobbaall vvaarriiaabbllee uusseedd bbyy ddttmmffee aanndd ddttmmffdd ffuunnccttiioonnss g glloobbaall ddttmmff__rrffrreeqq g glloobbaall ddttmmff__ccffrreeqq g glloobbaall ddttmmff__kkeeyy g glloobbaall ddttmmff__ffss g glloobbaall ddttmmff__ssiilleenncceelleenn g glloobbaall ddttmmff__ttoonneelleenn % % DDeeffiinnee tthhee ffrreeqquueenncciieess uusseedd iinn ssyynntthheessiizziinngg tthhee DDTTMMFF ssiiggnnaall % % EEaacchh ffrreeqquueennccyy ccoorrrreessppoonnddss ttoo aa rrooww oorr ccoolluummnn ooff kkeeyyss oonn tthhee kkeeyyppaadd,, % % eegg.. pprreessssiinngg ''**'' mmeeaannss tthhaatt tthhee ffrreeqquueenncciieess ffoorr rrooww 44 aanndd ccoolluummnn 11 sshhoouulldd % % bbee uusseedd.. TThhee rreessuullttiinngg DDTTMMFF ttoonnee iiss tthhee ttwwoo wwaavveeffoorrmmss ssuummmmeedd ttooggeetthheerr d dttmmff__rrffrreeqq == [[ 669977 777700 885522 994411]];; %% ffrreeqquueennccyy ccoommppoonneennttss ffoorr eeaacchh rrooww d dttmmff__ccffrreeqq == [[11220099 11333366 11447777 11663333]];; %% ffrreeqquueennccyy ccoommppoonneennttss ffoorr eeaacchh ccoolluummnn % % DDeeffiinnee tthhee tteelleepphhoonnee kkeeyyppaadd aass aa 22dd mmaattrriixx d dttmmff__kkeeyy == [[ ''11'' ''22'' ''33'' ''AA'';; ''44'' ''55'' ''66'' ''BB'';; ''77'' ''88'' ''99'' ''CC'';; ''**'' ''00'' ''##'' ''DD'']];; % % SSaammpplliinngg FFrreeqquueennccyy d dttmmff__ffss == 88000000;; d diisspp(([[''DDTTMMFF ssaammpplleerraattee sseett ttoo '' nnuumm22ssttrr((ddttmmff__ffss)) '' HHzz'']]));; % %DDuurraattiioonn ooff tthhee TToonnee ttoo ggeenneerraattee d dttmmff__ttoonneelleenn == rroouunndd((ddttmmff__ffss ** 00..5500));; %% CCoonnvveerrtt lleennggtthh ffrroomm sseeccoonnddss ttoo ssaammpplleess d diisspp(([[''DDTTMMFF ttoonnee lleennggtthh sseett ttoo '' nnuumm22ssttrr((ddttmmff__ttoonneelleenn)) '' ssaammpplleess'']]));; % %IInnsseerrtt SSiilleennccee lleennggtthhss bbeettwweeeenn ttoonneess ffoorr ddeetteeccttiioonn d dttmmff__ssiilleenncceelleenn == rroouunndd((ddttmmff__ffss ** 00..0011));; %% CCoonnvveerrtt lleennggtthh ffrroomm sseeccoonnddss ttoo ssaammpplleess d diisspp(([[''DDTTMMFF bbrreeaakk lleennggtthh sseett ttoo '' nnuumm22ssttrr((ddttmmff__ssiilleenncceelleenn)) '' ssaammpplleess'']]));; % % CCaallll EEnnccooddeerr FFuunnccttiioonn e ennccooddeeddTToonneess == ddttmmffee((nnuumm22eennccooddee));; % %ssoouunndd((eennccooddededTToonneess,,ddttmmff__ffss));; % %PPlloott tthhee eennccooddeedd TToonneess X X == fffftt((eennccooddeeddTToonneess));; N N == lleennggtthh((eennccooddeeddTToonneess));; f f == ((00::NN--11))//NN**ddttmmff__ffss;; f fiigguurree((11)),,pplloott((ff,, aabbss((XX)),,''gg''))
10
x xllaabbeell((''FFrreeqquueennccyy ((HHzz))'')) y yllaabbeell((''AAmmpplliittuuddee'')) t tiittllee((''FFFFTT AAmmpplliittuuddee SSppeeccttrruumm'')) % %RReettuurrnn TThhee DDeeccooddeedd TToonneess D Deeccooddeedd__DDiiggiittss == ddttmmffdd((eennccooddeeddTToonneess));; i iff ((ssttrrnnccmmpp((DDeeccooddeedd__DDiiggiittss,,nnuumm22eennccooddee,,lleennggtthh((nnuumm22eennccooddee)))) ==== 11)) ddiisspp(('' ''));; ddiisspp((''SSuucccceessffuullllyy ddeeccooddeedd tthhee ddiiaalleedd nnuummbbeerr''));; ddiisspp(('' ''));; ddiisspp((''TThhee ddiiaalleedd TTeelleepphhoonnee NNuummbbeerr wwaass''));; nnuumm22eennccooddee ddiisspp(('' ''));; ddiisspp((''TThhee DDeeccooddeedd TTeelleepphhoonnee NNuummbbeerr iiss ''));; DDeeccooddeded__DDiiggiittss e ellssee ddiisspp((''EErrrroorr IInn DDeeccooddiinngg''));; DDeeccooddeedd__DDiiggiittss e enndd