import numpy as np
import matplotlib.pyplot as plt
%pylab inline --no-import-all
Populating the interactive namespace from numpy and matplotlib
def plotSignal(t,x,ptitle='Signal'):
fig = plt.figure(figsize=(10,6))
ax1 = fig.add_axes([0, 0, 1, 0.8]) # [left, bottom, width, height]
ax1.set_xlabel('t')
ax1.set_ylabel('x')
ax1.set_title(ptitle)
ax1.fill_between(t,0,x,color='green', alpha=0.4)
ax1.plot(t, x, color='green', lw=6);
def step(t, t_0):
return 1 * ((t - t_0) >= 0) # Unit step
t = np.linspace(0, 7, 1000, endpoint=True)
# Time breakpoints
t0 = 0
t1 = 2
t2 = 3
t3 = 5
t4 = 7
# Step functions
u0 = step(t, t0)
u1 = step(t, t1)
u2 = step(t, t2)
u3 = step(t, t3)
u4 = step(t, t4)
# Pulse Signals
pu1 = u0 - u1
pu2 = u1 - u2
pu3 = u2 - u3
pu4 = u3 - u4
# First Pulse
fig = plt.figure(figsize=(16,2))
plt.subplot(1,4,1)
plt.plot(t,pu1,'g-')
plt.fill_between(t,0,pu1,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)')
plt.title('$u_0 - u_1$')
# Second Pulse
plt.subplot(1,4,2)
plt.plot(t,pu2,'g-')
plt.fill_between(t,0,pu2,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)');
plt.title('$u_1 - u_2$')
# Third Pulse
plt.subplot(1,4,3)
plt.plot(t,pu3,'g-')
plt.fill_between(t,0,pu3,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)');
plt.title('$u_2 - u_3$')
# Fourth Pulse
plt.subplot(1,4,4)
plt.plot(t,pu4,'g-')
plt.fill_between(t,0,pu4,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)');
plt.title('$u_3 - u_4$');
s1 = 20*np.exp(-2*t)*pu1
plotSignal(t,s1)
s2 = (10*t - 30) * pu2
plotSignal(t,s2)
s3 = (-10*t + 50) * pu3
plotSignal(t,s3)
s4 = (10*t - 70) * pu4
plotSignal(t, s4)
s_t = s1 + s2 + s3 + s4
plotSignal(t, s_t)
a.∫1−57et2cos(t)δ(t−2)dt=0: Sifting Property
Note: the limit from -5 to 1 doesn't include t0=2
def triangular(t,tau):
x = np.zeros(len(t))
for k,tk in enumerate(t):
if np.abs(tk) <= tau/1.:
x[k] = 1 - np.abs(tk)/tau
else:
x[k] = 0
return x
t = np.linspace(-3, 3, 1000, endpoint=True)
tri_1 = triangular(t-1,1)
plotSignal(t,tri_1)
a.) Re{x(t)}
b.) Im{x(t)}
t = np.linspace(0, 2*np.pi, 1000, endpoint=True)
x_t = np.sqrt(2) * (1+1j) * np.exp((np.pi/4)*1j) * np.exp((-1 + 2*np.pi*1j)*t)
x_real = np.real(x_t)
x_imag = np.imag(x_t)
plotSignal(t,x_real)
plotSignal(t,x_imag)
The sum x(t)+y(t) is periodic if x(t) and y(t) have a common period. That is, nT1=mT2.
t = np.linspace(0, 12*np.pi, 10000, endpoint=True)
x1 = np.exp(np.sin(t))
plotSignal(t,x1)
t = np.linspace(0, 12*np.pi, 10000, endpoint=True)
x2 = np.exp(t*np.sin(t))
plotSignal(t,x2)
t = np.linspace(0, 12*np.pi, 10000, endpoint=True)
x3 = np.sin(6*np.pi*t/7) + 2*np.cos(3*t/5)
plotSignal(t,x3)
Power Signal
t = np.linspace(-2, 3, 1000, endpoint=True)
# Time breakpoints
t1 = -1
t2 = 0
t3 = 1
t4 = 2
# Step functions
u1 = step(t,-1)
u2 = step(t,0)
u3 = step(t,1)
u4 = step(t,2)
# Pulse Signals
pu1 = u1 - u2
pu2 = u2 - u3
pu3 = u3 - u4
# First Pulse
fig = plt.figure(figsize=(16,2))
plt.subplot(1,3,1)
plt.plot(t,pu1,'g-')
plt.fill_between(t,0,pu1,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)')
plt.title('$u_1 - u_2$')
# Second Pulse
plt.subplot(1,3,2)
plt.plot(t,pu2,'g-')
plt.fill_between(t,0,pu2,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)');
plt.title('$u_2 - u_3$')
# Third Pulse
plt.subplot(1,3,3)
plt.plot(t,pu3,'g-')
plt.fill_between(t,0,pu3,color='green', alpha=0.4)
plt.xlabel('t ($s$)')
plt.ylabel('v ($t$)');
plt.title('$u_3 - u_4$');
s = (t+1)*pu1 + pu2 + 2*pu3
plotSignal(t, s)
xa = s * step(1-t,0)
plotSignal(t,xa)
xb = s * (step(t,0) - step(t-1,0))
plotSignal(t,xb)