function numbers = dtmf_decode(signal,display)


if ~exist('display','var') | isempty('display')
    display = 1;
end

% Sampling frequency
fs = 8192;

% The DTMF frequencies we are interested in
frqs = [ 697 770 852 941 1209 1336 1477 ];


% L is a vector of impulse response lengths for the filters
%   with center frequency given in frqs
L = [ ? ? ? ? ? ? ? ];

% G is a vector of center frequency gains for each bandpass filter
G = [ ? ? ? ? ? ? ? ];

% h_smooth is the impulse response of the post-rectifier
%   smoothing filter
h_smooth = ?

% threshold is the cutoff for deciding whether or not a signal
%   is present; defined as the fraction of the maximum value
threshold = ?


% Initialize the filter bank vector
filtered = [];

for i=1:length(frqs)
    % 'h' is the impulse response for our filter
    h = cos(2*pi*frqs(i)*(0:L(i)-1)'/fs)/G(i);
    
    % 'filtered' is the signal filtered by h
    filtered = [filtered filter(h,1,signal)];

end

% 'rectified' is the rectified filter
rectified = abs(filtered);
  
% 'smoothed' is the final output of the filter bank
smoothed = filter(h_smooth,1,rectified);
    

% Downsample the signal by some factor
factr = 100;
sm = smoothed(1:factr:end,:);


% Find the frames during which there appears to be no signal
signal_absent = find(max(sm,[],2) < threshold);


% Find the two bigest smoothed signals in each frame, and
%   recombine them into an estimated key press for each frame
[x,ind] = sort(sm,2);
number_select = [0 3 6 9 1 2 3];
number_select = number_select(ind);
numbers = sum(number_select(:,end-1:end),2);


% When the signal is absent, we'll assign a "null" key number
numbers(signal_absent) = -1;

% If a frame is the same as the one right before it, discard
numbers(1+find(diff(numbers) == 0)) = [];

% Get rid of "null" key numbers
numbers(numbers == -1) = [];


if display

    % Display a useful plot
    
    leg = {'697'; '770'; '852'; '941'; '1209'; '1336'; '1477'};
    t = (1:size(filtered,1))/fs;
    
    plot(t,smoothed);
    xlabel('Time'); ylabel('Amplitude')
    title('Rectified and Smoothed Filter Bank Outputs');
    legend(leg,0);
    hold on;
    plot(t([1 end]),[1 1]*threshold,'k:');
    hold off;

end
