MATLAB Rayleigh fading and white gaussian noise - Signal Processing Stack Exchange most recent 30 from dsp.stackexchange.com 2019-11-18T16:04:20Z https://dsp.stackexchange.com/feeds/question/16345 https://creativecommons.org/licenses/by-sa/4.0/rdf https://dsp.stackexchange.com/q/16345 1 MATLAB Rayleigh fading and white gaussian noise user3313661 https://dsp.stackexchange.com/users/8300 2014-05-19T20:48:35Z 2015-11-08T13:22:12Z <p>From the MATLAB code below where do these theoretical equations for Rayleigh fading and white Gaussian noise come from? Or how are they derived?</p> <pre><code>h = 1/sqrt(2)*[randn(nrx,ntx,N/ntx) + 1i*randn(nrx,ntx,N/ntx)]; % Rayleigh channel n = 1/sqrt(2)*[randn(nrx,N/ntx) + 1i*randn(nrx,N/ntx)]; % white gaussian noise, 0dB variance </code></pre> https://dsp.stackexchange.com/questions/16345/-/16351#16351 1 Answer by Phonon for MATLAB Rayleigh fading and white gaussian noise Phonon https://dsp.stackexchange.com/users/6 2014-05-20T00:50:25Z 2014-05-20T00:50:25Z <p>So, it looks like the Gaussian noise is correctly generated, while the Rayleigh channel is generated incorrectly.</p> <p>Namely, we're generating an array of real normally distributed random numbers and imaginary normally distributed random numbers, scaling both by $\frac{1}{\sqrt{2}}$. This works well for Gaussian, since on average their magnitude will indeed be 1 since $$\sqrt{ \frac{1}{\sqrt{2}}^2 + \frac{1}{\sqrt{2}}^2 } = 1.$$</p> <p>However, we can't directly get Rayleigh distribution by using Gaussian distribution alone (provided by <code>randn</code>). We should use <a href="http://www.mathworks.com/help/stats/raylrnd.html" rel="nofollow"><code>raylrnd</code></a> instead. In this case the same argument applies for the $\frac{1}{\sqrt{2}}$ scaling.</p> https://dsp.stackexchange.com/questions/16345/-/16385#16385 9 Answer by SleuthEye for MATLAB Rayleigh fading and white gaussian noise SleuthEye https://dsp.stackexchange.com/users/8952 2014-05-21T01:33:18Z 2015-10-18T21:37:07Z <p>The Rayleigh fading channel equation you provided comes from the property that given two independent zero-mean Gaussian random variables with equal variance $X \sim N(0,\sigma^2)$ and $Y \sim N(0,\sigma^2)$, the random variable $R = \sqrt{X^2+Y^2}$ is Rayleigh distributed (see for example <a href="http://en.wikipedia.org/wiki/Rayleigh_distribution#Related_distributions">wikipedia</a>). In the code you provided, the real and imaginary components (generated by independent calls to <code>randn</code>) generally meet this condition (or at least approximates it quite well for reasonable pseudo-random generator) and the magnitude of <code>h</code> would thus have a Rayleigh distribution.</p> <p>In addition, it is generally assumed that the signals' power is preserved on average, that is $E\{R^2\} = 1$. Now given how we defined $R$: \begin{align} E\{R^2\} &amp;= E\{X^2+Y^2\} \\ &amp;= E\{X^2\}+E\{Y^2\} &amp;\mbox{(linearity of expectation)} \\ &amp;= 2E\{X^2\} &amp;\mbox{(X and Y identically distributed)} \\ &amp;= 2\sigma^2 &amp;\mbox{(X and Y zero-mean Gaussian)} \end{align}</p> <p>So the signal power is preserved on average when $\sigma = 1/\sqrt{2}$. This is also the scaling factor that must be used if starting with unit variance Gaussian pseudo-random variables (as is the case with MATLAB's <code>randn</code>).</p> <p>Similarly, given a complex-valued Gaussian noise $n$ defined as $n = n_{\scriptsize \mbox{real}} + i\cdot n_{\scriptsize \mbox{imag}}$, where both real and imaginary components are Gaussian distributed with variance $\sigma_n^2$, the noise power is $E\{|n|^2\} = E\{n_{\scriptsize \mbox{real}}^2 + n_{\scriptsize \mbox{imag}}^2\}$. By a similar argument as above, it follows that $E\{|n|^2\} = 2\sigma_n^2$. To obtain noise with unitary power, we thus need $\sigma_n = 1/\sqrt{2}$.</p> <p>Note that the notion of unitary power only makes sense once a measurement unit has been established. Quite often the noise power is defined relative to the signal power. In that case, a noise power of 1 (or 0dB) in signal power's units would mean that the power of the noise is the same as that of the signal.</p>