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://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/cascade-deembed.md
Cascade and De-embed S-Parameter Networks
Chain RF components in series (cascade) and remove fixture effects from measurements (de-embed) using cascadesparams and deembedsparams.
Workflow
Load networks -- Load all S-parameter blocks
Align frequencies -- Interpolate all networks to a common frequency grid with
rfinterp1Cascade or de-embed -- Chain networks or remove fixtures
Verify -- Compare results against expectations; round-trip cascade+de-embed to check accuracy
Prerequisite: Frequency Alignment
All networks must share the same frequency vector and reference impedance. This is the most common source of errors.
% Find overlapping frequency range
fCommon = linspace(max(s1.Frequencies(1), s2.Frequencies(1)), ...
min(s1.Frequencies(end), s2.Frequencies(end)), 500);
% Interpolate all networks to the common grid
s1i = rfinterp1(s1, fCommon);
s2i = rfinterp1(s2, fCommon);Gotcha: cascadesparams and deembedsparams require identical frequency vectors. If you skip rfinterp1, you get a dimension mismatch error or silently wrong results. Always interpolate first.
Gotcha: Networks must share the same reference impedance. If impedances differ, re-normalize with newref before cascading: s2i = newref(s2i, s1i.Impedance).
Gotcha: rfinterp1 interpolates the real and imaginary parts independently (like interp1), not magnitude and angle. This can produce artifacts near sharp resonances or rapid phase transitions.
Cascading Networks
Connect networks in series -- output ports of one feed into input ports of the next.
% Two networks
sTotal = cascadesparams(s1i, s2i);
% Three or more networks
sChain = cascadesparams(s1i, s2i, s3i);Gotcha: cascadesparams assumes standard port ordering: ports 1:N are inputs, N+1:2N are outputs. If your ports follow a different convention, use snp2smp to reorder before cascading.
Identifying Input vs Output Ports
To determine which ports are inputs and which are outputs, inspect the S-parameter matrix at the lowest frequency: off-diagonal elements with the largest magnitude are the through connections.
s4 = sparameters('device.s4p');
S = s4.Parameters(:,:,1); % S-matrix at lowest frequency
disp(abs(S)); % Through paths have the largest off-diagonal magnitudes
% If S(2,1) and S(4,3) are the largest, then ports 1,3 are inputs and 2,4 are outputsFor typical 4-port differential pairs: through paths are S21 and S43, meaning ports 1,3 are near-end (input) and ports 2,4 are far-end (output). To use with cascadesparams, reorder so inputs are first:
% Reorder from [1,2,3,4] to [1,3,2,4] so ports 1,2=input and 3,4=output
sReordered = snp2smp(s4, [1 3 2 4]);
sCascade = cascadesparams(sReordered, sReordered);
% Reorder result back to original convention
sCascade = snp2smp(sCascade, [1 3 2 4]);Multi-Port Cascading
cascadesparams supports networks of different sizes when you specify how many ports connect via the third argument:
% Default (no 3rd arg): both must be 2N-port, connects last N to first N
sTotal = cascadesparams(s2a, s2b); % Two 2-port -> 2-port result
% With connection count (3rd arg): works with different-sized networks
sTotal = cascadesparams(s4, s2, 1); % 4-port + 2-port, connect 1 port
% Result: (4 + 2 - 2*1) = 4-portThe third argument specifies how many ports connect between the networks. The last M output ports of the first network connect to the first M input ports of the second. The result has (N1 + N2 - 2*M) ports.
For complex topologies where cascadesparams port ordering doesn't match your physical setup:
Use
snp2smpto reorder ports before cascadingOr use the
circuitobject for full topology control
De-embedding Fixtures
Remove fixture (test fixture, adapter, cable) effects from a measured DUT to recover the true device response.
Gotcha: deembedsparams always requires 3 arguments: deembedsparams(sMeasured, s1, s3) where s1 is the port-1 fixture and s3 is the port-2 fixture. Calling with only 2 arguments errors with "Not enough input arguments." For one-sided de-embedding, pass an ideal thru for the unused side.
Two-Sided De-embedding
% Measured: fixture1 + DUT + fixture2
% Goal: extract DUT S-parameters
sDUT = deembedsparams(sMeasured, sFixture1, sFixture2);One-Sided De-embedding
To de-embed only one side, construct an ideal thru for the other side:
nf = numel(sMeasured.Frequencies);
thruData = zeros(2, 2, nf);
thruData(1,2,:) = 1;
thruData(2,1,:) = 1;
sThru = sparameters(thruData, sMeasured.Frequencies, 50);
% Remove only the left fixture
sDUT = deembedsparams(sMeasured, sFixture1, sThru);
% Remove only the right fixture
sDUT = deembedsparams(sMeasured, sThru, sFixture2);Half-Fixture Extraction from 2x-Through
When you only have a through measurement of two identical fixtures back-to-back (no separate fixture characterization), extract one fixture using T-parameter matrix square root:
% Load 2x-through measurement (two identical fixtures cascaded)
s2xThru = sparameters('2x_through.s2p');
% Convert to T-parameters and take matrix square root at each frequency
T2x = s2t(s2xThru.Parameters);
nf = numel(s2xThru.Frequencies);
Tfixture = zeros(2, 2, nf);
for k = 1:nf
Tfixture(:,:,k) = sqrtm(T2x(:,:,k));
end
% Convert back to S-parameters
sFixture = sparameters(t2s(Tfixture), s2xThru.Frequencies, s2xThru.Impedance);
% Now de-embed DUT using the extracted fixture
sDUT = deembedsparams(sMeasured, sFixture, sFixture);Note: This assumes symmetric fixtures (identical left and right). For asymmetric fixtures, more advanced techniques are needed.
Synthetic Fixture Data (for testing)
freq = linspace(1e9, 20e9, 201);
loss = 10^(-0.5/20); % 0.5 dB per fixture
phase = reshape(exp(-1j*2*pi*freq*15e-12), 1, 1, []); % 15 ps delay
sData = [0.03 0; 0 0.03] + [0 loss; loss 0].*phase; % 2x2xN via implicit expansion
sOneFixture = sparameters(sData, freq, 50);
s2xThru = cascadesparams(sOneFixture, sOneFixture);4-Port De-embedding
deembedsparams works directly with 4-port (and N-port) networks -- same 3-argument syntax:
% 4-port fixture and 4-port measurement
sFixture4p = sparameters('fixture_4port.s4p');
sMeasured4p = sparameters('measured_4port.s4p');
% De-embed both sides (symmetric fixtures)
sDUT4p = deembedsparams(sMeasured4p, sFixture4p, sFixture4p);
% Or asymmetric fixtures
sDUT4p = deembedsparams(sMeasured4p, sFixtureLeft4p, sFixtureRight4p);All networks must have the same number of ports. Port ordering must be consistent across fixture and measurement.
Verification Pattern
Cascade then de-embed to verify round-trip accuracy:
% Build chain
sChain = cascadesparams(sFixture, sDUT, sFixture);
% Recover DUT
sRecovered = deembedsparams(sChain, sFixture, sFixture);
% Check error
origS21 = rfparam(sDUT, 2, 1);
recS21 = rfparam(sRecovered, 2, 1);
maxErr = max(abs(origS21 - recS21));
fprintf('Round-trip S21 max error: %.2e\n', maxErr);VNA Calibration Check (De-embed Through Standard)
Verify calibration by de-embedding fixtures from a known through measurement -- the result should be an ideal through (0 dB insertion loss, 0 phase):
% Measure through standard with fixtures in place
sThruMeasured = sparameters('through_measured.s2p');
% De-embed fixtures
sThruDeembedded = deembedsparams(sThruMeasured, sFixtureL, sFixtureR);
% Check deviation from ideal (S21 = 1, S11 = 0)
s21 = rfparam(sThruDeembedded, 2, 1);
s11 = rfparam(sThruDeembedded, 1, 1);
fprintf('S21 mag error: %.4f dB\n', max(abs(20*log10(abs(s21)))));
fprintf('S21 phase error: %.4f deg\n', max(abs(angle(s21)*180/pi)));
fprintf('S11 max: %.1f dB\n', max(20*log10(abs(s11))));Gotchas
Frequency alignment is required --
cascadesparamsanddeembedsparamsrequire identical frequency vectors. Alwaysrfinterp1to a common grid first, or you get dimension mismatch errors or silently wrong results.deembedsparamsalways requires 3 arguments --deembedsparams(sMeasured, s1, s3)where s1 is the port-1 fixture and s3 is the port-2 fixture. Calling with only 2 arguments errors. For one-sided de-embedding, pass an ideal thru for the unused side.rfinterp1interpolates real/imag independently -- (likeinterp1). Not magnitude and angle. Can produce artifacts near sharp resonances or rapid phase transitions.cascadesparamsassumes standard port ordering -- Ports 1:N are inputs, N+1:2N are outputs. If your ports follow a different convention, usesnp2smpto reorder before cascading.
Conventions
Always interpolate to a common frequency grid before cascading or de-embedding
Use
tiledlayout/nexttilewhen comparing original vs. cascaded/de-embedded resultsLabel plots clearly to distinguish standalone vs. cascaded responses
Verify de-embedding accuracy by round-tripping when fixture data is available
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