Random signals and stochastic processes

Lecture 5 · Digital Signal Processing · University of Klagenfurt, 2022

Nunzio Alexandro Letizia

This lecture

Lecture 5 of 6

  1. Random variables
  2. Random processes, stationarity, autocorrelation
  3. The power spectral density, and random signals through digital filters

From Digital Signal Processing at the University of Klagenfurt, first taught in 2020: this is the edition of summer 2022, 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 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 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

  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).
    • 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 p 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?

Ex. 1: 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. 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,\qquad G=\frac{1-3q^2+2q^3}{1-q}=1+q-2q^2=1.08

G(q) is a downward parabola, G(0)=G\left(\frac12\right)=1, with its global maximum G=\frac98 at q=\frac14.

Ex. 1 in Matlab

function prob = CoinTossing(n,k)
% probability of k heads (k can be an interval)
% out of n trials
p = 0.5; % Probability of getting head
if(length(k)==1)
    prob = nchoosek(n,k)*p^k*(1-p)^(n-k);
elseif(length(k)>1)
    prob = 0;
    for i=k(1):k(end)
        prob = nchoosek(n,i)*p^i*(1-p)^(n-i)+prob;
    end
end
%% Encode a bit b with N bits equal and choose the majority
N = 3;
q = 0:0.01:0.5; % prob of single error
p = 1-q;
P_e1 = q; % probability of error of the first trasmitter
P_e2 = q.^3+3*q.^2.*p;
D = (1-P_e2)./(1-P_e1); % GAIN
plot(q,D)

No saved run survives. What to expect: CoinTossing(10,5) returns 0.2461, and the gain plot is the parabola 1+q-2q^2, from 1 at q=0 up to 1.125 at q=0.25 and back to 1 at q=0.5.

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.

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. The output of a filter is y(n)=2x(n)-x(n-1).
    • Find the impulse response h(n).
    • The input x(n) is made of independent, zero mean, unit variance Gaussian samples. Find its autocorrelation r_{XX}(h)=E[x(n)\,x^*(n+h)] and its power spectral density R_{XX}(f).
    • Find the autocorrelation r_{YY}(h) and the PSD R_{YY}(f) of the output.
  2. The output of a filter is y(n)=0.5\,y(n-1)+x(n).
    • Find the transfer function H(z) and the impulse response h(n).
    • The input is made of zero mean Gaussian samples with PSD R_{XX}(f)=\mathrm{rect}\left(2f-\frac12\right), f\in[0,1). Find the PSD R_{YY}(f) of the output, and the output power M_y.

Ex. 2, continued

  1. (From the exam of 2020.) y(n)=\alpha\,y(n-1)+x(n)-x(n-1), with \alpha=0.5.
    • Find H(z) and sketch the zero/pole diagram; find h(n) and sketch it.
    • Find the frequency response and sketch its magnitude. What type of filter is it? What happens when |\alpha|\to1?
    • The input is made of independent, zero mean, unit variance Gaussian samples: find R_{YY}(f) and the output power M_y.

Ex. 2: solutions

1. h(n)=2\delta(n)-\delta(n-1). The samples are independent with unit variance, so r_{XX}(h)=\delta(h) and R_{XX}(f)=1: white noise. Then

r_{YY}(h)=E\left[(2x(n)-x(n-1))(2x(n+h)-x(n+h-1))\right]=5\delta(h)-2\delta(h-1)-2\delta(h+1)

R_{YY}(f)=5-4\cos(2\pi f)=\left|2-e^{-j2\pi f}\right|^2\cdot1=|\tilde H(f)|^2R_{XX}(f)

2. H(z)=\dfrac{1}{1-0.5z^{-1}}, h(n)=0.5^n\,1_0(n), and

R_{YY}(f)=|\tilde H(f)|^2R_{XX}(f)=\frac{\mathrm{rect}\left(2f-\frac12\right)}{\frac54-\cos(2\pi f)},\qquad M_y=\int_0^{1/2}\frac{df}{\frac54-\cos(2\pi f)}=\frac23

