TExcelTAD
Home › Fourier Analysis & Signals › Operations on Signals

Operations on Signals

Most of signal processing is built from a handful of operations on the time axis and on values: shifting, reversing, scaling time, and adding or multiplying signals. Their effect on the spectrum is the content of the later "shift" and "scaling" theorems, so it pays to be precise about them now.

Time shift, reversal and scaling

For a continuous signal x(t)x(t):

  • x(t−t0)x(t - t_0) is xx delayed by t0t_0 (shifted right when t0>0t_0 > 0),
  • x(−t)x(-t) is xx reversed in time,
  • x(at)x(at) with a>1a > 1 is compressed (plays faster), with 0<a<10 < a < 1 stretched.

Combined operations are easiest to read by asking "where does the original t=0t = 0 go?". For x(2t−6)=x(2(t−3))x(2t - 6) = x(2(t - 3)), the original origin moves to t=3t = 3 and the signal is compressed by 2.

python · try it yourself
import numpy as np

def x(t):                                  # a triangle pulse on [0, 2], peak at t = 1
    return np.clip(1 - np.abs(t - 1), 0, None)

t = np.arange(-1, 6, 0.5)
print("t:          ", t.tolist())
print("x(t):       ", np.round(x(t), 2).tolist())
print("x(t - 2):   ", np.round(x(t - 2), 2).tolist())
print("x(2t - 6):  ", np.round(x(2 * t - 6), 2).tolist())
print("x(-t + 2):  ", np.round(x(-t + 2), 2).tolist())
t:           [-1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5]
x(t):        [0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
x(t - 2):    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0]
x(2t - 6):   [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
x(-t + 2):   [0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

The delayed pulse peaks at t=3t = 3; x(2t−6)x(2t - 6) peaks at t=3.5t = 3.5, where 2t−6=12t - 6 = 1, and is half as wide.

Discrete time is different

For x[n]x[n] only integer shifts make sense, and time scaling becomes downsampling x[Mn]x[Mn] (keep every MM-th sample, which can lose information) or upsampling (insert zeros). Downsampling is the operation that causes aliasing.

python · try it yourself
import numpy as np

x = np.arange(10) ** 2                     # 0, 1, 4, 9, ...
print("x[n]      :", x.tolist())
print("x[n - 2]  :", np.concatenate([[0, 0], x[:-2]]).tolist(), "(zeros shifted in)")
print("x[2n]     :", x[::2].tolist())
up = np.zeros(2 * len(x[:5]), dtype=int)
up[::2] = x[:5]
print("upsampled :", up.tolist())
x[n]      : [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
x[n - 2]  : [0, 0, 0, 1, 4, 9, 16, 25, 36, 49] (zeros shifted in)
x[2n]     : [0, 4, 16, 36, 64]
upsampled : [0, 0, 1, 0, 4, 0, 9, 0, 16, 0]

Adding and multiplying

Adding signals mixes them (two instruments). Multiplying a signal by a sinusoid is modulation, the basis of AM radio; multiplying by a 0/1 pulse is windowing, which cuts out a segment. Both have simple effects on the spectrum (Shift, Scaling and Modulation).

python · try it yourself
import numpy as np

fs = 100
t = np.arange(0, 1, 1 / fs)
message = 1 + 0.5 * np.cos(2 * np.pi * 2 * t)          # slow "audio"
carrier = np.cos(2 * np.pi * 20 * t)                   # fast carrier
am = message * carrier
amp = 2 * np.abs(np.fft.rfft(am)) / len(t)
freqs = np.fft.rfftfreq(len(t), 1 / fs)
peaks = freqs[amp > 0.1]
print("frequencies present in the AM signal:", peaks.tolist())
print("their amplitudes:", np.round(amp[amp > 0.1], 3).tolist())
frequencies present in the AM signal: [18.0, 20.0, 22.0]
their amplitudes: [0.25, 1.0, 0.25]

Multiplying by the 20 Hz carrier moved the message's frequencies (0 and 2 Hz) to 2020 and 20±220 \pm 2 Hz.

In software

  • np.roll shifts circularly (samples wrap around); for a true delay pad with zeros, as above, or use scipy.ndimage.shift.
  • Changing playback speed without resampling (time scaling) also scales every frequency, which is why sped-up voices sound higher.

Exercises

Exercise 1: Where is the pulse?

A pulse x(t)x(t) is nonzero on [0,2][0, 2]. On which interval is y(t)=x(3−t)y(t) = x(3 - t) nonzero?

Answer

[1,3][1, 3].

Solution

y(t)≠0y(t) \ne 0 when 0≤3−t≤20 \le 3 - t \le 2, that is 1≤t≤31 \le t \le 3. The pulse was reversed and moved so that the original t=0t = 0 sits at t=3t = 3.

Exercise 2: Order of operations

Is x(2t−6)x(2t - 6) the same as "compress by 2, then delay by 6"?

Answer

No: compressing by 2 then delaying by 3 gives it; compressing then delaying by 6 gives x(2t−12)x(2t - 12).

Solution

Compressing gives z(t)=x(2t)z(t) = x(2t); delaying zz by dd gives z(t−d)=x(2t−2d)z(t - d) = x(2t - 2d). To get x(2t−6)x(2t - 6) we need d=3d = 3. Alternatively delay first by 6, x(t−6)x(t - 6), then compress: x(2t−6)x(2t - 6).

Exercise 3: Downsampling loses information (code)

Downsample x[n]=cos⁡(πn/2)x[n] = \cos(\pi n / 2) by 2 and by 4. What do you get?

Answer

By 2: 1,−1,1,−1,…1, -1, 1, -1, \ldots; by 4: all ones.

Solution
python · try it yourself
import numpy as np
n = np.arange(16)
x = np.round(np.cos(np.pi * n / 2)) + 0.0
print(x[::2].tolist())
print(x[::4].tolist())
[1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0]
[1.0, 1.0, 1.0, 1.0]

After downsampling by 4 the oscillation has vanished completely: the samples land on the peaks only, so the result looks like a constant. That is aliasing.

Test yourself

x(t−3)x(t - 3) is x(t)x(t)…

  1. advanced by 3
  2. delayed by 3
  3. compressed by 3
  4. reversed

x(2t)x(2t) compared with x(t)x(t)…

  1. lasts twice as long
  2. lasts half as long
  3. is delayed by 2
  4. has double amplitude

Multiplying a message by cos⁡(2πfct)\cos(2\pi f_c t) moves its spectrum to…

  1. 00
  2. around ±fc\pm f_c
  3. 2fc2 f_c only
  4. nowhere, it is unchanged