Scrambler design not working

7 visualizaciones (últimos 30 días)
RGR
RGR el 26 de Nov. de 2012
Hi i have code for a randomizer/scrambler & de-randomizer/de-scrambler but I am getting weird results as I tried simply preforming modulus 2 addition (XOR) with my polynomial but once I de-scramble it 3 bits seem to be wrong. To generate my 2 byte input sequence I just used seq=rand(1,16); seq=seq>0.5; scrambled=scrambler(seq) descrambled=descrambler(scrambled)
For me its always showing errors in the first 8 bits and the rest are fine, I don't know if this is a result of the process im using or just a coincidence.
% Scrambler: used to prevent spectral lines from forming in bit if true
% Sequence.
% Input:
% data: Bit sequence (2 bytes long)
% poly: randomizer polynomial (set to 16 bit as defualt)
% taps= 16,15,13,4 (defualt)
% Output: 2 byte (16 bit) scrambled binary sequence
function scrambled=scrambler(varargin)
% Defualt polynomial=[16 15 0 13 0 0 0 0 0 0 0 0 4 0 0 0];
if isempty(varargin)
fprintf('Please enter Input');
end
data=varargin{1};
if (length(varargin)>1)
polyn=varargin(2);
end
if (length(varargin)==1|isempty(polyn))
polyn=[1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0];
end
D=data'; % To use circshift we need a vector.
for i=1:length(data) % all the data 1 circulation through LFSR
if (i~=1) % Dont rotate vector on 1st try
data=circshift(data,1);
end
last=length(data);
% XOR Operations based on randomizer polynomial
for j=1: length(D)
if (polyn(j)==1&&j>1)
D(i)=xor(D(i),D(last));
last=j;
end
end
end
scrambled=D';
end
% Descrambler: used to de-randomize the binary sequence.
function descrambled=descrambler(varargin)
% Defualt polynomial=[16 15 0 13 0 0 0 0 0 0 0 0 4 0 0 0];
if isempty(varargin)
fprintf('Please enter Input');
end
scrambled=varargin{1};
if (length(varargin)>1)
polyn=varargin(2);
end
if (length(varargin)==1|isempty(polyn))
polyn=[1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0];
end
D=scrambled'; % To use circshift we need a vector.
for i=1:length(scrambled) % all the data 1 circulation through LFSR
if (i~=1) % Dont rotate vector on 1st try
scrambled=circshift(scrambled,1);
end
last=length(scrambled);
% XNOR Operations based on randomizer polynomial
for j=1: length(D)
if (polyn(j)==1&&j>1)
D(i)=~xor(D(i),D(last));
last=j;
end
end
end
descrambled=D';
end

Respuesta aceptada

RGR
RGR el 9 de Abr. de 2013
I forget what the solution was but I made a new scrambler which works code below:
if true
% code
% Scrambler: used to prevent spectral lines from forming in bit
% Sequence. [0 0 1 1] LFSR
function scrambled=scrambler(data)
% Initialize variables:
scrambled=[];
count=1;
% Set r1 and r2 initial values:
r1=0;r2=0;
% Cycle the data through the registers:
for i=1:length(data) % all the data 1 circulation through LFSR
% First two registers Pass all the data:
if (count==1)
r1=data(i);
result=r1;
end
if (count==2)
r2=data(i);
result=r2;
end
% Last two registers scramble data by xoring them
% with value of first two registers:
if (count==3)
r3=data(i);
result=xor(r3,r1);
end
if (count==4)
r4=data(i);
result=xor(r4,r2);
end
% Fill data in accumulator array:
scrambled=[scrambled result];
% Reset Counter:
if (count==4)
count=1;
else
count=count+1;
end
end
end

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by