You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
6.8 KiB
176 lines
6.8 KiB
function [cfgRx,cfgUsers,ind]= pktFormatDetect(ind,pktOffset,rx,cfgRx)
|
|
chanBW = cfgRx.ChannelBandwidth;
|
|
fs = wlanSampleRate(cfgRx);
|
|
pilotTracking = 'Joint';
|
|
%% Packet Format Detection
|
|
|
|
rxLLTF = rx(pktOffset+(ind.LLTF(1):ind.LLTF(2)),:);
|
|
lltfDemod = wlanLLTFDemodulate(rxLLTF,cfgRx.ChannelBandwidth);
|
|
lltfChanEst = wlanLLTFChannelEstimate(lltfDemod,cfgRx.ChannelBandwidth);
|
|
noiseVar = helperNoiseEstimate(lltfDemod);
|
|
|
|
% disp('Detect packet format...');
|
|
rxSIGA = rx(pktOffset+(ind.LSIG(1):ind.HESIGA(2)),:);
|
|
pktFormat = wlanFormatDetect(rxSIGA,lltfChanEst,noiseVar,cfgRx.ChannelBandwidth);
|
|
% fprintf(' %s packet detected\n\n',pktFormat);
|
|
%--------------0324----SU-special-----------
|
|
if strcmp(pktFormat,'Non-HT')
|
|
cfgRx = wlanNonHTConfig('SignalChannelBandwidth',true, ...
|
|
'BandwidthOperation','Static');
|
|
% cfgRx.PacketFormat = pktFormat;
|
|
ind = wlanFieldIndices(cfgRx);
|
|
cfgUsers = {cfgRx};
|
|
else
|
|
%--------------0324----SU-special-----------
|
|
|
|
% Set the packet format in the recovery object and update the field indices
|
|
cfgRx.PacketFormat = pktFormat;
|
|
ind = wlanFieldIndices(cfgRx);
|
|
|
|
%% L-LTF Channel Estimate
|
|
lltfDemod = wlanHEDemodulate(rxLLTF,'L-LTF',chanBW);
|
|
lltfChanEst = wlanLLTFChannelEstimate(lltfDemod,chanBW);
|
|
|
|
%% L-SIG and RL-SIG Decoding
|
|
% Extract L-SIG and RL-SIG fields
|
|
rxLSIG = rx(pktOffset+(ind.LSIG(1):ind.RLSIG(2)),:);
|
|
|
|
% OFDM demodulate
|
|
helsigDemod = wlanHEDemodulate(rxLSIG,'L-SIG',chanBW);
|
|
|
|
% Estimate CPE and phase correct symbols
|
|
helsigDemod = preHECommonPhaseErrorTracking(helsigDemod,lltfChanEst,'L-SIG',chanBW);
|
|
|
|
% Estimate channel on extra 4 subcarriers per subchannel and create full
|
|
% channel estimate
|
|
preheInfo = wlanHEOFDMInfo('L-SIG',chanBW);
|
|
preHEChanEst = preHEChannelEstimate(helsigDemod,lltfChanEst,preheInfo.NumSubchannels);
|
|
|
|
% Average L-SIG and RL-SIG before equalization
|
|
helsigDemod = mean(helsigDemod,2);
|
|
|
|
% Equalize data carrying subcarriers, merging 20 MHz subchannels
|
|
[eqLSIGSym,csi] = preHESymbolEqualize(helsigDemod(preheInfo.DataIndices,:,:), ...
|
|
preHEChanEst(preheInfo.DataIndices,:,:),noiseVar,preheInfo.NumSubchannels);
|
|
|
|
% Decode L-SIG field
|
|
[~,failCheck,lsigInfo] = wlanLSIGBitRecover(eqLSIGSym,noiseVar,csi);
|
|
|
|
if failCheck
|
|
disp(' ** L-SIG check fail **');
|
|
else
|
|
disp(' L-SIG check pass');
|
|
end
|
|
% Get the length information from the recovered L-SIG bits and update the
|
|
% L-SIG length property of the recovery configuration object
|
|
lsigLength = lsigInfo.Length;
|
|
cfgRx.LSIGLength = lsigLength;
|
|
|
|
% Measure EVM of L-SIG symbols
|
|
EVM = comm.EVM;
|
|
EVM.ReferenceSignalSource = 'Estimated from reference constellation';
|
|
EVM.Normalization = 'Average constellation power';
|
|
EVM.ReferenceConstellation = wlanReferenceSymbols('BPSK');
|
|
rmsEVM = EVM(eqLSIGSym);
|
|
fprintf(' L-SIG EVM: %2.2fdB\n\n',20*log10(rmsEVM/100));
|
|
|
|
% Calculate the receive time and corresponding number of samples in the
|
|
% packet
|
|
RXTime = ceil((lsigLength + 3)/3) * 4 + 20; % In microseconds
|
|
numRxSamples = round(RXTime * 1e-6 * fs); % Number of samples in time
|
|
|
|
%% HE-SIG-A Decoding
|
|
rxSIGA = rx(pktOffset+(ind.HESIGA(1):ind.HESIGA(2)),:);
|
|
sigaDemod = wlanHEDemodulate(rxSIGA,'HE-SIG-A',chanBW);
|
|
hesigaDemod = preHECommonPhaseErrorTracking(sigaDemod,preHEChanEst,'HE-SIG-A',chanBW);
|
|
|
|
% Equalize data carrying subcarriers, merging 20 MHz subchannels
|
|
preheInfo = wlanHEOFDMInfo('HE-SIG-A',chanBW);
|
|
[eqSIGASym,csi] = preHESymbolEqualize(hesigaDemod(preheInfo.DataIndices,:,:), ...
|
|
preHEChanEst(preheInfo.DataIndices,:,:), ...
|
|
noiseVar,preheInfo.NumSubchannels);
|
|
% Recover HE-SIG-A bits
|
|
[sigaBits,failCRC] = wlanHESIGABitRecover(eqSIGASym,noiseVar,csi);
|
|
|
|
% Perform the CRC on HE-SIG-A bits
|
|
if failCRC
|
|
disp(' ** HE-SIG-A CRC fail **');
|
|
else
|
|
disp(' HE-SIG-A CRC pass');
|
|
end
|
|
|
|
% Measure EVM of HE-SIG-A symbols
|
|
% release(EVM);
|
|
% if strcmp(pktFormat,'HE-EXT-SU')
|
|
% % The second symbol of an HE-SIG-A field for an HE-EXT-SU packet is
|
|
% % QBPSK.
|
|
% EVM.ReferenceConstellation = wlanReferenceSymbols('BPSK',[0 pi/2 0 0]);
|
|
% % Account for scaling of L-LTF for an HE-EXT-SU packet
|
|
% rmsEVM = EVM(eqSIGASym*sqrt(2));
|
|
% else
|
|
% EVM.ReferenceConstellation = wlanReferenceSymbols('BPSK');
|
|
% rmsEVM = EVM(eqSIGASym);
|
|
% end
|
|
% fprintf(' HE-SIG-A EVM: %2.2fdB\n\n',20*log10(mean(rmsEVM)/100));
|
|
|
|
%% Interpret Recovered HE-SIG-A bits
|
|
cfgRx = interpretHESIGABits(cfgRx,sigaBits);
|
|
ind = wlanFieldIndices(cfgRx); % Update field indices
|
|
% disp(cfgRx)
|
|
|
|
|
|
%% HE-SIG-B Decoding
|
|
if strcmp(pktFormat,'HE-MU')
|
|
if ~cfgRx.SIGBCompression
|
|
s = getSIGBLength(cfgRx);
|
|
%*********************************lql03.21修改*********************************
|
|
% 强制类型转换
|
|
indHESIGA2 = double(ind.HESIGA(2));
|
|
% Get common field symbols. The start of HE-SIG-B field is known
|
|
rxSym = rx(pktOffset+(indHESIGA2+(1:s.NumSIGBCommonFieldSamples)),:);
|
|
%*********************************lql03.21修改*********************************
|
|
% Decode HE-SIG-B common field
|
|
[status,cfgRx] = heSIGBCommonFieldDecode(rxSym,preHEChanEst,noiseVar,cfgRx);
|
|
|
|
% CRC on HE-SIG-B content channels
|
|
if strcmp(status,'Success')
|
|
fprintf(' HE-SIG-B (common field) CRC pass\n');
|
|
elseif strcmp(status,'ContentChannel1CRCFail')
|
|
fprintf(' ** HE-SIG-B CRC fail for content channel-1\n **');
|
|
elseif strcmp(status,'ContentChannel2CRCFail')
|
|
fprintf(' ** HE-SIG-B CRC fail for content channel-2\n **');
|
|
elseif any(strcmp(status,{'UnknownNumUsersContentChannel1','UnknownNumUsersContentChannel2'}))
|
|
error(' ** Unknown packet length, discard packet\n **');
|
|
else
|
|
% Discard the packet if all HE-SIG-B content channels fail
|
|
error(' ** HE-SIG-B CRC fail **');
|
|
end
|
|
% Update field indices as the number of HE-SIG-B symbols are
|
|
% updated
|
|
ind = wlanFieldIndices(cfgRx);
|
|
end
|
|
|
|
% Get complete HE-SIG-B field samples
|
|
rxSIGB = rx(pktOffset+(ind.HESIGB(1):ind.HESIGB(2)),:);
|
|
fprintf(' Decoding HE-SIG-B user field... \n');
|
|
% Decode HE-SIG-B user field
|
|
[failCRC,cfgUsers] = heSIGBUserFieldDecode(rxSIGB,preHEChanEst,noiseVar,cfgRx);
|
|
|
|
% CRC on HE-SIG-B users
|
|
if ~all(failCRC)
|
|
fprintf(' HE-SIG-B (user field) CRC pass\n\n');
|
|
numUsers = numel(cfgUsers);
|
|
elseif all(failCRC)
|
|
% Discard the packet if all users fail the CRC
|
|
error(' ** HE-SIG-B CRC fail for all users **');
|
|
else
|
|
fprintf(' ** HE-SIG-B CRC fail for at least one user\n **');
|
|
% Only process users with valid CRC
|
|
numUsers = numel(cfgUsers);
|
|
end
|
|
|
|
else % HE-SU, HE-EXT-SU
|
|
cfgUsers = {cfgRx};
|
|
numUsers = 1;
|
|
end
|
|
end
|