function [RL,med]=DBNR(an_root)
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
if nargin<1, an_root='RL'; end
%
view_global
%
D=dir(['*',an_root,'_AN*.mat']);
nfile=length(D);
for jfile=1:nfile,
    disp(['File ',int2str(jfile),': ',D(jfile).name]);
end
iif=str2num(input('Enter file numbers to process: ','s'));
D=D(iif);
%
tmin1=4; tmin2=14;
nfile=length(D);
for jfile=1:nfile,
	filename=D(jfile).name;
% Load _AN.mat file:
    eval(['load ',filename]);
    ncf=AN.dims(1);
% Median over phone number:
    RL(jfile).DB=data_avg(AN,[2],{[1] [] [] []},[4],0,0);
    RL(jfile).N=data_avg(AN,[2,1],{[2:ncf]' [] [] []},[4,1],0,0);
    RL(jfile).DBNR=RL(jfile).DB; 
    RL(jfile).DBNR.data=RL(jfile).DB.data - RL(jfile).N.data;
    RL(jfile).DBNR.dlab='DB-Noise Ratio - dB';
    RL(jfile).DBNR.clim=[floor(min(RL(jfile).DBNR.data(:))/5)*5, ceil(max(RL(jfile).DBNR.data(:))/5)*5];
    RL(jfile).DBNR.vdims=[1 3 2]; RL(jfile).DBNR.ii_img=-1; RL(jfile).DBNR.size=[-10/3,1.5];
    view5(RL(jfile).DBNR,[],0)
% Save figure number for overlaying line plots:
    fig_no(jfile)=gcf;
% Compute Median DBNR During Up Times:
    RL(jfile).DBNR.MED=data_avg(RL(jfile).DBNR,3,[],4,0,0),
    med(:,jfile)=[RL(jfile).DBNR.MED.data];
    RLN=RL(jfile);
    eval(['save ',D(jfile).name(1:end-7),'_RLN RLN']);
end
disp('Median over time = '),
disp(num2str(med,3));
% Overlay line plots;
ovlay(fig_no);
