%% Generate VHT Multi-User Waveform
% This example shows how to generate a VHT multi-user waveform from individual components. It also shows how to generate the same waveform by using the wlanWaveformGenerator function.
% Create a VHT configuration object, specifying three users and three transmit antennas.

vht = wlanVHTConfig('NumUsers',3,'NumTransmitAntennas',3);

% Set the number of space-time streams to the vector [1 1 1], which indicates that each user is assigned one space-time stream. Set the user positions to [0 1 2]. Set the group ID to 5. Group ID values from 1 to 62 apply for multiuser operation.

vht.NumSpaceTimeStreams = [1 1 1];
vht.UserPositions = [0 1 2];
vht.GroupID = 5;

% Set a different MCS value for each user.

vht.MCS = [0 2 4];

% Set the APEP length to 2000, 1400, and 1800 bytes. Each element corresponds to the number of bytes assigned to each user.

vht.APEPLength = [2000 1400 1800]

% Display the PSDU lengths for the three users. The PSDU length is a function of both the APEP length and the MCS value.

vht.PSDULength

% Display the field indices for the VHT waveform.

ind = wlanFieldIndices(vht)

% Create the individual fields that comprise the VHT waveform.

lstf = wlanLSTF(vht);
lltf = wlanLLTF(vht);
lsig = wlanLSIG(vht);
[vhtsigA,sigAbits] = wlanVHTSIGA(vht);
vhtstf = wlanVHTSTF(vht);
vhtltf = wlanVHTLTF(vht);
[vhtsigB,sigBbits] = wlanVHTSIGB(vht);

% Extract the first two VHT-SIG-A information bits and convert them to their decimal equivalent.

bw = bi2de(double(sigAbits(1:2)'))

% The value, 2, corresponds to an 80 MHz bandwidth (see wlanVHTSIGA).
% Extract VHT-SIG-A information bits 5 through 10, and convert them to their decimal equivalent.

groupid = bi2de(double(sigAbits(5:10)'))

% The extracted group ID, 5, matches the corresponding property in the VHT configuration object.
% Extract the packet length from the VHT-SIG-B information bits. For multiuser operation with an 80 MHz bandwidth, the first 19 bits contain the APEP length information. Convert the field lengths to their decimal equivalents. Multiply them by 4 because the length of the VHT-SIG-B field is expressed in units of 4 bytes.

pktLen = bi2de(double(sigBbits(1:19,:)'))*4

% Confirm that the extracted APEP length matches the value set in the configuration object.

isequal(pktLen',vht.APEPLength)

% Extract the MCS values from the VHT-SIG-B information bits. The MCS component is specified by bits 20 to 23.

mcs = bi2de(double(sigBbits(20:23,:)'))

% The values correspond to those set in the VHT configuration object.
% Create three data sequences, one for each user.

d1 = randi([0 1],vht.PSDULength(1)*8,1);
d2 = randi([0 1],vht.PSDULength(2)*8,1);
d3 = randi([0 1],vht.PSDULength(3)*8,1);

% Generate a VHT data field using these data sequences.

vhtdata = wlanVHTData({d1 d2 d3},vht);

% Generate a multiuser VHT waveform with windowing is disabled. Extract the data field from the waveform.

wv = wlanWaveformGenerator({d1 d2 d3},vht,'WindowTransitionTime',0);
wvdata = wv(ind.VHTData(1):ind.VHTData(2),:);

% Confirm that the two generation approaches produce identical results.

isequal(vhtdata,wvdata)

% Visualize the waveform by plotting its magnitude.

t = ((1:length(wv))'-1)/80e6;
plot(t,abs(wv))
xlabel('Time (s)')
ylabel('Magnitude')

% Copyright 2012 The MathWorks, Inc.