function y = ehtLSTF(cfgEHT,varargin)
%ehtLSTF Legacy Short Training Field (L-STF)
%
%   Y = ehtLSTF(CFGEHT) generates the legacy Short Training Field (L-STF)
%   time-domain signal for the EHT transmission format.
%
%   Y is the time-domain L-STF signal. It is a complex matrix of size
%   Ns-by-Nt where Ns represents the number of time-domain samples and Nt
%   represents the number of transmit antennas.
%
%   CFGEHT is the format configuration object of type <a
%   href="matlab:help('ehtMUConfig')">ehtMUConfig</a>.
%
%   Y = ehtLSTF(CFGEHT,OSF) generates a signal oversampled by the
%   oversampling factor OSF. When not specified, 1 is assumed.
%
%   Example: Generate an L-STF field for a 320 MHz, EHT MU PPDU format.
%
%     cfgEHT = ehtMUConfig('CBW320');
%     y = ehtLSTF(cfgEHT);
%     plot(abs(y));
%
%   See also ehtMUConfig, ehtLLTF.

%   Copyright 2020-2021 The MathWorks, Inc.

osf = 1;
if nargin>1
    osf = varargin{1};
end

LSTF = wlan.internal.lstfSequence();

% Number of tone used for scaling the signal. IEEE P802.11be/D1.0, Table 36-26
chBW = wlan.internal.cbwStr2Num(cfgEHT.ChannelBandwidth);
N_LSTF_TONE = wlan.internal.heToneScalingFactor('L-STF',chBW);
N_LLTF_TONE = wlan.internal.heToneScalingFactor('L-LTF',chBW);
N_LSIG_TONE = wlan.internal.heToneScalingFactor('L-SIG',chBW);
epsilon = sqrt(N_LLTF_TONE/N_LSIG_TONE); % Power scaling factor

% Mapping
cfgOFDM = wlan.internal.hePreHEOFDMConfig(cfgEHT.ChannelBandwidth);
Nfft = cfgOFDM.FFTLength*osf;
num20 = cfgOFDM.NumSubchannels;
LSTF = [zeros(6,1); LSTF; zeros(5,1)];
symOFDM = repmat(LSTF,num20,1); % Replicate for each BW
[lstf,scalingFactor] = ehtPreEHTFieldMap(symOFDM,N_LSTF_TONE,cfgEHT);

% OFDM modulate
modOut = wlan.internal.wlanOFDMModulate(lstf,0,varargin{:}); % 0 CP length
out = [modOut; modOut; modOut(1:Nfft/2,:)];
y = out*scalingFactor*epsilon;

end