Random signals and stochastic processes

Lecture 3 · Signal Processing for Communications · University of Klagenfurt, 2019

Nunzio Alexandro Letizia

This lecture

Lecture 3 of 7

  1. Random variables
  2. Random processes, stationarity, ergodicity
  3. The power spectral density and filtering

From Signal Processing for Communications at the University of Klagenfurt, which I taught in winter 2019: this is that edition, rebuilt for the web, so some of it may be a little dated. All lectures.

Random variables

01

Random variables

A random variable (r.v.) X(\omega) is a real-valued function defined on a probability space \Omega:

X(\omega):\Omega\to\mathbb{R}

It maps events, random phenomena in \Omega, into real outcomes. It is fully described by its cumulative distribution function (CDF):

F_X(a):=P[X\le a]

Properties:

  • F_X(a) is non-decreasing: if b\ge a, F_X(b)\ge F_X(a)
  • F_X(a) is bounded, 0\le F_X(a)\le1
  • \lim_{a\to-\infty}F_X(a)=0
  • \lim_{a\to+\infty}F_X(a)=1

The CDF of a continuous random variable, an S curve from zero to one, and its PDF, a bell-shaped peak.

Continuous random variables

If F_X(a) is continuous, the random variable is continuous, and the CDF can be written as

F_X(a)=\int_{-\infty}^{a}f_X(b)\,db

where f_X(a)=\dfrac{dF_X(a)}{da} is the probability density function (PDF). Properties:

  • f_X(a)\ge0
  • \displaystyle\int_{-\infty}^{+\infty}f_X(b)\,db=1
  • \displaystyle P[a<X\le b]=\int_a^bf_X(c)\,dc=F_X(b)-F_X(a)

Discrete random variables

If F_X(a) is piecewise constant, with a countable number of jumps, the random variable is discrete: X takes values, with nonzero probability, in an alphabet A=\{\alpha_1,\alpha_2,\dots,\alpha_n\}.

F_X(a)=\sum_{\alpha_i\in A}p_X(\alpha_i)\cdot1(a-\alpha_i)

where p_X(\alpha_i)=P[X=\alpha_i]=F_X(\alpha_i)-F_X(\alpha_i^-) is the probability mass function (PMF). The PDF, in the generalized sense, becomes a train of impulses:

f_X(a)=\sum_{\alpha_i\in A}p_X(\alpha_i)\cdot\delta(a-\alpha_i)

A discrete random variable on minus one, zero and one with masses a quarter, a half and a quarter: its PDF as three impulses, its CDF as a staircase.

Moments

continuous discrete
mean E[X]=m_X=\displaystyle\int_{-\infty}^{+\infty}a\,f_X(a)\,da E[X]=m_X=\displaystyle\sum_{\alpha_i\in A}\alpha_i\,p_X(\alpha_i)
power E[X^2]=M_X=\displaystyle\int_{-\infty}^{+\infty}a^2f_X(a)\,da E[X^2]=M_X=\displaystyle\sum_{\alpha_i\in A}\alpha_i^2\,p_X(\alpha_i)
variance \sigma_X^2=\displaystyle\int_{-\infty}^{+\infty}(a-m_X)^2f_X(a)\,da \sigma_X^2=\displaystyle\sum_{\alpha_i\in A}(\alpha_i-m_X)^2\,p_X(\alpha_i)

with \sigma_X^2=E\left[(X-m_X)^2\right]=M_X-m_X^2 in both cases.

Expectation theorem. For Y=g(X):

E[Y]=E[g(X)]=\int_{-\infty}^{+\infty}g(a)\,f_X(a)\,da\qquad\text{or}\qquad E[Y]=\sum_{\alpha_i\in A}g(\alpha_i)\,p_X(\alpha_i)

