clc;
H = dvbs2ldpc(1/2);% 产生不同码率的LDPC校验矩阵
enc = fec.ldpcenc(H); % Construct a default LDPC encoder object
% Generate and encode a random binary message
msg = randint(1,enc.NumInfoBits,2);%产生与校验矩阵相匹配的随机信息序列
codeword = encode(enc,msg);%产生LDPC码
xlswrite('ldpc',codeword')
xlswrite('msg',msg')
size(msg)
% Construct a companion LDPC decoder object
dec = fec.ldpcdec(H);
dec = fec.ldpcdec;
dec.DecisionType = 'Soft decision';
dec.OutputFormat = 'Information part';
dec.NumIterations = 50;
% % Stop if all parity-checks are satisfied
dec.DoParityChecks = 'Yes';
% Decode received signal
decodedmsg = decode(dec, codeword);
cor=0;
n=32400
for i=1:n
if msg(i)==decodedmsg(i)
cor=cor;
else cor=cor+1;
end
end
ber=cor/n