TExcelTAD

Signals

A signal is a function that carries information: x(t)x(t) for continuous time t∈Rt \in \mathbb{R} or x[n]x[n] for discrete time n∈Zn \in \mathbb{Z}. Square brackets mark discrete signals, the convention of Oppenheim and Willsky. This lesson introduces the basic signal families and the properties (energy, power, even and odd parts) used to classify them.

Continuous and discrete

A microphone produces a continuous signal; an audio file stores a discrete one, x[n]=x(nTs)x[n] = x(n T_s) with sampling period Ts=1/fsT_s = 1/f_s. When the samples are taken often enough, nothing is lost: that is the sampling theorem. The unit step and the unit impulse are the two building blocks of discrete signals:

u[n]={1n≥00n<0δ[n]={1n=00n≠0δ[n]=u[n]−u[n−1]u[n] = \begin{cases} 1 & n \ge 0 \\ 0 & n < 0 \end{cases} \qquad \delta[n] = \begin{cases} 1 & n = 0 \\ 0 & n \ne 0 \end{cases} \qquad \delta[n] = u[n] - u[n - 1]
python · try it yourself
import numpy as np

n = np.arange(-4, 6)
u = (n >= 0).astype(int)
delta = (n == 0).astype(int)
ramp = np.maximum(n, 0)
decay = (0.5 ** n) * u                     # a decaying exponential, zero for n < 0
print("n:     ", n.tolist())
print("u[n]:  ", u.tolist())
print("d[n]:  ", delta.tolist())
print("u[n]-u[n-1]:", (u - np.roll(u, 1) * (n > n[0])).tolist())
print("ramp:  ", ramp.tolist())
print("0.5^n u[n]:", np.round(decay, 4).tolist())
n:      [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
u[n]:   [0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
d[n]:   [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
u[n]-u[n-1]: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
ramp:   [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]
0.5^n u[n]: [0.0, 0.0, 0.0, 0.0, 1.0, 0.5, 0.25, 0.125, 0.0625, 0.0312]

Energy and power signals

The energy of a discrete signal is E=∑n∣x[n]∣2E = \sum_n \lvert x[n] \rvert^2 and its average power is P=lim⁡N→∞12N+1∑n=−NN∣x[n]∣2P = \lim_{N \to \infty} \frac{1}{2N+1}\sum_{n=-N}^{N} \lvert x[n] \rvert^2.

  • Finite energy (so zero power): pulses, decaying exponentials. Example: 0.5nu[n]0.5^n u[n] has E=∑n≥00.25n=4/3E = \sum_{n \ge 0} 0.25^n = 4/3.
  • Finite, nonzero power (so infinite energy): periodic signals, the step. A sinusoid of amplitude AA has power A2/2A^2/2.
python · try it yourself
import numpy as np

n = np.arange(0, 200)
x = 0.5 ** n
print("energy of 0.5^n u[n]:", round(float(np.sum(x ** 2)), 6), " exact 4/3 =", round(4 / 3, 6))

for N in (100, 1000, 10000):
    m = np.arange(-N, N + 1)
    s = 3 * np.cos(0.3 * m)
    print(f"N={N:5d}: power of 3cos(0.3n) = {np.mean(s ** 2):.4f}")
energy of 0.5^n u[n]: 1.333333  exact 4/3 = 1.333333
N=  100: power of 3cos(0.3n) = 4.4566
N= 1000: power of 3cos(0.3n) = 4.4981
N=10000: power of 3cos(0.3n) = 4.4999

The power approaches 32/2=4.53^2 / 2 = 4.5.

Even and odd parts

Every signal splits uniquely into an even and an odd part:

xe[n]=x[n]+x[−n]2,xo[n]=x[n]−x[−n]2,x=xe+xox_e[n] = \frac{x[n] + x[-n]}{2}, \qquad x_o[n] = \frac{x[n] - x[-n]}{2}, \qquad x = x_e + x_o

Cosines are even, sines are odd. This split explains why the Fourier transform of a real even signal is real (Duality and Symmetry).

python · try it yourself
import numpy as np

n = np.arange(-3, 4)
x = np.array([0, 0, 0, 1, 2, 3, 4], dtype=float)   # the ramp n + 1 for n >= 0
xr = x[::-1]                                       # x[-n] on the symmetric axis
xe, xo = (x + xr) / 2, (x - xr) / 2
print("x_e:", xe.tolist())
print("x_o:", xo.tolist())
print("sum equals x:", np.allclose(xe + xo, x))
x_e: [2.0, 1.5, 1.0, 1.0, 1.0, 1.5, 2.0]
x_o: [-2.0, -1.5, -1.0, 0.0, 1.0, 1.5, 2.0]
sum equals x: True

In software

  • scipy.signal.unit_impulse builds δ[n]\delta[n]; step responses of control systems (scipy.signal.step) answer "what happens when I switch it on?".
  • Energy detectors in voice-activity detection compute short-time energy over 10-30 ms frames.

Exercises

Exercise 1: Classify

Is x[n]=2x[n] = 2 (constant) an energy signal, a power signal or neither? What about x[n]=nx[n] = n?

Answer

The constant is a power signal (power 4); the ramp nn is neither.

Solution

The constant has infinite energy but average power 22=42^2 = 4. For x[n]=nx[n] = n the average of n2n^2 over [−N,N][-N, N] grows like N2/3N^2/3, so the power is infinite too.

Exercise 2: Energy of a geometric signal

Compute the energy of x[n]=anu[n]x[n] = a^n u[n] for ∣a∣<1\lvert a \rvert < 1.

Answer

E=1/(1−a2)E = 1/(1 - a^2).

Solution

E=∑n≥0a2nE = \sum_{n \ge 0} a^{2n} is a geometric series with ratio a2<1a^2 < 1, so E=1/(1−a2)E = 1/(1 - a^2). For a=0.5a = 0.5 that is 4/34/3.

Exercise 3: Even and odd parts of the step (code)

Compute the even and odd parts of u[n]u[n] on n=−3,…,3n = -3, \ldots, 3.

Answer

Even part 1/2 everywhere except 1 at n=0n = 0; odd part −1/2-1/2 for n<0n < 0, 0 at 0 and +1/2+1/2 for n>0n > 0.

Solution
python · try it yourself
import numpy as np
n = np.arange(-3, 4)
u = (n >= 0).astype(float)
print(((u + u[::-1]) / 2).tolist(), ((u - u[::-1]) / 2).tolist())
[0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.5] [-0.5, -0.5, -0.5, 0.0, 0.5, 0.5, 0.5]

The odd part is half of the sign function, 12sgn⁡(n)\tfrac{1}{2}\operatorname{sgn}(n).

Test yourself

Which signal has finite energy?

  1. cos⁡(n)\cos(n)
  2. u[n]u[n]
  3. 0.9nu[n]0.9^n u[n]
  4. the constant 1

The unit impulse can be written in terms of the step as…

  1. u[n]+u[n−1]u[n] + u[n-1]
  2. u[n]−u[n−1]u[n] - u[n-1]
  3. u[−n]u[-n]
  4. n u[n]n\,u[n]

A cosine signal is…

  1. odd
  2. even
  3. neither
  4. both