1 function [bits,bits_] = symb2bits(symb,M,bitorder)
3 if ~isvector(symb) || ~isa(symb,'uint16')
4 error('Input must be a vector (scalar) of type uint16.');
8 if nargin<2 || isempty(M) % M is not specified
9 log2M_ = nextpow2(symb_range.max);
13 if symb_range.min<1 || symb_range.max>M
14 error('Value out of range. Symbols must be in range 1:%d.',M);
18 bitorder = 'lsb-first'; % if bitorder not specified, assume LSB is first
20 lut = logical(arrayfun(@(x)x-48,dec2bin(0:M-1)))'; % LUT for converting decimal to binary LSB first
21 if strcmpi(bitorder,'lsb-first')
23 elseif ~strcmpi(bitorder,'msb-first')
24 % If order is not 'msb-first' at this point, bitorder is neither of two
25 % available options => throw an error.
26 error('Bit order can be set to ''lsb-first'' (default) or ''msb-first''.');
29 bits = false(log2M_,numel(symb));
30 for i=max(2,symb_range.min):symb_range.max
31 idx = symb==i; % Find indices for all symbols i
32 bits(:,idx) = repmat(lut(:,i),1,nnz(idx)); % Take value from the LUT
function findrange(in x)
Finds min-max range of a vector/matrix.