Tone generator¶
DTMF is a two-tone multi-frequency analogue signal, in other words, each symbol corresponds to a set of two frequencies.
Scope of application of DTMF tones: automatic telephone signalling between devices. In particular, such tones are used to control the connection between analogue equipment.
DTMF implementation¶
Connecting libraries.
Pkg.add(["WAV", "DSP"])
using Plots
using FFTW
using DSP
using WAV
Declaring system parameters¶
# symbols = ["1", "5", "0", "8", "6", "4", "7", "7", "0", "0", "0"]; # Набор символов
symbols = ["5", "0", "8"]; # Набор символов
lfg = [697 770 852 941]; # Группа нижних частот
hfg = [1209 1336 1477]; # Группа верхних частот
f = [reshape(ones(3, 1) * lfg, 1, 12); repeat(hfg, 1, 4)];
Fs = 8000; # Частота дискретизации 8 кГц
N = 800; # Длительность тональности 100 мс
t = [0:N-1;] ./ Fs; # 800 дискретов на Fs
pit = t * 2 * pi;
tones = zeros(N, length(symbols));
Filling in tonalities¶
for i = 1:length(symbols)
if symbols[i] == "1"
tones[:, i] = sum(sin.(f[:, 1] * pit'), dims=1)'
elseif symbols[i] == "2"
tones[:, i] = sum(sin.(f[:, 2] * pit'), dims=1)'
elseif symbols[i] == "3"
tones[:, i] = sum(sin.(f[:, 3] * pit'), dims=1)'
elseif symbols[i] == "4"
tones[:, i] = sum(sin.(f[:, 4] * pit'), dims=1)'
elseif symbols[i] == "5"
tones[:, i] = sum(sin.(f[:, 5] * pit'), dims=1)'
elseif symbols[i] == "6"
tones[:, i] = sum(sin.(f[:, 6] * pit'), dims=1)'
elseif symbols[i] == "7"
tones[:, i] = sum(sin.(f[:, 7] * pit'), dims=1)'
elseif symbols[i] == "8"
tones[:, i] = sum(sin.(f[:, 8] * pit'), dims=1)'
elseif symbols[i] == "9"
tones[:, i] = sum(sin.(f[:, 9] * pit'), dims=1)'
elseif symbols[i] == "*"
tones[:, i] = sum(sin.(f[:, 10] * pit'), dims=1)'
elseif symbols[i] == "0"
tones[:, i] = sum(sin.(f[:, 11] * pit'), dims=1)'
elseif symbols[i] == "#"
tones[:, i] = sum(sin.(f[:, 12] * pit'), dims=1)'
end
end
Specifies pauses between tones.
N8::Int64 = N / 8
tones = [tones; 0.05 * randn(N8, length(symbols))];
tones = [0.05 * randn(N8, 1); tones[:]];
Analysing the results¶
Let's plot the graph of the signal.
N = length(tones);
t = [0:N-1;] / Fs;
plot(1e3 * t, tones, xlabel="Время, мс", ylabel="Амплитуда", title="DTMF сигнал")
Plotting a graph of the spectrum.
The spectrum is plotted using the fast Fourier transform.
Spec = 10 * log10.(abs.(fftshift(fft(tones)) ./ 1000) .^ 2);
freqs = fftshift(fftfreq(length(t), Fs))
plot(freqs, Spec, xlim=(650, 1500), xticks=650:100:1500, xlabel="Частота, Гц", ylabel="Мощьность, дБ", title="Спектр DTMF сигнала")
From the presented graphs it is difficult to clearly understand what was the original set of symbols. For more convenient representation, let's build a spectrogram of the original signal.
spgr = DSP.spectrogram(tones[:,1], 255, 128; fs = Fs); # Создание спектрограммы исходного DTMF сигнала
Plots.heatmap(spgr.time.*1000, spgr.freq, pow2db.(spgr.power), xguide = "Время, мс", yguide = "Частота, Гц",ylim =(500, 1500), yticks=650:100:1500)
From the spectrogram it follows that the set of symbols was: 5,0,8.
Conclusion¶
By the end of the development of this example you have been shown the possibilities of implementing a tone generator in Engee, as well as the possibilities of visualising modulated signals to perform a convenient analysis of these signals.