www.pudn.com > mimo_ofdm.rar > ResolvetheLastBit.m, change:2004-11-20,size:1006b


function  [bits_alloc, energy_alloc] = ResolvetheLastBit(bits_alloc,energy_alloc,index,energytable,num_subc)

max_val = 0;

for i = 1:num_subc
    if (i ~= index & bits_alloc(i) == 1)
        if bits_alloc(i) ~= 0
            temp = energytable(i,bits_alloc(i)) ;   
        end
        if (temp > max_val)
            max_val = temp;
            max_ind = i;
        end
    end
end

min_val = Inf;
for i = 1:num_subc
    if (i~= index & bits_alloc(i) == 1)
        if bits_alloc(i) ~=0
            temp = energytable(i,bits_alloc(i) + 1);
        end
        if (temp  min_val)
            min_val = temp;
            min_ind = i;
        end
    end
end

if (min_val  max_val)
    bits_alloc(min_ind) = bits_alloc(min_ind) + 1;
    bits_alloc(index) = bits_alloc(index) - 1;
    energy_alloc(index) = energy_alloc(index) - min_val;
else
    bits_alloc(max_ind) = bits_alloc(max_ind) - 1;
    bits_alloc(index) = bits_alloc(index) + 1;
    energy_alloc(index) = energy_alloc(index) + max_val;
end