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

📄 gmc_16qam_turbodd.m

📁 B3g_phase2_C语言_Matlab程序及说明
💻 M
📖 第 1 页 / 共 2 页
字号:
clear
% Define parameters of MC filter banks
% Define parameters of MC filter banks
load ptfilter                                                             % load prototype filter coefficients which are saved in h
prototype_filter=h;
Carrier_number=16;                                                        % Number of subcarriers
SubCarrier_first=1;
SubCarrier_last=15;
Carrier_number_used=SubCarrier_last-SubCarrier_first+1;
Sampling_factor=18;                                                       % Factor of upsampling and downsampling
Oversampling_factor=2;    
Filter_length=217;                                                        % Length of filters in taps

% Define the slot structure
Spread_factor=8;                                                         % Spread factor
Subslot_number=8;                                                         % Number of subslots
Symbol_number_subslot=13;                                                  % Symbol number in a subslot
Symbol_number_slot=Subslot_number*Symbol_number_subslot;                  % Symbol number in a slot
Pilot_length=16;                                                          % Length of pilot signal in chips
Gaurd_length=8;                                                           % Length of gaurd time in chips
GaurdPilot_length=Gaurd_length+Pilot_length;                              % Total length of gaurd time and pilot signal in chips
SubslotData_length=Symbol_number_subslot*Spread_factor;                   % Length of data in a subslot in chips
Subslot_length=SubslotData_length+GaurdPilot_length;                      % Length of a subslot in chips
SlotData_length=Subslot_number*SubslotData_length;                        % Length of data in a slot in chips
Slot_length=Subslot_number*Subslot_length+GaurdPilot_length;              % Length of a slot in chips 

% Define spreading codes
Walsh=[1 1; 1 -1]/sqrt(2);                                                % Walsh matrix for speading codes 
for k=1:log2(Spread_factor)-1
    Walsh=[Walsh Walsh;Walsh -Walsh]/sqrt(2);
end
Code_channel=Spread_factor;                                               % Number of code channels
Walsh=Walsh(1:Code_channel,:)';                                           % The codes come from Walsh matrix 
Walsh=eye(Spread_factor);
% W_sequence=[1 j 1 -1 1 1 -1 -j 1 -j 1 1 1 -1 -1 j]/sqrt(16);
% for m=1:16
%     Walsh(m,:)=[W_sequence(16-m+2:16) W_sequence(1:16-m+1)];
% end


% Initialize the scrambler 
PN_RegStateI = [zeros(1,14) 1];  
PN_RegStateQ = [zeros(1,14) 1];  
PN_PolynI = [0 1 0 0 0 1 1 1 0 1 0 0 0 0 1];  
PN_PolynQ = [0 0 1 1 1 0 0 0 1 1 1 1 0 0 1];

%Define the channel
Antenna_number=64;                                                         % Number of receive antennas
Path_number=8;                                                            % Number of paths  
Path_number_mc=6;
% Path_Gain=[0.8084 0.462 0.253 0.259 0.0447 0.01];                         % Profile of channel model
% delay=[0 18 36  54 72  90]*2;                                             % Delays of paths

