function Conc_Channel = Macro_Code_Decoder(x,u,n,k,M,T,Channel)
u1 = mod(u,x); % u = u0x + u1;
u0 = (u - u1)/x;
if u0+1 == M-u0;
    n1 = x/2 - u1;
else
    n1 = x - u1; % n = 2n1 + (M-2u0-2)x = Mx - 2u;
end

preChannel = zeros(1,M*T);
postChannel = zeros(1,M*T+M-mod(length(Channel),M));
Conc_Channel = [preChannel Channel postChannel];
delays = zeros(1,length(Conc_Channel));
n_Erasures = 0;
u_Erasures = 0;
p_Available = 0;
k_Available = 0;

for index = T+1:length(Conc_Channel)/M;
    Current_Macro = Conc_Channel((index-1)*M+1:index*M);
    current_u_Erasures = x*sum(Current_Macro(1:u0)) + u1*Current_Macro(u0+1);
    current_n_Erasures = x*sum(Current_Macro(u0+2:M-u0-1)) + n1*Current_Macro(u0+1) + n1*Current_Macro(M-u0);
    current_k_Available = k*(M-sum(Current_Macro));
    if sum(Current_Macro) == 0;
        if n_Erasures == 0;
        else
            Available_ps = Current_Macro(M-u0:M);
            corresponding_us = fliplr(Conc_Channel((index-T-1)*M+1:(index-T-1)*M+u0+1));
            p_Available = p_Available + sum((-or(Available_ps,corresponding_us)+1).*[u1 x*ones(1,u0)]);
        end
        if u_Erasures == 0;
        else
            k_Available = k_Available + current_k_Available;
        end
    else
        n_Erasures = n_Erasures + current_n_Erasures;
        u_Erasures = u_Erasures + current_u_Erasures;
        Available_ps = Current_Macro(M-u0:M);
        corresponding_us = fliplr(Conc_Channel((index-T-1)*M+1:(index-T-1)*M+u0+1));
        p_Available = p_Available + sum((-or(Available_ps,corresponding_us)+1).*[u1 x*ones(1,u0)]);
        k_Available = k_Available + current_k_Available;
    end
    if p_Available >= n_Erasures;
        p_Available = 0;
        n_Erasures = 0;
        %Conc_Channel((index-T-1)*M+1:(index-T-1)*M+M) = -(sum(fliplr(Current_Macro(M-u0:M)))==0)+1;
        if Current_Macro(M-u0:M) == 0;
            Conc_Channel((index-T-1)*M+1:(index-T-1)*M+M) = 0;
        end
    end
    if k_Available >= u_Erasures;
        delays(Conc_Channel(1:index*M) == 1) = index - ceil(find(Conc_Channel(1:index*M) == 1)/M);
    end
end
Conc_Channel = Conc_Channel(length(preChannel)+1:length(Conc_Channel)-length(postChannel));