I found this code on quantization on page 314 in the book Modern Digital and Analog Communication Systems by B.P.Lathi and Zhi Ding. I can understand only half of the code. Please, someone, help in explaining the code.
function [q_out, Delta] = uniquan(sig_in, L) % L = number of uniform quantization levels % sig_in - input signal vector % Function Output % q_out - quantized output % Delta - quantization interval sig_pmax = max(sig_in); % finding the positive peak sig_nmax = min(sig_in); % finding the negative peak Delta = (sig_pmax - sig_nmax)/L; % quantization interval q_level = sig_nmax + Delta/2 : Delta : sig_pmax - Delta/2; %defining q-levels % Till here I understand the code. I am not able to understand from here. % Mainly not able to understand what is sigp doing sigp = (sig_in - sig_nmax)/Delta + 1/2; % convert into 1/2 to L+1/2 range qindex = round(sigp); % round to 1,2,3..... L levels qindex = min(qindex,L); % Eliminate L+1 as rare possibility q_out = q_level(qindex); % use index vector to generate output end