Delay_spread=10;                                                           % in us
Path_Gain=exp(-(0:1/(Path_number_mc-1):1)*3*log(10));
%Path_Gain=[0.8084 0.462 0.253 0.0 0.01 0.01];  
Path_Gain=Path_Gain/sqrt(Path_Gain*Path_Gain');

delay=round((0:1/(Path_number_mc-1):1)*Delay_spread*23.04);

% Path_Gain=10.^(([0 -1 -9 -10 -15 -20])/20);                                        % Profile of channel model
% Path_Gain=[Path_Gain/sqrt(Path_Gain*Path_Gain')];
% 
% delay=round([0 0.310 0.710  1.09 1.73  2.51]*23.04);   

Fc = 3.2e9;                                                               % Carrier frequency 
V =250;                                                                   % moving speed in km/h
Tc = 1/1.28e6/Sampling_factor;                                            % Chip width 
Time_Begin = 0;                                                           % Initializing the time
% Phase = 2*pi*rand(1,2);                                                   % Initializing the phase

% Define pilot signal
%Pilot_sequence=[-1 1 j -1 -1 -1 j 1 -1 1 j -1 -1 -1 j 1 -1 1 j -1 -1 -1 j 1];
Pilot_sequence=[1 j 1 -1 1 1 -1 -j 1 -j 1 1 1 -1 -1 j];
%Pilot_sequence=[1 j 1 -1 1 1 -1 -j 1 -j 1 1 1 -1 -1 j     1 j 1 -1 1 1 -1 -j 1 -j 1 1 1 -1 -1 j];

%Pilot_sequence=[ 1  1  1 1  (1-j)/sqrt(2) -1  (1+j)/sqrt(2) -j...
%                 j -1 -j 1  (1+j)/sqrt(2)  1  (1-j)/sqrt(2) -j...
%                -1  1 -1 1 (-1+j)/sqrt(2) -1 (-1-j)/sqrt(2) -j...
%                -j -1  j 1 (-1-j)/sqrt(2)  1 (-1+j)/sqrt(2) -j];
for m=1:Path_number
    Pilot_matrix(m,:)=[Pilot_sequence(Pilot_length-m+2:Pilot_length) Pilot_sequence(1:Pilot_length-m+1)];
end
Gaurd_Pilot=[Pilot_sequence(Pilot_length-Gaurd_length+1:Pilot_length) Pilot_sequence];
Gaurd_Pilot1=[zeros(1,Gaurd_length) Pilot_sequence];

% turbo code
poly_g1 = 11;			% 1 0 1 1
poly_g2 = 13;			% 1 1 0 1
MemLen = 3;
puncture = 0;			% puncture = 0,rate=1/2;puncture = 1,no puncture rate =1/3
nIter = 7;
CodeRate = 1/(2+puncture);
% end
nIterDD=4;

%trel=poly2trellis(9,[561 753]); 
InputN=1; OutputN=2;
%tblen=40;
Slot_number=64;
Symbol_bitN=4;                                                                % 2 for QPSK and 4 for 16QAM
Map_16QAM=[3+j*3 3+j 3-j*3 3-j 1+j*3 1+j 1-j*3 1-j -3+j*3 -3+j -3-j*3 -3-j -1+j*3 -1+j -1-j*3 -1-j]/sqrt(10);
%Map_16QAM=[-1-j -1-3*j -1+j -1+3*j -3-j -3-3*j -3+j -3+3*j 1-j 1-3*j 1+j 1+3*j 3-j 3-3*j 3+j 3+3*j]/sqrt(10);

%msg_L=Symbol_bitN*SlotData_length/OutputN*InputN*Slot_number-InputN*tblen;    % Number of message bits
msg_L=Symbol_bitN*SlotData_length/OutputN*InputN*4-MemLen;    % Number of message bits
code_L=Symbol_bitN*SlotData_length*4;
code_SlotL=Symbol_bitN*SlotData_length;
packet_N=Slot_number*Carrier_number_used/4;

[int_table0] = interleave(msg_L+MemLen, floor(sqrt((msg_L+MemLen)/2)));
[int_table] = interleave(code_L*packet_N,floor(sqrt((code_L*packet_N)/2)))+1;

Intl_length =Subslot_number;
% Raised cosine filter for interpolation
Interp_factor=3;
rcflt=rcosfir(0.15,6,Interp_factor,1);


% Bit error rate

ber=zeros(nIterDD,5);
format long

% Main loop

for Antenna_number=2.^(2:2);                                                         % Number of receive antennas
    
    SNR1=3; SNR2=12;
    
    Phase = 2*pi*rand(Antenna_number,2);                                                   % Initializing the phase
    
    
    for SNR=SNR1:SNR2
        
        errors=zeros(1,nIterDD);
        
        for k=1:2000      
            SNR
            k
            
            msg=randint(packet_N,msg_L,2);                                                                               % Random data
            %             msg=[msg zeros(Carrier_number,InputN*tblen)];
            for np=1:packet_N 
                %                 code(nc,:)=convenc(msg(nc,:),trel);                                                                            % Encode
                code_p(np,:) = TuEnc(msg(np,:), puncture, int_table0, poly_g1, poly_g2);
                
                %     code(nc,:)=reshape(vec2mat(code(nc,:),Subslot_number),1,code_L);                                               % Interleaving
            end
            code=reshape(code_p,1,code_L*packet_N);
            code=vec2mat(code(int_table),code_L*packet_N/Carrier_number_used);
                   
            [PN,PN_RegStateI,PN_RegStateQ]=Complex_PNGen(PN_PolynI,PN_PolynQ,PN_RegStateI,PN_RegStateQ,SlotData_length);   % get a complex PN sequence.
        
            for sn=0:Slot_number-1
                % Transmiter
                % Transmiter:Generate single-carrier baseband signals 
                
                for nc=1:Carrier_number_used 
                    s=[]; 
                    
                    
                    [x] = Modulation(code(nc,sn*code_SlotL+(1:code_SlotL)), 4);
                    
                    % Tmp_s=reshape((Walsh*reshape(x,Code_channel,Symbol_number_slot))',1,SlotData_length).*PN;                  % spread spectrum modulation and interleving
                    Tmp_s=x;
                    
                    Index_s=0;                                                                                                 % Insert pilot and gaurd 
                    for kk=1:Subslot_number
                        tmp=Tmp_s(Index_s+(1:SubslotData_length));
%                        tmp=reshape((Walsh*reshape(tmp,Code_channel,Symbol_number_subslot))',1,SubslotData_length).*PN((Index_s+(1:SubslotData_length))); 
                        tmp=[Gaurd_Pilot(nc)*Gaurd_Pilot tmp]; 
                        s=[s tmp];
                        Index_s=Index_s+SubslotData_length;
                    end
                    s=[s Gaurd_Pilot(nc)*Gaurd_Pilot];
                    sb(nc,:)=s;              
                end
                
                % Transmiter:Combine subcarrier baseband signals into multicarrier baseband signal
                st=mc_sfb(sb,Slot_length,prototype_filter,Carrier_number,SubCarrier_first,SubCarrier_last,Sampling_factor,Filter_length);
                 
%                 10*log10(max(abs(st))^2/mean(abs(st).^2))
                     
%                clip_value=sqrt(mean(abs(st).^2)*10^(8/10));
%                st(abs(st)>clip_value)=clip_value*exp(j*angle(st(abs(st)>clip_value)));
                
%                10*log10(max(abs(st))^2/mean(abs(st).^2))
               
                % Channel
                Signal_length=Sampling_factor*(Slot_length-1)+Filter_length+delay(Path_number_mc);                                 % Length of multicarrier baseband signal 

⌨️ 快捷键说明

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