Scrambler/Descrambler in 802.11 standard
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
Im trying to implement 802.11 scrambler/descrambler in matlab. Based on the standard, it should look sth like this:
My code looks like this:
data=zeros(1,7); %data
register=[1 0 1 1 1 0 1]; %initial state
for i=1:7
temp=xor(register(1),register(4)); % x7 and x4 xor
out(8-i,1)=xor(data(8-i,1),temp); %output bit
register=circshift(register',-1,1)'; %shift left
register(7)=data(8-i,1); %insert data to register
end
When im trying to descramble data, with same code and same initial state it gives wrong results.
What am i doing wrong??
Is there any way to guess or estimate initial state at the receiver side??
It is correct to sim this using comm. toolbox?
scr = comm.Scrambler(2, [0 -4 -7],...
[1 0 1 1 1 0 1]);
Best, Ernest
0 Kommentare
Antworten (4)
Recalist
am 17 Jul. 2015
Bearbeitet: Recalist
am 18 Jul. 2015
Hey,
I wrote some code for this which works. It is probably not the best, but perhaps okay for you.
This is how my scrambler/descrambler looks like:
function output_bits = scrambler_and_descrambler(input_bits, initial_state)
states = initial_state; %BE AWARE! example: [0 1 1 0 1 0 0] -> [MSB ... LSB] that means... [state7 ... state1]
for n=1:length(input_bits)
save_state_4 = states(4);
save_state_7 = states(7);
output_bits(n) = xor(input_bits(n),xor(states(4),states(7)));
states = circshift(states',1)';
states(1)= xor(save_state_4,save_state_7);
end
end
If you need a function that automatically finds the initial state out of a scrambeled bit-sequence you can use the following one: INFO: "service_field_bits_0_to_6" this are the first 7 Bits of you scrambeled bit-squence!
function initial_state_scramber = find_initial_state_scrambler(service_field_bits_0_to_6)
scrambler_states = [0 0 0 0 1 1 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1];
%added the last 7 Bits of scrambler_states to the front of the array.. so its more easy to evaluate the initial_state_scramber if the service_field_bits_0_to_6 are found at a position < 7 of the original scrambler_states bit-sequence
scrambler_states_extended = [1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1];
for n = 1:1:length(scrambler_states)-length(service_field_bits_0_to_6)
temp=0;
for m = 1:1:length(service_field_bits_0_to_6)
temp = temp + xor(scrambler_states(n+m-1),service_field_bits_0_to_6(m));
end
if (temp == 0)
pos=n;
end
end
initial_state_scramber = fliplr(scrambler_states_extended(pos:pos+6)); %Fliplr! very important to change LSB and MSB
end
And to test it all I wrote a little simulation:
bit_sequence = randi(2,1,40)-1; % generates random bit-sequence
bit_sequence(1:7) = zeros(1,7); % set first 7 bits to zero! (needed to retrieve the initial state of scrambler if your descrambler gets the scrambeled bits)
initial_states = [1 1 1 0 0 0 0]; % just some 7 bits as initial states..could also use randi(2,1,7)-1
scrambeled_bit_sequence = scrambler_and_descrambler(bit_sequence,initial_states);
retrieve_initial_state_out_of_scrambeled_bit_sequence =find_initial_state_scrambler(scrambeled_bit_sequence(1:7));
descrambeled_bit_sequence = scrambler_and_descrambler(scrambeled_bit_sequence,retrieve_initial_state_out_of_scrambeled_bit_sequence);
sum((descrambeled_bit_sequence - bit_sequence)~=0) % ans=0 means the bits were descrambeled correctly
0 Kommentare
HANS
am 18 Jun. 2018
Bearbeitet: Walter Roberson
am 20 Jun. 2018
Hi,
thank you and I appreciated for the response. There are some questions related to 'find_initial_state_scrambler' function.
1)
If it is written to have random 'scrambler_states' then there are some problems I guess. The input and descrambled sequence has errors w.r.t. almost half of the 'bit_sequence' parameter. Please could you look at below and please could you run the all code w/ below lines.
%
scrambler_states = [randi([0,1],1,2^numel(service_field_bits_0_to_6)-1)];
scrambler_states_extended = [scrambler_states(end-numel(service_field_bits_0_to_6)+1:end) scrambler_states];
2) It possible may happen that there may be no 'pos' parameter because of 'temp' not equals to 0 in that case I did below in a while loop
if ~exist('pos')
scrambler_states = [randi([0,1],1,2^numel(service_field_bits_0_to_6)-1)];
scrambler_states_extended = [scrambler_states(end-numel(service_field_bits_0_to_6)+1:end) scrambler_states];
end
but if 'pos' parameter has two values what can I do ? (for instance xor ing them ??=
Thx,
WR
0 Kommentare
Rich Simeon
am 8 Dez. 2023
The comm.Scrambler documentation was updated recently to address this issue. Please refer to Additive Scrambling of Input Data to give a thorough explanation and sample code on how an 802.11 scrambler can be implemented.
The comm.Scrambler System object implements multiplicative scrambling, whereas the 802.11 standard implements additive scrambling. Thus, the comm.Scrambler code snippet that was supplied in the question will not work. Multiplicative and additive scrambling are two different methods for implementing scrambling from a polynomial.
To implement additive scrambling, the comm.PNSequence System object should be used instead. The documentation provides sample code to implement the 802.11 scrambler as you have described using comm.PNSequence instead of comm.Scrambler. Please note that the Communications Toolbox will be needed to use this System object.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!