I\'m trying to implement a rectangular pulse train in python.
I searched scipy and there is no signal that implements. http://docs.scipy.org/doc/scipy/reference/sign
You could use the square function from scipy.signal:
Verbatim from here:
from scipy import signal
import matplotlib.pyplot as plt
t = np.linspace(0, 1, 500, endpoint=False)
plt.plot(t, signal.square(2 * np.pi * 5 * t))
plt.ylim(-2, 2)

Therefore, for your example, do this:
T=10
D=5
N=10
shift = 1/4 # number of cycles to shift (1/4 cycle in your example)
x = np.linspace(0, T*N, 10000, endpoint=False)
y=signal.square(2 * np.pi * (1/T) * x + 2*shift*np.pi)
plt.plot(x,y)
plt.ylim(-2, 2)
plt.xlim(0, T*N)
