⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generator.m

📁 Goertzel算法是DTMF信号检测的核心
💻 M
字号:
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);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -