% file: compute_noise_levels.m
%
% this functions computes the nominal noise level and the nominal signal+noise
% level
%
% arguments:
%  energy_cdf		array of the energy's cdf values
%  per_a		lower percentile
%  per_b		higher percentile
%  bins			number of bins in cdf
%
% return:
%  noise		nominal noise level
%  noise_sig		nominal signal+noise level
%

function [noise, noise_sig] = compute_noise_levels(energy,energy_cdf,per_a,per_b,bins)

% calculate the cdf values for the specified percentiles
%
temp_a = energy_cdf(bins) * per_a;
temp_b = energy_cdf(bins) * per_b;

a = energy_cdf <= temp_a;
bin_a = sum(a)+1;

a = energy_cdf <= temp_b;
bin_b = sum(a)+1;

% find the bins containing the percentiles specified
%
%for i=1:bins
%   if ( energy_cdf(i) > temp_a )
%      bin_a = i;
%      break;
%   end
%end
%for i=1:bins
%   if ( energy_cdf(i) > temp_b )
%      bin_b = i;
%      break;
%   end
%end

% compute the values of the nominal noise level 
% and the nominal signal+noise level
%
noise = (((max(energy)/bins)*bin_a) + ((max(energy)/bins)*(bin_a-1)))/2;
noise_sig = (((max(energy)/bins)*bin_b) + ((max(energy)/bins)*(bin_b-1)))/2;
