Generated banner for Matlab Model Rf
Generated logo for Matlab Model Rf

Matlab Model Rf

MathWorksOfficialCreated by MathWorks

  • Skill
  • Guidelines
  • Science and research
  • BSD-2-Clause
  • No issues found

From the author

RF Toolbox and RF Blockset in MATLAB -- S-parameter I/O, network conversions (S/Z/Y/ABCD/T/H/G, mixed-mode), cascade/de-embedding, rfbudget analysis, circuit composition, matching networks, amplifier stability, mixer spurs, rational fitting, SI channels, baseband processing, Circuit Envelope simulation. Trigger: sparameters, Touchstone, .s2p, .s4p, rfplot, smithplot, rfparam, rfwrite, zparameters, yparameters, abcdparameters, s2sdd, cascadesparams, deembedsparams, rfbudget, noise figure, OIP3, IIP3, amplifier, modulator, nport, rffilter, attenuator, seriesRLC, shuntRLC, lcladder, txline, circuit, setports, clone, matchingnetwork, stabilityk, stabilitymu, powergain, gammams, gammaml, mixerIMT, OpenIF, rational, rationalfit, stepresp, txlineWRLGC, rf.Amplifier, rf.Mixer, rf.Filter, rf.Sparameter, rfsystem, RF Blockset.
— the description by MathWorks

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured approach to utilizing MATLAB's RF Toolbox and RF Blockset for end-to-end RF system development. It covers workflows ranging from measured S-parameter data validation and network conversions to complex circuit-level design, amplifier stability analysis, and time-domain Circuit Envelope simulation. The documentation emphasizes best practices for script-based workflows, proper element handling, and avoiding common pitfalls in RF parameter manipulation and system modeling.

What it does

  • Validates and processes measured S-parameter data from Touchstone files.
  • Performs network parameter conversions and mixed-mode analysis.
  • Enables RF signal chain design and cascaded budget analysis.
  • Supports circuit-level composition and impedance matching network design.
  • Facilitates amplifier stability analysis and mixer intermodulation planning.
  • Provides tools for rational fitting and time-domain system simulation.

When to use it

  • When working with measured S-parameter data for validation or de-embedding.
  • When designing RF signal chains and performing cascaded budget analysis.
  • When composing arbitrary RF circuits using node-based netlists.
  • When analyzing amplifier stability or mixer spur performance.
  • When performing time-domain signal integrity or Circuit Envelope simulations.

Advantages

  • Unified workflow for both passive and active RF device characterization.
  • Strict adherence to MATLAB identifier and object handling rules prevents silent errors.
  • Comprehensive support for modern visualization tools like tiledlayout and smithplot.
  • Clear separation between script-based design workflows and interactive analysis.
  • Detailed guidance on avoiding common errors in port ordering and parameter units.

Usage examples

“How do I load an S-parameter file and plot it on a Smith chart?”
The agent will guide you to use sparameters() to load the file, followed by smithplot() for visualization, ensuring you handle reference impedance correctly via newref() if needed.
“Calculate the cascaded gain and noise figure for my RF chain.”
The agent will help you define elements using rfbudget, ensuring you set the SignalBandwidth and use clone() for reused elements, then run the budget analysis.
“How do I analyze the stability of an amplifier?”
The agent will instruct you to use stabilityk and stabilitymu, and calculate power gain using powergain with the correct linear-to-dB conversion.
“I need to export my S-parameters to a new file.”
The agent will provide the rfwrite command, specifically reminding you to include 'ForceOverwrite', true to avoid interactive dialogs.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/matlab/matlab-model-rf/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip matlab-model-rf.zip -d .agents/skills

Documentation by MathWorks

RF Toolbox and RF Blockset

Design, analyze, and simulate RF systems in MATLAB -- from measured S-parameter data through full time-domain Circuit Envelope simulation. One unified workflow covering passive networks, active device characterization, system cascade budgets, and behavioral time-domain modeling.

When to Use

Measured data workflows

  • Loading Touchstone files (.s1p through .snp), validating quality (passivity, causality, IEEE P370)

  • Plotting on Smith charts and rectangular plots, interpolating, re-referencing impedance

  • Converting between S, Z, Y, ABCD, T, H, G parameters; computing mixed-mode differential

  • Cascading and de-embedding S-parameter networks; fixture removal

