%*********************************lql03.21修改********************************* function [paraCal,tx_data,cfgUI,errorMessage] = TX_transmit(numPkt,SEED,cfgUI,feedback_data,txPSDUfile) % try if strcmp(cfgUI.DataType,'photo') pktLength = cfgUI.user1.APEPlength; % 包长度与包个数自适应判断 zjd3.26 if numPkt*pktLength >= length(txPSDUfile(:,1)) % 如果当前包长度在5个包内能传输当前数据量 for pktNum = 1:numPkt % 判断当前包长度下最少用几个包传数据 if pktNum*pktLength >= length(txPSDUfile(:,1)) numPkt = pktNum; break end end else % 当前包长度不能在5个包内能传输当前数据量,自动调整 if numPkt*7007 >= length(txPSDUfile(:,1)) for pktNum = 1:numPkt % 判断当前包长度下最少用几个包传数据 if pktNum*7007 >= length(txPSDUfile(:,1)) numPkt = pktNum; pktLength = 7007; break end end else for pktNum = 1:numPkt % 判断当前包长度下最少用几个包传数据 if pktNum*12012 >= length(txPSDUfile(:,1)) numPkt = pktNum; pktLength = 12012; break end end end end % 配置计算后的参数 cfgUI.user1.APEPlength = pktLength; cfgUI.user2.APEPlength = pktLength; cfgUI.user1.t = ones(1,numPkt); cfgUI.user2.t = ones(1,numPkt); end if strcmp(cfgUI.FeedbackMode,'feedback') [cfgHE,RU_index,cfgUI] = parameter_fromAlgorithm(cfgUI,feedback_data);% 根据反馈数据配置RU else [cfgHE,RU_index,cfgUI] = parameter_fromUI(cfgUI); % 参数与RU配置 end %*********************************lql03.21修改********************************* showResourceMatrix(cfgHE,cfgUI,RU_index); % 展示资源分配情况 txPSDU = DataGenerate(cfgUI,numPkt,SEED,cfgHE,txPSDUfile); % for i = 1:length(txPSDU) % txPSDU{i} = HESU_gen(txPSDU,cfgUI.ChannelBandwidth,cfgHE.User{1}.MCS); % end tx_data = []; % HE-SU if strcmp(cfgUI.UserMode,'SU') txPSDU = txPSDU{1}; % --------------------------------zjd0323修改----------------------- for pnum = 1 : numPkt [txPad,cfgHE]=TX_SU(cfgHE,txPSDU(:,pnum)); tx_awgn = wgn(600,cfgHE.NumTransmitAntennas,-20,'complex'); tx_data = [tx_data;txPad;tx_awgn]; % 帧间补零 end tx_data = [tx_awgn(1:50,:);tx_data]; % 帧头补零 elseif strcmp(cfgUI.UserMode,'MU') % HE-MU if strcmp(cfgUI.FeedbackMode,'feedback') %*********************************lql03.21修改********************************* % 补充虚拟用户的feedback_data for nuser = 1 : length(cfgHE.User) STAID = cfgHE.User{nuser}.STAID; if STAID == 0 eval(['Feedback_data.user' num2str(nuser) '= feedback_data.user2']); else eval(['Feedback_data.user' num2str(nuser) '= feedback_data.user' num2str(STAID)]); end end staFeedback = cell(1,length(cfgHE.User)); for userIdx = 1:length(cfgHE.User) eval(['staFeedback{userIdx} = Feedback_data.user' num2str(userIdx) '.staFeedback;']); end %*********************************lql03.21修改********************************* cfgNDP = wlanHESUConfig('APEPLength',0,'GuardInterval',0.8); % No data in an NDP cfgNDP.NumTransmitAntennas = cfgHE.NumTransmitAntennas;%?? cfgNDP.NumSpaceTimeStreams = 1;%?? % For each RU calculate the steering matrix to apply for ruIdx = 1:numel(cfgHE.RU) % Calculate the steering matrix to apply to the RU given the feedback steeringMatrix = heMUCalculateSteeringMatrix(staFeedback,cfgHE,cfgNDP,ruIdx); % Apply the steering matrix to each RU cfgHE.RU{ruIdx}.SpatialMapping = 'Custom'; cfgHE.RU{ruIdx}.SpatialMappingMatrix = steeringMatrix; end elseif strcmp(cfgUI.FeedbackMode,'openloop') for ruIdx = 1:numel(cfgHE.RU) % Apply the steering matrix to each RU % cfgHE.RU{ruIdx}.SpatialMapping = cfgUI.user1.SpatialMapping;%% --??? cfgHE.RU{ruIdx}.SpatialMapping = 'Hadamard'; end end % Generate waveform with idle period for pnum = 1 : numPkt userString = '{'; for nuser = 1 : length(cfgHE.User) userString = [userString 'txPSDU{' num2str(nuser) '}(:,pnum),']; end txPSDUtmp = eval([userString(1:(end-1)) '}']); %%------------需添加CRC tx = wlanWaveformGenerator(txPSDUtmp,cfgHE); tx_awgn = wgn(600,cfgHE.NumTransmitAntennas,-20,'complex'); % awgn(zeros(600,cfgHE.NumTransmitAntennas),20,'linear',1,'all'); tx_data = [tx_data;tx;tx_awgn]; % 帧间补零 end tx_data = [tx_awgn(1:50,:);tx_data]; % 帧头补零 % tx_data = awgn(tx_data,30,mean(abs(tx_data(1:1000)).^2)); % 添加噪声 end paraCal = calculate_PAPR(tx_data(1500:2500,:)); errorMessage = ''; % catch ErrorInfo % paraCal = 0; % tx_data = []; % cfgUI = struct(); % errorMessage = ErrorInfo.message; % end end