Scrambler and descrambler MATLAB source code

This section of MATLAB source code covers scrambler or randomizer matlab code. De-scrambler matlab code is provided to validate the scrambler.

scrambler circuit

Scrambler often referred as randomizer basically removes long stream of o's and 1's from the data. It is used in wireless transmitter and receiver chain. It is part of layer-1 or physical layer. Circuit on the left is the one most often used as scrambler circuit and is specified in IEEE wireless standards viz. wimax,wlan etc. we will see how we can develop matlab code for this circuit on this page.


Scrambler MATLAB Code

Scrambler_input=[80 255 16 9 48 255 80 0 25 0 145]
s=20255; %Initialization of scrambler circuit
rand_data=zeros(size(Scrambler_input));
for j=1:size(Scrambler_input,2);
for i=1:8
msb=bitxor(bitget(s,1),bitget(s,2));
s=bitshift(s,-1);
s=bitset(s,15,msb);
t=bitxor(bitget(Scrambler_input(j),9-i),msb);
rand_data(j)=bitset(rand_data(j),9-i,t);
end
end
scrambler_out=rand_data

Descrambler MATLAB Code

s=20255; %Initialization of de-scrambler circuit
descrambler_in=zeros(size(scrambler_out));
for j=1:size(scrambler_out,2);
for i=1:8
msb=bitxor(bitget(s,1),bitget(s,2));
s=bitshift(s,-1);
s=bitset(s,15,msb);
t=bitxor(bitget(scrambler_out(j),9-i),msb);
descrambler_in(j)=bitset(descrambler_in(j),9-i,t);
end
end
descrambler_out=descrambler_in

OUTPUT in the MATLAB Window

scrambler descrambler matlab code output

Useful Links to MATLAB codes

Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation  Time off estimation corr  Freq off estimation corr  channel estimation  11a WLAN channel  PN sequence generation  OFDMA Tx Rx  AES DES  carrier aggregation  CCDF  FIR Filter  IIR Filter  Low Pass FIR  Viterbi decoder  CRC8 CRC32 

RF and Wireless tutorials

WLAN  802.11ac  802.11ad  wimax  Zigbee  z-wave  GSM  LTE  UMTS  Bluetooth  UWB  IoT  satellite  Antenna  RADAR