gusucode.com > UWB_matlab源码程序 > CP0801/cp0801_Gnoise1.m

    %
% FUNCTION 8.2 : "cp0801_Gnoise1"
%
% Introduces additive white Gaussian noise over signal
%  'input'.
% Vector 'ebno' contains the target values of Eb/No (in dB)
% 'numbits' is the number of bits conveyed by the input
%  signal
% 
% Multiple output signals are generated, one signal for
% each target value of Eb/No. The array 'output' contains
% all the signals (input+AWGN), one signal per row.
% The array 'noise' contains the different realization of
% the Gaussian noise, one realization per each row
%
% Programmed by Guerino Giancola
%

function [output,noise] = ...
   cp0801_Gnoise1(input,ebno,numbits)

% -------------------------------
% Step One - Introduction of AWGN
% -------------------------------

Eb = (1/numbits)*sum(input.^2); % measured energy per bit
EbNo = 10.^(ebno./10);          % Eb/No in linear unit     
No = Eb ./ EbNo;                % Unilateral spectral
                                % density
nstdv = sqrt(No./2);            % Standard deviation for
                                % the noise

for j = 1 : length(EbNo)
        
    noise(j,:) = nstdv(j) .* randn(1,length(input));
    output(j,:) = noise(j,:) + input;
    
end