function v = makeCall(teleNum,buttonDuration,a,b,noiseVal)
% Simulate the calling of a phone number teleNum.
% Generate a signal for teleNum, which is a vector of integers in [0..9].
% Thus, [1 6 0 7 1 2 3 4 5 6 7] encodes a call to 1-607-123-4567.
% The tone for a given button push will last buttonDuration seconds.
% The gap (in seconds) between button pushes is randomly
% selected from the interval [a,b].
% The "true" signal is contaminated with noise at the level of
% noiseVal*randn noise.

% Sampling rate. This many numbers/sec in the digital signal:
Fs = 32768;

% The touchpad frequencies for the rows...
fR = [ 697 770 852 941];

% The touchpad frequencies for the columns...
fC = [ 1209 1336 1477];

k = length(teleNum);

% Silence for a RANDOM number of seconds at the start...
nSec= rand*0.1;
v = zeros(1,floor(Fs*nSec));

% Process each number
for j=1:k

% Sample times for the k-th button push. RANDOM element.
t = 0:(1/Fs):(rand+0.5)*buttonDuration;

% "Add in" the signal for the k-th button push..
[row,col] = findButton(teleNum(j));
y = (sin(2*pi*fR(row)*t) + sin(2*pi*fC(col)*t) )/2;
v = [v y];

% The in-between button gap...
gap = zeros(1,floor( Fs*(a+(b-a)*rand) ) );
v = [v gap];
end

% Contaminate the whole signal with noise...
L = length(v);
v = v + noiseVal*randn(1,L);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [row,col] = findButton(i)
% Determines the row and column indices of the button for digit i
if i==0
row = 4; col = 2;
else
row = ceil(i/3);
col = i-3*(row-1);
end