Ex. 1 (discrete)

  1. A Bernoulli random variable X\sim\mathrm{Ber}(p) takes only two values, 0 and 1: it is 1 when an experiment with probability p succeeds, 0 otherwise. Find its mean and variance.
  2. Toss a coin 10 times in a row: how likely is it to get heads exactly 5 times? In general, what is the probability p_{X,1000}(k) of getting k heads out of 1000 trials?
  3. A communication system transmits the binary digits 0 and 1. Non-idealities introduce a probability q=0.1 of receiving the wrong digit. To improve, the system transmits a redundant version, N=3: 000 for 0 and 111 for 1. The receiver decodes by majority (110\to1, 010\to0). (Assignment)
    • Find the probability of error P_e.
    • If P_c is the probability of a correct decision, find the gain G=\frac{P_c}{p}, where now p=1-q is the probability of a correct decision without redundancy.
    • Plot G=G(q) for q between 0 and 0.5. Is there a global maximum?
    • Plot G=G(q,N) for q between 0 and 0.5 and N odd between 1 and 101.

Ex. 1 (discrete): solutions

1. E[X]=0\cdot(1-p)+1\cdot p=p,\qquad V[X]=E[X^2]-E^2[X]=p-p^2=p(1-p)

2. X=\sum_iZ_i, Z_i\sim\mathrm{Ber}(p) independent. One sequence with 5 heads has probability p^5(1-p)^5, and there are \binom{10}{5} of them: the binomial distribution,

P[X=5]=\binom{10}{5}p^5(1-p)^5=\frac{252}{1024}\approx0.246\ \text{ for a fair coin},\qquad p_{X,1000}(k)=\binom{1000}{k}p^k(1-p)^{1000-k}

For many trials, by the central limit theorem, X is approximately \mathcal{N}\left(1000p,\ 1000p(1-p)\right).

3. Part of Assignment 3: solved after the continuous exercises.

Ex. 1 (continuous)

  1. Find the value of \alpha>0 such that f_X(x)=x\cdot e^{-\alpha x}\cdot1(x) is a valid PDF. Draw the function and find the mean, the variance and the CDF.
  2. Let \theta\sim\mathcal{U}\left(-\frac\pi2,\frac\pi2\right) be a uniform random phase, and X=\sin(\theta) a random phase modulation. Find E[X], the variance V[X], F_X(x) and f_X(x).
  3. Let X\sim\mathcal{U}(0,1) be a uniform random variable, and Y=X+\frac1X. Find (assignment):
    • E[Y];
    • F_Y(y);
    • f_Y(y);
    • a distribution X\sim M(\mu,\sigma^2), that is some law with mean \mu and variance \sigma^2, for which E[Y] exists.

Ex. 1 (continuous): solution of item 1

f_X\ge0; with \int_0^\infty x^ne^{-\alpha x}dx=\frac{n!}{\alpha^{n+1}}:

\int_0^{\infty}xe^{-\alpha x}\,dx=\frac{1}{\alpha^2}=1\ \Rightarrow\ \alpha=1,\qquad E[X]=\int_0^\infty x^2e^{-x}dx=2,\qquad V[X]=\int_0^\infty x^3e^{-x}dx-2^2=6-4=2

F_X(x)=\int_0^xb\,e^{-b}\,db=\Big[-(1+b)e^{-b}\Big]_0^x=\left(1-(1+x)e^{-x}\right)1(x)

The PDF peaks at \frac1e in x=1; it is the Gamma (Erlang) law of order 2, the sum of two independent unit exponentials.

My notes have no solution to this one: it is added for the web version.

Left: the PDF x times e to the minus x, zero for negative x, peaking at one over e at x equal to one, the mean 2 marked. Right: its CDF, an S curve from zero to one.

Ex. 1 (continuous): solution of item 2

f_\theta=\frac1\pi on \left(-\frac\pi2,\frac\pi2\right), so

E[X]=\int_{-\pi/2}^{\pi/2}\frac{\sin\vartheta}{\pi}\,d\vartheta=0,\qquad V[X]=E\left[\sin^2\theta\right]=\frac1\pi\int_{-\pi/2}^{\pi/2}\frac{1-\cos2\vartheta}{2}\,d\vartheta=\frac12

\sin is increasing on \left(-\frac\pi2,\frac\pi2\right), so for |x|<1

F_X(x)=P[\theta\le\arcsin x]=\frac1\pi\arcsin x+\frac12,\qquad f_X(x)=\frac{1}{\pi\sqrt{1-x^2}}

with F_X=0 for x\le-1, F_X=1 for x\ge1, and f_X=0 outside (-1,1).

