AUDSPACE - Auditory scale points specified by bandwidth

Program code:

function [y,n] = audspacebw(scale,flow,fhigh,bw,hitme)

%   AUTHOR : Peter L. Soendergaard

% ------ Checking of input parameters ---------

error(nargchk(3,5,nargin));

% Default parameters
if nargin<5
  hitme=-1;
end;

if nargin<4
  bw=1;
end;

if ~isnumeric(flow) || ~isscalar(flow) || flow<0
  error('%s: flow must be a non-negative scalar.',upper(mfilename));
end;

if ~isnumeric(fhigh) || ~isscalar(fhigh) || fhigh<0
  error('%s: fhigh must be a non-negative scalar.',upper(mfilename));
end;

if ~isnumeric(bw) || ~isscalar(bw) || bw<=0
  error('%s: bw must be a positive scalar.',upper(mfilename));
end;

if ~isnumeric(hitme) || ~isscalar(hitme)
  error('%s: hitme must be a scalar.',upper(mfilename));
end;

if flow>fhigh
  error('%s: flow must be less than or equal to fhigh.',upper(mfilename));
end;

if nargin==4 && hitme>=0
  if (hitmefhigh)
    error('%s: hitme must be in the interval from flow to fhigh.',upper(mfilename));
  end;
end;

% ------ Computation --------------------------

if hitme<0
  % Convert the frequency limits to auds.
  audlimits = freqtoaud(scale,[flow,fhigh]);
  audrange  = audlimits(2)-audlimits(1);

  % Calculate number of points, excluding final point
  n         = floor(audrange/bw);

  % The remainder is calculated in order to center the points
  % correctly between flow and fhigh.
  remainder = audrange-n*bw;

  audpoints = audlimits(1)+(0:n)*bw+remainder/2;

  % Add the final point
  n=n+1;

else
  % Convert the frequency limits to auds.
  audlimits    = freqtoaud(scale,[flow,fhigh,hitme]);
  audrangelow  = audlimits(3)-audlimits(1);
  audrangehigh = audlimits(2)-audlimits(3);

  % Calculate number of points, exluding final point.
  nlow = floor(audrangelow/bw);
  nhigh = floor(audrangehigh/bw);

  audpoints=(-nlow:nhigh)*bw+audlimits(3);
  n=nlow+nhigh+1;
end;

y = audtofreq(scale,audpoints);