登录后复制
clc;clear;close all;warning off;addpath 'functions\'q = 4; %定义伽罗达域,支持4,8,16nbits = log2(q); %多进制符号值EbNo = [0 0.5 1 1.5 2]; %信噪比%以下两个值设置小点,这样仿真可以快点,值较大的时候,仿真速度非常慢,但性能较好M = 24; %校验数N = 32; %矩阵长度t = 3; %权值 h = ldpc_generate(M,N,t,q,1); %产生矩阵H[H,G] = ldpc_h2g(h,q); %产生矩阵Gfor kk=1:length(EbNo) kk totalNumErr = 0; count = 0; SNR = 10^(EbNo(kk)/10); sigma = 1/(sqrt(SNR)); while (totalNumErr < 40)%仿真越长,效果越OK kk totalNumErr %产生一组随机数 x = floor(rand(1,size(G,1))*q); %进行多进制准循环LDPC编码 y = func_Ldpc_enc(x,G,q); %多进制信道处理 yb = (fliplr(de2bi(y,nbits)))'; yb = yb(:); zb = 2*yb-1; zb = zb + sigma*randn(size(zb)); f1=1./(1+exp(-2*zb/sigma^2)); f1 = f1(:); f1 = reshape(f1,nbits,length(y)); f0=1-f1; junk = ones(q,length(y)); [v0, v1, pp] = func_message_passing(f0,f1,junk); [z_hat,success, k] = func_Ldpc_dec_log(pp,H,q); x_hat = z_hat(size(G,2)+1-size(G,1):size(G,2)); x_hat = x_hat'; %统计误码率 totalNumErr = totalNumErr+(sum (x_hat~=x')); count = count + 1; end BERs(kk)=totalNumErr/(count*length(x));endfigure;semilogy(EbNo,BERs,'r-o');xlabel('EbN0');ylabel('BER');grid on;if q == 4 save ERR4_log.mat EbNo BERsendif q == 8 save ERR8_log.mat EbNo BERsendif q == 16 save ERR16_log.mat EbNo BERsend1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删