📄 dtmf_gen.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dtmf_gen.m - This program generates all the coefficients of IIR
% for DTMF tone generator
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all
% low freq group: fL = 697, 770, 852, 941 Hz
fL = [697 770 852 941];
% High freq group: fH = 1209, 1336, 1477, 1633 Hz
fH = [1209 1336 1477 1633];
% Coefficients for numerator
b0 = 0;
b1_fl = sin(2*pi*fL(1:4)/8000);
b1_fh = sin(2*pi*fH(1:4)/8000);
b2= 0;
b0_v = zeros(1,8);
b1_v = [b1_fl b1_fh];
b2_v = zeros(1,8);
b_v = [b0_v; b1_v; b2_v];
% Coefficients for denomerator
a0 = 1;
a1_fl = -2.*cos(2*pi*fL(1:4)/8000);
a1_fh = -2.*cos(2*pi*fH(1:4)/8000);
a2 = 1;
a0_v = ones(1,8);
a1_v = [a1_fl a1_fh];
a2_v = 1.*ones(1,8);
a_v = [a0_v; a1_v; a2_v];
% Select the keypad
key = [ '1' '2' '3' 'A'; '4' '5' '6' 'B'; '7' '8' '9' 'C'; '*' '0' '#' 'D'];
% User input a key
R = input('Key in the touch pad: ','s');
[i,j]= find(R == key);
while i == [ ];
disp('Wrong Key!!');
R = input('Key in the touch pad: ','s');
[i,j]= find(R == key);
end
% Display the key pressed
b1_first = b1_fl(i); a1_first = a1_fl(i);
b1_second = b1_fh(j); a1_second = a1_fh(j);
figure;
freqz([b0 b1_first b2], [a0 a1_first a2]); hold on;
freqz([b0 b1_second b2], [a0 a1_second a2]);
title('Frequency response of tone');
% Sound output (50 msec tone)
[H1,T] = impz([b0 b1_first b2], [a0 a1_first a2],400,8000);
[H2,T] = impz([b0 b1_second b2], [a0 a1_second a2],400,8000);
HT = H1+H2;
soundsc(HT);
figure; plot(T,HT); title('Impulse response of 50 msec tone');
figure; psd(HT); title('Power spectrum density of tone');
save tx_data_5 HT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -