Signals
A signal is a function that carries information: for continuous time or for discrete time . 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, with sampling period . 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:
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 and its average power is .
- Finite energy (so zero power): pulses, decaying exponentials. Example: has .
- Finite, nonzero power (so infinite energy): periodic signals, the step. A sinusoid of amplitude has power .
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 .
Even and odd parts
Every signal splits uniquely into an even and an odd part:
Cosines are even, sines are odd. This split explains why the Fourier transform of a real even signal is real (Duality and Symmetry).
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_impulsebuilds ; 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 (constant) an energy signal, a power signal or neither? What about ?
Answer
The constant is a power signal (power 4); the ramp is neither.
Solution
The constant has infinite energy but average power . For the average of over grows like , so the power is infinite too.
Exercise 2: Energy of a geometric signal
Compute the energy of for .
Answer
.
Solution
is a geometric series with ratio , so . For that is .
Exercise 3: Even and odd parts of the step (code)
Compute the even and odd parts of on .
Answer
Even part 1/2 everywhere except 1 at ; odd part for , 0 at 0 and for .
Solution
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, .
Test yourself
Which signal has finite energy?
- the constant 1
The unit impulse can be written in terms of the step as…
A cosine signal is…
- odd
- even
- neither
- both