zigbee and BER not redused when increase SNR

4 views (last 30 days)
maadh
maadh on 13 Apr 2013
I have this program .in the simulation, the bit error rate not reduce when increase SNR as the figure . i used 16 PN instead 32 bit, in future i want to make adaptive data rate according to SNR and BER .please any one can help me. the program is % Modulation, Demodulation %**********************PseudoNoise Table***********************************
PN= [0 0 1 1 1 1 1 0 0 0 1 0 0 1 0 1; 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 1; 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 0; 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0; 0 0 1 0 0 1 0 1 0 0 1 1 1 1 1 0; 1 0 0 0 1 0 0 1 0 1 0 0 1 1 1 1; 1 1 1 0 0 0 1 0 0 1 0 1 0 0 1 1; 1 1 1 1 1 0 0 0 1 0 0 1 0 1 0 0; 0 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0; 0 0 0 1 1 0 1 0 1 1 0 1 1 1 0 0; 0 0 0 0 0 1 1 0 1 0 1 1 0 1 1 1; 1 1 0 0 0 0 0 1 1 0 1 0 1 1 0 1; 0 1 1 1 0 0 0 0 0 1 1 0 1 0 1 1; 1 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0; 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0; 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 1];
%******************** Preparation part *********************************** sr=512000.0;% Symbol rate ml=2;% ml:Number of modulation levels (BPSK:ml=1, QPSK:ml=2,16QAM:ml=4) br=sr.*ml;% bit rate nd = 640;%Number of symbols that simulates in each loop 80*32/2 EbN0=0:2:30; IPOINT=8;% Number of oversamples imrmatrix=csvread('C:\Program Files\MATLAB\R2011b\cs\cm1_imr.csv',0,0); chnidx =2; %Starting point where we read channel impulse responses %************************* Filter initialization ************************* irfn=21; % Number of taps alfs=1.0; % Rolloff factor [xh]= hrollfcoef(irfn,IPOINT,sr,alfs,1);%Transmitter filter coefficients [xh2]=hrollfcoef(irfn,IPOINT,sr,alfs,0);%Receiver filter coefficients nloop=10;% Number of simulation loops chiplen=16; rawmsgone = randsrc(80,1,[0:15]); tx = [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]; %*********************DSSS spreading ****************************** for k = 1:length(rawmsgone); sym = rawmsgone(k); tx = [tx PN((sym+1),1:end)]; end; %********************************************************** for iii=1:nloop; for n=1:length(EbN0); ebn0=EbN0(n); txvec=tx; chn = imrmatrix(1:16,chnidx); %*************************** OQPSK Modulatio******************************** [ich,qch]=qpskmod(txvec,1,nd,ml); [ich1,qch1]=compoversamp(ich,qch,length(ich),IPOINT); ich21=[ich1 zeros(1,IPOINT/2)]; qch21=[zeros(1,IPOINT/2) qch1]; [ich2, qch2]=compconv(ich21,qch21,xh); %**************************** Attenuation Calculation ********************* spow=sum(ich2.*ich2+qch2.*qch2)/nd; attn=0.5*spow*sr/br*10.^(-ebn0/10); attn1=sqrt(attn); %******************** Add White Gaussian Noise (AWGN) ******************** [ichchm,qchchm]= compconv(ich2,qch2,chn); [ich3,qch3] = compconv(ichchm,qchchm,xh2); [ich4,qch4] = comb(ich3,qch3,attn1); % add white gaussian noise syncpoint=irfn*IPOINT+1; ich5=ich4(syncpoint:IPOINT:length(ich4)); qch5=qch4(syncpoint+IPOINT/2:IPOINT:length(qch4)); %**************************** OQPSK Demodulation***************************** [demodata]=qpskdemod(ich5,qch5,1,nd,ml); seqstart = 17; %*****************************DSSS De-spreading****************************** recovered = [-1 ]; temp = 0; result = zeros(16,16); while (seqstart+(chiplen) < length(demodata)); for j=1:16 result(j,1:end)= xor(demodata(seqstart:seqstart+(chiplen-1)),PN(j,1:end)); end; for ii=1:16 r(ii) = sum(result(ii,1:end)); end; [m,minidx] = min(r); recovered = [recovered (minidx-1)]; seqstart = seqstart + chiplen; end; compmsg = rawmsgone'; [nErrors,BER(n)] = biterr(recovered(2:end),compmsg(1:length(compmsg)-2)); end % for n=1:length(EbN0) if (chnidx < 12); chnidx = chnidx +2; end; end; % for iii=1:nloop0 BERtheory = berfading(EbN0,'psk',4,1); semilogy(EbN0,BERtheory,'b-',EbN0,BER,'r*'); legend('Theoretical BER','Empirical BER'); xlabel('SNR (dB)'); ylabel('BER'); title('Offset-QPSK'); <http://mathworks.com/matlabcentral/images/surf.gif> % i used this program to modulation and oversampling and ... % Program 3-3 % hrollfcoef.m % % Generate coefficients of Nyquist filter % % programmed by H.Harada %
function [xh] = hrollfcoef(irfn,ipoint,sr,alfs,ncc)
%****************** variables *********************** % irfn : Number of symbols to use filtering % ipoint : Number of samples in one symbol % sr : symbol rate % alfs : rolloff coeficiense % ncc : 1 -- transmitting filter 0 -- receiving filter % ***************************************************
xi=zeros(1,irfn*ipoint+1); xq=zeros(1,irfn*ipoint+1);
point = ipoint; tr = sr ; tstp = 1.0 ./ tr ./ ipoint; n = ipoint .* irfn; mid = ( n ./ 2 ) + 1; sub1 = 4.0 .* alfs .* tr; % 4*alpha*R_s
for i = 1 : n
icon = i - mid;
ym = icon;
if icon == 0.0
xt = (1.0-alfs+4.0.*alfs./pi).* tr; % h(0)
else
sub2 =16.0.*alfs.*alfs.*ym.*ym./ipoint./ipoint;
if sub2 ~= 1.0
x1=sin(pi*(1.0-alfs)/ipoint*ym)./pi./(1.0-sub2)./ym./tstp;
x2=cos(pi*(1.0+alfs)/ipoint*ym)./pi.*sub1./(1.0-sub2);
xt = x1 + x2; % h(t) plot((1:length(xh)),xh)
else % (4alphaRst)^2 = 1plot((1:length(xh)),xh)
xt = alfs.*tr.*((1.0-2.0/pi).*cos(pi/4.0/alfs)+(1.0+2.0./pi).*sin(pi/4.0/alfs))./sqrt(2.0);
end % if sub2 ~= 1.0
end % if icon == 0.0
if ncc == 0 % in the case of receiver
xh( i ) = xt ./ ipoint ./ tr; % normalization
elseif ncc == 1 % in the case of transmitter
xh( i ) = xt ./ tr; % normalization
else
error('ncc error');
end % if ncc == 0
end % for i = 1 : n
%******************** end of file ************************* % Program 3-9 % qpskmod.m % % Function to perform QPSK modulation % % Programmed by H.Harada %
function [iout,qout]=qpskmod(paradata,para,nd,ml)
%****************** variables *********************** % paradata : input data (para-by-nd matrix) % iout :output Ich data % qout :output Qch data % para : Number of paralell channels % nd : Number of data % ml : Number of modulation levels % (QPSK ->2 16QAM -> 4) % ***************************************************
m2=ml./2;
paradata2=paradata.*2-1; count2=0;
for jj=1:nd
isi = zeros(para,1); isq = zeros(para,1);
for ii = 1 : m2 isi = isi + 2.^( m2 - ii ) .* paradata2((1:para),ii+count2); isq = isq + 2.^( m2 - ii ) .* paradata2((1:para),m2+ii+count2); end
iout((1:para),jj)=isi; qout((1:para),jj)=isq;
count2=count2+ml;
end
%******************** end of file ************************* % Program 3-8 % compoversamp.m % % Insert zero data to Ich and Qch input data % % programmed by H.Harada %
function [iout,qout] = compoversamp( idata, qdata , nsymb , sample)
%****************** variables *********************** % idata : input Ich data % qdata : input Qch data % iout : output Ich data % qout : output Qch data % nsymb : Number of burst symbol % sample : Number of oversample % ***************************************************
iout=zeros(1,nsymb*sample); qout=zeros(1,nsymb*sample); iout(1:sample:1+sample*(nsymb-1))=idata; qout(1:sample:1+sample*(nsymb-1))=qdata;
%******************** end of file ************************* % Program 3-7 % compconv.m % % Function to perform convolution between signal and filter % % programmed by H.Harada and M.Okita %
function [iout, qout] = compconv(idata, qdata, filter)
% ************************************************************** % idata : ich data sequcence % qdata : qch data sequcence % filter : filter tap coefficience % **************************************************************
iout = conv(idata,filter); qout = conv(qdata,filter);
%******************** end of file ************************* % Program 3-7 % compconv.m % % Function to perform convolution between signal and filter % % programmed by H.Harada and M.Okita %
function [iout, qout] = compconv(idata, qdata, filter)
% ************************************************************** % idata : ich data sequcence % qdata : qch data sequcence % filter : filter tap coefficience % **************************************************************
iout = conv(idata,filter); qout = conv(qdata,filter);
%******************** end of file *************************% Program 2-4 % comb.m % % Generate additive white gausian noise % % Programmed by H.Harada %
function [iout,qout] = comb (idata,qdata,attn)
%****************** variables *********************** % idata : input Ich data % qdata : input Qch data % iout output Ich data % qout output Qch data % attn : attenuation level caused by Eb/No or C/N %******************************************************
iout = randn(1,length(idata)).*attn; qout = randn(1,length(qdata)).*attn;
iout = iout+idata(1:length(idata)); qout = qout+qdata(1:length(qdata));
% **********************end of file*********************************** % Program 3-10 % qpskdemod.m % % Function to perform QPSK demodulation % % programmed by H.Harada %
function [demodata]=qpskdemod(idata,qdata,para,nd,ml)
%****************** variables *********************** % idata :input Ich data % qdata :input Qch data % demodata: demodulated data (para-by-nd matrix) % para : Number of paralell channels % nd : Number of data % ml : Number of modulation levels % (QPSK ->2 16QAM -> 4) % ***************************************************
demodata=zeros(para,ml*nd); demodata((1:para),(1:ml:ml*nd-1))=idata((1:para),(1:nd))>=0; demodata((1:para),(2:ml:ml*nd))=qdata((1:para),(1:nd))>=0;

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!