function teleNum = findNumber(v)
% Deciphers telephone call signal v

Fs = 32768;

% Determine the segmentation points
plot(v)
title('Click on the x-values that separate button pushes. Press Enter.',...
'fontsize', 12)
[x,y] = ginput;
x = floor(x);
x = [1; x; length(v)];

teleNum = [];
for k=1:length(x)-1
% Process the k-th segment...
y = v(x(k):x(k+1));
N = length(y);
% Perform a Fourier analysis...
f = (0:N-1)*Fs/N;
p = abs(fft(y));
% Use ginput to identify the two "spikes"...
plot(f,p)
title(sprintf('Digit %d. Click on the two spikes.', k))
axis([500 1700 0 800])
[omega,z] = ginput(2);
omega = sort(omega);
% omega(1) is the smaller frequency. What is closest row value?
[m, row] = min( abs([ 697 770 852 941]-omega(1)));
% omega(2) is the larger frequency. What is closest column value?
[m, col] = min( abs([1209 1336 1477]-omega(2)));
if row==4
teleNum = [teleNum 0];
else
teleNum = [teleNum col+3*(row-1)];
end
end

close % close figure window