Fourier Series

Provides methods to compute Fourier series.

class sympy.series.fourier.FourierSeries[source]

Represents Fourier sine/cosine series.

This class only represents a fourier series. No computation is performed.

For how to compute Fourier series, see the fourier_series() docstring.

scale(s)[source]

Scale the function by a term independent of x.

f(x) -> s * f(x)

This is fast, if Fourier series of f(x) is already computed.

Examples

>>> from sympy import fourier_series, pi
>>> from sympy.abc import x
>>> s = fourier_series(x**2, (x, -pi, pi))
>>> s.scale(2).truncate()
-8*cos(x) + 2*cos(2*x) + 2*pi**2/3
scalex(s)[source]

Scale x by a term independent of x.

f(x) -> f(s*x)

This is fast, if Fourier series of f(x) is already computed.

Examples

>>> from sympy import fourier_series, pi
>>> from sympy.abc import x
>>> s = fourier_series(x**2, (x, -pi, pi))
>>> s.scalex(2).truncate()
-4*cos(2*x) + cos(4*x) + pi**2/3
shift(s)[source]

Shift the function by a term independent of x.

f(x) -> f(x) + s

This is fast, if Fourier series of f(x) is already computed.

Examples

>>> from sympy import fourier_series, pi
>>> from sympy.abc import x
>>> s = fourier_series(x**2, (x, -pi, pi))
>>> s.shift(1).truncate()
-4*cos(x) + cos(2*x) + 1 + pi**2/3
shiftx(s)[source]

Shift x by a term independent of x.

f(x) -> f(x + s)

This is fast, if Fourier series of f(x) is already computed.

Examples

>>> from sympy import fourier_series, pi
>>> from sympy.abc import x
>>> s = fourier_series(x**2, (x, -pi, pi))
>>> s.shiftx(1).truncate()
-4*cos(x + 1) + cos(2*x + 2) + pi**2/3
sigma_approximation(n=3)[source]

Return \(\sigma\)-approximation of Fourier series with respect to order n.

Sigma approximation adjusts a Fourier summation to eliminate the Gibbs phenomenon which would otherwise occur at discontinuities. A sigma-approximated summation for a Fourier series of a T-periodical function can be written as

\[s(\theta) = \frac{1}{2} a_0 + \sum _{k=1}^{m-1} \operatorname{sinc} \Bigl( \frac{k}{m} \Bigr) \cdot \left[ a_k \cos \Bigl( \frac{2\pi k}{T} \theta \Bigr) + b_k \sin \Bigl( \frac{2\pi k}{T} \theta \Bigr) \right],\]

where \(a_0, a_k, b_k, k=1,\ldots,{m-1}\) are standard Fourier series coefficients and \(\operatorname{sinc} \Bigl( \frac{k}{m} \Bigr)\) is a Lanczos \(\sigma\) factor (expressed in terms of normalized \(\operatorname{sinc}\) function).

Parameters

n : int

Highest order of the terms taken into account in approximation.

Returns

Expr

Sigma approximation of function expanded into Fourier series.

Examples

>>> from sympy import fourier_series, pi
>>> from sympy.abc import x
>>> s = fourier_series(x, (x, -pi, pi))
>>> s.sigma_approximation(4)
2*sin(x)*sinc(pi/4) - 2*sin(2*x)/pi + 2*sin(3*x)*sinc(3*pi/4)/3

Notes

The behaviour of sigma_approximation() is different from truncate() - it takes all nonzero terms of degree smaller than n, rather than first n nonzero ones.

References

R573

https://en.wikipedia.org/wiki/Gibbs_phenomenon

R574

https://en.wikipedia.org/wiki/Sigma_approximation

truncate(n=3)[source]

Return the first n nonzero terms of the series.

If n is None return an iterator.

Parameters

n : int or None

Amount of non-zero terms in approximation or None.

Returns

Expr or iterator

Approximation of function expanded into Fourier series.

Examples

>>> from sympy import fourier_series, pi
>>> from sympy.abc import x
>>> s = fourier_series(x, (x, -pi, pi))
>>> s.truncate(4)
2*sin(x) - sin(2*x) + 2*sin(3*x)/3 - sin(4*x)/2
sympy.series.fourier.fourier_series(f, limits=None, finite=True)[source]

Computes Fourier sine/cosine series expansion.

Returns a FourierSeries object.

Examples

>>> from sympy import fourier_series, pi, cos
>>> from sympy.abc import x
>>> s = fourier_series(x**2, (x, -pi, pi))
>>> s.truncate(n=3)
-4*cos(x) + cos(2*x) + pi**2/3

Shifting

>>> s.shift(1).truncate()
-4*cos(x) + cos(2*x) + 1 + pi**2/3
>>> s.shiftx(1).truncate()
-4*cos(x + 1) + cos(2*x + 2) + pi**2/3

Scaling

>>> s.scale(2).truncate()
-8*cos(x) + 2*cos(2*x) + 2*pi**2/3
>>> s.scalex(2).truncate()
-4*cos(2*x) + cos(4*x) + pi**2/3

Notes

Computing Fourier series can be slow due to the integration required in computing an, bn.

It is faster to compute Fourier series of a function by using shifting and scaling on an already computed Fourier series rather than computing again.

e.g. If the Fourier series of x**2 is known the Fourier series of x**2 - 1 can be found by shifting by -1.

References

R575

mathworld.wolfram.com/FourierSeries.html