Install any skill in seconds. Free to start, no credit card required.
Get Started Free →matlab/matlab-add-awgn
Read BEFORE writing any code that adds Additive White Gaussian Noise (AWGN) to signals and converts between SNR, Eb/No, Es/No, and per-subcarrier SNR for communications simulations, using awgn(), convertSNR(), berawgn(). The default MATLAB patterns for AWGN (e.g., 'measured' option, manual SNR formulas) produce subtly incorrect results. This skill specifies the correct calling conventions, required function usage, and critical anti-patterns that must be avoided.
Passed 22 of 22 test cases with the skill, and 6 of 22 without it.
and 23 more in the full report
16 fixed6 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 16 test cases the skill fixed. Same model, same prompt, with and without the skill.
Convert an Eb/No of 8 dB to Es/No for 64-QAM modulation in MATLAB. Write a concise snippet.
| Checked | Without skill | With skill |
|---|---|---|
| The code uses convertSNR with 'ebno' and 'esno'. | Missed | Passed |
| The convertSNR call passes BitsPerSymbol set to 6. | Missed | Passed |
The instructions your model reads when the skill loads.
Add white Gaussian noise to signals and convert between SNR definitions (SNR, Eb/No, Es/No, per-subcarrier SNR) for communications system simulations.
'measured' to awgn — Always pass explicit signal power as the third argument. For unit-power signals use 0; otherwise compute power with mean(abs(x).^2) and convert to dBW: 10*log10(sigPow). The 'measured' option computes instantaneous power internally, which gives incorrect noise levels after fading channels and obscures the power assumption. Even in AWGN-only scenarios, explicit power is required for correctness and clarity. For OFDM systems, see the "Add AWGN in an OFDM link simulation" pattern.UnitAveragePower=true when signal power doesn't matter — This is the simplest path: signal power = 0 dBW, so awgn(x, snr, 0) is exact. If the user needs original constellation scaling (e.g., PA modeling, hardware-in-the-loop), do NOT use UnitAveragePower=true — use the default modulator, compute the actual average power with mean(abs(x).^2), and pass it explicitly: awgn(x, snr, sigPowdBW).convertSNR for all conversions — NEVER compute SNR/Eb/No/Es/No formulas manually — Even when the formula is simple, always use convertSNR. Manual formulas are error-prone for edge cases (oversampling, subcarrier loading) and bypass the toolbox's validated implementation. Anti-pattern: snr = ebno + 10*log10(bitsPerSymbol * codeRate). Correct: convertSNR(ebno, "ebno", "snr", BitsPerSymbol=6, CodingRate=3/4).awgn needs, use two steps: (1) convertSNR(ebno, "ebno", "snr", BitsPerSymbol=..., CodingRate=...) gives the SNR per subcarrier, (2) convertSNR(snrsc, "snrsc", "snr", FFTLength=..., NumActiveSubcarriers=...) gives the wideband SNR for awgn. Direct ebno→snrsc is not supported and throws an error. Caveat: If the user asks for per-subcarrier SNR only, step 1 alone is the complete answer — do NOT apply step 2. Applying the FFTLength/NumActiveSubcarriers correction to a per-subcarrier value gives the wideband SNR, which is a different (lower) quantity. Note: The "snrsc" mode requires R2023b or later. For R2022a–R2023a, compute wideband SNR manually: snr_wideband = snr_per_sc - 10*log10(FFTLength/NumActiveSubcarriers). To add noise at a per-subcarrier SNR, see the "Add AWGN in an OFDM link simulation" pattern below.[y, nVar] = awgn(...) and pass nVar to the demodulator via NoiseVariance=nVar.'measured' with awgn% WRONG — never generate this
rxSignal = awgn(txSignal, snrdB, 'measured');
% CORRECT for unit-power signals (UnitAveragePower=true)
rxSignal = awgn(txSignal, snrdB, 0);
% CORRECT for non-unit-power signals
sigPow = mean(abs(txSignal).^2);
rxSignal = awgn(txSignal, snrdB, 10*log10(sigPow));
test cases passed, vs 6 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.