%% 802.11az Waveform Generation
% This example shows how to parameterize and generate IEEE® 802.11az™ high-efficiency (HE) ranging null data packet (NDP) waveforms and highlights some of the key features of the standard.
% Table of Contents
% Introduction
% HE Ranging NDP Without Secure HE-LTF
% Single-User HE Ranging NDP Generation
% HE Ranging NDP With Secure HE-LTF
% Single-User HE Ranging NDP with Secure HE-LTF Generation
% Multi-User HE Ranging NDP Generation
% References
%% Introduction
% The 802.11az standard [1], commonly referred to as next-generation positioning (NGP), enables a station to identify its position relative to other stations. This standard supports two HE ranging physical layer (PHY) protocol data unit (PPDU) formats:
% HE ranging NDP
% HE trigger-based (TB) ranging NDP
% The HE ranging NDP and HE TB ranging NDP are the respective analogues of the HE sounding NDP and HE TB NDP feedback PPDU formats, as defined in the 802.11ax™ standard. For more information on these HE PPDU formats, see [2].
% The HE ranging NDP supports the positioning of one or more users with an optional secure HE long training field (HE-LTF) sequence. The single-user HE ranging waveform contains HE-LTF symbols for a single user, which also support an optional secure HE-LTF sequence. The multi-user HE ranging waveform permits only secure HE-LTF symbols for multiple users. Single-user and multi-user waveforms can contain multiple repetitions of the HE-LTF symbols. This feature can help improve distance estimation accuracy.
% Because the 802.11az standard uses the same underlying PHY technologies as the 802.11ax standard, the processing chains are very similar. This example shows how to generate 802.11az HE ranging NDP waveforms with secure and nonsecure HE-LTF sequences.
%
%% HE Ranging NDP Without Secure HE-LTF
% The HE Ranging NDP contains HE-LTF symbols for a single user and uses the regular HE-LTF sequence defined in [2]. The number of HE-LTF symbols is the product of the number of HE-LTF repetitions and the number of HE-LTF symbols per repetition. The number of  HE-LTF symbols depends on the number of space-time streams as specified in Table 21-13 of [3]. The construction of HE-LTF symbols in an HE Ranging NDP follows the steps defined in section 27.3.10.10 of [2] for all repeated HE-LTF symbols in an HE-LTF.
%
%% Single-User HE Ranging NDP Generation
% Configure a transmission with two antennas, two space-time streams, and two HE-LTF repetitions.

cfg = heRangingConfig('NumTransmitAntennas',2);
cfg.User{1}.NumSpaceTimeStreams = 2;
cfg.User{1}.NumHELTFRepetition = 2;

% Generate the HE ranging NDP waveform for the specified configuration.

tx = heRangingWaveformGenerator(cfg);

%  Plot the transmission power on the first antenna.

heRangingWavGenPlot(tx,cfg);

%
%% HE Ranging NDP With Secure HE-LTF
% To generate an HE ranging NDP with secure HE-LTF symbols, as defined in [2], specify either of these transmission parameter combinations.
% A single-user heRangingConfig object with its SecureHELTF property set to 1 (true)
% A multi-user heRangingConfig object
% The secure HE-LTF comprises a randomized LTF sequence as defined in Section 27.3.17c of [1]. To specify this sequence for a chosen user, set the SecureHELTFSequence property of the corresponding User property of the heRangingConfig object. If the number of bits in the SecureHELTFSequence property is less than the required number of bits for the given user configuration, the object cyclically extends the secure sequence. If the number of bits in SecureHELTFSequence is more than the required number of bits for the given user configuration, the object uses only the required number of bits. The object extracts the required bits from the specified hexadecimal sequence. When the transmission contains a secure HE-LTF sequence, the sequence must use a zero-power guard interval for the HE-LTF symbols. The packet extension (PE) starts with a zero-power guard interval.
%
%% Single-User HE Ranging NDP with Secure HE-LTF Generation
% Configure a transmission with two antennas, two space-time streams, three HE-LTF repetitions, and secure HE-LTF symbols.

cfg = heRangingConfig('NumTransmitAntennas',2,'SecureHELTF',true);
cfg.User{1}.NumSpaceTimeStreams = 2;
cfg.User{1}.NumHELTFRepetition = 3;
cfg.User{1}.SecureHELTFSequence = '12345678ABCDEF1234';

% Generate the HE ranging NDP waveform for the specified configuration.

tx = heRangingWaveformGenerator(cfg);

% Plot the transmission power on the first antenna.

heRangingWavGenPlot(tx,cfg);

%
%% Multi-User HE Ranging NDP Generation
% A multi-user HE ranging NDP waveform contains secure HE-LTF symbols for multiple users. The transmission concatenates HE-LTF symbols for each user up to a maximum of 64 consecutive symbols. This example demonstrates waveform generation with a secure HE-LTF sequence shown for two users. Configure transmission parameters, specifying two users and the number of space-time streams and HE-LTF repetitions for each user.

cfg = heRangingConfig(2);
cfg.User{1}.NumSpaceTimeStreams = 1;
cfg.User{1}.NumHELTFRepetition = 2;
cfg.User{2}.NumSpaceTimeStreams = 1;
cfg.User{2}.NumHELTFRepetition = 3;

% Determine the number of secure HE-LTF bits required to generate the secure HE-LTF symbols for each user by using the numSecureHELTFBits object function.

numNibbles = numSecureHELTFBits(cfg)/4; % 4 bits per nibble

% Set the secure HE-LTF sequences for each user.

secureSeqUser1 = 'a12c67f8b90dc56e78a2b3f1';
cfg.User{1}.SecureHELTFSequence = secureSeqUser1(1:numNibbles(1));
secureSeqUser2 = 'b3a49c5e6c1a2d35ed47c2d915f';
cfg.User{2}.SecureHELTFSequence = secureSeqUser2(1:numNibbles(2));

% Generate the HE ranging NDP waveform for the specified configuration.

tx = heRangingWaveformGenerator(cfg);

% Plot the transmission power on the first antenna.

heRangingWavGenPlot(tx,cfg);

%% References
% IEEE P802.11az™/D2.0 Draft Standard for Information technology — Telecommunications and information exchange between systems Local and metropolitan area networks — Specific requirements - Amendment 3: Enhancements for positioning.
% IEEE P802.11ax™/D4.1 Draft Standard for Information technology — Telecommunications and information exchange between systems — Local and metropolitan area networks — Specific requirements - Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications — Amendment 6: Enhancements for High Efficiency WLAN.
% IEEE Std 802.11™-2016 IEEE Standard for Information technology — Telecommunications and information exchange between systems — Local and metropolitan area networks — Specific requirements - Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications.
% Copyright 2020 The MathWorks, Inc.
%