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

📄 waterfill.asv

📁 很好的OFDM的基于MATLAB的仿真程序包
💻 ASV
字号:
function [gn,bn,en,Nuse,btot] = waterfill(H,Ex_bar,Ntot,gap,Noise_var)

% Pn is the channel pulse response
% Ex_bar is the normalized energy
% Ntot is the total number of subchannels
% gap is the gap in dB
% Noise_var is the variance of the noise
%
% gn is subchannel gain
% en is the energy in the nth subchannel
% bn is the bit in the nth subchannel
% Nuse is the number of subchannel used
% btot is the bit rate

% ------- waterfill.m --------------------------------------
% Black team
% April-12-05
% ----------------------------------------------------------

% dB into normal scale
gap = 10^(gap/10);

% initialization
en = zeros(1,Ntot);
bn = zeros(1,Ntot);
gn = zeros(1,Ntot);

% find gn for multitone
norm = norm(
noise_sub = Noise_var / ;
gn = (abs(H).^2 )./ Noise_var;

% Now do waterfilling 

%sort
[gn_sorted, Index] = sort(gn);     % sort gain, and get Index

gn_sorted = fliplr(gn_sorted);  % flip left/right to get the largest first
Index = fliplr(Index);        

num_zero_gn = length(find(gn_sorted == 0));  % number of zero gain subchannels
Nuse = Ntot - num_zero_gn;    	% Number of used channels, Ntot - (number of zero gain subchannels)

while(1) 
 	K = 1 / Nuse * (Ntot * Ex_bar + gap * sum(1./gn_sorted(1:Nuse))); 
 	En_min = K - gap / gn_sorted(Nuse);	% En_min occurs in the worst channel
 	if (En_min < 0)		
    		Nuse = Nuse - 1;  % If negative En, continue with less channels
 	else 
    		break;       % If all En positive, done.
 	end
end

En = K - gap./gn_sorted(1:Nuse); 		        
Bn = .5 * log2(K * gn_sorted(1:Nuse) / gap); 	

bn(Index(1:Nuse)) = round(Bn);		% return values in original index
en(Index(1:Nuse)) = En;		

for i = 1:Ntot
    if (bn(i) > 8)
        bn(i) = 8;
    elseif (mod(bn(i),2) ~= 0 & bn(i) ~= 1)
        bn(i) = bn(i) - 1;
    elseif (bn(i)< 1)
        bn(i) = 0;
    end
end

% calculate bitrate
btot = sum(bn);

⌨️ 快捷键说明

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