%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generate the dial tone for the digit 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fs = 44100;    % sampling frequency

freqA =  770;  % the first frequency
freqB = 1336;  % the second frequency

% Create time interval from 0 to 2 seconds
t = 0 : 1/fs : 2;
	
% Calculate the two waves and add them
waveA = sin(2 * pi * freqA * t);
waveB = sin(2 * pi * freqB * t);
	
waveSum = (waveA + waveB) / 2;
    
% Play it on the speakers 
sound(waveSum, fs);
pause(3)

% Save it to a .WAV file
audiowrite('touch-tone-5.wav',  waveSum, fs);

% Plot the wave
figure;  plot(1:1000, waveSum(1:1000));
xlabel('Sample number (only the first 1000)');
ylabel('Amplitude');
title('The dial tone wave for the digit 5');

% Plot the sampled wave
figure;  plot(1:1000, waveSum(1:1000));
hold on; plot(1:1000, waveSum(1:1000), 'r.');
xlabel('Sample number (only the first 1000)');
ylabel('Amplitude');
title('The sampled dial tone wave for the digit 5');

% Plot waveA
figure;  plot(1:1000, waveA(1:1000));
xlabel('Sample number (only the first 1000)');
ylabel('Amplitude');
title('The first requency at 770 Hz for the digit 5');

% Plot waveB
figure;  plot(1:1000, waveB(1:1000));
xlabel('Sample number (only the first 1000)');
ylabel('Amplitude');
title('The second requency at 1336 Hz for the digit 5');
