📄 gmc_16qam_tc.m
字号:
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=14;
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=16; % Spread factor
Subslot_number=8; % Number of subslots
Symbol_number_subslot=5; % Symbol number in a subslot
Symbol_number_slot=Subslot_number*Symbol_number_subslot; % Symbol number in a slot
Pilot_length=32; % Length of pilot signal in chips
Gaurd_length=16; % 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
% 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=1; % Number of receive antennas
Path_number=12; % 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
Path_Gain=exp(-(0:0.2:1)*3*log(10));
Path_Gain=Path_Gain/sqrt(Path_Gain*Path_Gain');
delay=round((0:1/5:1)*10*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];
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];
% 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 = 4;
CodeRate = 1/(2+puncture);
% end
trel=poly2trellis(9,[561 753]);
InputN=1; OutputN=2;
tblen=40;
Slot_number=20;
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*Slot_number-MemLen; % Number of message bits
msg_SlotL=Symbol_bitN*SlotData_length/OutputN*InputN;
code_L=Symbol_bitN*SlotData_length*Slot_number;
code_SlotL=Symbol_bitN*SlotData_length;
K1=code_L/64;
K2=64;
int_table1 = WcdmaTurboInterleaver(K1)';
int_table2 = WcdmaTurboInterleaver(K2)';
for n=1:K2
int_table((n-1)*K1+1:n*K1)=K1*(int_table2(n)-1)+int_table1;
end
%int_table0 = WcdmaTurboInterleaver(msg_L+MemLen)-1;
[int_table0] = interleave(msg_L+MemLen, floor(sqrt((msg_L+MemLen)/2)));
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(3,20);
format long
% Main loop
for Antenna_number=2.^(0:0); % Number of receive antennas
SNR1=15; SNR2=20;
for SNR=SNR1:SNR2
errors=0;
for k=1:2000
SNR
k
msg=randint(Carrier_number_used,msg_L,2); % Random data
% msg=[msg zeros(Carrier_number,InputN*tblen)];
for nc=1:Carrier_number_used
% code(nc,:)=convenc(msg(nc,:),trel); % Encode
code(nc,:) = TuEnc(msg(nc,:), puncture, int_table0, poly_g1, poly_g2);
% code(nc,:)=reshape(vec2mat(code(nc,:),Subslot_number),1,code_L); % Interleaving
end
code=vec2mat(reshape(code,1,code_L*Carrier_number_used),code_L);
code=code(:,int_table);
for sn=0:Slot_number-1
% Transmiter
% Transmiter:Generate single-carrier baseband signals
[PN,PN_RegStateI,PN_RegStateQ]=Complex_PNGen(PN_PolynI,PN_PolynQ,PN_RegStateI,PN_RegStateQ,SlotData_length); % get a complex PN sequence.
for nc=1:Carrier_number_used
s=[];
% x=((1-2*code(nc,sn*code_SlotL+(1:2:code_SlotL)))+j*(1-2*code(nc,sn*code_SlotL+(2:2:code_SlotL))))/sqrt(2); % QPSK mapping
x=Map_16QAM(bi2de(vec2mat(code(nc,sn*code_SlotL+(1:code_SlotL)),4),'left-msb')'+1); % 16QAM mapping
%[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=reshape((Walsh*reshape(x,Code_channel,Symbol_number_slot)),1,SlotData_length).*PN; % spread spectrum modulation without interleving
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -