clear
clc
global code_len; code_len = 4095;
global shortCodeLen; shortCodeLen = 1600;%ISE=2216
global shortInfoNum; shortInfoNum = 1480;%ISE=2072
% global shortCodeLen; shortCodeLen = 1200;%ISE=2216
% global shortInfoNum; shortInfoNum = 1080;%ISE=2072
global t_bch; t_bch = 10;%纠错单位
global alpha_to;
global sorted_alpha_to;
global rdncy; rdncy = 120; %rdncy为冗余比特的位数,纠错10bit,截短4095
global reverseBitNum;
load('alpha_to.txt','-ascii'); %本原BCH码和非本原BCH码码长
load('sorted_alpha_to.txt','-ascii');
global generator;
generator=bchgenpoly(code_len,code_len-rdcny);generator=double(generator.x);
N=8191; K=0.5;%N为信号长度,K为符号1所占的比例
SNR1=-3;SNR2=7;
berNum=0;
frame=1000;
j=1;wuzhen=[];wz=0
tic
for idSNR = SNR1 :0.25: SNR2
berNum=0;
for r = 1:frame
[X,length_X]=gen_source(N,K); %生成信源
% data1=X(1:1480);data2=X(1481:3360);data3=X(3361:4680);
data1=X(1:1456);data2=X(1481:3336);data3=X(3361:4656);
% data4=X(1:1056);data5=X(1201:2256);data6=X(2401:3456);data7=X(3601:4656);
CRC_code1=crc_add(data1,24);%加CRC-24编码
CRC_code2=crc_add(data2,24);
CRC_code3=crc_add(data3,24);
% CRC_code4=crc_add(data4,24);CRC_code5=crc_add(data5,24);CRC_code6=crc_add(data6,24);CRC_code7=crc_add(data7,24);
%----------------------------------------encdoe
[ bch_encode_out1 , bch_encode_out_len ] = BCHencode(CRC_code1,shortInfoNum);
[ bch_encode_out2 , bch_encode_out_len ] = BCHencode(CRC_code2,shortInfoNum);
[ bch_encode_out3 , bch_encode_out_len ] = BCHencode(CRC_code3,shortInfoNum);
% [ bch_encode_out4 , bch_encode_out_len ] = BCHencode(CRC_code4,shortInfoNum);
% [ bch_encode_out5 , bch_encode_out_len ] = BCHencode(CRC_code5,shortInfoNum);
% [ bch_encode_out6 , bch_encode_out_len ] = BCHencode(CRC_code6,shortInfoNum);
% [ bch_encode_out7 , bch_encode_out_len ] = BCHencode(CRC_code7,shortInfoNum);
m=2;%QPSK调制,m=2
QPSK_a1 = reshape(bch_encode_out1,m,[])';%整形
QPSK_a2 = reshape(bch_encode_out2,m,[])';QPSK_a3 = reshape(bch_encode_out3,m,[])';
% QPSK_a4 = reshape(bch_encode_out1,m,[])';QPSK_a5 = reshape(bch_encode_out2,m,[])';
% QPSK_a6 = reshape(bch_encode_out3,m,[])';QPSK_a7 = reshape(bch_encode_out3,m,[])';
QPSK_out1 = pskmod(QPSK_a1,2);
QPSK_out2 = pskmod(QPSK_a2,2);QPSK_out3 = pskmod(QPSK_a2,2);
QPSK_out4 = pskmod(QPSK_a4,2);QPSK_out5 = pskmod(QPSK_a5,2);
QPSK_out6 = pskmod(QPSK_a6,2);QPSK_out7 = pskmod(QPSK_a7,2);
QPSK_out1_noi = awgn(QPSK_out1,idSNR,'measured',[],'dB');
QPSK_out2_noi = awgn(QPSK_out2,idSNR,'measured',[],'dB');QPSK_out3_noi = awgn(QPSK_out3,idSNR,'measured',[],'dB');
QPSK_dem1=pskdemod(QPSK_out1_noi,2); %QPSK解调
QPSK_dem2=pskdemod(QPSK_out2_noi,2); QPSK_dem3=pskdemod(QPSK_out3_noi,2);
QPSK_bi1=reshape((QPSK_dem1)',1,[]);
QPSK_bi2=reshape((QPSK_dem2)',1,[]);QPSK_bi3=reshape((QPSK_dem3)',1,[]);
berNum1(r)=sum(xor(QPSK_bi1,bch_encode_out1))+sum(xor(QPSK_bi2,bch_encode_out2))+berNum1(r)=sum(xor(QPSK_bi3,bch_encode_out3));
%----------------Decode
[ bch_decode_out1,bch_decode_out_len,errArray] = BCHdecode(QPSK_bi1,shortCodeLen);
[ bch_decode_out2,bch_decode_out_len,errArray] = BCHdecode(QPSK_bi2,shortCodeLen);
[ bch_decode_out3,bch_decode_out_len,errArray] = BCHdecode(QPSK_bi3,shortCodeLen);
berNum3(r)=sum(xor(bch_decode_out1(1:shortInfoNum),CRC_code1))+sum(xor(bch_decode_out2(1:shortInfoNum),CRC_code2))+sum(xor(bch_decode_out3(1:shortInfoNum),CRC_code3));
end
Pe1(j)=sum(berNum1);%Pe2(j)=sum(berNum2);
Pe3(j)=sum(berNum3);%Pe4(j)=sum(berNum4);
SNR_x(j)=idSNR;
j=j+1;
end
toc
for i=1:length(SNR_x)
SNR=exp(SNR_x(i)*log(10)/10);
theo_err(i)=qfunc(sqrt(2*SNR));
end
save Pe1.mat Pe1
save Pe3.mat Pe3