function cb = crmucb( gmin, gmax, mu, cbsize )
% function cb = crmucb( gmin, gmax, mu, cbsize )
%
% Create gain codebook for gain-shape vector quantization
% according to mu-function y = sign(x) * ( log(1+mu*abs(x)) / log(1+mu) )
%
% gmin:   minimim gain
% gmax:   maximum gain  
% mu:     mu 
% cbsize: codebook size
%  
% Author:  Markus Hauenstein
% Date:    32.01.2002 
% Contact: www.markus-hauenstein.de

% helper variables
l = log(1+mu);
k = 1/l;
m = 1/mu;

% compand gmin & gmax
ymin = sign(gmin) * k * log( 1+mu*abs(gmin) );  
ymax = sign(gmax) * k * log( 1+mu*abs(gmax) );  

% linear interpolation between ymin and ymax
y = [ymin : (ymax-ymin)/(cbsize-1) : ymax];

% expand y
cb = sign(y).*(m*(exp(l*sign(y).*y)-1));

