|
ADVERTISEMENT

|
|
% This Program
is (C) of Abhishek Mitra, B.Tech 3rd Yr 2002
am@i...
%
5.5 Mbps CCK Simulation using specs from IEEE 802.11b, No
guarantees
and warrantees!
%The
first Symbol in time = symbol number zero (even)
clear;
clc;
%phase
information for even symbol phases used in DQPSK
pe(1,1)=0;
% d0d1 =00
pe(1,2)=pi/2;
%d0d1 =01
pe(1,4)=pi;
%d0d1 = 11
pe(1,3)=3*pi/2;
%d0d1 =10
%phase
information for odd symbol phases used in DQPSK
po(1,1)=pi;
%d0d1 = 00
po(1,2)=3*pi/2;
%d0d1 = 01
po(1,4)=0;
%d0d1 = 11
po(1,3)=pi/2;
%d0d1 = 10
%len
= number of nibbles
len=2;
%select
'len' number of nibbles and fill in random bits in 'data'
data=randint(1,len*4);
%initially
before any data transmission DQPSK phase = 0
p1=0;
samples=4000;
%generate
linear spaced x axis
x=linspace(0,2*pi,samples);
%generate
carrier @ 220cps, (2.4GHz carrier, 11M chips / sec) or 11/8
=
1.375 Msymbols /sec
%220
cps cosine (I) and sine (Q) carriers
s=sin(220*x);
c=cos(220*x);
%I
matrix stores Inphase waveforms
I=[];
%initialize I
%Q
matrix stores Quadrature phase waveforms
Q=[];
%initialize Q
%loop
to find out the CCK codes for each nibble according to IEEE
802.11b
specs
%for
5.5Mbps data rate 'd0d1d2d3' = nibble, d0 = LSB, d3= MSB
%p1,p2,p3,p4
are the four phase parameters to generate CCK codes
%p1
rotates the whole CCK vector (code) by a given amount
%p2
rotates all odd code chips
%p3
rotates all odd pairs of code chips
%p4
rotates all all quads of code chips
%d3,d4
are two bits which are sent by selecting one of the four CCK
code
symbols
%Two
more bits d0,d1 are sent by QPSK modulating the whole code
symbol.
for
n=1:len %n counts the current nibble
nibble=data(4*(n-1)+1:4*n);
%select the nth nibble
d0=nibble(1);
%store the bits LSB first in d0 thru d3
d1=nibble(2);
d2=nibble(3);
d3=nibble(4);
%take
d0 and d1
d01=bin2dec(dec2base(2*d0,2))+bin2dec(dec2base(d1,2));
%convert
d01 to decimal equivalent and choose the initial DQPSK
phase
from the odd / even
%symbol
phase tables as stored in lines 8-11 and 13-16
%These
have been taken from the IEEE standard
if
mod(n-1,2) == 1 %check odd / even symbol(nibble)
p1=po(1,d01+1)+p1;
%if odd, new phase1(?1) = old phase1(?1) +
DQPSK
rotation (looked up from the table 'po')
if
p1>2*pi
p1=p1-2*pi;
end;
else
p1=pe(1,d01+1)+p1;
%if even, new phase1(?1) = old phase1(?1)
+
DQPSK rotation (looked up from the table 'pe')
if
p1>2*pi
p1=p1-2*pi;
end;
end;
p1;
p2=(d2*pi)+pi/2;%determine
p2
p3=0;%p3
kept 0 throughout for 5.5Mb/s
p4=d3*pi;
%determine p4
%calculate
the 'nth' CCK symbol (8 complex chips according to
the
equation given in the IEEE 802.11b standard)
code(n,:)=[exp(j*(p1+p2+p3+p4)),exp(j*(p1+p3+p4)),exp(j*
(p1+p2+p4)),-exp(j*(p1+p4)),exp(j*(p1+p2+p3)),exp(j*(p1+p3)),-exp(j*
(p1+p2)),exp(j*p1)].*exp(j*pi/4);
%code1(n,:)=[exp(j*(p1+p2+p3+p4)),exp(j*(p1+p3+p4)),exp(j*
(p1+p2+p4)),-exp(j*(p1+p4)),exp(j*(p1+p2+p3)),exp(j*(p1+p3)),-exp(j*
(p1+p2)),exp(j*p1)];
%the
code word is rotated by pi/4 (45 deg.) so that
constellation
%points
do not fall on the axes but are between the axes!
for
t=1:8
Re=real(code(n,t));%Real
part of the chip (1 to 8)
Im=imag(code(n,t));%Imaginary
part of the chip (1 to 8)
I=horzcat(I,Re*c);%generate
I carrier, by appending the
appropriate
waveform calculated from phase information from the chip
in
question
Q=horzcat(Q,Im*s);%generate
Q carrier by appending the
appropriate
waveform
%
'c' vector is Cosine carrier (I), 's'vector = Sine
Carrier
(Q)
end;
end;
%
plot I and Q after all sending all the CCK symbols
%subplot(2,1,1);
%plot(I);
%subplot(2,1,2);
%plot(Q);
%Tx
= transmitted waveform, add I and Q
Tx=I+Q;
%plot(Tx);
%Sent
to Medium
%Rx
= Tx;
Rx=AWGN(Tx,-15);
% Noise Channel SNR = -10dbB
%
Receiver Section Starts
%Rx
= received waveform
%figure;
%plot(Rx);
%figure;
%init
Tc
Tc=[];
%Tc
stores the Cosine waveform of duration of carrier
for
t=1:8*len %generate number of points as that of carrier
waveform
%len
is number of nibbles
Tc=horzcat(Tc,c);
% Tc is cosine, 'c' vector is cosine @ 224 cps
end;
RxI=Rx.*Tc;
%mixing Received waveform and cosine(Tc) to Obtain I
Channel
subplot(2,1,1);
plot(RxI);%
I component obtained in RxI
%Init
Ts
Ts=[];
%Ts
stores the Sine waveform of duration of carrier
%generate
number of points as that of carrier waveform
for
t=1:8*len %len is number of nibbles
Ts=horzcat(Ts,s);
% T is sine, s is sine @ 224 cps
end;
subplot(2,1,2);
RxQ=Rx.*Ts;
%mixing Received waveform and sine (Ts)
Ts=[];
Tc=[];
plot(RxQ);%
Q component obtained in RxQ
%
Third order FIR low pass filter
alpha=0.998;%
filter coeff
beta
= 0.0001; % filter coeff
gamma
= 0.000001; % filter coeff
LRxQ=zeros(1,size(RxQ,2));
% LRxQ = Received (Q channel), filtered
LRxI=zeros(1,size(RxI,2));
% LRxI = Received (I channel), filtered
for
t=4:size(RxQ,2)
LRxQ(t)=LRxQ(t-1)*alpha
+ RxQ(t) + LRxQ(t-2)*beta + LRxQ(t-3)
*gamma;
%low pass filtering(Integrating numerically) 3rd order FIR
LRxI(t)=LRxI(t-1)*alpha+
RxI(t) + LRxI(t-2)*beta + LRxI(t-3)
*gamma;
%low pass filtering(Integrating numerically) 3rd order FIR
end;
figure;
subplot(2,1,1);
LRxI=LRxI/10;
% Amplitude Normalization
LRxQ=LRxQ/10;
plot(LRxI);
%plot low pass filtered I channel waveform
subplot(2,1,2);
plot(LRxQ);
%plot low pass filtered Q channel waveform
new_phase=[];
step
= samples; %for detection of binary '1' or '0'
start
= samples/2; %start at the first bit of I / Q channel data
high_data=5;
% detection threshold
low_data=-5;
% detection threshold
j=1;
k=1;
c=sin(pi/4);
% reusing variable c
for
t=start:step:size(LRxI,2)-start %move through complete waveform
and
detect '0' or '1'
if
LRxI(t)>high_data
tempI(j)=c;
%store the values in variable tempI
elseif
LRxI(t)<low_data
tempI(j)=c*-1;
end;
j=j+1;
end;
t=0;
j=1;
for
t=start:step:size(LRxQ,2)-start
if
LRxQ(t)>high_data
tempQ(j)=c*i;
elseif
LRxQ(t)<low_data
tempQ(j)=c*-i;
end;
j=j+1;
end;
code;
clear
j;
clear
i;
rxcode=(tempI+tempQ)*exp(-j*pi/4);
% de rotate by pi/4 rxcode stores
the
received chips
rxcode=round(rxcode);
%rounding off
cck_code(1,:)=[j
1 j -1 j 1 -j 1]; %the CCK codes
cck_code(2,:)=[-j
-1 -j 1 j 1 -j 1];
cck_code(3,:)=[-j
1 -j -1 -j 1 j 1];
cck_code(4,:)=[j
-1 j 1 -j 1 j 1];
rxdata=[];
%free
flag_ninety=0;
symb=0;
even_symb_flag=0;%if
the symbol is even numbered
odd_symb_flag=0;%if
the symbol is odd numbered
ref_phase=0;
%phase after processing previous symbol
delta_phase=[];
for
n=1:8:size(rxcode,2)
cck_test=(rxcode(n:n+7))
%cck_test contains the 8 chips for a
symbol
if
mod(symb,2)==1 %This is an odd symbol
cck_test=cck_test*exp(-j*pi)
%forming one of the four the
complementary
codes
odd_symb_flag=1
%assert odd symbol flag
even_symb_flag=0;
else
odd_symb_flag=0;
even_symb_flag=1
%assert even symbol flag
end;
if
round(imag(cck_test(1)))==0
cck_test=cck_test*exp(j*3*pi/2)
%forming one of the four the
complementary
codes
flag_ninety=1;
%because the symbol has an additional phase
shift
by pi/2
end;
cc1=round(crosscorr(cck_test,cck_code(1,:),1))
%cross correlation
to
find bits, d3d4
cc2=round(crosscorr(cck_test,cck_code(2,:),1))
%cross correlation
to
find bits, d3d4
cc3=round(crosscorr(cck_test,cck_code(3,:),1))
%cross correlation
to
find bits, d3d4
cc4=round(crosscorr(cck_test,cck_code(4,:),1))
%cross correlation
to
find bits, d3d4
cc1=cc1(2);cc2=cc2(2);cc3=cc3(2);cc4=cc4(2);
%take the
coefficient
with lag = 0
if
flag_ninety==1
if
cc1==1 | cc2==1 | cc3==1 | cc4==1
new_phase=pi/2;
%quadrature phase of current symbol
end;
if
cc1==-1 | cc2==-1 | cc3==-1 | cc4==-1
new_phase=3*pi/2;
%quadrature phase of current symbol
end;
elseif
flag_ninety==0
if
cc1==1 | cc2==1 | cc3==1 | cc4==1
new_phase=2*pi;
%quadrature phase of current symbol
end;
if
cc1==-1 | cc2==-1 | cc3==-1 | cc4==-1
new_phase=pi;
%quadrature phase of current symbol
end;
end;
if
mod(symb,2)==1 %new phase is the phase of the quad demod for
the
current symbol
new_phase=new_phase+pi;
%to compensate for extra rotation of
odd
numbered symbols
end;
if
new_phase >= 2*pi
new_phase=new_phase-2*pi;
%normalize phase angles between 0
and
2*pi
end;
new_phase
%ref_phase
stores the phase of the demod. after the last symbol
was
%processed.
if
new_phase == 0 & ref_phase == pi/2 | new_phase == pi/2 &
ref_phase
== pi | new_phase == pi & ref_phase == 3*pi/2
delta_phase
= 3*pi/2; % cases where phase shift is 3*pi/2
elseif
new_phase == 0 & ref_phase == 3*pi/2
delta_phase
= pi/2; % a case where phase shift is pi/2
else
delta_phase=new_phase-ref_phase;
%rest of the cases
end;
delta_phase
= abs(delta_phase); %only +ve value of phase shift
if
delta_phase >= 2*pi
delta_phase=delta_phase-2*pi;%normalize
phase angles between
0
and 2*pi
end;
%decoding
bits d0,d1 of the nibble by method given in page 44 of
IEEE
specs.
if
even_symb_flag == 1
if
delta_phase == 0
rxdata=horzcat(rxdata,[0
0]);
end;
if
delta_phase == pi/2
rxdata=horzcat(rxdata,[0
1]);
end;
if
delta_phase == pi
rxdata=horzcat(rxdata,[1
1]);
end;
if
delta_phase == 3*pi/2
rxdata=horzcat(rxdata,[1
0]);
end;
end;
if
odd_symb_flag ==1
if
delta_phase == pi
rxdata=horzcat(rxdata,[0
0])
end;
if
delta_phase == 3*pi/2
rxdata=horzcat(rxdata,[0
1])
end;
if
delta_phase == 0
rxdata=horzcat(rxdata,[1
1])
end;
if
delta_phase == pi/2
rxdata=horzcat(rxdata,[1
0])
end;
end;
%
decoding bits d3,d4 by method tabulated in page 45 of IEEE specs
%
if correlation coeff. for the corresponding Complementary Key = 1
then
%
select the appropriate di-bits
if
cc1==1 | cc1==-1
rxdata=horzcat(rxdata,[0
0])
elseif
cc2==1 | cc2==-1
rxdata=horzcat(rxdata,[0
1])
elseif
cc3==1 | cc3==-1
rxdata=horzcat(rxdata,[1
0])
elseif
cc4==1 | cc4==-1
rxdata=horzcat(rxdata,[1
1])
end;
ref_phase=new_phase;
%reference phase for the next symbol.
flag_ninety=0;
%reset flag for pi/2 phase shift
symb=symb+1;
%increment symbol counter
end;
rxdata
data
error
= sum(abs(rxdata-data))%calculate errors
|