load('TXPackets\transmit_data.mat','tx_data','cfgUI'); snr = 30; if cfgUI.numUsers == 1 CommMode = 'HE-SU'; else CommMode = 'HE-MU'; end %***************************************** % number of (real + virtual) users RU_index = RU_alloc(cfgUI); allocInfo = wlan.internal.heAllocationInfo(RU_index); cfgUI.numUsers = allocInfo.NumUsers; %***************************************** rx_data = chanPass(tx_data,cfgUI,snr,CommMode); for i =1:cfgUI.numUsers matName = ['rx_for_User',num2str(i),'.mat']; if cfgUI.numUsers == 1 rx = rx_data; save(['TXPackets\',matName],'rx'); else rx = rx_data{i}; save(['TXPackets\',matName],'rx'); end end %% function rx = chanPass(txPad,cfgUI,snr,CommMode) numTx = cfgUI.numTx; numRx = cfgUI.numRx; guardInterval = 0.8;% Guard interval in Microseconds cfgNDP = wlanHESUConfig('APEPLength',0,'GuardInterval',guardInterval); % No data in an NDP cfgNDP.ChannelBandwidth = cfgUI.ChannelBandwidth; cfgNDP.NumTransmitAntennas = numTx; cfgNDP.NumSpaceTimeStreams = numRx; if strcmp(CommMode,'HE-SU') % Create and configure the TGax channel chanBW = cfgNDP.ChannelBandwidth; tgaxChannel = wlanTGaxChannel; tgaxChannel.DelayProfile = 'Model-B'; tgaxChannel.NumTransmitAntennas = cfgNDP.NumTransmitAntennas; tgaxChannel.NumReceiveAntennas = numRx; tgaxChannel.TransmitReceiveDistance = 5; % Distance in meters for NLOS tgaxChannel.ChannelBandwidth = chanBW; tgaxChannel.LargeScaleFadingEffect = 'None'; fs = wlanSampleRate(cfgNDP); tgaxChannel.SampleRate = fs; tgaxChannel.RandomStream = 'mt19937ar with seed'; tgaxChannel.Seed = 5; % Get occupied subcarrier indices and OFDM parameters ofdmInfo = wlanHEOFDMInfo('HE-Data',cfgNDP); stream = RandStream('combRecursive','Seed',99); % stream.Substream = snr; RandStream.setGlobalStream(stream); % Create an instance of the AWGN channel per SNR point simulated awgnChannel = comm.AWGNChannel; awgnChannel.NoiseMethod = 'Signal to noise ratio (SNR)'; awgnChannel.SignalPower = 1/tgaxChannel.NumReceiveAntennas; % Account for noise energy in nulls so the SNR is defined per % active subcarrier awgnChannel.SNR = snr-10*log10(ofdmInfo.FFTLength/ofdmInfo.NumTones); % Pass through a fading indoor TGax channel % reset(tgaxChannel); % Reset channel for different realization rx = tgaxChannel(txPad); % Pass the waveform through AWGN channel rx = awgnChannel(rx); elseif strcmp(CommMode,'HE-MU') tgaxBase = wlanTGaxChannel; tgaxBase.DelayProfile = 'Model-D'; % Delay profile tgaxBase.NumTransmitAntennas = cfgNDP.NumTransmitAntennas; % Number of transmit antennas tgaxBase.NumReceiveAntennas = numRx; % Each user has two receive antennas tgaxBase.TransmitReceiveDistance = 10; % Non-line of sight distance tgaxBase.ChannelBandwidth = cfgNDP.ChannelBandwidth; tgaxBase.SampleRate = wlanSampleRate(cfgNDP); % Set a fixed seed for the channel tgaxBase.RandomStream = 'mt19937ar with seed'; % Generate per-user channels numUsers = cfgUI.numUsers; % Number of users simulated in this example tgax = cell(1,numUsers); for userIdx = 1:numUsers % tgaxBase.Seed = randi(100); tgaxBase.Seed = userIdx; tgax{userIdx} = clone(tgaxBase); tgax{userIdx}.UserIndex = userIdx; % Set unique user index end awgnChannel = comm.AWGNChannel; awgnChannel.NoiseMethod = 'Signal to noise ratio (SNR)'; awgnChannel.SignalPower = 1/numRx; % Account for noise energy in nulls so the SNR is defined per % active subcarrier awgnChannel.SNR = snr; rxUsers = cell(1,numUsers); % allocInfo = ruInfo(cfgNDP); % 使数据经过信道 for userIdx = 1:numUsers tgaxClone = cloneChannels(tgax); rxUsers{userIdx} = tgaxClone{userIdx}(txPad); rxUsers{userIdx} = awgnChannel(rxUsers{userIdx}); end rx = rxUsers; end end function tgaxClone = cloneChannels(tgax) % Clone the channels before running to ensure the same realization can be % used in the next simulation tgaxClone = cell(size(tgax)); numUsers = numel(tgax); for i=1:numUsers tgaxClone{i} = clone(tgax{i}); end end