matlab-add-awgn
Skill8 starsChanged 5 months agoMITView on GitHub
Add Additive White Gaussian Noise (AWGN) noise and convert between SNR, Eb/No, Es/No, and per-subcarrier SNR for communications simulations. Use when adding noise to signals, converting between SNR definitions, setting up noise for coded or OFDM systems, or obtaining noise variance for soft-decision demodulation.
In this repository58 other files it gives its agents.
- skills/writing-polish/humanizer/AGENTS.mdAGENTS.md
- frontend-designSkill
- ask-mattSkill
- codebase-designSkill
- code-reviewSkill
- diagnosing-bugsSkill
- domain-modelingSkill
- github-codex-keySkill
- github-ssh-key-pushSkill
- implementSkill
- improve-codebase-architectureSkill
- prototypeSkill
- setup-matt-pocock-skillsSkill
- tddSkill
- to-issuesSkill
- to-prdSkill
- triageSkill
- huggingface-accelerateSkill
- quantizing-models-bitsandbytesSkill
- gpuboxSkill
- evaluating-llms-harnessSkill
- ml-training-recipesSkill
- peft-fine-tuningSkill
- experiment-tracking-swanlabSkill
- unslothSkill
- matlab-agentic-toolkit-setupSkill
- matlab-build-appSkill
- matlab-create-live-scriptSkill
- matlab-debuggingSkill
- matlab-design-digital-filterSkill
- matlab-display-imageSkill
- matlab-install-productsSkill
- matlab-list-productsSkill
- matlab-map-database-objectsSkill
- matlab-model-serdes-systemsSkill
- matlab-modernize-codeSkill
- matlab-read-databaseSkill
- matlab-review-codeSkill
- matlab-testingSkill
- matlab-use-duckdbSkill
- matlab-write-databaseSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- teachSkill
- writing-great-skillsSkill
- ara-compilerSkill
- ara-research-managerSkill
- research-paper-notesSkill
- ara-rigor-reviewerSkill
- brainstorming-research-ideasSkill
- creative-thinking-for-researchSkill
- academic-plottingSkill
- ml-paper-writingSkill
- paper-spineSkill
- humanizerSkill
- prompt-optimizerSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Add white Gaussian noise to signals and convert between SNR definitions (SNR, Eb/No, Es/No, per-subcarrier SNR) for communications system …
- Distinctive: line 117
If you have SNR, convert to Eb/No first:
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AWGN & SNR Management
Add white Gaussian noise to signals and convert between SNR definitions (SNR, Eb/No, Es/No, per-subcarrier SNR) for communications system simulations.
When to Use
- Adding noise to a signal in a link simulation
- Converting between Eb/No, Es/No, SNR, or per-subcarrier SNR
- Setting up the correct SNR for a coded, oversampled, or OFDM system
- Obtaining noise variance to pass to a soft-decision demodulator
When NOT to Use
- Configuring fading channels (delay profile, Doppler, antenna arrays)
Must-Follow Rules
- Know your signal power explicitly — Compute or measure your signal's average power before any channel impairments, and pass it to
awgnas the third argument. Usebandpower(x)(Signal Processing Toolbox) ormean(abs(x).^2)to measure. The'measured'option is a convenience for quick checks only — it computes instantaneous power, which gives incorrect noise levels after fading channels where signal power fluctuates but thermal noise is fixed. - Use
UnitAveragePower=truewhen signal power doesn't matter — This is the simplest path: signal power = 0 dBW, soawgn(x, snr, 0)is exact. If the user needs original constellation scaling (e.g., PA modeling, hardware-in-the-loop), do NOT useUnitAveragePower=true— use the default modulator, compute the actual average power withmean(abs(x).^2), and pass it explicitly:awgn(x, snr, sigPowdBW). - Use
convertSNRfor all conversions — Do not compute SNR relationships manually.convertSNRhandles the formulas correctly and avoids sign errors or forgotten factors. - Understand what
"snr"means inconvertSNR— In the OFDM context,convertSNR(ebno, "ebno", "snr")returns the SNR per subcarrier (not wideband SNR). If the user asks for per-subcarrier SNR, this single call is the complete answer — do NOT continue to step 2. Directebno→snrscconversion is not supported — it throws an error. The two-step path to wideband SNR is: (1)ebno→"snr"gives SNR per subcarrier, (2)convertSNR(snrsc, "snrsc", "snr")gives wideband SNR forawgn. Only do step 2 when you need the wideband SNR to pass toawgn. - Capture noise variance for soft demodulation — Use
[y, nVar] = awgn(...)and passnVarto the demodulator viaNoiseVariance=nVar.
Key Functions
| Function | Purpose |
awgn | Add AWGN to a signal at a specified SNR |
convertSNR | Convert between ebno, esno, snr, and snrsc |
berawgn | Theoretical BER over AWGN for standard modulations (PSK, QAM, FSK, DPSK, PAM) |
Gotchas
'measured' gives wrong noise after fading channels
Thermal noise in a receiver is dominated by the noise figure and bandwidth — it does not change when the signal fades. The 'measured' option in awgn computes instantaneous signal power and scales noise to match, which artificially keeps the instantaneous SNR constant through fades. Use 'measured' only for quick AWGN-only checks.
% WRONG after fading: Noise tracks fading — instantaneous SNR stays constant
rxFaded = fadingChannel(txSig);
rxNoisy = awgn(rxFaded, snr, 'measured');
% CORRECT: Compute signal power before fading, pass explicitly
sigPow = mean(abs(txSig).^2);
sigPowdBW = 10*log10(sigPow);
rxFaded = fadingChannel(txSig);
rxNoisy = awgn(rxFaded, snr, sigPowdBW);
% SIMPLEST: Use unit-power signal, then 0 dBW is exact
txSig = qammod(data, M, UnitAveragePower=true); % power = 0 dBW
rxFaded = fadingChannel(txSig);
rxNoisy = awgn(rxFaded, snr, 0);awgn default assumes 0 dBW signal power
Calling awgn(x, snr) without a third argument assumes the signal has 0 dBW (1W) average power. This is only correct if the signal actually has unit average power. For non-normalized signals, compute the actual power and pass it explicitly.
ebno↔snrsc conversion is not supported
convertSNR supports these paths:
| From | To | Supported | Notes |
ebno | snr | Yes | For OFDM: gives SNR per subcarrier (not wideband) |
ebno | esno | Yes | |
esno | snr | Yes | |
snr | snrsc | Yes | "snr" = wideband SNR, "snrsc" = per-subcarrier |
ebno | snrsc | No | Throws error. Use two-step: ebno→"snr" then "snrsc"→"snr" |
esno | snrsc | No | Throws error. Same two-step path required |
snrsc | ebno | No | Use two-step: "snrsc"→"snr" then "snr"→"ebno" |
snrsc | esno | No | Use two-step: "snrsc"→"snr" then "snr"→"esno" |
Fading channel path gain normalization
The awgn(rxFaded, snr, 0) pattern assumes the fading channel preserves
average signal power. This is true when NormalizePathGains=true (the default
for comm.RayleighChannel and comm.RicianChannel). If NormalizePathGains
is false, the channel applies its actual path gains and the average received
power shifts — you must account for this in the power argument to awgn.
% NormalizePathGains=true (default): pre-fading power is correct
chan = comm.RayleighChannel(NormalizePathGains=true, ...);
rxFaded = chan(txSig);
rxNoisy = awgn(rxFaded, snr, 0); % 0 dBW is still correct
% NormalizePathGains=false: adjust for average path gain
chan = comm.RayleighChannel(NormalizePathGains=false, ...
AveragePathGains=[0 -3 -6], ...);
avgGaindB = 10*log10(sum(10.^(chan.AveragePathGains/10)));
rxFaded = chan(txSig);
rxNoisy = awgn(rxFaded, snr, avgGaindB); % account for channel gainNoise variance is total, not per-component
The second output of awgn is the total noise variance. For complex signals, the per-component (I or Q) variance is half this value:
[y, nVar] = awgn(x, snr, 0);
% nVar = total noise variance
% nVar/2 = per-component (I or Q) varianceberawgn takes Eb/No, not SNR
If you have SNR, convert to Eb/No first:
ebno = convertSNR(snr, "snr", "ebno", BitsPerSymbol=log2(M));
ber = berawgn(ebno, 'qam', M);Patterns
Add AWGN to a unit-power signal
M = 16;
data = randi([0 M-1], 1000, 1);
txSig = qammod(data, M, UnitAveragePower=true);
snrdB = 15;
[rxSig, noiseVar] = awgn(txSig, snrdB, 0);Convert Eb/No to SNR for a coded system
M = 64; % 64-QAM
bitsPerSymbol = log2(M); % 6
codeRate = 3/4; % LDPC code rate
samplesPerSymbol = 4; % Pulse shaping oversampling
ebnoDb = 10;
snrDb = convertSNR(ebnoDb, "ebno", "snr", ...
BitsPerSymbol=bitsPerSymbol, ...
CodingRate=codeRate, ...
SamplesPerSymbol=samplesPerSymbol);OFDM conversion: Eb/No → per-subcarrier SNR → wideband SNR
In the OFDM context, convertSNR(ebno, "ebno", "snr") returns the SNR per subcarrier (not wideband SNR). To get the wideband SNR needed by awgn, convert from "snrsc" to "snr".
M = 64;
bitsPerSymbol = log2(M);
codeRate = 3/4;
fftLen = 256;
numActiveSC = 200;
ebnoDb = 10;
% Step 1: Eb/No → per-subcarrier SNR
snrscDb = convertSNR(ebnoDb, "ebno", "snr", ...
BitsPerSymbol=bitsPerSymbol, ...
CodingRate=codeRate);
% Step 2: Per-subcarrier SNR → wideband SNR (for awgn)
snrWbDb = convertSNR(snrscDb, "snrsc", "snr", ...
FFTLength=fftLen, ...
NumActiveSubcarriers=numActiveSC);Capture noise variance for soft-decision demodulation
M = 16;
data = randi([0 M-1], 1000, 1);
txSig = qammod(data, M, UnitAveragePower=true);
snrDb = 12;
[rxSig, noiseVar] = awgn(txSig, snrDb, 0);
% Pass noise variance to demodulator for accurate LLR computation
softBits = qamdemod(rxSig, M, UnitAveragePower=true, ...
OutputType="llr", ...
NoiseVariance=noiseVar);After Adding Noise
- Validate against theory — Compare simulated BER to theoretical BER using
berawgn. See references/snr-conversion-guide.md. - Estimate required Eb/No — Use
berawgnover a range plusinterp1to estimate the Eb/No for a target BER. The result is an approximation (accuracy depends on Eb/No step size). Works for any modulationberawgnsupports. See references/snr-conversion-guide.md. - Visualize the noisy signal — Use
scatterplotorcomm.ConstellationDiagramto inspect the received constellation. - Measure EVM — Use
comm.EVMto quantify signal degradation from noise.
References
| Load when... | Reference |
Need theoretical BER curves, conversion formulas, berawgn usage, or common system examples | references/snr-conversion-guide.md |
Copyright 2026 The MathWorks, Inc.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

