?? campello_algo.m
字號:
% campello_algo.m% --------------% This function is used by Campello's algorithm to allocate bits and energy for % each subchannel optimally.function [bits_alloc, energy_alloc] = campello_algo(bits_alloc,energy_alloc,energytable,total_bits,num_subc,M) bt = sum(bits_alloc);% We can't transmit more than M*(Number of subchannel) bitsif total_bits > M*num_subc total_bits = M*num_subc;endwhile (bt ~= total_bits) if (bt > total_bits) max_val = 0; max_ind = ceil(rand(1)*num_subc); for i = 1:num_subc if bits_alloc(i) ~= 0 temp = energytable(i,bits_alloc(i)) ; else temp = 0; end if (temp > max_val) max_val = temp; max_ind = i; end end if (bits_alloc(max_ind) > 0) bits_alloc(max_ind) = bits_alloc(max_ind) -1; energy_alloc(max_ind) = energy_alloc(max_ind) - max_val; bt = bt-1; end else min_val = Inf; min_ind = ceil(rand(1)*num_subc); for i = 1:num_subc if bits_alloc(i) ~=0 & bits_alloc(i) <9 temp = energytable(i,bits_alloc(i) + 1); else temp = Inf; end if (temp < min_val) min_val = temp; min_ind = i; end end if (bits_alloc(min_ind) < 8) bits_alloc(min_ind) = bits_alloc(min_ind) +1; if (min_val==inf) min_val = energytable(min_ind,bits_alloc(min_ind)); end energy_alloc(min_ind) = energy_alloc(min_ind) +min_val; bt = bt+1; end end endfor i = 1:length(bits_alloc) if (mod(bits_alloc(i),2) == 1 & bits_alloc(i) ~=1) [bits_alloc,energy_alloc] = ResolvetheLastBit(bits_alloc,energy_alloc,i,energytable,num_subc); endend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -