gusucode.com > wlan工具箱matlab源码程序 > wlan/wlanexamples/helperNoiseEstimate.m
function est = helperNoiseEstimate(rxSym,varargin) %helperNoiseEstimate Estimate noise power using L-LTF % % EST = HELPERNOISEESTIMATE(RXSYM) estimates the mean noise power in % watts using the demodulated L-LTF symbols, assuming 1ohm resistance. % The estimated noise power in Non-HT packet is averaged over the number % of receive antennas. % % RXSYM is the frequency-domain signal corresponding to the L-LTF. % It is a complex matrix or 3-D array of size Nst-by-2-by-Nr, where Nst % represents the number of used subcarriers in the L-LTF, and Nr % represents the number of receive antennas. Two OFDM symbols in the % L-LTF field are used to estimate the noise power. % % EST = HELPERNOISEESTIMATE(RXSYM,CHANBW,NUMSTS) returns the estimated % noise power in VHT or HT fields using the specified channel bandwidth, % CHANBW, and number of space-time streams, NUMSTS, for the specific % user. The number of subcarriers used within each field and the scaling % applied during demodulation differs between the Non-HT and HT/VHT % fields. Therefore the estimated noise power after demodulation in % HT/VHT fields is calculated by scaling the estimated noise power in the % L-LTF. % % EST = HELPERNOISEESTIMATE(...,'Per Antenna') specifies the option of % estimating the noise for each receive antenna. When this option is % specified EST is a row vector of length Nr. % % Example: % % Estimate the noise variance of an HT packet. % % cfgHT = wlanHTConfig; % Create packet configuration % chanBW = cfgHT.ChannelBandwidth; % numSTS = cfgHT.NumSpaceTimeStreams; % noisePower = -20; % awgnChannel = comm.AWGNChannel; % awgnChannel.NoiseMethod = 'Variance'; % awgnChannel.Variance = 10^(noisePower/10); % % Nst = 56; % Data and pilot OFDM subcarriers in 20MHz, HT format % Nfft = 64; % FFT size for 20MHz bandwidth % nVarHT = 10^(noisePower/10)*(Nst/Nfft); % Non-HT noise variance % % NumRxAnts = 1; % % Average noise estimate over 100 independent noise realization % for n=1:100 % % Generate LLTF and add noise % rxSym = awgnChannel(wlanLLTF(cfgHT)); % y = wlanLLTFDemodulate(rxSym,cfgHT); % noiseEst(n) = helperNoiseEstimate(y,chanBW,numSTS); % end % % % Check noise variance estimates without Channel % noiseEstError = 10*log10(mean(noiseEst))-10*log10(nVarHT); % disp(['Error between noise variance and mean estimated noise ', ... % 'power(dB): ' num2str(noiseEstError,'%2.2f ')]); % % See also wlanLLTF, wlanLLTFDemodulate. % Copyright 2015-2016 The MathWorks, Inc. %#codegen narginchk(1,4); % Validate symbol type validateattributes(rxSym,{'double'},{'3d','finite'}, ... 'helperNoiseEstimate','L-LTF OFDM symbol(s)'); % Two L-LTF symbols are required to estimate the noise coder.internal.errorIf(size(rxSym,2)~=2, ... 'wlan:helperNoiseEstimate:IncorrectNumSyms'); numSC = size(rxSym,1); % Minimal optional parameter checks if nargin == 2 % (rxSym,'Per Antenna') validateNType(varargin{1}); average = false; scalingFactor = 1; % Noise scaling factor elseif nargin == 3 % (rxSym, chanBW, numSTSu) chanBW = varargin{1}; % chanBW: CBW20/40/80/160 validateInput(chanBW,numSC); numSTSu = varargin{2}; % numSTSu: 1,...,8 average = true; % Noise scaling factor scalingFactor = noiseScaling(chanBW,numSC,numSTSu); elseif nargin == 4 % (rxSym, chanBW, numSTSu, 'Per Antenna') chanBW = varargin{1}; % chanBW: CBW20/40/80/160 validateInput(chanBW,numSC); numSTSu = varargin{2}; % numSTSu: 1,...,8 validateNType(varargin{3}); average = false; % Noise scaling factor scalingFactor = noiseScaling(chanBW,numSC,numSTSu); else % (rxSym) average = true; scalingFactor = 1; end % Noise estimate noiseEst = sum(abs(rxSym(:,1,:) - rxSym(:,2,:)).^2,1)/(2*numSC); if average noise = mean(noiseEst); else noise = squeeze(noiseEst).'; end % Scale est = noise*scalingFactor; end %------------------------------------------------------------------------- function out = noiseScaling(chanBW,numSC,numSTSu) % Get the number of occupied subcarriers in HT and VHT fields. % The number of used subcarriers for HT and VHT are same therefore % fix the string input of the following helper function to VHT. % The guard type is not relevant for numbers alone. [~,vhtData,vhtPilots] = wlan.internal.wlanGetOFDMConfig(chanBW, ... 'Long', 'VHT'); NstVHT = numel(vhtData)+numel(vhtPilots); out = (NstVHT/numSC)*numSTSu; end %------------------------------------------------------------------------- function validateInput(chanBW,numSC) % Get number of used subcarriers in NonHT format [~,nonhtData,nonhtPilots] = wlan.internal.wlanGetOFDMConfig(chanBW, ... 'Long', 'Legacy'); nonhtNst = numel(nonhtData)+numel(nonhtPilots); % Validate number of subcarriers in input coder.internal.errorIf(numSC~=nonhtNst, ... 'wlan:helperNoiseEstimate:IncorrectNumSC',nonhtNst,numSC); end %------------------------------------------------------------------------- function validateNType(nType) coder.internal.errorIf( ~( strcmpi(nType, 'Per Antenna')), ... 'wlan:helperNoiseEstimate:InvalidNoiseEstType'); end % [EOF]