
function [Bit_index_rx_para,Con_rx_para] = Detector_LLR_QIM(Subblock_rx,M,N,K,Nsym,G,Pn_f)
  
%% Index map generation using combinatorial number theory 
Nc = nchoosek(N,K); % number of combinations
bi = floor(log2(Nc)); % number of bits carried by index selection

V = (0:N-1)';
C = nchoosek(V,K);
CC = C + 1;

Index_map = CC(1:2^bi,:);
Decimal_map = 0:(2^bi-1);

%% Constellation set for different M
Con_decimal = 0:(M-1);
S = pammod(Con_decimal,M,0,'gray');

%% Calculate LLR value
LLR_value = zeros(G*Nsym,N);
temp = zeros(G*Nsym,N);

for g = 1:G*Nsym
    for i = 1:N
        for j = 1:M
            temp(g,i) = temp(g,i) + ...
                     exp(- abs(Subblock_rx(g,i) - S(j))^2/Pn_f*2);
        end
        
        LLR_value(g,i) = log(K/(N-K)) + abs(Subblock_rx(g,i))^2/Pn_f*2 + log(temp(g,i));
    end
end

%% Find the index information
[V,I] = sort(LLR_value,2);
Index_rx = sort(I(:,(N-K+1):N),2);

%% Index and constellaton extraction
Decimal_index_rx = zeros(G*Nsym,1);
Con_rx_para = zeros(G*Nsym,K);

for i = 1:G*Nsym
    for j = 1:2^bi
        if Index_rx(i,:) == Index_map(j,:);
            Decimal_index_rx(i) = Decimal_map(j);
            Con_rx_para(i,:) = Subblock_rx(i,Index_map(j,:));
        end
    end
end

Bit_index_rx_para = de2bi(Decimal_index_rx,'left-msb');

