HE/DataGenerate.m
2024-03-30 16:35:40 +08:00

82 lines
3.1 KiB
Matlab

function txPSDU = DataGenerate(cfgUI,numPkt,SEED,arg,txPSDUByteUser)
%*********************************lql03.21修改*********************************
numUsers = cfgUI.numUsers;
DataType = cfgUI.DataType;
if isnumeric(arg)
if cfgUI.numUsers == 1
cfgHE = wlanHESUConfig;
else
cfgHE = wlanHEMUConfig(193);
end
psduLength = ones(1,numUsers)*arg;
else
if isfield(arg,'InterleavLen')
psduLength = arg.PacketSize;
else
cfgHE = arg;
psduLength = getPSDULength(cfgHE); % PSDU length in bytes
end
end
% psduLength = getPSDULength(cfgHE); % PSDU length in bytes
%*********************************lql03.21修改*********************************
if numUsers==1
txPSDU = cell(1,1);
else
allocInfo = ruInfo(cfgHE);
txPSDU = cell(1,allocInfo.NumUsers);
end
% [len,width] = size(txPSDUByteUser(:,:,1));
if strcmp(cfgUI.DataType,'photo')
txPSDUBin = ones(length(txPSDUByteUser(:,1))*8,numUsers);
for userIdx = 1:numUsers
txPSDUBin(:,userIdx) = reshape(int2bit(txPSDUByteUser(:,userIdx),8),1,[]);
end
end
for i = 1:numPkt
if numUsers==1
rng(i+SEED);
switch DataType
case 'test'
txPSDU{1}(:,i) = randi([0 1],psduLength*8,1);
case 'text'
case 'photo'
% 将第i个包对应的内容赋值给第i个包 zjd3.26
if i*psduLength*8 <= length(txPSDUBin)
txPSDU{1}(:,i) = txPSDUBin((i-1)*psduLength*8+1:i*psduLength*8,:);
elseif i*psduLength*8 > length(txPSDUBin) && (i-1)*psduLength*8 < length(txPSDUBin)
padLength = psduLength*8-(length(txPSDUBin)-(i-1)*psduLength*8);
txPSDU{1}(:,i) = [txPSDUBin((i-1)*psduLength*8+1:length(txPSDUBin),:);randi([0 1],padLength,1)];
else
txPSDU{1}(:,i) = randi([0 1],psduLength*8,1);
end
end
else
switch DataType
case 'test'
for ii = 1:allocInfo.NumUsers
rng(i+ii+SEED);
txPSDU{ii}(:,i) = randi([0 1],psduLength(ii)*8,1); % Generate random PSDU
end
case 'text'
case 'photo'
for ii = 1:allocInfo.NumUsers
% 将第i个包对应的内容赋值给第i个包 zjd3.26
if i*psduLength(ii)*8 <= length(txPSDUBin)
txPSDU{ii}(:,i) = txPSDUBin((i-1)*psduLength(ii)*8+1:i*psduLength(ii)*8,ii);
elseif (i*psduLength(ii)*8 > length(txPSDUBin)) && ((i-1)*psduLength(ii)*8 < length(txPSDUBin))
padLength = psduLength(ii)*8-(length(txPSDUBin)-(i-1)*psduLength(ii)*8); % 计算需要补多少随机数
txPSDU{ii}(:,i) = [txPSDUBin((i-1)*psduLength(ii)*8+1:length(txPSDUBin),ii);randi([0 1],padLength,1)];
else
txPSDU{ii}(:,i) = randi([0 1],psduLength(ii)*8,1);
end
end
end
end
end
end