122 lines
4.3 KiB
Matlab
122 lines
4.3 KiB
Matlab
function [txPad,cfgHE]=TX_SU(cfgHE,txPSDU)
|
||
|
||
if isfield(cfgHE,'InterleavLen')
|
||
tx = SU_Special(cfgHE,txPSDU);
|
||
% Add trailing zeros to allow for channel delay
|
||
txPad = [tx; zeros(30,1)];
|
||
else
|
||
|
||
% psduLength = getPSDULength(cfgHE); % PSDU length in bytes
|
||
% txPSDUcrc = TX_CRC32(txPSDU(1:(psduLength*8 - 32)));
|
||
txPSDUcrc = txPSDU;
|
||
tx = wlanWaveformGenerator(txPSDUcrc,cfgHE);
|
||
|
||
% Add trailing zeros to allow for channel delay
|
||
txPad = [tx; zeros(30,cfgHE.NumTransmitAntennas)];
|
||
|
||
end
|
||
end
|
||
|
||
function crcData = TX_CRC32(dataPacketBits)
|
||
poly = [32,26,23,22,16,12,11,10,8,7,5,4,2,1,0];
|
||
crcGen32 = comm.CRCGenerator(...
|
||
'Polynomial', poly, ...
|
||
'InitialConditions', 1, ... % Initial states of the internal shift register 移位寄存器
|
||
'DirectMethod', true, ...
|
||
'FinalXOR', 1); % 打开 XOR操作
|
||
crcData = crcGen32(dataPacketBits);
|
||
end
|
||
%%
|
||
function tx = SU_Special(WaveformPara,txPSDU)
|
||
|
||
% tx_STF = STS_modulation(NumerologyNo); % STF
|
||
|
||
scrData = TX_CRC32_Scramble(txPSDU);
|
||
trellis = poly2trellis(7,[171 133]);
|
||
tx_encoded_bit = convenc(scrData,trellis,WaveformPara.puncpat);
|
||
tx_padded_bit = [tx_encoded_bit;zeros(WaveformPara.DataPadding,1)];
|
||
%---------------------------------------------
|
||
dataMod = qammod(tx_padded_bit,WaveformPara.Mod,'InputType','bit','UnitAveragePower',true);
|
||
WaveformPara.Power_sym = mean(abs(dataMod).^2);
|
||
dataMod = reshape(dataMod,WaveformPara.UsedSubcarrier,[]);
|
||
|
||
% 获取信道响应 %假设已知前一时刻的信号
|
||
% 生成信道响应
|
||
% N_carriers = WaveformPara.N_FFT;
|
||
% rng(2);
|
||
% channel_response=sqrt(1/2)*(randn(1,N_carriers)+1i*randn(1,N_carriers));
|
||
% % 窗的数目
|
||
% N_windows = 8;
|
||
% % 定义量化水平总数
|
||
% N_level = 10;
|
||
% % 最小CP值,外部条件,取决于最大延迟拓展,有最小CP值>最大延迟拓展
|
||
% min_len_CP = 30;
|
||
% % 测试函数
|
||
% CPset = Generate_CP(channel_response,N_windows,N_level,min_len_CP);
|
||
|
||
% 物理层加密
|
||
% [serialOFDMsym,WaveformPara.pilot,myFrameLen] = tx_FFTSymbolGen_PilotBlockPN(dataMod,WaveformPara,CPset); % 加CP的地方
|
||
[serialOFDMsym,WaveformPara.pilot] = tx_FFTSymbolGen_PilotBlockPN(dataMod,WaveformPara);
|
||
WaveformPara.Power_sig = mean(abs(serialOFDMsym).^2);
|
||
txdata = serialOFDMsym/sqrt(WaveformPara.Power_sig);
|
||
|
||
cfg = wlanNonHTConfig('SignalChannelBandwidth',true, ...
|
||
'BandwidthOperation','Static');
|
||
cfg.MCS = WaveformPara.MCS;
|
||
cfg.PSDULength = WaveformPara.PacketSize; %0-4095
|
||
% tx_STF = STS_modulation(NumerologyNo); % STF
|
||
FrameNo = WaveformPara.NumerologyNo;
|
||
tx_STF = wlanLSTF(cfg); % STF
|
||
tx_LTF = wlanLLTF(cfg); % LTF
|
||
[tx_SIG, tx_sigdata] = newLSIG(cfg,FrameNo);% SIG
|
||
|
||
tx = [tx_STF;tx_LTF;tx_SIG;serialOFDMsym;zeros(30,1)];
|
||
|
||
|
||
end
|
||
|
||
|
||
function [serialOFDMsym,pilot] = tx_FFTSymbolGen_PilotBlockPN(dataModInMatrix,WaveformPara,SysParameters)
|
||
|
||
numOfdmSymbol = WaveformPara.FrameSymNum;
|
||
N_used = WaveformPara.UsedSubcarrier;
|
||
CP_Len = WaveformPara.CP_Len;
|
||
|
||
pnSequence = comm.PNSequence('Polynomial',[8 6 5 4 0], ...
|
||
'SamplesPerFrame',N_used,'InitialConditions',[0 0 0 0 0 0 0 1]);
|
||
|
||
% pilotPower = WaveformPara.Power_sym;
|
||
% pilot = generatePilot(pnSequence,pilotPower);
|
||
pilot = generatePilot(pnSequence,1);
|
||
|
||
m = WaveformPara.PilotNum-1;
|
||
dataModAddPilot = zeros(N_used,numOfdmSymbol);
|
||
for i = 1:m
|
||
dataModAddPilot(:,(i-1)*(WaveformPara.PilotInterval+1)+1:i*(WaveformPara.PilotInterval+1)) = ...
|
||
[pilot,dataModInMatrix(:,(i-1)*WaveformPara.PilotInterval+1:i*WaveformPara.PilotInterval)];
|
||
end
|
||
dataModAddPilot(:,m*(WaveformPara.PilotInterval+1)+1:end) = ...
|
||
[pilot,dataModInMatrix(:,m*WaveformPara.PilotInterval+1:end)];
|
||
|
||
dataModAddPilot_shift = [zeros(1,WaveformPara.FrameSymNum);...
|
||
dataModAddPilot(1:(N_used-1)/2,:);...
|
||
zeros(WaveformPara.NullSubcarrier,WaveformPara.FrameSymNum);...
|
||
dataModAddPilot(1+(N_used-1)/2:end,:)];
|
||
|
||
|
||
OFDMsym = ifft(dataModAddPilot_shift,[],1)*sqrt(WaveformPara.N_FFT)/sqrt(N_used)*sqrt(WaveformPara.N_FFT);
|
||
|
||
OFDMsymAddCP = [OFDMsym(WaveformPara.N_FFT-CP_Len+1:end,:);OFDMsym];
|
||
|
||
serialOFDMsym = reshape(OFDMsymAddCP,[],1);
|
||
|
||
end
|
||
|
||
function pilot = generatePilot(pnSequence,Power)
|
||
|
||
pilot = pnSequence();
|
||
|
||
bpskModulator = comm.BPSKModulator;
|
||
pilot = bpskModulator(pilot)*sqrt(Power);
|
||
end
|