EE-410L Communication Systems Lab · Lab 12 · Implementation of random numbers and probability density function on MATLABAll labs

Noise is random. Its shape is not.

Ten minutes of reading with the examples of the manual. Move the sliders, then type the examples in MATLAB and compare.

01

Why randomness

A real channel adds noise and makes the received signal fade. Neither can be predicted sample by sample, but both follow a known distribution. To test a receiver in MATLAB we generate random numbers with that distribution and add them to the signal: Gaussian numbers for thermal noise, Rayleigh numbers for the fading of a mobile radio link without line of sight.

Pseudorandom. MATLAB's numbers come from an algorithm (the Mersenne Twister). They look random, but the same seed always gives the same numbers, which is what makes a simulation repeatable.
02

pdf and PDF

pdff(x)how likely a value near x is; area under it is 1
PDF (CDF)F(x) = P(X ≤ x) = ∫−∞x f(u)durises from 0 to 1
IntervalP(a < X ≤ b) = F(b) − F(a)the area of f between a and b

The probability density function f(x) gives the likelihood of a value near x; in a receiver x can be the received voltage. The probability that X falls in an interval is the area under f(x) over that interval. The probability distribution function F(x), also called the cumulative distribution function, adds the area up to x. A histogram of many random numbers, scaled so its area is 1, approaches the pdf.

03

Random numbers in MATLAB

Uniformrand(M,N)values in (0, 1)
Normalrandn(M,N)mean 0, standard deviation 1
Repeatablerng('default'), s = rng, rng(s)reset, save, restore

Example 1 scales rand to an interval: a + (b − a)·rand(1,100) lies between a and b, and hist(N,10) counts the numbers in ten equal bins. With only 100 numbers the bars are uneven; raise the count and every bar approaches n/10, the flat shape of the uniform pdf. After rng('default') (and right after MATLAB starts) the first five values of rand are 0.8147, 0.9058, 0.127, 0.9134, 0.6324, and the first five of randn are 0.5377, 1.8339, -2.2588, 0.8622, 0.3188. Example 3 saves the generator with s = rng and restores it with rng(s), so z2 equals z1 exactly.

input in example 1. The listing asks for the two integers with input; type 1 and 5 to get figure 1. In a script that should run without questions, set the two values in the code instead. hist is an older function; histogram(N,10) draws the same counts.
04

The Gaussian distribution

pdff(x) = e−(x−µ)²/2σ² / (σ√(2π))the bell curve
Peak1/(σ√(2π))0.3989 for the standard normal
Spread68 % within µ ± σ95 % within µ ± 2σ

µ is the mean (also the median and the mode) and σ the standard deviation; the variance is σ². The manual draws the standard normal (µ = 0, σ = 1) with pdf('Normal',x,0,1), whose peak is 0.3989 at x = 0. Thermal noise in every receiver is Gaussian, because it is the sum of a huge number of tiny independent effects (the central limit theorem).

05

The Rayleigh distribution

pdff(x) = (x/B²)·e−x²/2B², x ≥ 0raylpdf(x,B)
Peakat x = B, f = e−1/2/B0.6065 for B = 1
OriginR = √(X² + Y²)X, Y Gaussian, mean 0, σ = B

The length of a vector whose two components are independent zero mean Gaussians with the same σ = B follows the Rayleigh distribution: the wind speed from its two components, or the magnitude of a complex number with Gaussian real and imaginary parts. The histogram in the demo is made exactly that way, from pairs of Gaussian numbers, and it follows raylpdf.

The listing stops in MATLAB R2026a. In ylabel('pdf --- > ' , 'fontsize ' ,12) the property name has a space at the end, and MATLAB stops with an error about an unknown property. Write ylabel('pdf --->','fontsize',12) without the spaces (and 'fontsize' instead of ' fontsize' in xlabel). The Gaussian listing has the same kind of space in 'Normal '; pdf accepts it.
06

Rayleigh fading

In a city a mobile phone rarely sees the base station directly. The signal arrives along many reflected paths with random phases, and their sum is a complex Gaussian: its magnitude, the received amplitude, is Rayleigh distributed and drops deep into fades several times per wavelength of movement. Rayleigh fading is the standard model when there is no line of sight (urban streets, the ionosphere and the troposphere). With a strong direct path the amplitude follows the Rician distribution instead.

07

Check yourself

Q1What is the use of probability density in telecommunication?

It describes quantities that cannot be predicted exactly, such as noise voltage and fading amplitude. With the pdf of the noise we can find the probability of a bit error, design the decision threshold, and simulate a channel by generating random numbers with the same distribution.

Q2What is a probability density function?

A function f(x) ≥ 0 whose area over an interval is the probability that the random variable falls in that interval; its total area is 1. Its integral up to x is the probability distribution (cumulative) function F(x) = P(X ≤ x).

Q3Write down the mathematical relationship for the Gaussian distribution.

f(x) = (1/(σ√(2π)))·exp(−(x − µ)²/(2σ²)), where µ is the mean and σ the standard deviation.

Q4Explain the relationship of the Gaussian distribution.

The curve is a symmetric bell centred on the mean µ. σ sets its width: about 68 % of the values lie within µ ± σ, 95 % within µ ± 2σ and 99.7 % within µ ± 3σ. A larger σ gives a wider, lower curve because the area stays 1. With µ = 0 and σ = 1 it is the standard normal distribution.

Q5What is standard deviation?

The square root of the variance: σ = √(E[(X − µ)²]). It measures how far the values spread from the mean, in the same units as the values. For noise, σ² is the noise power.

Q6What is the use of the Rayleigh distribution?

It models the amplitude of a signal that reaches the receiver along many paths with no line of sight (Rayleigh fading in mobile radio), and any magnitude of a vector with two independent zero mean Gaussian components, such as wind speed.

Q7Explain the mathematical relationship for the Rayleigh distribution.

f(x) = (x/B²)·exp(−x²/(2B²)) for x ≥ 0 and 0 for x < 0. B is the σ of each Gaussian component. The pdf starts at 0, peaks at x = B with height e^(−1/2)/B, and has a long tail; its mean is B√(π/2).

Q8How are random numbers generated in MATLAB?

rand gives uniform numbers in (0, 1), randn standard normal numbers, randi random integers, and random or raylrnd numbers of other distributions. They are pseudorandom, from the Mersenne Twister by default; rng sets the seed (rng('default') resets it, s = rng saves it and rng(s) restores it) so a result can be repeated.