Last active
August 29, 2015 14:01
-
-
Save msiemens/6672efc032769758423b to your computer and use it in GitHub Desktop.
SymPy Fourier Series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fourier_series(f, frange, t, t_0): | |
k = symbols('k', integer=True, positive=True, zero=False) | |
a_k = 2/t_0*(integrate(f * cos(2*pi/t_0*k*t), [t, frange[0], frange[1]])) | |
a_k = [a_k.subs(k, i) for i in range(1, 10)] | |
b_k = 2/t_0*(integrate(f * sin(2*pi/t_0*k*t), [t, -t_0/2, t_0/2])) | |
b_k = [b_k.subs(k, i) for i in range(1, 10)] | |
# Amplitude | |
d_k = [sqrt(a**2 + b**2) for a, b in zip(a_k, b_k)] | |
# Phase | |
phi_k = [atan(b/a) for a, b in zip(a_k, b_k)] | |
return a_k, b_k, d_k, phi_k |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment