       Re: Extract Coefficients of Fourier Series

• To: mathgroup at smc.vnet.net
• Subject: [mg58822] Re: Extract Coefficients of Fourier Series
• From: Peter Pein <petsie at dordos.net>
• Date: Wed, 20 Jul 2005 00:29:21 -0400 (EDT)
• References: <dbie2e\$brj\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```mchangun at gmail.com schrieb:
> Hi All,
>
> I have a set of points which have I fitted to a fourier serires with
> the TrigFit function.  This gives me a fourier series.  What I want is
> to extract all the coefficients of the series, square them, then sum
> them.  How do I this (more specifically, the extraction step?
>
>

In:=
data = Table[4*x*(1 - x), {x, 0, 1, 1/1000}];
tf = TrigFit[data, 3, {x, 0, 1}]
Out=
0.666 - 0.40609304265918433*Cos[2*Pi*x] -
0.10152126067464604*Cos[4*Pi*x] - 0.04511907883733167*Cos[6*Pi*x] +
0.0012745085996715144*Sin[2*Pi*x] + 0.0006372480229067737*Sin[4*Pi*x] +
0.0004248250408689751*Sin[6*Pi*x]

In:= Cases[tf, a_?NumberQ | a_.(_Cos | _Sin) :> a, 1]

Out=
{0.666, -0.40609304265918433,
-0.10152126067464604,
-0.04511907883733167,
0.0012745085996715144,
0.0006372480229067737,
0.0004248250408689751}

In:= %.%
Out= 0.6208120678738216

I splitted the instructions for easy verifying, the whole thing would be
written in one function:

coeffSqSum[tf_]:=
Plus@@Cases[tf, a_?NumberQ | a_.(_Cos | _Sin) :> a^2, 1];

Leave the altenative a_?NumberQ out if you don't want the contant term