with t=\tan(\pi f) and \cos(2\pi f)=\frac{1-t^2}{1+t^2}: \ M_y=\frac4\pi\int_0^\infty\frac{dt}{9t^2+1}=\frac23. The PSD is not even on [0,1), so x(n) must be complex: a real process has an even PSD.

Ex. 2: solution of item 3

H(z)=\dfrac{1-z^{-1}}{1-0.5z^{-1}}: a zero at z=1, a pole at z=0.5. Partial fractions, H(z)=2-\dfrac{1}{1-0.5z^{-1}}:

h(n)=2\delta(n)-0.5^n\,1_0(n)=\left[1,\ -0.5,\ -0.25,\ -0.125,\dots\right]

|\tilde H(f)|^2=\frac{\left|1-e^{-j2\pi f}\right|^2}{\left|1-0.5e^{-j2\pi f}\right|^2}=\frac{2-2\cos(2\pi f)}{\frac54-\cos(2\pi f)}

zero at f=0, maximum |\tilde H|=\frac43 at f=\frac12: a high-pass filter. As |\alpha|\to1 the pole closes on the zero: they cancel everywhere except near f=0, and the filter becomes a narrow notch that only removes the DC component.

With white unit-variance input, R_{YY}(f)=\dfrac{2-2\cos(2\pi f)}{\frac54-\cos(2\pi f)} and

M_y=\sum_n|h(n)|^2=1+\sum_{n\ge1}0.25^n=\frac43

Item 3 had no written solution in my notes: this one is added for the web version.

Assignment 4

The output of a filter is y(n)=\cos(\alpha)\cdot x(n)+\sin(\alpha)\cdot x(n-1).

  1. Find the transfer function H_\alpha(z) and sketch the zero/pole diagram varying \alpha.
  2. The input is made of zero mean Gaussian samples with PSD R_{XX,\beta}(f)=\mathrm{rect}\left(\frac{f-\beta/2}{\beta}\right), f\in[0,1), \beta\in[0,1]. Find the PSD R_{YY,\alpha,\beta}(f) of the output.
  3. Find the output power M_{y,\alpha,\beta}.
  4. For which value of \alpha is the output power equal to 1?
  5. In practice you have access to independent, zero mean, unit variance Gaussian samples w(n). How can you build from w(n) samples x(n) with the PSD of point b? Verify in Matlab.

Assignment 4: a solution

a. H_\alpha(z)=\cos\alpha+\sin\alpha\,z^{-1}: a pole at z=0 and a zero at z=-\tan\alpha, which moves from 0 (\alpha=0) to -1, on the unit circle (\alpha=\frac\pi4), and out to infinity as \alpha\to\frac\pi2, where the filter is a pure delay.

b. |\tilde H_\alpha(f)|^2=\cos^2\alpha+\sin^2\alpha+2\sin\alpha\cos\alpha\cos(2\pi f)=1+\sin(2\alpha)\cos(2\pi f), so

R_{YY,\alpha,\beta}(f)=\left(1+\sin(2\alpha)\cos(2\pi f)\right)\mathrm{rect}\left(\frac{f-\beta/2}{\beta}\right)

c. \displaystyle M_{y,\alpha,\beta}=\int_0^\beta\left(1+\sin(2\alpha)\cos(2\pi f)\right)df=\beta+\frac{\sin(2\alpha)\sin(2\pi\beta)}{2\pi}

d. M_y=1 needs \sin(2\alpha)\sin(2\pi\beta)=2\pi(1-\beta), impossible for \beta<1, since |\sin(2\pi\beta)|<2\pi(1-\beta). For \beta=1 (white input) M_y=1 for every \alpha: the filter has unit energy, \cos^2\alpha+\sin^2\alpha=1.

e. Filter w(n) through an ideal filter with |H(f)|^2=R_{XX,\beta}(f), for instance by zeroing the DFT bins outside [0,\beta); then R_{XX}=|H|^2R_{WW}=|H|^2. As in Ex. 2, a PSD only on [0,\beta) is not even, so x(n) is complex.

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