MathGroup Archive 2009

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

Search the Archive

Re: Efficiently compute Fourier coefficients for discrete function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105453] Re: Efficiently compute Fourier coefficients for discrete function
  • From: dh <dh at metrohm.com>
  • Date: Thu, 3 Dec 2009 06:14:55 -0500 (EST)
  • References: <hf5jko$qrd$1@smc.vnet.net>


Kelly Jones wrote:

> Mathematica-wise, how to efficiently compute the Fourier coefficients

> for a function defined at finite "random" points. Example:

> 

> This defines Sin[3*x] for 100 random values of x:

> 

> l = Table[Random[],{i,1,100}]

> l2 = Table[{l[[i]],Sin[3*l[[i]]]},{i,1,Length[l]}]

> 

> This calculates the nth Fourier coefficient:

> 

> pfourier[s_,n_] := Sum[s[[i]][[2]]*Exp[-I*n*s[[i]][[1]]], {i,1,Length[s]}]

> 

> (I realize I'm off by a factor of pi; I'm only interested in relative

> size for now).

> 

> As expected, the imaginary/sine part of the 3rd coefficient has the

> greatest magnitude:

> 

> Table[Im[pfourier[l2,n]],{n,1,10}]

> 

> I could compute pfourier[l2,n] for all n, but that seems inefficient.

> 

> Is there a simpler function (similar to Fourier and FourierTransform)

> that does this?

> 

Hi Kelly,$

there is no ready made function for this, but you may easily mke one. E.g:



ff[d_] := d[[All, 2]] . Exp[-I # d[[All, 1]]] & /@ Range[0, Length[d]];



and then ff[l2] would give the transformed data.



Daniel




  • Prev by Date: NDSolve with momentum
  • Next by Date: 3D Model of a Bitmap
  • Previous by thread: Re: Efficiently compute Fourier coefficients for discrete function
  • Next by thread: Re: Efficiently compute Fourier coefficients for discrete function