From: Asel Kosmurzina on
Hi, i took a msk code from www.dsplog.com and tried to modify it to test the ieee 802.15.4. There are several links on that site for ieee 802.15.4. Currently I am getting simulated ber results all approximately same for all the cases of Eb_No values. Can you help me to find why? thanks in advance!

clear

PN = [
1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0;
1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 0;
0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0;
0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1;
0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1;
0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 0;
1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 1;
1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 1;
1 0 0 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1;
1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1;
0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1;
0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0;
0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 1 1 0;
0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1;
1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0;
1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0;
];

N = 5*10^5; % number of bits or symbols

fsHz = 1; % sampling period
T = 4; % symbol duration

Eb_N0_dB = [0:10]; % multiple Eb/N0 values

ct = cos(pi*[-T:N*T-1]/(2*T));
st = sin(pi*[-T:N*T-1]/(2*T));

for ii = 1:length(Eb_N0_dB)
tx = [];

% MSK Transmitter
ipBit = round(rand(1,N/32)*15);

for k=1:length(ipBit)
sym = ipBit(k);
tx = [tx PN((sym+1),1:end)];
end

ipMod = 2*tx - 1; % BPSK modulation 0 -> -1, 1 -> 1

ai = kron(ipMod(1:2:end),ones(1,2*T)); % even bits
aq = kron(ipMod(2:2:end),ones(1,2*T)); % odd bits

ai = [ai zeros(1,T) ]; % padding with zero to make the matrix dimension match
aq = [zeros(1,T) aq ]; % adding delay of T for Q-arm

% MSK transmit waveform
xt = 1/sqrt(T)*[ai.*ct + j*aq.*st];

% Additive White Gaussian Noise
nt = 1/sqrt(2)*[randn(1,N*T+T) + j*randn(1,N*T+T)]; % white gaussian noise, 0dB variance

% Noise addition
yt = xt + 10^(-Eb_N0_dB(ii)/20)*nt; % additive white gaussian noise

% MSK receiver
% multiplying with cosine and sine waveforms
xE = conv(real(yt).*ct,ones(1,2*T));
xO = conv(imag(yt).*st,ones(1,2*T));

bHat = zeros(1,N);
bHat(1:2:end) = xE(2*T+1:2*T:end-2*T); % even bits
bHat(2:2:end) = xO(3*T+1:2*T:end-T); % odd bits

result=zeros(16,1);
chiplen=32;
seqstart=1;
recovered = [];

while(seqstart<length(bHat))
A = bHat(seqstart:seqstart+(chiplen-1));
for j=1:16
B = PN(j,1:end);
result(j)=sum(A.*B);
end

[value,index] = max(result);
recovered = [recovered (index-1)];
seqstart = seqstart+chiplen;
end;


%# create binary string - the 4 forces at least 4 bits
bstr1 = dec2bin(ipBit,4);
bstr2 = dec2bin(recovered,4);

%# convert back to numbers (reshape so that zeros are preserved)
out1 = str2num(reshape(bstr1',[],1))';
out2 = str2num(reshape(bstr2',[],1))';

% counting the errors
nErr(ii) = size(find([out1 - out2]),2);
end

nErr/(length(ipBit)*4) % simulated ber
theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))) % theoretical ber
 | 
Pages: 1
Prev: calling library dll question
Next: cell