def fs_approx(Xk,fk,t):
x_approx = np.zeros(len(t))<EOL>for k,Xkk in enumerate(Xk):<EOL><INDENT>if fk[k] == <NUM_LIT:0>:<EOL><INDENT>x_approx += Xkk.real*np.ones(len(t))<EOL><DEDENT>else:<EOL><INDENT>x_approx += <NUM_LIT:2>*np.abs(Xkk)*np.cos(<NUM_LIT:2>*np.pi*fk[k]*t+np.angle(Xkk))<EOL><DEDENT><DEDENT>return x_approx<EOL>
Synthesize periodic signal x(t) using Fourier series coefficients at harmonic frequencies

Assume the signal is real so coefficients Xk are supplied for nonnegative
indicies. The negative index coefficients are assumed to be complex
conjugates.

Parameters
----------
Xk : ndarray of complex Fourier series coefficients
fk : ndarray of harmonic frequencies in Hz
t : ndarray time axis corresponding to output signal array x_approx

Returns
-------
x_approx : ndarray of periodic waveform approximation over time span t

Examples
--------
>>> t = arange(0,2,.002)
>>> # a 20% duty cycle pulse train
>>> n = arange(0,20,1) # 0 to 19th harmonic
>>> fk = 1*n % period = 1s
>>> t, x_approx = fs_approx(Xk,fk,t)
>>> plot(t,x_approx)