The CDF of the sine of a uniform phase, rising from zero at minus one to one at one, and its PDF, a U shape diverging at both ends.

Assignment 3

Solve the two exercises marked as assignment in the previous slides.

a. A communication system transmits the binary digits 0 and 1, each received wrong with probability q=0.1. With redundancy N=3 (000 for 0, 111 for 1) and majority decoding (110\to1, 010\to0):

  • find the probability of error P_e;
  • find the gain G=\frac{P_c}{p}, with P_c the probability of a correct decision and p=1-q the same without redundancy;
  • plot G=G(q) for q between 0 and 0.5. Is there a global maximum?
  • plot the 3D function G=G(q,N) for q between 0 and 0.5 and N odd between 1 and 101.

b. Let X\sim\mathcal{U}(0,1) and Y=X+\frac1X. Find E[Y], F_Y(y), f_Y(y), and a distribution X\sim M(\mu,\sigma^2) for which E[Y] exists.

Assignment 3: the solution, a

An error needs at least 2 of the 3 digits wrong:

P_e=\binom32q^2(1-q)+q^3=3q^2-2q^3=0.028

G=\frac{1-3q^2+2q^3}{1-q}=\frac{(1-q)^2(1+2q)}{1-q}=1+q-2q^2=1.08

G(q) is a downward parabola, G(0)=G\left(\frac12\right)=1; from G'(q)=1-4q=0, its global maximum is G=\frac98 at q=\frac14.

For any odd N a word is decoded correctly when at most \frac{N-1}{2} digits are wrong:

P_c(q,N)=\sum_{j=0}^{\frac{N-1}{2}}\binom Nj\,q^j(1-q)^{N-j},\qquad G(q,N)=\frac{P_c(q,N)}{1-q}

Assignment 3: the solution, a, continued

The surface is pinned at 1 on three edges: G(0,N)=1, G\left(\frac12,N\right)=\frac{1/2}{1/2}=1, and G(q,1)\equiv1.

For 0<q<\frac12, P_c\to1 as N\to\infty, so G\to\frac{1}{1-q}<2. The peak over q grows with N and moves right: 1.125 at q=0.25 for N=3, 1.32 at 0.32 for N=11, 1.64 at 0.41 for N=101. The bound 2 is never reached.

My notes have no solution to this last plot: it is added for the web version.

The gain G as a function of q for N equal to 1, 3, 5, 11, 51 and 101: flat at one for N equal to 1, then humps that grow taller and move right as N grows, all back to one at q equal to a half.

G(q,N) for a few odd N: slices of the 3D surface

Assignment 3: the solution, b

The mean diverges near X=0:

E[Y]=E[X]+E\left[\tfrac1X\right]=\frac12+\int_0^1\frac{dx}{x}=+\infty

On (0,1), x\mapsto x+\frac1x decreases onto (2,\infty), with inverse x(y)=\frac{y-\sqrt{y^2-4}}{2}. So, for y\ge2,

F_Y(y)=P\left[X\ge x(y)\right]=1-\frac{y-\sqrt{y^2-4}}{2}

f_Y(y)=\frac12\left(\frac{y}{\sqrt{y^2-4}}-1\right),\quad y>2

and F_Y=f_Y=0 for y<2. The tail f_Y\sim\frac{1}{y^2} is what makes the mean infinite.

Left: the density of Y, zero below 2, diverging at 2, then decaying like one over y squared. Right: its CDF, rising steeply from 2 and slowly toward one.

Assignment 3: the solution, b, continued

E[Y] exists when E\left[\frac1X\right] does, that is when X has little probability near 0. Two examples:

  • X\sim\mathcal{U}(a,b) with 0<a<b: \ E[Y]=\frac{a+b}{2}+\frac{\ln b-\ln a}{b-a};
  • X lognormal, X=e^G with G\sim\mathcal{N}(\mu,\sigma^2): then \frac1X=e^{-G} and

E[Y]=e^{\mu+\sigma^2/2}+e^{-\mu+\sigma^2/2}=2\,e^{\sigma^2/2}\cosh\mu

A Gaussian X does not work: its density is positive at 0, and E\left[\frac1X\right] diverges as for the uniform.

My notes have no solution to exercise b: it is added for the web version.

