Realize a suitable MATLAB function to add AWGN noise. Function written should sa
ID: 3875790 • Letter: R
Question
Realize a suitable MATLAB function to add AWGN noise. Function written should satisfy the requirements given against it. Function should generate error message if wrong arguments are passed. To generalize the function if optional arguments are not given as input a default value can be set. Note: function should accept arguments containing signal, Signal to noise ratio in dB (optional argument) and the signal power (optional argument) Hint: If signal power is specified as an argument, signal should be scaled to the desired level and before noise is added.Explanation / Answer
if (meas == 1) % <-- if using signal power to determine appropriate noise power
p = sum( abs( x(:)) .^ 2) / length(x(:));
if (strcmp(type,"dB"))
p = 10 * log10(p);
endif
endif
if (strcmp(type,"linear"))
np = p / snr;
else % <-- in dB
np = p - snr;
endif
y = x + wgn (m, n, np, 1, seed, type, out);
if (strcmp(type,"dBW"))
np = 10 ^ (p/10);
elseif (strcmp(type,"dBm"))
np = 10 ^((p - 30)/10);
elseif (strcmp(type,"linear"))
np = p;
endif
if(!isempty(seed))
randn("state",seed);
endif
if (strcmp(out,"complex"))
y = (sqrt(imp*np/2))*(randn(m,n)+1i*randn(m,n)); % imp=1 assuming impedance is 1 Ohm
else
y = (sqrt(imp*np))*randn(m,n);
endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.