matlab wgn未定义,解决matlab缺少awgn和wgn函数的问题

将以下两个.m文件放到同一文件夹内运行

ps:这两个m文件来自  "MATLAB\R2009a\toolbox\comm\comm"

awgn.m

function y=awgn(varargin)

%AWGN Add white Gaussian noise to a signal.

% Y = AWGN(X,SNR) adds white Gaussian noise to X. The SNR is in dB.

% The power of X is assumed to be 0 dBW. If X is complex, then

% AWGN adds complex noise.

%

% Y = AWGN(X,SNR,SIGPOWER) when SIGPOWER is numeric, it represents

% the signal power in dBW. When SIGPOWER is 'measured', AWGN measures

% the signal power before adding noise.

%

% Y = AWGN(X,SNR,SIGPOWER,STATE) resets the state of RANDN to STATE.

%

% Y = AWGN(..., POWERTYPE) specifies the units of SNR and SIGPOWER.

% POWERTYPE can be 'db' or 'linear'. If POWERTYPE is 'db', then SNR

% is measured in dB and SIGPOWER is measured in dBW. If POWERTYPE is

% 'linear', then SNR is measured as a ratio and SIGPOWER is measured

% in Watts.

%

% Example 1:

% % To specify the power of X to be 0 dBW and add noise to produce

% % an SNR of 10dB, use:

% X = sqrt(2)*sin(0:pi/8:6*pi);

% Y = awgn(X,10,0);

%

% Example 2:

% % To specify the power of X to be 3 Watts and add noise to

% % produce a linear SNR of 4, use:

% X = sqrt(2)*sin(0:pi/8:6*pi);

% Y = awgn(X,4,3,'linear');

%

% Example 3:

% % To cause AWGN to measure the power of X and add noise to

% % produce a linear SNR of 4, use:

% X = sqrt(2)*sin(0:pi/8:6*pi);

% Y = awgn(X,4,'measured','linear');

%

% See also WGN, RANDN, and BSC.

% Copyright 1996-2008 The MathWorks, Inc.

% $Revision: 1.9.4.6 $ $Date: 2008/08/22 20:23:43 $

% --- Initial checks

error(nargchk(2,5,nargin,'struct'));

% --- Value set indicators (used for the string flags)

pModeSet = 0;

measModeSet = 0;

% --- Set default values

sigPower = 0;

pMode = 'db';

measMode = 'specify';

state = [];

% --- Placeholder for the signature string

sigStr = '';

% --- Identify string and numeric arguments

for n=1:nargin

if(n>1)

sigStr(size(sigStr,2)+1) = '/';

end

% --- Assign the string and numeric flags

if(ischar(varargin{n}))

sigStr(size(sigStr,2)+1) = 's';

elseif(isnumeric(varargin{n}))

sigStr(size(sigStr,2)+1) = 'n';

else

error('comm:awgn:InvalidArg','Only string and numeric arguments are allowed.');

end

end

% --- Identify parameter signatures and assign values to variables

switch sigStr

% --- awgn(x, snr)

case 'n/n'

sig = varargin{1};

reqSNR = varargin{2};

% --- awgn(x, snr, sigPower)

case 'n/n/n'

sig = varargin{1};

reqSNR = varargin{2};

sigPower = varargin{3};

你可能感兴趣的:(matlab,wgn未定义)