% Plot Fourier transform of finite-duration DTMF signals.
% 
% ELEC 470, R. Kozick, Spring 1998

T = 0.5;       % DTMF signal duration, in seconds
A = 1;         % Amplitude of each cosine signal

dtmfr = [697, 770, 852, 941];  % DTMF row frequencies in Hz
dtmfc = [1209, 1336, 1477];    % DTMF column frequencies in Hz

f = 0:1:2000;

% Generate Fourier transform of each finite-duration cosine

Gr1 = (A*T/2)*( sinc(T*(f-dtmfr(1))) + sinc(T*(f+dtmfr(1))) );
Gr2 = (A*T/2)*( sinc(T*(f-dtmfr(2))) + sinc(T*(f+dtmfr(2))) );
Gr3 = (A*T/2)*( sinc(T*(f-dtmfr(3))) + sinc(T*(f+dtmfr(3))) );
Gr4 = (A*T/2)*( sinc(T*(f-dtmfr(4))) + sinc(T*(f+dtmfr(4))) );

Gc1 = (A*T/2)*( sinc(T*(f-dtmfc(1))) + sinc(T*(f+dtmfc(1))) );
Gc2 = (A*T/2)*( sinc(T*(f-dtmfc(2))) + sinc(T*(f+dtmfc(2))) );
Gc3 = (A*T/2)*( sinc(T*(f-dtmfc(3))) + sinc(T*(f+dtmfc(3))) );

% Generate the Fourier transform of the 12 DTMF signals

G1 = Gr1 + Gc1;
G2 = Gr1 + Gc2;
G3 = Gr1 + Gc3;
G4 = Gr2 + Gc1;
G5 = Gr2 + Gc2;
G6 = Gr2 + Gc3;
G7 = Gr3 + Gc1;
G8 = Gr3 + Gc2;
G9 = Gr3 + Gc3;
Ga = Gr4 + Gc1;
G0 = Gr4 + Gc2;
Gb = Gr4 + Gc3;

% Plot one of the Fourier transforms -- the amplitude is plotted.

X = G4;       % Choose which DTMF spectrum to plot

figure(1)
plot(f, abs(X))
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Amplitude Spectrum')
