scrambler.m

来自「802.15 dsss 物理协议层方针代码」· M 代码 · 共 68 行

M
68
字号
function scrambler_out=scrambler(si,input )
%scrambler
%A scrambler is employed to support clock recovery, it is used for the MAC
%header and frame body
%PRBS generator is: g(D)=1+D14+D15
%
% Arguments: si - seed identifier
%       seed identifier         seed value
%       0,0                         1111 1111 1111 111
%       0,1                         0111 0000 1111 111
%       1,0                         0111 1111 0000 000
%       1,1                         0111 1000 0000 111
%                      input - input data
%       input data should be 15 bits
%
%Author: Liu Hantao
%
%==============================================================
%check the input arguments
if (nargin ~= 2) 
    error('incorrect number of input arguments - two expected')
end
%check the length of input data
%zerp padding to make sure n is integer
l=length(input);
if rem(length(input),15) > 0
    input=[input,zeros(size(1:15-rem(length(input),15)))];
end
n=length(input)/15;
%==============================================================
%determine the initialization sequence from the seed identifier
switch si
    case 00
        init=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
    case 01
        init=[0 1 1 1 0 0 0 0 1 1 1 1 1 1 1];
    case 10
        init=[0 1 1 1 1 1 1 1 0 0 0 0 0 0 0];
    case 11
        init=[0 1 1 1 1 0 0 0 0 0 0 0 1 1 1];
    otherwise
        error('unknown or improper seed identifier')
end
%==============================================================
%scramble the input date
% Jin modified here====================
% for i=0:n-1
%     for j=1:15
%         %modulo-2 addition to the 14th and 15th of the shift registers
%         x=xor(init(14),init(15));
%         %obtain the scrambled input data bit
%         s=xor(input(15*i+j),x);
%         scrambler_out(15*i+j)=s;
%         %realize the function of shift registers
%         init=[s,init(1:14)];
%     end
% end
% to here==============================

for i=1:15
    x(i)=xor(init(14),init(15));
    init=[ x(i) init(1:14)];
end
for j=1:n
scrambler_out_temp((j-1)*15+1:j*15)=xor(x,input((j-1)*15+1:j*15));
end
scrambler_out=scrambler_out_temp(1:l);

⌨️ 快捷键说明

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