global Lc1;
global Lc2;
global Lc3;
global Lc4;
global Lc5;
global Lc6;
global Lc7;
global Lc8;
global Lc9;
global Lc10;
R=1/2;
Mo=2;
numerrmin =1000;
SNRdB=1:0.5:3;
BER_bit=zeros(size(SNRdB));
codewordH=[0,0,0,0,0,0,0,0,0,0];
modulatedsig=1-2*codewordH;
for k=1:length(SNRdB)
fprintf('SNR:%d\n',SNRdB(k))
frame=0;
numerr=0;
rat_err=0;
EbN0_lin=10^(SNRdB(k)/10);
EsN0_lin=EbN0_lin*R*log2(Mo);
Es= 1 ;
N0=Es/EsN0_lin;
sigma=sqrt(N0/2);
while(numerr < numerrmin)
fprintf('frame : %d\n',frame)
frame = frame + 1;
bruit= randn(size(modulatedsig));
receivedsig =modulatedsig+sigma.*bruit;
Lci = (4.*(receivedsig./N0));
Lc1=Lci(1);
Lc2= Lci(2);
Lc3=Lci(3);
Lc4=Lci(4);
Lc5=Lci(5);
Lc6=Lci(6);
Lc7=Lci(7);
Lc8=Lci(8);
Lc9=Lci(9);
Lc10=Lci(10);
Lc1=timeseries(Lc1);
Lc2=timeseries(Lc2);
Lc3=timeseries(Lc3);
Lc4=timeseries(Lc4);
Lc5=timeseries(Lc5);
Lc6=timeseries(Lc6);
Lc7=timeseries(Lc7);
Lc8=timeseries(Lc8);
Lc9=timeseries(Lc9);
Lc10=timeseries(Lc10);
s=sim('LDPCMatlabSimulink');
x1=getdatasamples(x1,1);
x2=getdatasamples(x2,1);
x3=getdatasamples(x3,1);
x4=getdatasamples(x4,1);
x5=getdatasamples(x5,1);
x6=getdatasamples(x6,1);
x7=getdatasamples(x7,1);
x8=getdatasamples(x8,1);
x9=getdatasamples(x9,1);
x10=getdatasamples(x10,1);
SMS=[x1 x2 x3 x4 x5 x6 x7 x8 x9 x10];
[Num1,Rat1] = biterr(codewordH,SMS);
numerr=numerr+Num1;
rat_err=rat_err+Rat1;
if frame>2
break ;
end
BER_bit(k)=rat_err/frame;
end
end
semilogy(SNRdB, BER_bit,'v-r','LineWidth',2);
grid on;
xlabel('SNR,(dB)')
ylabel('(BER)')