?? generator.m
字號(hào):
function [dtmf_output,Num_of_samples,SNR] = generator(dial_num,Num_of_samples,NoisePow)
%
% Function to generate the DTMF signals
%
% Author: Pranam Janney Date: 15/05/04 Time: 17:50
% Email: pranamjanney@yahoo.com
%
% Usage:
% [dtmf_output,Num_of samples] = generator(dial_num,Num_of_samples,NoisePow);
% Inputs:
% dial_num = Number that is dialled
% Num_of_samples = Number of samples
% NoisePow = Noise power used to corrupt the signal
% Outputs:
% dtmf_output = the combination of two sinesoids corresponding to the
% number dialled
% Num_of_samples = Number of samples
% SNR = Signal to Noise Ratio
%
%
Fs = 8000; % Sampling frequency
Ts = 1/Fs;
T = Ts*(0:Num_of_samples-1)';
switch dial_num
case 0
F1 = 941;
F2 = 1336;
case 1
F1 = 697;
F2 = 1209;
case 2
F1 = 697;
F2 = 1336;
case 3
F1 = 697;
F2 = 1477;
case 'A'
F1 = 697;
F2 = 1633;
case 4
F1 = 770;
F2 = 1209;
case 5
F1 = 770;
F2 = 1336;
case 6
F1 = 770;
F2 = 1477;
case 'B'
F1 = 770;
F2 = 1633;
case 7
F1 = 852;
F2 = 1209;
case 8
F1 = 852;
F2 = 1336;
case 9
F1 = 852;
F2 = 1477;
case 'C'
F1 = 852;
F2 = 1633;
case '*'
F1 = 941;
F2 = 1209;
case '#'
F1 = 941;
F2 = 1477;
otherwise
F1 = 941;
F2 = 1633;
end;
first_sine = cos(2*pi*F1*T); % first sinusoidal signal
second_sine = cos(2*pi*F2*T); % second sinusoidal signal
%dtmf_output = first_sine + second_sine;
d = first_sine + second_sine;
%%% Adding noise to the generated DTMF output
% NoisePow has to be below 5 for getting the correct decode output
dtmf_output = d + NoisePow * rand(size(d));
% Generating Tones
sound(dtmf_output);
% Signal to Noise Ratio
if NoisePow == 0
SNR = 0;
else
SNR = 10 * log10(sum(d - dtmf_output) .^ 2) / sum (dtmf_output .^ 2);
end
% figure(1);
% title('THE DTMF OUTPUT');
% plot(dtmf_output);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -