📄 gmc_16qam_cha.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=2;
SubCarrier_last=13;
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=4; % 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 12 30 52 78 90]*2; % Delays of paths
Path_Gain=exp(-(0:5)/3);
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];
% Define Error Code
trel=poly2trellis(9,[561 753]);
InputN=1; OutputN=2;
tblen=64;
Slot_number=4;
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);
msg_L=Symbol_bitN*SlotData_length/OutputN*InputN*Slot_number-InputN*tblen; % 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;
Intl_length =Subslot_number;
% Raised cosine filter for interpolation
rcflt3=rcosfir(0.15,6,3,1);
% Bit error rate
ber=zeros(3,20);
format long
% Main loop
for Antenna_number=2.^(0:0); % Number of receive antennas
SNR1=10; 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_used,InputN*tblen)];
for nc=1:Carrier_number_used
code(nc,:)=convenc(msg(nc,:),trel); % Encode
code(nc,:)=reshape(vec2mat(code(nc,:),Intl_length),1,code_L); % Interleaving
end
%code=vec2mat(reshape(code,1,code_L*Carrier_number_used),code_L);
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
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
Index_s=0; % Insert pilot and gaurd
for kk=1:Subslot_number
tmp=Tmp_s(Index_s+(1:SubslotData_length));
tmp=[Gaurd_Pilot tmp];
s=[s tmp];
Index_s=Index_s+SubslotData_length;
end
s=[s Gaurd_Pilot];
sb(nc,:)=s;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -