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

📄 turbounitray.asv

📁 根据TD-SCDMA系统的特点
💻 ASV
📖 第 1 页 / 共 2 页
字号:
% This script simulates the classical turbo encoding-decoding system. 
% It simulates parallel concatenated convolutional codes.
% Two component rate 1/2 RSC (Recursive Systematic Convolutional) component encoders are assumed.
% First encoder is terminated with tails bits. (Info + tail) bits are scrambled and passed to 
% the second encoder, while second encoder is left open without tail bits of itself.
%
% Random information bits are modulated into +1/-1, and transmitted through a AWGN channel.
% Interleavers are randomly generated for each frame.
%
% Log-MAP algorithm without quantization or approximation is used.
% By making use of ln(e^x+e^y) = max(x,y) + ln(1+e^(-abs(x-y))),
% the Log-MAP can be simplified with a look-up table for the correction function.
% If use approximation ln(e^x+e^y) = max(x,y), it becomes MAX-Log-MAP.
%
% Copyright Nov 1998, Yufei Wu
% MPRG lab, Virginia Tech.
% for academic use only

clear all


matrix0=(1/sqrt(8))*[1 1;1 exp(i*4*pi/8);1 exp(i*8*pi/8);1 exp(i*12*pi/8);1 exp(i*16*pi/8);1 exp(i*20*pi/8);1 exp(i*24*pi/8);1 exp(i*28*pi/8)]; 
  
% Generate Unitray Matrix 

smatrix=diag(exp([i*pi*2/256 i*pi*2*5/256 i*pi*2*16/256 i*pi*2*36/256 i*pi*2*57/256 i*pi*2*105/256 i*pi*2*151/256 i*pi*2*253/256]));
% channel parmater
fc=2000;
v=120;
startT=0;
endT=0.000675;
deltaT=0.00000078125;
fchip=1.28;
delayTime=[0,781,1563,2344];
averagePower=[0,-3,-6,-9];

% generated channel 

% Write display messages to a text file

% (diary turbo_logmap.txt)

% Choose decoding algorithm 
dec_alg = 0;
% dec_alg = input(' Please enter the decoding algorithm. (0:Log-MAP, 1:SOVA)  default 0    ');
% if isempty(dec_alg)
   
% end
input=4;
% Frame size
switch  input
     case 1 
        L_total = 117;   
     case 2
        L_total =469    
     case 3
        L_total =938        % 144  
     case 4  
        L_total =2346
     end
% L_total = input(' Please enter the frame size (= info + tail, default: 400)   ');
% if isempty(L_total)
   	       % infomation bits plus tail bits
% end

% Code generator
g = [ 1 1 1;
         1 0 1 ];
% g = input(' Please enter code generator: ( default: g = [1 1 1; 1 0 1 ] )      ');
 % If isempty(g)
   
% end
%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, puncturing into rate 1/2; 
%puncture = 1, no puncturing
% puncture = input(' Please choose punctured / unpunctured (0/1): default 0 ');
% if isempty(puncture) 
    puncture = 1;
% end

% Code rate
rate = 1/(2+puncture);   

% Fading amplitude; a=1 in AWGN channel
a = 1;
% Number of iterations
% niter = input(' Please enter number of iterations for each frame: default 5       ');
% if isempty(niter) 
   niter = 4;
%% end   
% Number of frame errors to count as a stop criterior
ferrlim = input(' Please enter number of frame errors to terminate: default 15        ');
if isempty(ferrlim)
   ferrlim = 5;
end   

EbN0db = input(' Please enter Eb/N0 in dB : default [2.0]    ');
if isempty(EbN0db)
   EbN0db = [1.0];
end

fprintf('\n\n----------------------------------------------------\n'); 
if dec_alg == 0
   fprintf(' === Log-MAP decoder === \n');
else
   fprintf(' === SOVA decoder === \n');
end
fprintf(' Frame size = %6d\n',L_total);
fprintf(' code generator: \n');
for i = 1:n
    for j = 1:K
        fprintf( '%6d', g(i,j));
    end
    fprintf('\n');
end        
if puncture==0
   fprintf(' Punctured, code rate = 1/2 \n');
else
   fprintf(' Unpunctured, code rate = 1/3 \n');
end
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));
end
fprintf('\n----------------------------------------------------\n\n');
    
fprintf('+ + + + Please be patient. Wait a while to get the result. + + + +\n');

for nEN = 1:length(EbN0db)
   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
    N0=10^(-EbN0db/10);         % noise power
    noiseRoot0=sqrt(N0/2);       % noise range
  noise=(randn(16,44)+j*randn(16,44))*noiseRoot0; % randon noise
% Clear bit error counter and frame error counter
   errs(nEN,1:niter) = zeros(1,niter);
   nferr(nEN,1:niter) = zeros(1,niter);

   nframe = 0;    % clear counter of transmitted frames
%   while nferr(nEN, niter)<ferrlim
   while nframe <10
      nframe = nframe + 1;    
      x = round(rand(1, L_total-m));    % info. bits
      [temp, alpha] = sort(rand(1,L_total));        % random interleaver mapping
      en_output = 2*encoderm( x, g, alpha, puncture )+1 ; % encoder output (+1/0)
      
      % channel paramter
       h1=sum(Rayleigh_Doppler_multiPath(fc,v,startT,endT,deltaT,fchip,delayTime,averagePower))/864;
 
       h2=sum(Rayleigh_Doppler_multiPath(fc,v,startT,endT,deltaT,fchip,delayTime,averagePower))/864; 

      
       source1111=[en_output zeros(1,2)]; % coded sign lengh=1760
 
   linkmatrix=zeros(1760,4);
 
 for TT=1:4  % 20ms data 
  
   sourcereshape=zeros(1,440);
   containmatrix=zeros(440,4);
   sourcereshape=reshape(source1111((TT-1)*1760+1:TT*1760),440,4);% different sign
% index11=1
% for k=1:4
  %    seedframe(index)=sourceshape(k,:);
    %  index11=index11+1;
 % end

% source 
for kk=1:4         % the one frame start      
changesource=reshape(sourcereshape(:,kk),8,55);

dsource=zeros(8,55); % after decesion sign matrix

% spreadcode1=zeros(1,44);% spread array 

unitraymatrix=zeros(8,55);  % unitray modulate matrix
unitraymatrix1=zeros(8,55);

rsource1=zeros(1,440);  % after despread  sign

index1=1;
for ii=1:55  % construct unitrary matrix
number(index1)=[128 64 32 16 8 4 2 1]*changesource(:,ii);
index1=index1+1;
end

for iii=1:55 % construct matrix
smatrix1=sqrt(8)*smatrix^number(iii)*matrix0;
unitraymatrix(:,iii)=unitraymatrix(:,iii)+smatrix1(:,1); % the first antenna
unitraymatrix1(:,iii)=unitraymatrix1(:,iii)+smatrix1(:,2); % the second antenna
end

% the first antenna spread
spreadcode1=reshape(unitraymatrix,1,440);% symbols frame 
uspreadcode11=spreadcode1(1:44);
uspreadcode12=spreadcode1(45:88);
uspreadcode13=spreadcode1(89:132);
uspreadcode14=spreadcode1(133:176);
uspreadcode15=spreadcode1(177:220);
uspreadcode16=spreadcode1(221:264);
uspreadcode17=spreadcode1(265:308);
uspreadcode18=spreadcode1(309:352);
uspreadcode19=spreadcode1(353:396);
uspreadcode10=spreadcode1(397:440);

source11 =uspreadcode11*WQ(1);
x11 = ovsf(1)' * source11;                 % spreading
s11 = x11.*(scramble'*ones(1,44));               


source12 = uspreadcode12*WQ(2);
x12 = ovsf(2)' * source12;                 % spreading
s12 = x12.*(scramble'*ones(1,44));        

source13 =uspreadcode13*WQ(3);
x13 = ovsf(3)' * source13;                 % spreading
s13 = x13.*(scramble'*ones(1,44));

source14 =uspreadcode14*WQ(4);
x14 = ovsf(4)' * source14;                 % spreading
s14 = x14.*(scramble'*ones(1,44));

source15 =uspreadcode15*WQ(5);
x15 = ovsf(5)' * source15;                 % spreading
s15 = x15.*(scramble'*ones(1,44));

source16 =uspreadcode16*WQ(6);
x16 = ovsf(6)' * source16;                 % spreading
s16 = x16.*(scramble'*ones(1,44));

source17 =uspreadcode17*WQ(7);
x17 = ovsf(7)' * source17;                 % spreading
s17 = x17.*(scramble'*ones(1,44));

source18 =uspreadcode18*WQ(8);
x18 = ovsf(8)' * source18;                 % spreading
s18 = x18.*(scramble'*ones(1,44));

source19 =uspreadcode19*WQ(9);
x19 = ovsf(9)' * source19;                 % spreading

⌨️ 快捷键说明

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