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

📄 wfill.m

📁 两个灌水算法仿真程序。欢迎大家下载
💻 M
字号:
function wline=wfill(vec, pcon, tol)
%   WFILL: The Water Filling algorithm.
%   WLINE = WFILL(VEC, PCON, TOL) performs the water filling algorithm 
%   with the given total power constrain to approach Shannon capacity 
%   of the channel. 
%   The water filling algorithm is based on an interative procedure, so the tolerance
%   must be assigned to determine the end-of-loop.
%   
%   VEC is a noise absolute or relative level in LINEAR units at different frequencies, 
%   space or whatever bins. PCON is a total power constrain given in the same units as the VEC.
%   TOL is an acceptable tolerance in the units of VEC.
%   WLINE indicates the WATERLINE level in units of VEC so that: 
%
%                       abs(PCON-SUM(MAX(WLINE-VEC, 0)))<=TOL
%   
%   The algorithm is built such a way that PCON>=SUM(MAX(WLINE-VEC, 0)) and never 
%   PCON<SUM(MAX(WLINE-VEC, 0)).
%
%   VEC must be a row vector representing a noise level. PCON and TOL must be scalars in 
%   the same units as VEC.

%   Example:
%   
%   Input: VEC=[1 3 5 4]
%          PCON=7
%          TOL=1e-5
%
%   Output: WLINE=5
%
%   The function doesn't check the formats of VEC, PCON and TOL, as well as a number of the
%   input and output parameters.
%
% Author: G. Levin, May, 2003
%
% References:
%   T. M. Cover and J. A. Thomas, "Elements of Information Theory", John Wiley & Sons,
%   Inc, 1991.

N=length(vec);

%first step of water filling
wline=min(vec)+pcon/N; %initial waterline
ptot=sum(max(wline-vec,0)); %total power for current waterline
 
%gradual water filling
while abs(pcon-ptot)>tol
    wline=wline+(pcon-ptot)/N;
    ptot=sum(max(wline-vec,0));
end
%st=cputime;        % 程序开始运行时的cpu时间
% 程序开始

% 程序结束
%et=cputime-st      % 计算程序运行所用的时间


⌨️ 快捷键说明

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