System design and analysis

  • Building RF signal chains from behavioral elements (amplifier, modulator, rffilter, nport, etc.)

  • Computing cascaded gain, noise figure, IP3, SNR, output power with rfbudget

  • Comparing Friis vs Harmonic Balance solver accuracy

  • Exporting to RF Blockset Simulink models, Communications Toolbox, or MATLAB scripts

Circuit-level design

  • Composing arbitrary RF circuits with node wiring (SPICE-like netlist)

  • Designing impedance matching networks (L, Pi, Tee topologies, Richards stubs)

  • Analyzing amplifier stability (K-factor, mu), power gain, and matching conditions

  • Mixer intermodulation analysis and spur-free IF frequency planning

Time-domain and signal integrity

  • Fitting S-parameters to rational models; computing TDR, impulse, step responses

  • Exporting broadband circuit models to SPICE or Verilog-A

  • Building SI channel models from nport blocks, lossy transmission lines, and parasitics

  • Processing complex baseband signals through rf.Amplifier, rf.Mixer, rf.Filter System Objects

  • Full Circuit Envelope time-domain simulation via rfsystem (no Simulink knowledge required)

When NOT to Use

  • Antenna design and radiation patterns -- use Antenna Toolbox

  • RF propagation modeling (path loss, fading, ray tracing) -- use Communications Toolbox or Phased Array System Toolbox

  • SerDes/high-speed serial link equalization (FFE, CTLE, DFE, IBIS-AMI) -- use SerDes Toolbox

  • Radar waveform design or phased arrays -- use Phased Array System Toolbox

Must-Follow Rules

These apply across ALL RF Toolbox workflows. Violating them produces silent errors or blocks execution.

Universal
  1. rfwrite blocks on existing files -- Always pass 'ForceOverwrite', true. Without it, MATLAB opens an interactive overwrite dialog that halts unattended execution.

  2. Elements cannot be reused -- The same element object cannot appear twice in an rfbudget or circuit. Use clone(element) for independent copies.

  3. Element Name must be a valid MATLAB identifier -- No spaces, no special characters. Use 'IFAmp' not 'IF Amp'.

  4. Use tiledlayout/nexttile -- Not subplot. For all multi-panel figures.

  5. rfparam returns complex, not dB -- Always use 20*log10(abs(rfparam(...))) for dB magnitude.

S-Parameters and Network Parameters
  1. sparameters(filename, Z0) is invalid -- Cannot pass reference impedance at load time. Load first, then newref(s, Z0).

  2. rfinterp1 interpolates real/imag independently -- Not magnitude and angle. Can produce artifacts near sharp resonances.

  3. Frequency alignment required for cascade/de-embed -- cascadesparams and deembedsparams require identical frequency vectors. Always rfinterp1 to a common grid first.

  4. deembedsparams always requires 3 arguments -- (sMeasured, sFixture1, sFixture2). For one-sided, pass an ideal thru for the unused side.

  5. Mixed-mode port ordering is the #1 error source -- s2sdd option 1 (default) treats ports 1,2 as positive and 3,4 as negative. Verify which option matches your VNA port numbering.

  6. snp2smp argument order: ports before impedance -- snp2smp(s, portList, Z0), not snp2smp(s, Z0, portList).

rfbudget and Elements
  1. SignalBandwidth is required -- The 4th positional arg to rfbudget. Without it, NF/IP3/SNR remain empty.

  2. Passive NF equals loss -- For rfelement, NF should equal abs(Gain). Prefer attenuator which handles this automatically.

  3. nport Name is positional -- nport('file.s2p', 'MyName'), not name-value syntax.

  4. rffilter: ResponseType is shape, FilterType is algorithm -- rffilter('FilterType', 'Bandpass') errors. Use rffilter('ResponseType', 'Bandpass').

  5. show(b) opens a GUI -- Produces no command-window output. Use properties (b.TransducerGain, b.NF) for programmatic access.

Circuit Composition
  1. setports/setterminals can only be called once -- Plan topology before defining terminals.

  2. 2-port RF elements use 4-node mapping -- add(ckt, [in out inRef outRef], elem) for amplifier, modulator, nport, all txline types. Primitive 2-terminal elements (resistor, capacitor, inductor) use 2-node mapping.

  3. Primitive constructors are positional -- resistor(100, 'R1'), not resistor('Resistance', 100).

  4. setterminals takes a node vector -- setterminals(ckt, [1 2]), not setterminals(ckt, 1, 2).

  5. All txline constructors use name-value pairs only -- No positional arguments.

Amplifier Analysis
  1. powergain gain type string must be last -- powergain(s, 50, 50, 'Gt'), not powergain(s, 'Gt', 50, 50).

  2. powergain returns linear, not dB -- Convert with 10*log10(g) (power gain uses 10x, not 20x).

  3. Gmag returns NaN when conditionally stable -- Use Gmsg at frequencies where K < 1.

Rational Fitting
  1. rational vs rationalfit -- Use rational for new code (AAA). Use rationalfit only for delay extraction.

  2. Single-param fit returns plain vectors; multi-port returns cell arrays -- Always check with iscell(result).

  3. freqresp takes Hz -- Not rad/s. Pass s.Frequencies directly.

System Objects (rf.*)
  1. rf.Amplifier/rf.Mixer use 1-ohm power -- Vin = sqrt(Pin_W). This differs from rfsystem which uses 50-ohm.

  2. rf.Filter frequencies are ABSOLUTE RF -- PassFreq_bp=[2.395e9 2.405e9] means absolute GHz. Not baseband offsets.

  3. Properties locked during use -- Call release(obj) before modifying Nontunable properties.

rfsystem
  1. Requires rfbudget -- rfsystem takes an rfbudget, not raw elements.

  2. close_system needs save flag -- Use close_system(rfs, 0) to discard changes.

  3. IdealizedBaseband only supports amplifier/modulator/rffilter/nport -- Other elements require CircuitEnvelope.

Workflow Quick Reference

TaskEntry PointDetails
Load/plot S-parameterssparameters, rfplot, smithplotreference/sparameters-io.md
Convert S/Z/Y/ABCD, mixed-modezparameters, s2sdd, snp2smpreference/network-conversions.md
Cascade or de-embed networkscascadesparams, deembedsparamsreference/cascade-deembed.md
Create rfbudget elementsamplifier, modulator, rffilter, etc.reference/rfbudget-elements.md
Run cascade budget analysisrfbudget, rfplot(b, 'Pout')reference/rfbudget-analysis.md
Compose RF circuitscircuit, add, setportsreference/circuit-composition.md
Design matching networksmatchingnetwork, richardsreference/matching-networks.md
Analyze amplifier stability/gainstabilityk, powergain, gammamsreference/amplifier-analysis.md
Mixer spurs and IF planningmixerIMT, OpenIFreference/mixer-analysis.md
Fit rational models, TDRrational, stepresp, generateSPICEreference/rational-fitting.md
Build SI channel modelsnport + txlineWRLGC + circuitreference/si-channel-modeling.md
Process complex basebandrf.Amplifier, rf.Mixer, rf.Filterreference/baseband-processing.md
Time-domain system simulationrfsystem, Circuit Envelopereference/system-simulation.md

Conventions

Code Style
  • Use tiledlayout/nexttile for multi-panel figures (not subplot)

  • Always label axes with units (GHz, dB, ns, dBm) and include figure titles

  • Name elements descriptively for readable topology ('LNA', 'DCBlock', 'PCBTrace')

  • Use clone() liberally for element reuse

Script-First Workflow

For design, analysis, or sweep tasks -- write code to .m files on disk, not inline snippets. For quick one-off checks, inline evaluate_matlab_code is fine.

Modern APIs
  • tiledlayout/nexttile instead of subplot

  • datetime instead of datenum

  • rational instead of rationalfit (unless delay extraction needed)

  • smithplot instead of smith

  • rfplot for S-parameter visualization (handles dB conversion automatically)

References

Load the relevant reference file before writing code for a specific workflow. Each reference contains correct calling conventions, constructor arguments, property names, gotchas, and executable code patterns.


Copyright 2026 The MathWorks, Inc.


Files

reference/amplifier-analysis.md

RF Amplifier Stability and Gain Analysis

Evaluate stability, power gain, matching, and quality of active RF devices using S-parameter data.

Passivity and Causality

Passivity

A passive network cannot produce energy. Active devices (amplifiers) are expected to fail passivity — that is normal.

[isPass, idxNonPass] = ispassive(s);
if ~isPass
    fprintf('Non-passive at %d of %d frequencies\n', numel(idxNonPass), numel(s.Frequencies));
    sFixed = makepassive(s);            % Enforce passivity
end

Gotcha: makepassive(sparametersObj) directly modifies S-parameter data point-by-point to force passivity — it does not optimize. This is different from makepassive(fitObj) on a rational fit, which performs an optimization over the fit residues (see reference/rational-fitting.md). Only use makepassive on S-parameter data for small numerical violations (e.g., measurement noise on passive devices). It is NOT appropriate for active devices — the result will not represent the original network.

Causality
if iscausal(s)
    disp('S-parameters are causal');
end

Stability Analysis

Rollett Stability Factor (K)

The classic two-condition test for unconditional stability:

[k, b1, b2, delta] = stabilityk(s);
% Unconditionally stable when K > 1 AND |delta| < 1
isUnconditional = (k > 1) & (abs(delta) < 1);

fprintf('K range: %.3f to %.3f\n', min(k), max(k));
fprintf('Unconditionally stable at %d of %d frequencies\n', ...
    sum(isUnconditional), numel(k));

Output meanings:

  • k — Rollett stability factor (unconditionally stable when K > 1)

  • b1 — Auxiliary stability measure: 1 - |S11|^2 - |S22|^2 + |delta|^2. Sign of b1 indicates which stability circle (source or load) contains the Smith chart center. Positive b1 means the stable region for the source includes the center.

  • b2 — Same as b1 but for the load plane: 1 - |S22|^2 - |S11|^2 + |delta|^2 (symmetric formula)

  • delta — Determinant of the S-matrix: S11*S22 - S12*S21. Unconditional stability requires |delta| < 1 in addition to K > 1.

Edwards-Sinsky Stability Factor (mu)

Single-condition test — preferred because one parameter suffices:

mu = stabilitymu(s);
% Unconditionally stable when mu > 1

figure;
plot(s.Frequencies/1e9, mu, 'LineWidth', 1.5);
yline(1, 'r--', 'Stability Boundary');
xlabel('Frequency (GHz)'); ylabel('\mu');
title('Edwards-Sinsky Stability Factor'); grid on;

Power Gain

Gain Metrics
Function CallMetricDescription
powergain(s, 'Gmag')Maximum available gainValid only when unconditionally stable (K > 1)
powergain(s, 'Gmsg')Maximum stable gainUse when conditionally stable (K < 1)
powergain(s, Zs, Zl, 'Gt')Transducer gainActual gain with specific source/load impedances
powergain(s, Zs, 'Ga')Available gainWith specific source impedance
powergain(s, Zl, 'Gp')Operating power gainWith specific load impedance

Gotcha: The gain type string must be the last argument. powergain(s, 'Gt', 50, 50) errors — use powergain(s, 50, 50, 'Gt') instead.

gmag = powergain(s, 'Gmag');           % Maximum available gain
gmsg = powergain(s, 'Gmsg');           % Maximum stable gain

gt = powergain(s, 50, 75, 'Gt');       % Transducer gain (Zs=50, Zl=75)
ga = powergain(s, 50, 'Ga');           % Available gain (Zs=50)
gp = powergain(s, 75, 'Gp');           % Operating power gain (Zl=75)

Gotcha: powergain returns linear gain, NOT dB. Convert with 10*log10(g) (power gain uses 10x, not 20x).

Gotcha: Gmag returns NaN at frequencies where the device is conditionally stable (K < 1). Use Gmsg at those frequencies.

Gotcha: Gmsg returns Inf when S12 approaches zero (unilateral device). Guard with isfinite(gmsg) before converting to dB.

Combined Gain Plot Pattern
gmag = powergain(s, 'Gmag');
gmsg = powergain(s, 'Gmsg');

figure;
plot(s.Frequencies/1e9, 10*log10(gmag), ...
     s.Frequencies/1e9, 10*log10(gmsg), '--', 'LineWidth', 1.5);
xlabel('Frequency (GHz)'); ylabel('Gain (dB)');
title('Maximum Available / Stable Gain');
legend('Gmag', 'Gmsg'); grid on;

Reflection Coefficients

For impedance matching design — compute the reflection coefficients needed for simultaneous conjugate match or for given termination impedances.

gin  = gammain(s, zl);                 % Input reflection coefficient (given load Zl)
gout = gammaout(s, zs);                % Output reflection coefficient (given source Zs)
gms  = gammams(s);                     % Source match for simultaneous conjugate match
gml  = gammaml(s);                     % Load match for simultaneous conjugate match
Converting Gamma to Impedance

To convert a reflection coefficient to impedance (e.g., for matching network targets):

Z0 = 50;
Zs = Z0 * (1 + gms) ./ (1 - gms);    % Source impedance for conjugate match
Zl = Z0 * (1 + gml) ./ (1 - gml);    % Load impedance for conjugate match
Frequency Interpolation

