%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
def switch_on(x, x0, slope=20):
"""
switch from 0 to 1 at x0
Parameters
----------
slope : float
defines how steep is the switching function
"""
return 1/( 1+ np.exp(slope*(x-x0)) )
def switch_off(x, x0, slope=20):
"""
switch from 1 to 0 at x0
"""
return 1 - switch_on(x, x0, slope)
N = 1000
tt = np.linspace(-10, 10, N)
tt = np.linspace(0, 3.5, N)
# on_off_on
yy1 = switch_on(tt, 0.9)
yy2 = switch_off(tt, 2.1)
yy3 = switch_on(tt, 0.9) + switch_off(tt, 2.1)
plt.plot(tt, yy1)
plt.plot(tt, yy2)
offset = 0.3 # for better visability
plt.plot(tt, yy3 + offset)
signal = np.sinc(5*(tt - 1.6)) * 100
signal_mod = signal * yy3
plt.figure()
plt.plot(tt, signal, lw=0.2)
plt.plot(tt, signal_mod)
[<matplotlib.lines.Line2D at 0x7fd208a0ecc0>]