📄 turbo_sys_demo.m
字号:
clcclear all dec_alg = 0; L_total = 400; % infomation bits plus tail bits g = [ 1 1 1; 1 0 1 ];%g = [1 1 0 1; 1 1 1 1];%g = [1 1 1 1 1; 1 0 0 0 1];[n,K] = size(g); m = K - 1;nstates = 2^m; puncture = 0;% Code raterate = 1/(2+puncture); % Fading amplitude; a=1 in AWGN channela = 1; niter = 10; EbN0db = 0:0.5:2;nn=0;for nEN = 1:length(EbN0db) nn=nn+1; errall=0; en = 10^(EbN0db(nEN)/10); % convert Eb/N0 from unit db to normal numbers L_c = 4*a*en*rate; % reliability value of the channel sigma = 1/sqrt(2*rate*en); % standard deviation of AWGN noise% Clear bit error counter and frame error counter nframe = 0; % clear counter of transmitted frames while nframe<100 nframe = nframe + 1; x = round(rand(1, L_total-m)); % info. bits [temp, alpha] = sort(rand(1,L_total)); % random interleaver mapping en_output = encoderm( x, g, alpha, puncture ) ; % encoder output (+1/-1) r = en_output+sigma*randn(1,L_total*(2+puncture)); % received bits yk = demultiplex(r,alpha,puncture); % demultiplex to get input for decoder 1 and 2 % Scale the received bits rec_s = 0.5*L_c*yk;% Initialize extrinsic information L_e(1:L_total) = zeros(1,L_total); for iter = 1:niter% Decoder one L_a(alpha) = L_e; % a priori info. if dec_alg == 0 L_all = logmapo(rec_s(1,:), g, L_a, 1); % complete info. else L_all = sova0(rec_s(1,:), g, L_a, 1); % complete info. end L_e = L_all - 2*rec_s(1,1:2:2*L_total) - L_a; % extrinsic info.% Decoder two L_a = L_e(alpha); % a priori info. if dec_alg == 0 L_all = logmapo(rec_s(2,:), g, L_a, 2); % complete info. else L_all = sova0(rec_s(2,:), g, L_a, 2); % complete info. end L_e = L_all - 2*rec_s(2,1:2:2*L_total) - L_a; % extrinsic info. % Estimate the info. bits xhat(alpha) = (sign(L_all)+1)/2;% Number of bit errors in current iteration err(iter) = length(find(xhat(1:L_total-m)~=x));% Count frame errors for the current iteration end %iter error(nframe)=length(find(xhat(1:L_total-m)~=x)); errall=errall+error(nframe); end %end while ber(nn)=errall./(nframe*(L_total-m)); fprintf('ber=%g\n',ber(nn)) end %end snr xx=[0:0.5:2]; plot(xx,ber)%diary off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -