www.gusucode.com > wlan工具箱matlab源码程序 > wlan/wlanexamples/helperReferenceSymbols.m
function refSym = helperReferenceSymbols(varargin) %helperReferenceSymbols Find the closest constellation point % % REFSYM = helperReferenceSymbols(CFGFORMAT) returns the constellation % used in a single-user transmission as a column vector of complex % symbols. Only OFDM formats are supported. CFGFORMAT is the format % configuration object of type <a href="matlab:help('wlanVHTConfig')">wlanVHTConfig</a>, <a href="matlab:help('wlanHTConfig')">wlanHTConfig</a>, or % <a href="matlab:help('wlanNonHTConfig')">wlanNonHTConfig</a>, which specifies the parameters for the VHT, % HT-Mixed, and Non-HT formats, respectively. % % REFSYM = helperReferenceSymbols(CFGVHTMU,USERNUMBER) returns the % constellation used in a transmission for an individual user of interest % in a VHT multi-user configuration. CFGVHTMU must be a <a href="matlab:help('wlanVHTConfig')">wlanVHTConfig</a> % object with NumUsers > 1. USERNUMBER is the user of interest, specified % as an integer from 1 to NumUsers, where NumUsers is the number of users % in the transmission. % % REFSYM = helperReferenceSymbols(SYM,CFGFORMAT) returns the closest % constellation point for given symbols SYM and single-user format % configuration object CFGFORMAT. SYM is an array containing complex % symbols of type double. % % REFSYM = helperReferenceSymbols(SYM,CFGVHTMU,USERNUMBER) returns the % closest constellation point for given symbols SYM for an individual % user of interest in a VHT multi-user configuration. CFGVHTMU must be a % <a href="matlab:help('wlanVHTConfig')">wlanVHTConfig</a> object with NumUsers > 1. % % % Example 1: Plot a noisy QPSK constellation with reference points % % sym = awgn(1/sqrt(2)*qammod(randi([0 3],100,1),4),20); % Noisy QPSK % cfgVHT = wlanVHTConfig('MCS',1); % MCS1 = QPSK % refSym = helperReferenceSymbols(cfgVHT); % figure; % plot(sym,'b.'); % hold on; % plot(refSym,'ro'); % legend('Symbols','Ref','Location','South'); % % % Example 2: Plot the EVM per symbol of a noisy QPSK constellation % % sym = awgn(1/sqrt(2)*qammod(randi([0 3],100,1),4),20); % Noisy QPSK % cfgVHT = wlanVHTConfig('MCS',1); % MCS1 = QPSK % ref = helperReferenceSymbols(sym,cfgVHT); % figure; % plot(100*sqrt((real(sym)-real(ref)).^2+(imag(sym)-imag(ref)).^2)); % xlabel('Symbol number'); % ylabel('EVM (%)'); % Copyright 2016 The MathWorks, Inc. %#codegen narginchk(1,3); % First argument should be numeric (symbols) or a confguration object validateattributes(varargin{1}, ... {'numeric','wlanVHTConfig','wlanHTConfig','wlanNonHTConfig'},{},mfilename,'first argument'); userNumPresent = false; % Assume USERNUMBER not passed as an argument userNum = 1; % Assume SU configuration if isa(varargin{1},'numeric') % REFSYM = helperReferenceSymbols(SYM,CFGFORMAT,...) narginchk(2,3) sym = varargin{1}; cfgFormat = varargin{2}; calcRef = true; % Input symbols provided; calculate reference if nargin>2 % REFSYM = helperReferenceSymbols(SYM,CFGFORMAT,USERNUMBER) userNumPresent = true; userNum = varargin{3}; end else % REFSYM = helperReferenceSymbols(CFGFORMAT,...) narginchk(1,2) cfgFormat = varargin{1}; calcRef = false; % No input symbols provided; do not calculate reference if nargin>1 % REFSYM = helperReferenceSymbols(CFGFORMAT,USERNUMBER) userNumPresent = true; userNum = varargin{2}; end end % Validate the configuration object validateattributes(cfgFormat,{'wlanVHTConfig','wlanHTConfig', ... 'wlanNonHTConfig'},{'scalar'},mfilename,'format configuration object'); coder.internal.errorIf( ... isa(cfgFormat,'wlanNonHTConfig') && ~strcmp(cfgFormat.Modulation,'OFDM'), ... 'wlan:helperReferenceSymbols:InvalidNonHTModulation') if userNumPresent % Validate the user number input against configuration object if a MU % VHT object, otherwise assume SU if isa(cfgFormat,'wlanVHTConfig') && cfgFormat.NumUsers>1 validateattributes(userNum,{'numeric'},{'integer','scalar','>=',1,'<=',4},mfilename,'user number'); coder.internal.errorIf(userNum>cfgFormat.NumUsers, ... 'wlan:helperReferenceSymbols:InvalidUserNum',userNum,cfgFormat.NumUsers); else % Force user number to be 1 if not a VHT MU object (therefore SU) userNum = 1; end end % Get the constellation used for the transmission % Generate bit input for all symbols and constellation map mcsTable = wlan.internal.getRateTable(cfgFormat); x = reshape(de2bi((0:((2^mcsTable.NBPSCS(userNum))-1)),'left-msb').', ... mcsTable.NBPSCS(userNum)*2^mcsTable.NBPSCS(userNum),1); const = wlan.internal.wlanConstellationMapper(x,mcsTable.NBPSCS(userNum)); if calcRef % REFSYM = helperReferenceSymbols(SYM,CFGFORMAT,...) % Determine the closest reference constellation point for each symbol refSym = complex(zeros(size(sym))); for i = 1:numel(sym) [~,idx] = min(abs(sym(i)-const)); refSym(i) = const(idx); end else % REFSYM = helperReferenceSymbols(CFGFORMAT,...) refSym = const; end end