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 wikipedia). In the code you provided, the real and imaginary components (generated by independent calls to randn
) generally meet this condition (or at least approximates it quite well for reasonable pseudo-random generator) and the magnitude of h
would thus have a Rayleigh distribution.
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\} &= E\{X^2+Y^2\} \\
&= E\{X^2\}+E\{Y^2\} &\mbox{(linearity of expectation)} \\
&= 2E\{X^2\} &\mbox{($X$ and $Y$ identically distributed)} \\
&= 2\sigma^2 &\mbox{($X$ and $Y$ zero-mean Gaussian)}
\end{align}
$$
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 randn
).
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}$.
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.