Create Custom RF Blockset™ Models
This example shows how to write your own nonlinear RF Blockset Circuit Envelope model in Simscape® language, build the custom library and use it in RF Blockset simulation.
The system consists of:
- The input signal specified in Simulink Ramp block has linearly increasing magnitude. The carrier frequency(Input_Freq) is specified in RF Blockset Inport block. This setup allows to observe the nonlinearity behavior in various input settings.
- The nonlinear device is a basic voltage amplifier (polynomial voltage controlled voltage source), modeled by a Simscape custom block. The device equations are written in passband (time) domain and assume instantaneous voltage V(t) and current I(t) values. These equations are interpreted by RF Blockset envelope solver in both passband and baseband domains (zero and nonzero carrier frequencies). The output frequencies (Output_Freqs) contain higher order harmonics (integer multiples) of the input frequency due to the nonlinearity of the amplifier.
- Scope displays the magnitudes of the output voltages at frequencies Output_Freqs, which are specified at RF Blockset Outport.
- Load resistors and ground nodes are needed to make the circuit electrically sound. By construction, the resistor values do not affect the output voltage.
Examine the Model
Type open_system('simrfV2_custom_polynomial') at the Command Window prompt. Double-click the "Custom Nonlinearity" block
The file vcvs_poly_3.ssc describing the custom device is located inside the package +simrfV2_custom_elements. You can see the source code of the file by clicking on the "View source" link on the block, or opening it from the command prompt
If you copy the +simrfV2_custom_elements directory to a place where you have write permission, you can modify vcvs_poly_3.ssc source file and build the library simrfV2_custom_elements_lib.slx with the command
See Creating Custom Components documentation for more details.
Examine the custom library created by Simscape compiler
Run the Model with Default Settings
By default, both input and output frequencies are set to 0, so the result is a regular passband simulation. The input voltage is linearly increasing, Vin(t) = t, so the output plots the relationship between input and output voltages Vout(Vin).
Select Simulation > Run.
Observe the cubic polynomial specified in the 'Custom Nonlinearity' model with the saturation input voltage kicking in at time 0.7 seconds, which corresponds to the input voltage of 0.7V.
Run the Model with Non-zero Input Carrier
Set the input carrier frequency to 1GHz and the output frequencies to the harmonics of the input. For non-zero input frequency, RF Blockset interprets the input as a complex baseband signal (this particular signal is real, so it has only the in-phase part).
Type the following in Command Prompt:
Input_Freq = 1e9; Output_Freqs = (1:5)*Input_Freq;
Even coefficients c0 and c2 are equal to zero, so the output has only odd harmonics (1GHz and 3GHz) until the input voltage reaches saturation. Other harmonics are introduced for the larger values of input voltage because of the saturation effects.
The relationship between the output curves, polynomial coefficients and IP2/IP3/P1db coefficients is well-studied in the literature [1,2].
RF Blockset model could be written as a regular time-domain electrical model in Simscape language (including the models with derivatives, such as capacitors and inductors, which are not shown in this demo). As with any other model description language, the user is responsible for the validity of the model:
- There has to be the correct number of equations.
- Equations could not be degenerate, unstable, or discontinuous (try to avoid negative resistances or sharp nonlinearities).
- Even the correctly written model might have a convergence error during the simulation.
- Kundert, Ken. "Accurate and Rapid Measurement of IP2 and IP3." The Designers Guide Community, Version 1b, May 22, 2002.
- Chen, Jesse. "Modeling RF systems." The Designers Guide Community, Version 1, 6 March 2005.