matlab/matlab-generate-5g-waveform
> Generate 3GPP-compliant 5G NR downlink and uplink baseband waveforms. Use to create NR signals, test model (TM) waveforms, fixed reference channels (FRC), test and measurement (T&M) signals, or test vectors for conformance testing. Covers configuring data, control, and broadcast DM-RS, PT-RS, CORESET, and BWP parameters including bandwidth, subcarrier spacing (SCS), modulation (QPSK, QAM), numerology, FR1, FR2, TDD, FDD, and multi-bandwidth-part setups. Use for signal generation, RF instrument playback, or IQ baseband synthesis. Requires 5G Toolbox.
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-generate-5g-waveform
Generate standard-compliant 5G NR downlink and uplink waveforms for test and
measurement, simulation, and verification using nrWaveformGenerator.
nrCDLChannel, nrTDLChannelnrPDSCHDecode, nrDLSCHDecoder| Need | API | Notes |
|------|-----|-------|
| Standard test model (TM) | hNRReferenceWaveformGenerator | Predefined 3GPP configs. See test-models-and-frc.md |
| Fixed reference channel (FRC) | hNRReferenceWaveformGenerator | DL and UL FRCs |
| Custom DL waveform | nrDLCarrierConfig + nrWaveformGenerator | Full control over all DL channels |
| Custom UL waveform | nrULCarrierConfig + nrWaveformGenerator | Full control over all UL channels |
Do NOT use primitive-level functions (nrCarrierConfig + nrPDSCH +
nrOFDMModulate) for waveform generation. These are for individual channel
signal processing, not waveform construction. nrWaveformGenerator handles
channel multiplexing, power scaling, and OFDM modulation correctly.
cfg = nrDLCarrierConfig('FR1', 20, 30); % DL: FR1, 20 MHz, 30 kHz SCS
cfg = nrULCarrierConfig('FR1', 20, 15); % UL: FR1, 20 MHz, 15 kHz SCS
This auto-populates SCSCarriers, BandwidthParts, SSBurst/CORESET (DL only),
and a default PDSCH or PUSCH with valid parameters sized to the bandwidth.
Requires R2026a or later. On earlier releases, use the manual approach
shown in the Narrow Bandwidth DL pattern — create nrDLCarrierConfig with
no arguments and set SCSCarriers, BandwidthParts, and channels explicitly.
Constructor side effect: For DL, the constructor adds a dedicated SCS
carrier for SSBurst if the requested SCS doesn't match the default SSB
numerology. For example, nrDLCarrierConfig('FR1', 5, 30) creates a hidden
15 kHz carrier (20 RBs) for SSBurst Case A. Use manual config instead when
you need exact control over the number of SCS carriers.
cfg.PDSCH{1}.Modulation = '64QAM';
cfg.PDSCH{1}.Power = -3;
cfg.PDSCH{1}.DMRSPower = -6;
cfg.NumSubframes = 10;
cfg.SampleRate = 245.76e6; % Oversampled rate (default: minimum for the BW)
validateConfig checks structural rules but doesnot detect channel conflicts (e.g., overlapping PDSCH/CSI-RS, CSI-RS/SSBurst).
Always call nrWaveformGenerator to catch these:
[waveform, info] = nrWaveformGenerator(cfg);
openInGenerator(cfg);
sr = info.ResourceGrids(1).Info.SampleRate;
grid = info.ResourceGrids(1).ResourceGridBWP;
hNRReferenceWaveformGenerator is an example helper — set up a working
directory with setupExample before use (no path modification needed):
[exDir, ~] = setupExample('5g/NRTestModelWaveformGenerationExample', fullfile(tempdir, 'tmfrc'));
workDir = fullfile(tempdir, 'myTMWaveform');
mkdir(workDir);
copyfile(fullfile(exDir, '*'), workDir);
cd(workDir);
Then generate:
wavegen = hNRReferenceWaveformGenerator('NR-FR1-TM1.1', '10MHz', '15kHz', 'FDD');
[waveform, waveinfo] = generateWaveform(wavegen);
displayResourceGrid(wavegen);
See references/test-models-and-frc.md for
all valid model names and options.
| Function / Class | Purpose |
|-----------------|---------|
| nrWaveformGenerator | Generate time-domain waveform from carrier config |
| nrDLCarrierConfig | DL carrier config (wraps all DL channels) |
| nrULCarrierConfig | UL carrier config (wraps all UL channels) |
| nrSCSCarrierConfig | SCS carrier: SubcarrierSpacing, NSizeGrid, NStartGrid |
| nrWavegenBWPConfig | BWP: SubcarrierSpacing, NSizeBWP, NStartBWP |
| nrWavegenPDSCHConfig | PDSCH: Modulation, Power, DMRSPower, PRBSet |
| nrWavegenPUSCHConfig | PUSCH: Modulation, Power, DMRSPower |
| nrWavegenPUCCH0Config .. nrWavegenPUCCH4Config | PUCCH formats 0–4 |
| nrWavegenSRSConfig | SRS config |
| nrWavegenPDCCHConfig | PDCCH config (links via SearchSpaceID) |
| nrCORESETConfig | CORESET: FrequencyResources, Duration |
| nrSearchSpaceConfig | Links PDCCH to CORESET via IDs |
| nrWavegenSSBurstConfig | SS burst: BlockPattern, TransmittedBlocks |
| nrWavegenCSIRSConfig | CSI-RS config |
| hNRReferenceWaveformGenerator | Standard TMs and FRCs (example helper) |
| validateConfig | Check structural rules (method on carrier config) |
| openInGenerator | Open config in 5G Waveform Generator app |
If you need to verify property names, check valid values for a config
object, or look up parameters not covered in this skill, consult the online
documentation links in references/documentation-links.md.
Do not mix API levels. These primitive objects are incompatible with
nrWaveformGenerator:
| Use with nrWaveformGenerator | Do NOT use with nrWaveformGenerator |
|-------------------------------|--------------------------------------|
| nrDLCarrierConfig / nrULCarrierConfig | nrCarrierConfig |
| nrWavegenPDSCHConfig | nrPDSCHConfig |
| nrWavegenPUSCHConfig | nrPUSCHConfig |
These parameter constraints cause the most errors. Check all of them before
calling nrWaveformGenerator.
Look up NSizeGrid from the bandwidth tables. The simplified constructor
(R2026a+) handles this automatically. To look up values programmatically:
nrDLCarrierConfig.FR1BandwidthTable
nrDLCarrierConfig.FR2BandwidthTable
NStartBWP >= NStartGrid
NStartBWP + NSizeBWP <= NStartGrid + NSizeGrid
The BWP SubcarrierSpacing must exactly match one SCS carrier's
SubcarrierSpacing.
Each bit set to 1 in FrequencyResources allocates 6 RBs. Total must
not exceed NSizeBWP:
6 * sum(FrequencyResources) <= NSizeBWP
Max bits to set: floor(NSizeBWP / 6). For narrow bandwidths:
| NSizeBWP | Max bits | Example FrequencyResources |
|----------|----------|---------------------------|
| 11 | 1 | [1 zeros(1,44)] |
| 24 | 4 | [1 1 1 1 zeros(1,41)] |
| 51 | 8 | [ones(1,8) zeros(1,37)] |
The SCS carrier at the SSB numerology must have NSizeGrid >= 20.
| BlockPattern | SSB SCS |
|-------------|---------|
| Case A | 15 kHz |
| Case B | 30 kHz |
| Case C | 30 kHz |
| Case D | 120 kHz |
| Case E | 240 kHz |
When the user does not specify SSB parameters, choose a BlockPattern that
matches the user's SCS carrier so no extra carrier is needed:
| User's SCS | Use BlockPattern | SSB SCS |
|------------|-----------------|---------|
| 15 kHz | Case A | 15 kHz |
| 30 kHz | Case B | 30 kHz |
| 60 kHz | Case B (FR1) | 30 kHz — add a 30 kHz carrier if none exists |
| 120 kHz | Case D | 120 kHz |
When the user explicitly requests SSB parameters that require a different
SCS than the main carrier, add a dedicated SCS carrier for the SSB:
% Example: user wants Case A (15 kHz SSB) on a 30 kHz carrier
scsSSB = nrSCSCarrierConfig;
scsSSB.SubcarrierSpacing = 15;
scsSSB.NSizeGrid = 20; % Minimum for SSB
scsSSB.NStartGrid = 0;
cfg.SCSCarriers{end+1} = scsSSB;
cfg.SSBurst.BlockPattern = 'Case A';
Disable SSBurst only when the carrier is too narrow to support any SSB
(e.g., 5 MHz / 30 kHz → 11 RBs at 30 kHz, and no room for a 20-RB carrier
at any SSB numerology):
cfg.SSBurst.Enable = false;
When multiple SCS carriers coexist, Point A is positioned so the
highest-SCS carrier is centered within the channel bandwidth. This means
the lower-SCS carrier may need fewer RBs than the bandwidth table maximum.
For example, 40 MHz with a full 30 kHz carrier (106 RBs) only fits 214 RBs
at 15 kHz, not the table value of 216. Always call validateConfig(cfg) to
check, and reduce NSizeGrid if needed.
Within the same BWP, nrWaveformGenerator automatically reserves REs for
CSI-RS — conflicts only arise between DM-RS and CSI-RS. Across different
BWPs that overlap in frequency, CSI-RS defaults span the full BWP and can
collide with PDSCH, PDCCH, or SSBurst. Fix with NumRB and RBOffset:
csirs1 = nrWavegenCSIRSConfig;
csirs1.BandwidthPartID = 1;
csirs1.NumRB = 106; % Match PDSCH1 frequency region
csirs1.RBOffset = 0;
csirs1.SymbolLocations = 6; % Avoid PDCCH symbols 0-2
CSI-RS can also conflict with SSBurst when their frequency regions overlap.
This applies to any CSI-RS on any BWP — check each one. To resolve, try
these approaches in order:
NumRB/RBOffset — narrow the CSI-RS to a frequency region thatdoes not overlap the SSBurst carrier (works when SSBurst does not span
the full bandwidth)
SymbolLocations — move CSI-RS to symbols not used by SSBurstCSIRSPeriod — adjust periodicity and slot offset so CSI-RS avoidsslots containing SSBurst
The right fix depends on the overall parameter set. Always call
nrWaveformGenerator to verify no conflicts remain.
Within the same BWP and RNTI, nrWaveformGenerator automatically reserves
REs for PDCCH (via the CORESET region). PDCCH conflicts with PDSCH when:
To resolve, separate them in time (SymbolAllocation, SlotAllocation) or
frequency (PRBSet).
max(PRBSet) < NSizeBWP
For full-band allocation: PRBSet = 0:NSizeBWP-1.
PDCCH.SearchSpaceID must reference a valid SearchSpace, which must
reference a valid CORESET via CORESETID. All IDs must exist.
% 20 MHz, 30 kHz SCS downlink waveform with 64QAM PDSCH
cfg = nrDLCarrierConfig('FR1', 20, 30);
cfg.PDSCH{1}.Modulation = '64QAM';
cfg.NumSubframes = 10;
[waveform, info] = nrWaveformGenerator(cfg);
% Plot resource grid
figure;
imagesc(abs(info.ResourceGrids(1).ResourceGridBWP(:,:,1)));
axis xy;
xlabel('OFDM Symbols');
ylabel('Subcarriers');
title('5G NR DL Resource Grid');
colorbar;
% 20 MHz, 15 kHz SCS uplink waveform with QPSK PUSCH
cfg = nrULCarrierConfig('FR1', 20, 15);
cfg.PUSCH{1}.Modulation = 'QPSK';
cfg.NumSubframes = 10;
[waveform, info] = nrWaveformGenerator(cfg);
Narrow bandwidths need manual config because CORESET defaults are too wide.
SSBurst must be disabled here because there is no SCS carrier at the SSB
numerology. (The simplified constructor avoids this by adding one automatically.)
cfg = nrDLCarrierConfig;
cfg.ChannelBandwidth = 5;
cfg.SCSCarriers = {nrSCSCarrierConfig};
cfg.SCSCarriers{1}.SubcarrierSpacing = 30;
cfg.SCSCarriers{1}.NSizeGrid = 11; % 5 MHz at 30 kHz
cfg.BandwidthParts = {nrWavegenBWPConfig};
cfg.BandwidthParts{1}.SubcarrierSpacing = 30;
cfg.BandwidthParts{1}.NSizeBWP = 11;
% SSB needs 20 RBs — disable for 11-RB carrier
cfg.SSBurst.Enable = false;
% CORESET: max 1 group (6 RBs) for 11-RB BWP
cfg.CORESET{1}.FrequencyResources = [1 zeros(1,44)];
cfg.CORESET{1}.Duration = 2; % Must be 2 for interleaved mapping with 1 group
cfg.PDCCH{1}.Enable = false; % Only 2 CCEs — too few for default AggregationLevel
% PDSCH: fit within BWP
cfg.PDSCH{1}.PRBSet = 0:10;
cfg.PDSCH{1}.Power = -3;
cfg.PDSCH{1}.DMRSPower = -6;
[waveform, info] = nrWaveformGenerator(cfg);
% NR-FR1-TM1.1 at 10 MHz, 15 kHz SCS
wavegen = hNRReferenceWaveformGenerator('NR-FR1-TM1.1', '10MHz', '15kHz', 'FDD');
[waveform, waveinfo] = generateWaveform(wavegen);
displayResourceGrid(wavegen);
To modify test model parameters (e.g., enable transport coding):
wavegen = makeConfigWritable(wavegen);
pdschArray = [wavegen.Config.PDSCH{:}];
[pdschArray.Coding] = deal(true);
wavegen.Config.PDSCH = num2cell(pdschArray);
[waveform, waveinfo] = generateWaveform(wavegen);
For waveforms with multiple bandwidth parts and numerologies, see
references/multi-bwp-guidance.md.
[waveform, info] = nrWaveformGenerator(cfg) returns:
| Field | Contents |
|-------|----------|
| waveform | Complex time-domain samples (N x P, P = antennas) |
| info.ResourceGrids(k).ResourceGridBWP | Grid sized to BWP (NSizeBWP*12 subcarriers) |
| info.ResourceGrids(k).ResourceGridInCarrier | Grid sized to full carrier |
| info.ResourceGrids(k).Info.SampleRate | Waveform sample rate |
| info.ResourceGridSSBurst.ResourceGrid | SSB grid (DL only) |
| info.WaveformResources.PDSCH | Per-slot PDSCH resources (indices, symbols) |
There is no field called ResourceGrid in info.ResourceGrids. Use
ResourceGridBWP or ResourceGridInCarrier.
[waveform, waveinfo] = generateWaveform(wavegen) for
hNRReferenceWaveformGenerator returns:
| Field | Contents |
|-------|----------|
| waveinfo.ResourceGridBWP | Resource grid |
| waveinfo.Info.SampleRate | Sample rate |
.m script and open it in the MATLAB editor with edit('scriptName.m')nrWaveformGenerator, not primitive functions (nrPDSCH + nrOFDMModulate)nrDLCarrierConfig('FR1', bw, scs) when possiblenrWavegenPDSCHConfig (not nrPDSCHConfig) with nrWaveformGeneratorDMRSPower (not PowerDMRS), PTRSPower (not PowerPTRS), NSizeGrid (not NRB), ChannelBandwidth (not Bandwidth)SCSCarriers, BandwidthParts, CORESET, PDSCH, PUSCH are cell arrays — use {}SSBurst is a direct object — use . not {}tiledlayout/nexttile for multi-panel figuresCopyright 2026 The MathWorks, Inc.
Take matlab/matlab-generate-5g-waveform from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.