⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 campello_algo.m

📁 code for signal Processing in OFDM calculation.
💻 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) bits
if total_bits > M*num_subc
    total_bits = M*num_subc;
end

while (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
    
end

for 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);
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -