Matlab Model Rf
MathWorksOfficialCreated by MathWorks
- Skill
- Guidelines
- Science and research
- BSD-2-Clause
- No issues found
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
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/matlab/matlab-model-rf/downloadUnzip 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
rfwriteblocks on existing files -- Always pass'ForceOverwrite', true. Without it, MATLAB opens an interactive overwrite dialog that halts unattended execution.Elements cannot be reused -- The same element object cannot appear twice in an rfbudget or circuit. Use
clone(element)for independent copies.Element Name must be a valid MATLAB identifier -- No spaces, no special characters. Use
'IFAmp'not'IF Amp'.Use
tiledlayout/nexttile-- Notsubplot. For all multi-panel figures.rfparamreturns complex, not dB -- Always use20*log10(abs(rfparam(...)))for dB magnitude.
S-Parameters and Network Parameters
sparameters(filename, Z0)is invalid -- Cannot pass reference impedance at load time. Load first, thennewref(s, Z0).rfinterp1interpolates real/imag independently -- Not magnitude and angle. Can produce artifacts near sharp resonances.Frequency alignment required for cascade/de-embed --
cascadesparamsanddeembedsparamsrequire identical frequency vectors. Alwaysrfinterp1to a common grid first.deembedsparamsalways requires 3 arguments --(sMeasured, sFixture1, sFixture2). For one-sided, pass an ideal thru for the unused side.Mixed-mode port ordering is the #1 error source --
s2sddoption 1 (default) treats ports 1,2 as positive and 3,4 as negative. Verify which option matches your VNA port numbering.snp2smpargument order: ports before impedance --snp2smp(s, portList, Z0), notsnp2smp(s, Z0, portList).
rfbudget and Elements
SignalBandwidthis required -- The 4th positional arg torfbudget. Without it, NF/IP3/SNR remain empty.Passive NF equals loss -- For
rfelement, NF should equalabs(Gain). Preferattenuatorwhich handles this automatically.nportName is positional --nport('file.s2p', 'MyName'), not name-value syntax.rffilter:
ResponseTypeis shape,FilterTypeis algorithm --rffilter('FilterType', 'Bandpass')errors. Userffilter('ResponseType', 'Bandpass').show(b)opens a GUI -- Produces no command-window output. Use properties (b.TransducerGain,b.NF) for programmatic access.
Circuit Composition
setports/setterminalscan only be called once -- Plan topology before defining terminals.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.Primitive constructors are positional --
resistor(100, 'R1'), notresistor('Resistance', 100).setterminalstakes a node vector --setterminals(ckt, [1 2]), notsetterminals(ckt, 1, 2).All txline constructors use name-value pairs only -- No positional arguments.
Amplifier Analysis
powergaingain type string must be last --powergain(s, 50, 50, 'Gt'), notpowergain(s, 'Gt', 50, 50).powergainreturns linear, not dB -- Convert with10*log10(g)(power gain uses 10x, not 20x).Gmagreturns NaN when conditionally stable -- UseGmsgat frequencies where K < 1.
Rational Fitting
rationalvsrationalfit-- Userationalfor new code (AAA). Userationalfitonly for delay extraction.Single-param fit returns plain vectors; multi-port returns cell arrays -- Always check with
iscell(result).freqresptakes Hz -- Not rad/s. Passs.Frequenciesdirectly.
System Objects (rf.*)
rf.Amplifier/rf.Mixer use 1-ohm power --
Vin = sqrt(Pin_W). This differs from rfsystem which uses 50-ohm.rf.Filter frequencies are ABSOLUTE RF --
PassFreq_bp=[2.395e9 2.405e9]means absolute GHz. Not baseband offsets.Properties locked during use -- Call
release(obj)before modifying Nontunable properties.
rfsystem
Requires rfbudget --
rfsystemtakes an rfbudget, not raw elements.close_systemneeds save flag -- Useclose_system(rfs, 0)to discard changes.IdealizedBaseband only supports amplifier/modulator/rffilter/nport -- Other elements require CircuitEnvelope.
Workflow Quick Reference
| Task | Entry Point | Details |
|---|---|---|
| Load/plot S-parameters | sparameters, rfplot, smithplot | reference/sparameters-io.md |
| Convert S/Z/Y/ABCD, mixed-mode | zparameters, s2sdd, snp2smp | reference/network-conversions.md |
| Cascade or de-embed networks | cascadesparams, deembedsparams | reference/cascade-deembed.md |
| Create rfbudget elements | amplifier, modulator, rffilter, etc. | reference/rfbudget-elements.md |
| Run cascade budget analysis | rfbudget, rfplot(b, 'Pout') | reference/rfbudget-analysis.md |
| Compose RF circuits | circuit, add, setports | reference/circuit-composition.md |
| Design matching networks | matchingnetwork, richards | reference/matching-networks.md |
| Analyze amplifier stability/gain | stabilityk, powergain, gammams | reference/amplifier-analysis.md |
| Mixer spurs and IF planning | mixerIMT, OpenIF | reference/mixer-analysis.md |
| Fit rational models, TDR | rational, stepresp, generateSPICE | reference/rational-fitting.md |
| Build SI channel models | nport + txlineWRLGC + circuit | reference/si-channel-modeling.md |
| Process complex baseband | rf.Amplifier, rf.Mixer, rf.Filter | reference/baseband-processing.md |
| Time-domain system simulation | rfsystem, Circuit Envelope | reference/system-simulation.md |
Conventions
Code Style
Use
tiledlayout/nexttilefor multi-panel figures (notsubplot)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/nexttileinstead ofsubplotdatetimeinstead ofdatenumrationalinstead ofrationalfit(unless delay extraction needed)smithplotinstead ofsmithrfplotfor 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
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md9.8 KiB
- manifest.yaml536 B
- reference/amplifier-analysis.md9.3 KiB
- reference/amplifier-models.md2.8 KiB
- reference/amplifier-nonlinear-models.md6.2 KiB
- reference/baseband-processing.md18.5 KiB
- reference/cascade-deembed.md9.0 KiB
- reference/circle-computations.md7.3 KiB
- reference/circuit-composition.md14.1 KiB
- reference/ifft-step-response.md16.8 KiB
- reference/lumped-to-distributed.md2.7 KiB
- reference/matching-networks.md10.8 KiB
- reference/mixer-analysis.md11.0 KiB
- reference/network-conversions.md9.6 KiB
- reference/rational-fitting.md19.8 KiB
- reference/rfbudget-analysis.md8.4 KiB
- reference/rfbudget-elements.md16.8 KiB
- reference/rffilter-synthesis.md2.8 KiB
- reference/si-channel-modeling.md17.8 KiB
- reference/sparameters-io.md12.0 KiB
- reference/system-simulation.md12.9 KiB
- reference/time-domain-analysis.md3.0 KiB
- reference/transmission-lines.md2.8 KiB
reference/si-channel-modeling.md
Signal Integrity Channel Modeling
Build SI channel models by cascading measured S-parameter blocks (nport), lossy frequency-dependent transmission lines (txlineWRLGC, txlineWtable), and lumped parasitic elements (resistor, capacitor, inductor) in RF Toolbox circuit objects. Extract insertion loss, return loss, and crosstalk, then bridge to time-domain analysis via rational fitting.
Lumped Parasitic Elements
Primitive R/L/C elements model vias, bond wires, pad capacitance, and termination resistors in SI channels. Each has terminals p (positive) and n (negative):
r = resistor(50, 'Rterm'); % 50 Ohm termination
c = capacitor(0.1e-12, 'Cvia'); % via pad capacitance
l = inductor(0.5e-9, 'Lvia'); % via barrel inductanceGotcha: Primitive constructors are positional only: resistor(100, 'R1'). Name-value syntax like resistor('Resistance', 100) is not supported.
Handle semantics: Changing a property after adding to a circuit immediately affects the circuit -- no need to re-add.
Via Model (Lumped Subcircuit)
via = circuit('Via');
add(via, [1 2], inductor(0.5e-9, 'Lvia'));
add(via, [2 0], capacitor(0.1e-12, 'Cvia'));
setports(via, [1 0], [2 0]);ESD/Decoupling Parasitic
esd = circuit('ESD');
add(esd, [1 0], capacitor(0.3e-12, 'Cesd'));
add(esd, [1 0], resistor(1e6, 'Resd')); % parallel RC to ground
setports(esd, [1 0]); % 1-port shunt elementnport Elements in Circuit
Embed measured or simulated S-parameter data (Touchstone files) as circuit elements. This is the primary building block for SI channel models -- connectors, packages, PCB segments, and fixtures are all characterized as S-parameter data.
2-Port nport
np = nport('connector.s2p');
np.Name = 'ConnIn';
ckt = circuit('Simple');
add(ckt, [1 2 0 0], np); % 4 nodes: p1+->1, p2+->2, p1-->0, p2-->0
add(ckt, [2 3], inductor(0.5e-9, 'L1'));
setports(ckt, [1 0], [3 0]);A 2-port nport has 4 terminals (p1+, p2+, p1-, p2-), so add takes a 4-element node vector.
4-Port nport
A 4-port nport has 8 terminals. Two node-mapping forms:
np4 = nport('device.s4p');
np4.Name = 'Dev4P';
% Explicit 8-node form: [p1+ p2+ p3+ p4+ p1- p2- p3- p4-]
add(ckt, [1 2 3 4 0 0 0 0], np4); % all negatives grounded
% Shorthand N-node form: negatives implicitly grounded
add(ckt, [1 2 3 4], np4); % same resultPort Selection and Termination
Use setports on the circuit to select which nport ports become external ports. Unexposed ports are left open-circuited -- add explicit resistors for proper termination:
s4 = sparameters('device.s4p');
Z0 = s4.Impedance;
np4 = nport(s4);
np4.Name = 'Dev4P';
ckt = circuit('PortSelect');
add(ckt, [1 2 3 4 0 0 0 0], np4);
% Terminate unused ports 2 and 4 with matched loads
add(ckt, [2 0], resistor(Z0, 'Term2'));
add(ckt, [4 0], resistor(Z0, 'Term4'));
% Expose only ports 1 and 3 as a 2-port network
setports(ckt, [1 0], [3 0]);
freq = s4.Frequencies;
s = sparameters(ckt, freq); % S21 here equals S31 of original 4-portGotcha: Without explicit termination on unused ports, extracted S-parameters will differ from the original -- open-circuit reflections alter the network response.
Differential Port Mapping
For differential signaling, use the full 2N-node form with non-grounded negative terminals:
np4 = nport('diffpair.s4p');
np4.Name = 'DiffChan';
ckt = circuit('DiffAnalysis');
add(ckt, [1 2 3 4 5 6 7 8], np4); % non-grounded negatives
setports(ckt, [1 5], [3 7]); % differential: (p1+,p1-) -> (p3+,p3-)Critical: every negative terminal must have a current path. Each nport port requires current to flow in through pi+ and return through pi-. If a negative terminal is mapped to a node that is not connected to anything (not grounded, not used as a port reference, not connected to another element), the current path is broken and the nport produces zero transmission (~-260 dB). There are three valid approaches:
Ground all negatives (simplest):
add(ckt, [1 2 3 4 0 0 0 0], np)— all returns share node 0Use negatives as port references:
setports(ckt, [1 5], [3 7])— the port definition itself closes the loop throughpi-Connect negatives to other elements: tie them to resistors, other nport terminals, etc.
Never leave negative terminals on isolated floating nodes.
Circuit Differential Ports vs s2sdd
Decision rule: Use s2sdd to extract the true differential-mode response from a multi-port S-parameter measurement. Use setports with differential node pairs only when ports physically correspond to differential terminals (balanced amplifier with + and - pins).
The circuit approach (setports with differential node pairs) and the s2sdd function are not equivalent:
setports(ckt, [1 3], [2 4])with grounded negatives creates a physical voltage measurement between two single-ended nodes that each have their own ground return. This is effectively a series combination — it gives results like 2× the single-ended loss.s2sddperforms a mathematical modal decomposition of the full S-matrix. It algebraically separates differential and common modes without requiring a physical current path.
For extracting the true differential-mode response from a 4-port file, use s2sdd on the extracted S-parameters rather than trying to replicate it with differential setports. The circuit setports differential form is appropriate when ports physically correspond to differential terminals (e.g., a balanced amplifier with explicit + and - pins).
After extracting sparameters, convert to mixed-mode for differential/common-mode analysis:
s = sparameters(ckt, freq);
sdd = s2sdd(s.Parameters, 2); % 2x2xK differential array
% Wrap in sparameters with doubled impedance (differential Z0 = 2x single-ended)
sDiff = sparameters(sdd, s.Frequencies, 2*s.Impedance);Reusing nport Data in Multiple Circuits
When building multiple circuits from the same S-parameter data (e.g., comparing broken vs. fixed topology, or using the same connector at input and output), create a fresh nport() for each circuit or use clone():
% WRONG: reusing the same nport object in two circuits
np = nport('device.s4p', 'Dev');
add(ckt1, [1 2 3 4 0 0 0 0], np);
add(ckt2, [1 2 3 4 0 0 0 0], np); % ERROR: already belongs to ckt1
% CORRECT: clone or create fresh
add(ckt2, [1 2 3 4 0 0 0 0], clone(np));
% or
np2 = nport('device.s4p', 'Dev2');
add(ckt2, [1 2 3 4 0 0 0 0], np2);Multi-Port Channel Extraction
For a 4-port channel (e.g., near-end and far-end crosstalk):
np4 = nport('coupled_traces.s4p');
np4.Name = 'Traces';
ckt = circuit('CoupledChannel');
add(ckt, [1 2 3 4 0 0 0 0], np4);
setports(ckt, [1 0], [2 0], [3 0], [4 0]); % full 4-port extraction
s = sparameters(ckt, freq);
% S21 = through, S31 = NEXT, S41 = FEXT (depending on port assignment)Frequency-Dependent Transmission Lines
txlineWRLGC and txlineWtable model lossy transmission lines with frequency-dependent parameters. Both are 2-port/4-terminal elements that work in circuit and rfbudget.
txlineWRLGC -- W-Element RLGC Model
Models frequency-dependent loss using an analytic formula (Djordjevic-Sarkar wideband model):
tw = txlineWRLGC;
tw.Lo = 350e-9; % inductance per unit length (H/m)
tw.Co = 130e-12; % capacitance per unit length (F/m)
tw.Ro = 2.0; % DC resistance (Ohm/m)
tw.Rs = 5e-4; % skin-effect resistance coefficient (Ohm/m/sqrt(Hz))
tw.Go = 0; % DC conductance (S/m)
tw.Gd = 1e-11; % dielectric loss conductance (S/m/Hz)
tw.LineLength = 0.05; tw.Name = 'PCBTrace'; % 50 mm| Property | Default | Description |
|---|---|---|
Lo | 1e-9 | Inductance per unit length (H/m) |
Co | 4e-13 | Capacitance per unit length (F/m) |
Ro | 0 | DC series resistance (Ohm/m) |
Rs | 0 | Skin-effect resistance coefficient |
Go | 0 | DC shunt conductance (S/m) |
Gd | 0 | Dielectric loss conductance |
DielectricFrequency | 1e9 | Reference frequency for Gd (Hz) |
Nline | 1 | Number of signal conductors |
LineLength | 1 | Physical length (m) |
StubMode | 'NotAStub' | 'NotAStub', 'Series', or 'Shunt' |
Termination | 'NotApplicable' | 'NotApplicable', 'Short', or 'Open' |
Typical parameter ranges for common PCB technologies (50-Ohm single-ended):
| Technology | Lo (nH/m) | Co (pF/m) | Ro (Ohm/m) | Rs | Gd (S/m/Hz) |
|---|---|---|---|---|---|
| FR4 microstrip (outer layer) | 300-400 | 100-140 | 1-5 | 3e-4 to 8e-4 | 5e-12 to 2e-11 |
| FR4 stripline (inner layer) | 350-450 | 120-160 | 2-8 | 4e-4 to 1e-3 | 1e-11 to 5e-11 |
| Low-loss (Megtron6, Rogers) | 300-400 | 100-140 | 1-4 | 3e-4 to 6e-4 | 1e-12 to 5e-12 |
These are approximate starting points. For accurate models, extract RLGC parameters from a 2D field solver (e.g., Ansys Q2D, Cadence Sigrity) matched to your actual stackup geometry.
txlineWtable -- Table-Based Frequency-Dependent Model
Specifies R, L, G, C at discrete frequency points with interpolation. Use when you have extracted or measured per-unit-length parameters at specific frequencies:
wt = txlineWtable;
fpts = [1e8 1e9 10e9];
wt.R = [0.5 1.0 2.0]; wt.Rfreq = fpts; % Ohm/m
wt.L = [260 250 248]*1e-9; wt.Lfreq = fpts; % H/m
wt.C = [100 100 99]*1e-12; wt.Cfreq = fpts; % F/m
wt.G = [0 1e-4 1e-3]; wt.Gfreq = fpts; % S/m
wt.Lhf = 248e-9; wt.Chf = 99e-12; % HF asymptotes
wt.LineLength = 0.1; wt.Name = 'MeasuredTrace';When to Use Each
| Model | Use Case | Properties |
|---|---|---|
txlineRLCGLine | Constant RLCG -- quick estimates, frequency-independent loss | R, L, C, G |
txlineWRLGC | Analytic frequency-dependent loss -- PCB traces, cables with skin effect | Lo, Co, Ro, Rs, Go, Gd |
txlineWtable | Measured/extracted RLCG data at discrete frequencies | R, L, C, G + Rfreq, Lfreq, Cfreq, Gfreq |
Do NOT confuse property names across types: txlineRLCGLine uses simple R, L, C, G; txlineWRLGC uses Lo, Co, Ro, Rs, Go, Gd. Setting R on a txlineWRLGC or Lo on a txlineRLCGLine errors.
Using in Circuit
All transmission lines have 4 terminals (p1+, p2+, p1-, p2-):
ckt = circuit('TraceLoss');
add(ckt, [1 2 0 0], tw); % 4-node mapping
setports(ckt, [1 0], [2 0]);
s = sparameters(ckt, linspace(1e8, 20e9, 500));Mixed Topology Channel Models
Combine lumped elements, nport S-parameter blocks, and transmission lines in a single circuit -- the core pattern for SI channel modeling:
Connector-Trace-Via-Connector Channel
np_conn = nport('connector.s2p');
np_conn.Name = 'ConnIn';
trace = txlineWRLGC(Name='PCBTrace');
trace.Lo = 350e-9; trace.Co = 130e-12;
trace.Ro = 2.0; trace.Rs = 5e-4;
trace.Gd = 1e-11; trace.LineLength = 0.05;
via = circuit('Via');
add(via, [1 2], inductor(0.5e-9, 'Lvia'));
add(via, [2 0], capacitor(0.1e-12, 'Cvia'));
setports(via, [1 0], [2 0]);
ckt = circuit('Channel');
add(ckt, [1 2 0 0], np_conn); % input connector
add(ckt, [2 3 0 0], trace); % PCB trace
add(ckt, [3 4 0 0], via); % via transition
add(ckt, [4 5 0 0], clone(np_conn)); % output connector (cloned)
setports(ckt, [1 0], [5 0]);
freq = linspace(1e8, 10e9, 500);
s = sparameters(ckt, freq);
figure; tiledlayout(1, 2);
nexttile; rfplot(s, 2, 1); title('S21 -- Insertion Loss');
nexttile; rfplot(s, 1, 1); title('S11 -- Return Loss');Differential Channel with Package
sPkg = sparameters('package.s4p');
Z0 = sPkg.Impedance;
pkg = nport(sPkg); pkg.Name = 'Package';
chan = nport('diffpair.s4p'); chan.Name = 'DiffTrace';
ckt = circuit('DiffChannel');
add(ckt, [1 2 3 4 0 0 0 0], pkg);
add(ckt, [2 4 5 6 0 0 0 0], chan); % ports 2,4 of pkg feed into channel
% Terminate unused package port 3 (near-end crosstalk victim)
add(ckt, [3 0], resistor(Z0, 'TermNEXT'));
% Expose: pkg port 1 -> channel port output
setports(ckt, [1 0], [5 0], [6 0]); % 3-port: input, thru, FEXT
s = sparameters(ckt, sPkg.Frequencies);Multi-Path Analysis (Clone + Different Ports)
The clone() + different setports() pattern lets you analyze multiple signal paths through the same topology without rebuilding:
% Build an RC interconnect with crosstalk coupling
base = circuit('Interconnect');
add(base, [1 2], resistor(50, 'R1'));
add(base, [2 0], capacitor(1e-12, 'C1'));
add(base, [2 3], resistor(50, 'R2'));
add(base, [3 0], capacitor(1e-12, 'C2'));
add(base, [2 4], resistor(100, 'Rxtalk'));
add(base, [4 0], capacitor(2e-12, 'Cxtalk'));
% Main signal path
cktMain = clone(base);
setports(cktMain, [1 0], [3 0]);
% Crosstalk path
cktXtalk = clone(base);
setports(cktXtalk, [1 0], [4 0]);
freq = linspace(1e6, 10e9, 500);
sMain = sparameters(cktMain, freq);
sXtalk = sparameters(cktXtalk, freq);Time-Domain Bridge
After extracting S-parameters, fit with rational for TDR/impulse:
s21 = rfparam(s, 2, 1);
[fit, errdb] = rational(s.Frequencies, s21);
[yImp, tImp] = impulse(fit, 1e-12, 5000);See reference/rational-fitting.md for complete TDR recipes and reference/time-domain-analysis.md for end-to-end SI time-domain examples.
Result Extraction Patterns
After extracting S-parameters from a circuit, use these patterns to get numeric values for plotting or analysis:
s = sparameters(ckt, freq);
% Pattern 1a: rfplot (simplest) -- plots S-parameter directly
rfplot(s, 2, 1); % magnitude in dB vs frequency
% Pattern 1b: rfparam -- returns Kx1 vector, ready for custom plotting
s21 = rfparam(s, 2, 1); % Kx1 complex vector
plot(freq/1e9, 20*log10(abs(s21)));
% Pattern 2: s.Parameters -- returns 1x1xK, MUST squeeze before plotting
s21_raw = s.Parameters(2,1,:); % 1x1xK -- CANNOT plot directly
s21 = squeeze(s.Parameters(2,1,:)); % Kx1 after squeeze
% Get value at a specific frequency index
idx = 250;
val_dB = 20*log10(abs(s21(idx)));
% rfparam does NOT accept a frequency index argument:
% rfparam(s, 2, 1, idx) -- ERROR: "Too many input arguments"
% rfparam(s, 2, 1) -- CORRECT: returns full vector, then index itKey rule: rfparam(s, i, j) takes exactly 3 arguments (object, row, col). Never pass a 4th argument for frequency index — index the result vector instead.
Gotchas
nport node count: min N, max 2N -- an N-port nport needs at least N nodes (negatives implicitly grounded) and at most 2N nodes. Fewer than N errors. For clarity, prefer the explicit 2N form with
0for grounded negatives.Unexposed nport ports are open-circuited -- when using
setportsto expose only some ports of a multi-port nport, unused ports are left open. Add explicitresistor(Z0)terminations (where Z0 matches the S-parameter reference impedance, e.g.,s.Impedance) for correct S-parameter extraction.nport.Input/Outputare for rfbudget only -- these numeric port indices select the through-path forrfbudget. Incircuit, use node mapping andsetportsinstead.LineLengthnotLength-- all transmission line objects useLineLengthfor physical length. UsingLengtherrors.txlineWtable needs multi-point RLCG data in circuit -- scalar R/L/G/C values (single frequency point) error with "number of data points should be equal to the number of frequency points" when extracting
sparametersfrom a circuit. Provide at least 2 frequency points in each RLCG table.txlineWRLGC/txlineWtable constructors don't accept
StubMode/Termination-- set these as properties after construction. Only RLGC, length, and name parameters are accepted in the constructor.txlineWRLGC
Nline>1with matrix Lo/Co -- multi-line coupled extraction has a sparameters bug in R2026a. Workaround: extract each line individually.Elements cannot be reused without cloning -- an element can only belong to one circuit or rfbudget at a time. Use
clone()to create independent copies. Without cloning, adding the same element a second time errors or silently produces incorrect results.setports/setterminalscan only be called once -- plan your topology before defining terminals.Primitive constructors are positional --
resistor(100, 'R1'), notresistor('Resistance', 100).Element Name must be a valid MATLAB identifier -- no spaces, no leading digits.
Floating negative terminals produce ~-260 dB transmission -- if any nport negative terminal is mapped to a node with no current path (not grounded, not a port reference, not connected to another element), the nport produces effectively zero transmission. Always use one of the three valid approaches: ground all negatives, use them as port references in
setports, or connect them to other elements.Do not include DC (0 Hz) in frequency vectors for transmission line models --
linspace(0, fmax, N)causes singularities in txlineWRLGC and txlineWtable at f=0 (division by zero in RLGC calculations). Start from a small positive frequency:linspace(fmax/N, fmax, N)or uselogspace.rfwriteblocks on existing files -- Always pass'ForceOverwrite', truetorfwrite. Without it, MATLAB opens an interactive "Overwrite?" dialog that blocks unattended execution.
Conventions
Use
tiledlayout/nexttilefor multi-panel channel analysis plotsAlways label axes with units (dB, GHz, ns) and include figure titles
Name elements descriptively for readable topology:
'ConnIn','PCBTrace','Lvia','Cpad'Use
clone()liberally -- it deep-copies all nested elements and subcircuitsPlot both S21 (insertion loss) and S11 (return loss) for channel characterization
For differential channels, convert to mixed-mode S-parameters with
s2sddafter extraction
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.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-model-rf.zip