Elementary operations on signals#
Here we will explore addition and scaling operations on signals.
Consider the following CT signal:
\(x(t)=\cos(t)\).
You can add a constant b
to this signal. Let us see the effect of this
operation by plotting the new signal:
\(y(t)=x(t)+b=\cos(t)+b\).
import sympy as sym
t = sym.symbols('t', real=True)
# scalar constant
b = 1
# the signals:
x = sym.cos(t)
y = sym.cos(t)+b
p1 = sym.plot(x, (t, 0, 2*sym.pi), legend=True, label='cos(t)', show=False);
p2 = sym.plot(y, (t, 0, 2*sym.pi), legend=True, label='cos(t)+b', show=False);
p1.append(p2[0])
p1.show()
![_images/7f8595414bbfed92db3594730b53b1df885a09219e0d322ddd674a32d51abf5e.png](_images/7f8595414bbfed92db3594730b53b1df885a09219e0d322ddd674a32d51abf5e.png)
Change the value of constant b
above to see its effect.
When you multiply a signal with a scalar number, the value of the signal scales accordingly. Observe the plots of \(x(t)\) and \(y(t)\) below.
# scalar constant
a = 0.5
# the signal:
x = sym.cos(t)
y = a*sym.cos(t)
p1 = sym.plot(x, (t, 0, 2*sym.pi), legend=True, label='cos(t)', show=False);
p2 = sym.plot(y, (t, 0, 2*sym.pi), legend=True, label='a cos(t)', show=False);
p1.append(p2[0])
p1.show()
![_images/1c05d153d43e687f08352f6f8e97a8162b1adc1c8b8b93211a1c171cc16b201a.png](_images/1c05d153d43e687f08352f6f8e97a8162b1adc1c8b8b93211a1c171cc16b201a.png)
You can combine both operations to obtain:
\(y(t) = a x(t) + b\).
Change the values of a
and b
below to see their effects.
# scalar constant
a = 0.5
b = -0.5
# the signal:
x = sym.cos(t)
y = a*sym.cos(t)+b
p1 = sym.plot(x, (t, 0, 2*sym.pi), legend=True, label='cos(t)', show=False);
p2 = sym.plot(y, (t, 0, 2*sym.pi), legend=True, label='a cos(t)+b', show=False);
p1.append(p2[0])
p1.show()
![_images/93d9384e2080f2668fd7f9866df29d4253b1f98541243708fa6cc32c0ea1f0ae.png](_images/93d9384e2080f2668fd7f9866df29d4253b1f98541243708fa6cc32c0ea1f0ae.png)
We can also add two or more signals together to obtain a more complicated signal.
Let us now create two signals, \(x\) and \(y\), and add them to obtain a third signal, \(z\). Let
\(x(t) = \cos(t) -\frac{1}{2}\),
\(y(t) = \frac{1}{5} t \), and
\(z(t) = x(t) + y(t)\).
The following code creates \(z(t)\) and plots it.
x = sym.cos(t)-0.5
y = 0.2*t
z = x + y
sym.plot(z);
![_images/850524a91a9e2ee3c9038c467db287305e4a7473331ed5058c979991cdc625b7.png](_images/850524a91a9e2ee3c9038c467db287305e4a7473331ed5058c979991cdc625b7.png)
Exercise: Play with the coefficients of \(x\), \(y\), and \(t\) above. Observe how the shape of \(z(t)\) changes.
Related content:
Explore different types of signals.