Scrambler design not working
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spectral Measurements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!