Zigbee Transceiver

This MATLAB source code covers zigbee transceiver matlab code. It mentions zigbee transmitter code. The reverse to be carry out for zigbee matlab receiver part.

Figure depicts simple Zigbee transceiver internal modules. Data from MAC is fed to the zigbee PHY part and the baseband(PHY) is interfaced with RF tranceiver using DAC/ADC.

zigbee transceiver

There are two different zigbee physical layers one designed for 868/915MHz and the other for 2450MHz frequency band. Refer Zigbee Physical layers for more. We will see zigbee matlab code for 2450 MHz frequency band. As shown in the figure, zigbee PHY consists of CRC module which adds redundancy to zigbee mac payload, bits to symbol conversion, symbol to chip conversion and OQPSK modulator. SImulation of half sine wave pulse shaping is not carried out in the matlab code.

Zigbee Matlab code-Transmitter part

% Data_gen = randint(1,10,255)
% D=dec2bin(Data_gen);
% D= reshape(D,1,80);
%% 8 bit CRC calculation
% D1=[D zeros(1,8)];
% crc_val=HCS(D);
% crc_bin=dec2bin(crc_val,8);
% D2=[D1(1:80) crc_bin];
% B1=reshape(D2,11,8);
%Binary number generator for 88 bits
bits_in=[];
for i=1:88
num=round(rand(1));
bits_in=[bits_in num];
end

%%Arranging 1 x 88 into 11 x 8 matrix form for bits to symbol conversion
bits_in1=[];
for i = 1:length(bits_in)/8
b1=bits_in( (((8*i)-8)+1):(8*i) );
bits_in1(i,:)=b1;
end

%% bits to symbol conversion nibble wise
bits_in1=num2str(bits_in1);
bits_in1=bin2dec(bits_in1);

sym_out=[];
for i=1:11
n1=bitand(bits_in1(i),15,'uint8');
n2=bitand(bitshift(bits_in1(i),-4),15,'uint8');
sym_out=[sym_out n1 n2];
end

%%Chip Table for mapping symbol(decimal from 0 to 15) to chips(32bit)
tab=['11011001110000110101001000101110'; ...
'11101101100111000011010100100010'; ...
'00101110110110011100001101010010'; ...
'00100010111011011001110000110101'; ...
'01010010001011101101100111000011'; ...
'00110101001000101110110110011100'; ...
'11000011010100100010111011011001'; ...
'10011100001101010010001011101101'; ...
'10001100100101100000011101111011'; ...
'10111000110010010110000001110111'; ...
'01111011100011001001011000000111'; ...
'01110111101110001100100101100000'; ...
'00000111011110111000110010010110'; ...
'01100000011101111011100011001001';...
'10010110000001110111101110001100'; ...
'11001001011000000111011110111000'];

%Symbol to Chip conversion
chip_out=[];

for i=1:22
sym_in=sym_out(i);
chip_out=[chip_out tab(sym_in+1,1:32)];
end

chip_in = chip_out;

mapped_in=[str2num(chip_in(:))]';

%%Could not able to introduce half bit delay in matlab so introducing 1 bit
%%delay
% mapped_in1=mapped_in;
% for i =2:2:704
% mapped_in1(i+2) = mapped_in(i);
% end
% mapped_in1(2)=0;

mapped_in1=mapped_in;

% %%QPSK IMPLEMENTATION
% mapper_out=mapping(mapped_in',2,0.707);
% plot(real(mapper_out),imag(mapper_out),'*r');

%%OQPSK IMPLEMENTATION
mapper_out=mapping(mapped_in1',2,0.707);
plot(real(mapper_out),imag(mapper_out),'*r');

data_td = ifft(mapper_out); %converting frequency domain data to time domain before up conversion
plot(abs(data_td));

fc=1e3; %1KHz RF Carrier Say
Fs=10e3; % 10 KHz sampling frequency
t=0:1/Fs:352*1e-4; %time scale..
t=t(2:end); % making no. of samples equal to size of data
data_td=data_td.';
data_td_uc=data_td'.*exp(j*2*pi*fc*t); % upconverting baseband to 1KHz
data_fd = fft(data_td_uc); % converting back to frequency domain for plotting purpose
%data_fd=fliplr(data_fd);
pwelch(real(data_fd),[],[],[],Fs,'twosided');


Half bit delay is not implemented in the matlab code, instead 1 bit delay is shown. The same can be implemented in zigbee vhdl code or verilog code while implementing for FPGA hardware as needed. Zigbee matlab code for receiver part is reverse of the modules mentioned above. It will have OQPSK demodulator, chip to symbol conversion and symbol to bit conversion.

Zigbee Resources

what is zigbee   Zigbee network architecture basics   Zigbee Protocol Stack   Zigbee Physical layers   Zigbee physical layer frame   Zigbee MAC layer frames   Zigbee frequency bands   Zigbee Compliance Test 

Useful Links to MATLAB codes

Refer following links to download MATLAB codes as needed.
OFDM Preamble generation
channel estimation
SC-FDMA
PN sequence generation
OFDMA Tx Rx
carrier aggregation
CRC8 CRC32

RF and Wireless tutorials

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