⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 turbo_test.asv

📁 turbo 码matlab编译码程序
💻 ASV
字号:
clear allL_info =378;	  % infomation size (frame= info + tail(2*m bits)channel=1;        %AWGN case  channel=1 Rayleigh case
CSI=1;            %1 means CSI, 0 means no CSI
p=3;              % p=1/rate, only consider p=2 or 3 or 4 g = [1 0 1 1; 1 1 0 1; 1 1 1 1];% encoder generatorniter = 8;        % the number of iterations
[n,K] = size(g); m = K - 1;          %shift register memorymax_states = 2^m; 	%trellis statesL_frame=L_info+2*m; % z RSC encoder need z*m bits tail bit to flash the memory. 
ferrlim = 5;        % Number of frame errors to count as a stop criterior.EbN0db = [4];fprintf('\n\n----------------------------------------------------\n'); fprintf(' === Modified Addition MAP decoder === \n');fprintf(' Frame size = %6d\n',L_frame);
fprintf(' Channel condition = %6d\n',channel);fprintf(' code generator: \n');for i = 1:n    for j = 1:K        fprintf( '%6d', g(i,j));    end    fprintf('\n');
end       
fprintf('code rate =1/%d.',p);
fprintf('\n');fprintf(' iteration number =  %6d\n', niter);fprintf(' terminate frame errors = %6d\n', ferrlim);fprintf(' Eb / N0 (dB) = ');for i = 1:length(EbN0db)    fprintf('%10.2f',EbN0db(i));endfprintf('\n----------------------------------------------------\n\n');fprintf('+ + + + Please be patient. Wait a while to get the result. + + + +\n');

%generate order for interleaverindex=interleaver(L_info);  % wcdma interleaverfor nEN = 1:length(EbN0db)    snr_b = 10^(EbN0db(nEN)/10);
    
    sigma = sqrt(p/(2*snr_b)); 	% standard deviation of AWGN noise
    
    % Clear bit error counter and frame error counter    errs(nEN,1:niter) = zeros(1,niter);    nferr(nEN,1:niter) = zeros(1,niter);
    nframe(nEN) = 0;% clear counter of transmitted frames    while ((nferr(nEN, niter)<ferrlim)&(nframe(nEN)<10))        nframe(nEN) = nframe(nEN) + 1
        
        %generatr [0 1] source information.
        x=round(rand(1,L_info)); 
        
        en_output =encode(x,g,p,index);
        noise=randn(size(en_output))*sigma;
        %r1 are received signals.
        if channel==1            a_p=randn(size(en_output))/sqrt(2);
            a_q=randn(size(en_output))/sqrt(2);
            a=sqrt(a_p.^2+a_q.^2);
            r1 =a.*(2*en_output-1)+noise;
        else
            r1 =(2*en_output-1)+noise;                    end
        if channel==0            a=ones(size(en_output));        else if CSI==0                a=0.8862*ones(size(en_output));            end        end        snr_b = 10^(4/10);        L_c =4*a*snr_b/p; 	% reliability value of the channel          
        r=L_c.*r1;
        %serial to parrel output
        
        p_output=s_to_p(r,p,m);
        % Initialize extrinsic information      
        L_e_21 = zeros(1,L_info+m);
        % tail bits need pay attention
        %extract received signal to y_k, y_k_primee.
        if p==4
            y_k=[p_output(1:3,1:(L_info+m))];
        else
            y_k=[p_output(1:2,1:(L_info+m))];
        end
        
        y_k_prime(1,:)=[p_output(1,index) p_output(1,(L_info+1+m):L_frame)];
        if p==4   
            y_k_prime(2,:)=[p_output(4,1:L_info) p_output(4,(L_info+1+m):L_frame)];
            y_k_prime(3,:)=[p_output(5,1:L_info) p_output(5,(L_info+1+m):L_frame)];
        else
            y_k_prime(2,:)=[p_output(3,1:L_info) p_output(3,(L_info+1+m):L_frame)];
        end
        iter=1;
        while iter<=niter    
            % Decoder one
            L_e_12 =log_map1(y_k,L_e_21,g);  % input to decoder2 as a priori information.
            
            % Decoder two
            L_e_12_prime=[L_e_12(index) zeros(1,m)];
            L_e_21_prime = log_map1(y_k_prime,L_e_12_prime,g);  %input to decoder1 as a priori informations. 
            temp_L_e_21(index) =L_e_21_prime(1:L_info);   %de-interleaver, a priori info. 
            %pad 0 to the tail bits
            L_e_21=[temp_L_e_21 zeros(1,m)];
            % Estimate the info. bits        
            xhat1 = (sign(L_e_21+L_e_12+y_k(1,:))+1)/2;
            %dump tail bits
            xhat=xhat1(1:L_info);
            % Number of bit errors in current iteration
            err(iter) = length(find(xhat~=x));
            % Count frame errors for the current iteration
            % Count frame errors for the current iteration
            if err(iter)>0
                nferr(nEN,iter) = nferr(nEN,iter)+1;
            end 
            %err(iter) not change any more after 2 times exit the iter loop.
            if (iter>=2)&(err(iter)==err(iter-1))
                if err(iter)~=0               
                    nferr(nEN,iter+1:niter) = nferr(nEN,iter+1:niter)+1;
                end            
                err(iter+1:niter)=err(iter);
                iter=niter;
            end %end iter>=3 loop
            iter=iter+1;                 
            
        end	%iter
        
        errs(nEN,1:niter) = errs(nEN,1:niter) + err(1:niter);
        
    end	%end while
    % Total number of bit errors and frame errors for all iterations
    
    ber(nEN,:) = errs(nEN,1:niter) /(nframe(nEN)*L_info);   
    fer(nEN,:) = nferr(nEN,:)/nframe(nEN);
    %save data into file
    ber_file=fopen('ber_file.txt','a+');
    ber        fprintf(ber_file,'wcdma \n');        if channel==0        fprintf(ber_file,'AWGN channel \n');    else channel==1        fprintf(ber_file,'Rayleigh fading channel \n');    end    if CSI==0        fprintf(ber_file,'no channel information \n');    else        fprintf(ber_file,'perfect channel information \n');    end    for l=1:niter
        fprintf(ber_file,'%8.4e \n',ber(nEN,l));
    end
    fprintf(ber_file,'\n');
    fclose(ber_file);
    
end 		%nEN








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -