%% RF Noise Modeling
% This example shows how to use the RF Blockset(TM) Circuit Envelope
% library to simulate noise and calculate noise power. Results are compared
% against theoretical calculations and a Communications Toolbox(TM)
% reference model.
% 
% Copyright 2017-2019 The MathWorks, Inc.
 
%%
% The model is shown below.
model = 'RFNoise';
open_system(model);
sim(model);
 
%% System Architecture
% The RF system, shown in white, consists of:
%
% * A |Configuration| block, which sets global simulation parameters for
% the RF Blockset system. With the *Simulate Noise* option checked, noise
% is included in the simulation.
%
% * An |External Noise| source with a power spectral density of $4kT_sR$
% applied at the input. In this equation, $k$ is the Boltzmann constant,
% $T_s$ is the temperature of the source, and $R$ is the noise reference
% impedance. The calculated noise level of -174 dBm/Hz is used in this
% example. The |External Noise| source is an explicit signal.
%
% * An |Amplifier| block with a specified power gain and noise figure.
% * A |Voltage Sensor| (i.e. |Outport|) block, with the *Source type*
% parameter set to *Voltage*.
% * Source and load resistors.
% 
% The Communications Toolbox reference system, shown in green,
% consists of:
%
% * |Gain| blocks that model amplifier gain and loading effects.
% * Two |Receiver Thermal Noise| blocks that model the external noise
% and the amplifier noise, respectively. 
%
% The |Calculate Power| block computes RMS noise power. Note that the
% Communications Toolbox signal is referenced to 1 ohm, while RF
% Blockset power is computed for the actual load $R_load$ .
% 
% The example model defines variables for block parameters using a callback
% function. To access model callbacks, select *MODELING* > *Model Settings*
% > *Model Properties* and click the Callbacks tab in the Model Properties
% window.
%
 
%% Running the Example
% # Type |open_system('RFNoiseExample')| at the Command Window prompt.
% # Select *Simulation* > *Run*.
%
% The |Noise Power Display| block verifies that the RF Blockset and
% Communications Toolbox noise models are equivalent.
 
%% Computing RF System Noise
% To enable noise in the RF Blockset circuit envelope environment:
% 
% * In the |Configuration| block dialog, select *Simulate noise*.
% * Specify a *Temperature*. RF Blockset uses this value to calculate the
% equivalent noise temperature inside the amplifier.
% * Specify the *Noise figure (dB)* parameter of any amplifiers or mixers
% in the system.
%
% In the example, for a specified LNA gain of 4 dB and noise figure of 3
% dB, the output noise is calculated using the following equations:
% 
% $$G_1 = 2.5119 \mbox{  (4 dB)}$$
%
% $$F_1 = 1.9953 \mbox{  (3 dB)}$$
%
% The next equation converts the noise factor to an equivalent noise
% temperature. $T$ is the *Temperature* parameter of the RF Blockset
% |Configuration| block.
%
% $$T_e = (F_1 - 1)*T = 288.63$$
% 
% The final equation calculates the output noise power. $T_s$ is the
% temperature of the SimRF(TM) |External Noise| block and the Communications
% Toolbox |External Noise Floor| block.
%
% $$N_{out,sys} = 10\log_{10}{\left(k(T_s + T_e)G_1\right)} + 30 = -166.97
% \mbox{ dBm/Hz}$$
%
% The available noise power is the power that can be supplied by a
% resistive source when it is feeding a noiseless resistive load equal to
% the source resistance. The green |External Noise Floor| block generates
% an available power referenced to 50 ohms.
%
% The |Front End Gain| block models the voltage divider due to the source
% resistance and the input impedance of the amplifier.
%
% The green |Reference Amplifier Noise| and |Amplifier Gain| blocks model
% the noise added by the amplifier and the amplifier gain, respectively.
%
% The output of the Communications Toolbox |Amplifier Gain| block is
% equal to the voltage across the RF Blockset |R_load| block.

bdclose(model)
