function [Smoothed, Frq, Df]=specsmoo4wave(SS,DD)

%*****************************************************
% Smooths spectra.
% [Smoothed, Frq]=specsmooth(SS,DD)
%
% Inputs:  SS is the spectrum to be smoothed
%          DD is the sampling rate
% Outputs: Smoothed is the smoothed spectrum
%          Frq is the frequency of smoothed points
%******************************************************

% Larger Rdi yields fewer points in the smoothed spectrum
% Rdi = .2;      % 31 points output from 4097 input
% Rdi = .175;    % 35 points output from 4097 input
% Rdi = .15;     % 41 points output from 4097 input
% Rdi = .125;    % 47 points output from 4097 input
% Rdi = .123;    % 49 points output from 4097 input
% Rdi = .118;    % 50 points output from 4097 input
Rdi = .05;       % 78 points output from 2048 input

SS = SS(2:end); % skip F=0

jj = 1;   % bin counter
Mj = 1;   % marker to point # at start of bin
Di = 0;   % # points in bin
ii = 0;   % point counter

Slength = length(SS);
Dfx = DD/(Slength*2);   % spectrum delta F

while ii<Slength;       % halt loop at last point
   if ii == Slength;
      break;
   end;
   % compute # points in bin
   Di = round(Rdi*(Mj+Di));  % nonlinear bin width
   Smoothed(jj) = 0;
   for ii = Mj:Mj+Di;
      if ii==Slength;
         break;
      end;
      Smoothed(jj) = Smoothed(jj) + SS(ii);
   end;
   Smoothed(jj) = Smoothed(jj)./(Di+1);
   Frq(jj) = (Mj+Di/2)*Dfx; % bin centroid frequency
   Df(jj) = (Di+1)*Dfx;     % delta f for this bin
   Mj = Mj+Di+1;       % increment lower bin edge to next new point
   jj = jj+1;          % increment bin counter
end;
Smoothed = Smoothed(1:length(Frq)-1);
Df = Df(1:length(Frq)-1);
Frq = Frq(1:length(Frq)-1);
