资源描述:
《MATLAB-生成高斯噪声wgn函数.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、functiony=wgn(varargin)%WGNGeneratewhiteGaussiannoise.%Y=WGN(M,N,P)generatesanM-by-NmatrixofwhiteGaussiannoise.%PspecifiesthepoweroftheoutputnoiseindBW.%%Y=WGN(M,N,P,IMP)specifiestheloadimpedanceinOhms.%%Y=WGN(M,N,P,IMP,STATE)resetsthestateofRANDNtoSTATE.%%Additionalflagsthatcanfoll
2、owthenumericargumentsare:%%Y=WGN(...,POWERTYPE)specifiestheunitsofP.POWERTYPEcan%be'dBW','dBm'or'linear'.LinearpowerisinWatts.%%Y=WGN(...,OUTPUTTYPE);Specifiestheoutputtype.OUTPUTTYPEcan%be'real'or'complex'.Iftheoutputtypeiscomplex,thenP%isdividedequallybetweentherealandimaginarycom
3、ponents.%%Example1:%%Togeneratea1024-by-1vectorofcomplexnoisewithpower%%of5dBmacrossa50Ohmload,use:%Y=wgn(1024,1,5,50,'dBm','complex')%%Example2:%%Togeneratea256-by-5matrixofrealnoisewithpower%%of10dBWacrossa1Ohmload,use:%Y=wgn(256,5,10,'real')%%Example3:%%Togeneratea1-by-10vectorof
4、complexnoisewithpower%%of3Wattsacrossa75Ohmload,use:%Y=wgn(1,10,3,75,'linear','complex')%%SeealsoRANDN,AWGN.%Copyright1996-2008TheMathWorks,Inc.%$Revision:1.11.4.5$$Date:2008/08/0112:17:45$%---Initialcheckserror(nargchk(3,7,nargin,'struct'));%---Valuesetindicators(usedforthestrings)
5、pModeSet=0;cplxModeSet=0;%---Setdefaultvaluesp=[];row=[];col=[];pMode='dbw';imp=1;cplxMode='real';seed=[];%---PlaceholdersforthenumericandstringindexvaluesnumArg=[];strArg=[];%---Identifystringandnumericarguments%Anemptyinposition4(Impedance)or5(Seed)areconsiderednumericforn=1:nargi
6、nif(isempty(varargin{n}))switchncase4if(ischar(varargin{n}))error('comm:wgn:InvalidDefaultImp','Thedefaultimpedanceshouldbemarkedby[].');end;varargin{n}=imp;%Impedancehasadefaultvaluecase5if(ischar(varargin{n}))error('comm:wgn:InvalidNumericInput','Thedefaultseedshouldbemarkedby[].'
7、);end;varargin{n}=[];%Seedhasnodefaultotherwisevarargin{n}='';end;end;%---Assignthestringandnumericvectorsif(ischar(varargin{n}))strArg(size(strArg,2)+1)=n;elseif(isnumeric(varargin{n}))numArg(size(numArg,2)+1)=n;elseerror('comm:wgn:InvalidArg','Onlystringandnumericargumentsareallow
8、ed.');end;end;%---B