MATLAB AWGN
y = awgn(x,SNR) :在信号x中加入高斯白噪声。信噪比SNR以dB为单位。x的强度假定为0dBW。如果x是复数,就加入复噪声。
y = awgn(x,SNR,SIGPOWER) 如果SIGPOWER是数值,则其代表以dBW为单位的信号强度;如果SIGPOWER为’measured’,则函数将在加入噪声之前测定信号强度。
function y = awgn(varargin)
%#codegen
narginchk(2,5);
% Validate signal input
sig = varargin{1};
validateattributes(sig, {‘numeric’}, …
{‘nonempty’}, ‘awgn’, ‘signal input’);
% Validate SNR input
reqSNR = varargin{2};
validateattributes(reqSNR, {‘numeric’}, …
{‘real’,‘scalar’,‘nonempty’}, ‘awgn’, ‘SNR input’);
% Validate signal power
if nargin >= 3
if strcmpi(varargin{3}, ‘measured’)
sigPower = sum(abs(sig( : )).^2)/numel(sig); % linear
else
validateattributes(varargin{3}, {‘numeric’}, …
{‘real’,‘scalar’,‘nonempty’}, ‘awgn’, ‘signal power input’);