MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FourierTrigSeries[] and user-defined function

  • To: mathgroup at
  • Subject: [mg96632] Re: [mg96628] FourierTrigSeries[] and user-defined function
  • From: Daniel Lichtblau <danl at>
  • Date: Wed, 18 Feb 2009 04:21:16 -0500 (EST)
  • References: <>

sagrailo at wrote:
> Am trying to have Mathematica to generated coefficient of Fourier
> trigonometric series for simple step function, defined as follows:
>   f[x_ /; Mod[x, 2*Pi] <= Pi] := 1
>   f[x_ /; Mod[x, 2*Pi] > Pi] := 2
> I'm able to get the plot of the function:
>   Plot[f[x], {x, 0, 2*Pi}, PlotRange -> {0, 3}]
> However, when I try to generate Fourier coefficients:
>   FourierTrigSeries[f[x], x, 10]
> Mathematica is just repeating the above expression as output (and
> passing the expression to N[] or Evaluate[] doesn't help.
> Any suggestion here?  Also, is it possible to not use Mod[] in the
> function definition above, and to have Mathematica to "know" that it
> should "extend" given function so that it behaves as periodic
> function?
> Thanks.

FourierTrigSeries will implicitly make the function periodic; all it 
does involves integrals over one period. You might define the function 
as a sum of box functions. Each of those can be done as unit steps with 
two borders (in Mathematica, that is UnitStep with two arguments). Mod 
will not work in this setting because FourierTrigSeries and related 
functions do not have any ability to handle an unevaluated "symbolic" Mod.

I assume your period is intended go from -2*Pi to 2*Pi, hence the 
nondefault FourierParameters setting below. Possibly instead you just 
mean to have a period from -Pi to Pi, in which case just shift your 
definition (which appears to be from 0 to 2*Pi and change the code below 
as needed.

f[x_] := 2*UnitStep[x + 2*Pi, 2*Pi - x] - UnitStep[x + Pi, Pi - x]
In[47]:= g[x_] =
  FourierTrigSeries[f[x], x, 9, FourierParameters -> {1, 1/2}]

Out[47]= 3/2 - (2*Cos[x/2])/Pi + (2*Cos[(3*x)/2])/(3*Pi) -
    (2*Cos[(5*x)/2])/(5*Pi) + (2*Cos[(7*x)/2])/(7*Pi) -

Checking with Plot shows something plausible.

Plot[g[x], {x, -20, 20}]

Daniel Lichtblau
Wolfram Research

  • Prev by Date: Re: Extract Integrate values
  • Next by Date: Re: weird interpolation issues
  • Previous by thread: FourierTrigSeries[] and user-defined function
  • Next by thread: Help with project needed