If the desired analysis frequency is not in the S-parameter data, interpolate first:

sInterp = rfinterp1(s, targetFreq);   % Interpolate to specific frequency
gms_f0 = gammams(sInterp);            % Now compute at exact frequency
Circuit Implementation of Matching Networks

After computing gammams/gammaml, translate to matching network circuits using matchingnetwork (for lumped/stub synthesis) or circuit (for assembling txlineMicrostrip stubs with nport amplifier blocks). Key points for circuit assembly:

  • Use circuit for the nport + transmission line + setports workflow

  • Call setports only once per circuit, after all elements are add()ed and wired

  • If combining sub-circuits (e.g., input match + amplifier + output match), build each as a separate circuit object, then compose them in a parent circuit using setterminals

Noise Parameters

The noiseParameters object stores noise data (minimum noise figure, optimum reflection coefficient, equivalent noise resistance) that accompanies amplifier S-parameter data.

Constructor
np = noiseParameters(fmin, freq, z0);
% fmin: minimum noise figure (linear, not dB) at each frequency
% freq: frequency vector in Hz
% z0: reference impedance for Rn normalization
Rn Normalization Convention

The Rn property (equivalent noise resistance) is normalized to z0:

% If measured Rn data is in ohms (absolute):
np = noiseParameters(fmin, freq, 1);   % z0=1: Rn values ARE resistance in ohms
np.Rn = measuredRn_ohms;

% If Rn data is normalized to 50 ohm:
np = noiseParameters(fmin, freq, 50);  % z0=50: Rn = Rn_actual/50
np.Rn = measuredRn_normalized;

Many datasheets give Rn in ohms, so z0=1 is more intuitive for direct entry.

Gotcha: z0 only affects Rn normalization — it does NOT affect Fmin or GammaOpt. Do not confuse noise reference impedance with S-parameter reference impedance.

Circle Computations (Stability, Noise, Gain)

For plotting stability circles, noise circles, and available gain circles on the Smith chart, see reference/circle-computations.md. Summary:

  • Call smithplot() with no arguments to create an empty Smith chart with grid lines

  • Then hold on + plot(real(pts), imag(pts)) to overlay any circle or curve

  • Circle points: center + radius * exp(1j*linspace(0, 2*pi, 201))

  • Formulas for center/radius of stability, noise, and gain circles are in the reference file

Gotchas

  1. powergain gain type string must be the last argument -- powergain(s, 'Gt', 50, 50) errors. Use powergain(s, 50, 50, 'Gt').

  2. powergain returns linear gain, not dB -- Convert with 10*log10(g) (power gain uses 10x, not 20x).

  3. Gmag returns NaN when conditionally stable -- At frequencies where K < 1, Gmag is undefined. Use Gmsg at those frequencies instead.

  4. Gmsg returns Inf for unilateral devices -- When S12 approaches zero, Gmsg blows up. Guard with isfinite(gmsg) before converting to dB.

  5. Do not apply makepassive to amplifiers -- Active devices are expected to be non-passive. makepassive(sparametersObj) modifies data point-by-point and does NOT represent the original active device.

  6. makepassive on S-parameters vs rational fits -- makepassive(sparametersObj) is a crude point-by-point fix. makepassive(fitObj) on a rational fit runs an optimization over residues (see reference/rational-fitting.md). Only use on S-parameter data for small numerical violations on passive devices.

  7. setports can only be called once per circuit -- If you get "terminals already set", you are calling setports on a circuit that already has ports defined. Build all elements and wiring first, then call setports once at the end.

  8. gammams/gammaml return complex values -- Convert to impedance with Z = Z0*(1+gamma)./(1-gamma). Convert to magnitude/angle with abs(gamma) and angle(gamma)*180/pi.

Conventions

  • Use tiledlayout/nexttile for multi-panel stability/gain figures

  • Always label axes with units (GHz, dB) and include figure titles

  • Plot a yline(1, 'r--') stability boundary on mu plots for visual clarity

  • Active devices are expected to be non-passive — do not apply makepassive to amplifiers


Copyright 2026 The MathWorks, Inc.


Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Node.js

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
MathWorks
Publisher
MathWorks (Official)
Source
matlab/matlab-agentic-toolkit · skills-catalog/rf-and-mixed-signal/matlab-model-rf · commit 2a7f215
Licence
BSD 2-Clause License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.md)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-model-rf.zip