Assignment 3 in Matlab

% vary N,q
m = 0:50;
N = 2*m+1;
% ...
        P_e(k,:) = nchoosek(i,j)*q.^(i-j).*p.^j+P_e(k,:);
    end
    G(k,:) = (1-P_e(k,:))./p;
end
surf(N,q,G')
%% Ex.2 assignment
p = 100000;
T = 0.1; % Resolution
X = rand(1,p);
Y = X+1./X;
eps = T/2;
y = [2:T:10]+eps;
f_y = 0.5*(y./sqrt(y.^2-4)-1);
A = Y(Y<11);
histogram(A,'Normalization','pdf')
hold on
plot(y,f_y,'LineWidth', 3)

The first script sums the probabilities of decoding wrong, then plots the surface G(q,N); the second draws 10^5 samples of Y and compares their histogram with f_Y.

No saved run survives. What to expect: the surface whose slices are on the previous slide, and a histogram on top of f_Y, steep at y=2.

One catch: the histogram keeps only Y<11, about 91\% of the samples, and normalizes over those, so its bars sit about 10\% above f_Y.

Random processes

02

Random processes

A random process (r.p.) X(\omega,t) is a real (or complex) function of two variables:

X(\omega,t):\Omega\times\mathbb{R}\to\mathbb{R}

It can be read as a time series of random variables; stochastic signals are realizations of random processes. The complete statistical description is given by the joint CDF, for any N and any instants t_1,\dots,t_N:

F_X(\mathbf{a},\mathbf{t})=P\left[X(t_1)\le a_1,X(t_2)\le a_2,\dots,X(t_N)\le a_N\right]

The second-order description is given by the mean, the power and the autocorrelation:

m_X(t_1)=E[X(t_1)],\qquad M_X(t_1)=E\left[|X(t_1)|^2\right],\qquad r_{XX}(t_1,t_2)=E\left[X(t_1)\,X^*(t_2)\right]

Stationarity and ergodicity

Stationarity concerns the distributions of the random variables: in a stationary process

F_X(\mathbf{a},\mathbf{t})=F_X(\mathbf{a},\mathbf{t}+\tau)\quad\text{for any real }\tau

Ergodicity concerns averages: a process is ergodic if the statistical averages (mean, power and so on, also called ensemble averages) equal the time averages of a single realization.

For stationary processes, mean, power and variance do not depend on time, and the autocorrelation function (ACF) depends only on the difference \tau=t_2-t_1:

r_{XX}(\tau)=E\left[X(t)\,X^*(t+\tau)\right]

A wide sense stationary (WSS) process is stationary in mean, power and autocorrelation.

Examples

1. Show that the random process X(t)=A\cdot\cos(2\pi t+\varphi), with A constant and \varphi a uniform random variable in [-\pi,\pi], is

  • wide sense stationary;
  • ergodic in mean, power and autocorrelation.

2. Let X(t)=A\cdot\cos(2\pi t), with A a uniform random variable in [-1,1]. Is X(t)

  • wide sense stationary?
  • ergodic in mean, power and autocorrelation?

Example 1: the solution

Average over \varphi, with density \frac{1}{2\pi}:

m_X(t)=\frac{A}{2\pi}\int_{-\pi}^{\pi}\cos(2\pi t+\varphi)\,d\varphi=0

With \cos\alpha\cos\beta=\frac12\cos(\alpha-\beta)+\frac12\cos(\alpha+\beta), the term in 2\varphi averages to zero:

r_{XX}(t,t+\tau)=\frac{A^2}{2}E\left[\cos(2\pi\tau)+\cos(4\pi t+2\pi\tau+2\varphi)\right]=\frac{A^2}{2}\cos(2\pi\tau),\qquad M_X=r_{XX}(0)=\frac{A^2}{2}

None depends on t: the process is WSS. One realization, \varphi=\varphi_0, has the time averages

\overline{x}=\lim_{T\to\infty}\frac1T\int_{-T/2}^{T/2}A\cos(2\pi t+\varphi_0)\,dt=0,\qquad \overline{x^2}=\frac{A^2}{2},\qquad \overline{x(t)\,x(t+\tau)}=\frac{A^2}{2}\cos(2\pi\tau)

the same as the ensemble averages, for every \varphi_0: ergodic in mean, power and autocorrelation.

My notes have no solution to this one: it is added for the web version.

Example 2: the solution

E[A]=0 and E[A^2]=\frac12\int_{-1}^{1}a^2\,da=\frac13, so

m_X(t)=E[A]\cos(2\pi t)=0,\qquad M_X(t)=\frac13\cos^2(2\pi t),\qquad r_{XX}(t,t+\tau)=\frac13\cos(2\pi t)\cos\big(2\pi(t+\tau)\big)

The power and the autocorrelation depend on t: not WSS (the statistics repeat with period 1, a cyclostationary process).

One realization, A=a, has the time averages

\overline{x}=0,\qquad \overline{x^2}=\frac{a^2}{2},\qquad \overline{x(t)\,x(t+\tau)}=\frac{a^2}{2}\cos(2\pi\tau)

The mean is 0 both ways: ergodic in mean. The other two change with the realization, while the ensemble ones change with t: not ergodic in power nor in autocorrelation.

My notes have no solution to this one: it is added for the web version.

Properties

For a WSS process:

  • r_{XX}(\tau)=r_{XX}^*(-\tau)
  • M_X=r_{XX}(0)\ge|r_{XX}(\tau)|
  • r_{XX}(\tau) is a positive semidefinite function

For two processes X(t) and Y(t), the cross-correlation is

r_{XY}(t_1,t_2)=E\left[X(t_1)\,Y^*(t_2)\right]

  • if it is zero, the two processes are orthogonal;
  • if r_{XY}(t_1,t_2)=m_X(t_1)\,m_Y^*(t_2), they are uncorrelated.

The Cauchy-Schwarz inequality for WSS processes: \ 0\le|r_{XY}(\tau)|^2\le M_X\cdot M_Y.

Power spectral density

03

The power spectral density

The power spectral density (PSD) R_X(f) of the process X(t) is the Fourier transform of its autocorrelation:

R_X(f)=\int_{-\infty}^{+\infty}r_{XX}(\tau)\,e^{-j2\pi f\tau}\,d\tau

  • R_X(f) is a real function, and R_X(f)\ge0
  • if r_{XX}(\tau) is real, R_X(f) is real and even
  • M_X=r_{XX}(0)=\displaystyle\int_{-\infty}^{+\infty}R_X(f)\,df

Estimating a PSD in Matlab

%% PSD of a random process
rng default
Fs = 1000;
eps = 0.00001;
t = 0+eps:1/Fs:1-1/Fs;
x = sin(pi*t).^2./((pi*t).^2) + 0.1*randn(size(t));
N = length(x);
X = fft(x);
X = X(1:N/2+1);
psdx = (1/(Fs*N)) * abs(X).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;
plot(freq,10*log10(psdx))
%OR
figure
periodogram(x,rectwin(length(x)),length(x),Fs)

Matlab periodogram: a peak near zero frequency, then a noisy floor around minus 50 dB per hertz up to 500 Hz.

the periodogram, saved from the run

One realization: a \mathrm{sinc}^2 pulse plus white noise. The pulse puts its power near 0 Hz, the noise spreads a flat floor over the whole band, here about -50 dB/Hz, roughness included: a single periodogram is a noisy estimate.

Filtering a random process

The PSD is the fundamental tool to describe random processes through filters. Let x(t) be a WSS process and h(t) a real filter:

x(t) h(t) y(t)=\displaystyle\int_I x(\tau)h(t-\tau)\,d\tau

Then

  • y(t) is WSS;
  • m_y=m_x\cdot H(0)=m_x\cdot A(h);
  • r_{yy}(\tau)=h_-^**h*r_{xx}(\tau), with h_-(t)=h(-t), and R_y(f)=|H(f)|^2\cdot R_x(f).

X(t) is a white Gaussian noise process if it is a stationary Gaussian process with zero mean and a flat PSD,

R_X(f)=\frac{N_0}{2}\quad\text{for all }f

Ex. 2

  1. Let X(t)=A\cdot\cos(2\pi f_0t+\varphi), with A and \varphi uniform i.i.d. in [-\pi,\pi]. Compute the PSD R_X(f).
  2. A communication system transmits identically distributed symbols a(kT), with a(kT) and a(hT) uncorrelated random variables for k\neq h. Compute the PSD R_a(f).
  3. Let x(t) be a Gaussian process with zero mean and PSD R_X(f)=R_0\,\mathrm{triangle}(fT). It is filtered by an interpolation filter with impulse response h(t)=\frac1T\mathrm{sinc}\left(\frac tT\right). Evaluate P\left[|y(t)|<V_0\right].

Ex. 2, continued

  1. Let x(t) be a Gaussian process with zero mean and PSD R_X(f)=R_0\,\mathrm{triangle}\left(\frac fB\right). Evaluate P\left[x(t)+x\left(t-\frac{1}{2B}\right)+x\left(t-\frac1B\right)>2\right]

On the original slide this item is marked as an assignment, but it never made it into Assignment 3.

Ex. 2: solutions

1. A and \varphi are independent, and E_A[A^2]=\frac{1}{2\pi}\int_{-\pi}^{\pi}a^2\,da=\frac{\pi^2}{3}. With \cos\alpha\cos\beta=\frac12\cos(\alpha+\beta)+\frac12\cos(\alpha-\beta), the term in 2\varphi averages to zero:

r_{XX}(\tau)=\frac{\pi^2}{6}\cos(2\pi f_0\tau),\qquad R_X(f)=\frac{\pi^2}{12}\left[\delta(f-f_0)+\delta(f+f_0)\right]

3. H(f)=\mathrm{rect}(fT), so R_Y(f)=R_0\,\mathrm{triangle}(fT)\,\mathrm{rect}(fT), and y(t) is Gaussian with zero mean and

\sigma_Y^2=M_Y=\int_{-\frac{1}{2T}}^{\frac{1}{2T}}R_0\,\mathrm{triangle}(fT)\,df=\frac{3R_0}{4T},\qquad P\left[|y(t)|<V_0\right]=1-2Q\left(V_0\sqrt{\frac{4T}{3R_0}}\right)

with Q(z)=P[Z>z] for Z\sim\mathcal{N}(0,1).

Ex. 2: solution of item 2

The alphabet is not given: call m_a=E[a], M_a=E\left[|a|^2\right] and \sigma_a^2=M_a-|m_a|^2. Uncorrelated means E\left[a(kT)\,a^*(hT)\right]=|m_a|^2 for k\neq h, so

r_a(mT)=E\left[a(kT)\,a^*(kT+mT)\right]=\sigma_a^2\,\delta_{m,0}+|m_a|^2

On \mathbb{Z}(T) the PSD is R_a(f)=T\sum_mr_a(mT)\,e^{-j2\pi fmT}, and the constant gives a comb of lines:

R_a(f)=T\sigma_a^2+|m_a|^2\sum_n\delta\left(f-\frac nT\right)

A flat part plus spectral lines at the multiples of \frac1T. Zero-mean symbols (antipodal \pm1, symmetric PAM or QAM) are white, R_a(f)=T\sigma_a^2; on-off symbols \{0,1\} give \frac T4+\frac14\sum_n\delta\left(f-\frac nT\right).

My notes have no solution to this one: it is added for the web version.

Ex. 2: solution of item 4

The sum is the output of the filter h(t)=\delta(t)+\delta\left(t-\frac{1}{2B}\right)+\delta\left(t-\frac1B\right), so y(t) is Gaussian with zero mean. Expanding the 9 products in E[y^2(t)], with r_{XX} even:

M_Y=3r_{XX}(0)+4r_{XX}\left(\tfrac{1}{2B}\right)+2r_{XX}\left(\tfrac1B\right)

From R_X(f)=R_0\,\mathrm{triangle}\left(\frac fB\right), r_{XX}(\tau)=R_0B\,\mathrm{sinc}^2(B\tau), with \mathrm{sinc}^2\left(\frac12\right)=\frac{4}{\pi^2} and \mathrm{sinc}^2(1)=0:

\sigma_Y^2=M_Y=R_0B\left(3+\frac{16}{\pi^2}\right)\approx4.62\,R_0B,\qquad P[y(t)>2]=Q\left(\frac{2}{\sigma_Y}\right)