mapping.m

来自「国外大学的同志作出来的好程序」· M 代码 · 共 42 行

M
42
字号
function output=mapping(info, constell, priority_type);
%Mapping maps info into two dimensional constellations.
%priority_type sets the Most Signficant Bit.
%
if nargin<2 | nargin>3,
    disp('[Mapping]Number of inputs should be 2 or 3.');
    return;
end
if nargin==2 | (nargin==3 && isempty(priority_type)),
    priority_type='msb_first';
end

if size(constell,1)>1 & size(constell, 2)>1,
    disp('[Mapping]Error: Only two dimensional constellations are supported.');
    return;
end
constell_rate=log2(length(constell));
if strcmp(lower(priority_type), 'msb_first');
    mapping_radix=2.^[constell_rate-1:-1:0];
elseif strcmp(lower(priority_type), 'lsb_first');
    mapping_radix=2.^[0: constell_rate-1];
else
    disp('[Mapping]Error: Wrong priority type!');
    return;
end

%pad info with some zeros if needed.
tval=mod(size(info, 1), constell_rate);
if tval~=0,
    info=[info; zeros(constell_rate-tval, size(info, 2))];
end

%modulation
mapping_blknum=size(info, 1)/constell_rate;
output=zeros(mapping_blknum, size(info, 2));
for ic=1: mapping_blknum,
    currentInputVec=info((ic-1)*constell_rate+1: ic*constell_rate, :);
    currentInput=mapping_radix*currentInputVec;
    output(ic, :)=constell(currentInput+1);
end

⌨️ 快捷键说明

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