function hq = fir_coeff_quantizer(h,N,M)
% function hq = fir_coeff_quantizer(h,N,M)
% by DRB 10-Nov-2008
% h = unquantized (ideal) filter coefficients
% N = number of total bits including sign bit (signed integer assumed)
% M = number of fractional bits


% scale coefficeints so we can do integer quantization
hscaled = h*2^M;

% check for saturation
% upper limit
UL = 2^(N-1)-1;
i1 = find(hscaled>UL);
hscaled(i1) = UL;
% lower limit
LL = -2^(N-1);
i2 = find(hscaled<LL);
hscaled(i2) = LL;

% now scale coefficients back down to fractional interpretation
hq = round(hscaled)/(2^M);
