modulation.m

来自「很好的OFDM的基于MATLAB的仿真程序包」· M 代码 · 共 46 行

M
46
字号
function y = modulation(x,b,e)

% x is input bits, in the form of row vector
% y is modulated output, in the form of row vector
% b is the subcarrier bit allocation, b(i) is the number of bits allocated to ith subcarrier 
% e is the subcarrier energy allocation, same size as b

% ------- modulation.m -------------------------------------
% Black team
% April-11-05
% ----------------------------------------------------------

% load the modulation sheme
% Eb = 1 in every .mat file
load bpsk.mat;
load qpsk.mat;
load 16qam.mat;
load 64qam.mat;
load 256qam.mat;

y=[];

b2 = zeros(1,length(b));
b2(1)=1;

for i = 1:length(b)
    b2(i+1) = b(i) + b2(i);
end

for i = 1:length(b)
    switch b(i)
        case{1}
            y = [y p2( x(b2(i)) + 1 ) * sqrt(e(i))];      % *e(i)??? energy. how to set? or sqrt(e(i))
        case{2}
            y = [y p4( bi2de( [x( b2(i) : (b2(i+1)-1) )],'left-msb') + 1) * sqrt(e(i))];
        case{4}
            y = [y p16( bi2de( [x( b2(i) : (b2(i+1)-1) )],'left-msb') + 1) * sqrt(e(i))];
        case{6}
            y = [y p64( bi2de( [x( b2(i) : (b2(i+1)-1) )],'left-msb') + 1) * sqrt(e(i))];      
        case{8}
            y = [y p256( bi2de( [x( b2(i) : (b2(i+1)-1) )],'left-msb') + 1) * sqrt(e(i))];
        otherwise
            y =[y 0];
    end
end

⌨️ 快捷键说明

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