I am using sympy to carry on some symbolic math manipulations.
Start by creating a Fourier series representation of a rectangular pulse train (duty cycle < 50%), then try to access the multiplying factors, i.e. a_n and b_n of the standard Fourier series.
In a nutshell:
import sympy as sy
from sympy import fourier_series, pi, cos, sin
from sympy.abc import t
from sympy.functions.special.delta_functions import Heaviside
T = sy.symbols('T')
s = fourier_series(Heaviside(t) - Heaviside(t-1/4), (t, 0, 1))
s.truncate(3)
1/π*sin(2πt)+1/π*sin(4πt)+1/π*cos(2πt)+0.25
I would then like to access the coefficients of the base functions. To this extent, I thought I should use as_coefficient(expr).
This produces the expected results in a simpler case:
g = 1/(pi*T)*sin(2*pi*t)
g.as_coefficient(sin(2*pi*t))
1/πT
However, with the object returned by fourier_series, this does not seem to work:
a = s.truncate(3)
a.as_coefficient(sin(2*pi*t))
returns nothing (not even a warning or message).
Other methods like s.as_Add() or s.as_Mul() return both a full expression where the a_n is tied to its sin(2*pi*n*t) term (or b_n to its dual).

