Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to use the discrete Fourier transform for function that represented as list of values.

I started with an easy task to check my understanding. I tried to get the amplitude values for 2*Sin[x]. I think they should be somwhere about 2. But using the discrete Fourier operation produces something quite different. Can someone tell me where my mistakes are?

Here is what I tried.

data = Table[2*Sin[x], {x, 0, 100}];
ListPlot[data, Joined -> True]

enter image description here

ListPlot[Abs[Fourier[data]], Joined -> True, PlotRange -> All]

enter image description here

ListPlot[
  Table[Abs[FourierTransform[2*Sin[x], x, w]] /. 
    DiracDelta -> DiscreteDelta, {w, 0.1, 10, 0.1}], 
  Joined -> True, 
  PlotRange -> All]

enter image description here

How can I get the same results from 'Fourier' as I get from 'FourierTransform'?

share|improve this question
    
related –  Sektor Mar 15 at 12:07
2  
Have you looked at the definition of Fourier and FourierTransform in the documentation? It is given in the first bullet point under Details and Options for both functions. –  Simon Woods Mar 15 at 12:14
    
I understand that there is a difference in the way of having the result. The question is - how to reach the same results for this two operations. –  user12991 Mar 15 at 12:37

1 Answer 1

Paying close attention to the documentation for Fourier and FourierTransform one notes that the coefficients of the Sum/Integral terms are different; therefore, to obtain a discrete transform with amplitudes equal to those from the continuous transform, one must multiply the former by Sqrt[2 Pi / n] where n is the length of the dataset:

The continuous waveform:

DiscretePlot[
 Evaluate[Abs@FourierTransform[2 Sin[x], x, w] /. 
   DiracDelta -> DiscreteDelta], {w, 0, 2}]

Mathematica graphics

and the discrete waveform:

With[{datalength = 100}, 
 ListPlot[(Sqrt[2 Pi]/Sqrt[datalength]) Abs[
    Fourier[Table[2*Sin[x], {x, 0, datalength}]]], Joined -> True, 
  PlotRange -> {{0, 2}, All}, DataRange -> {0, 2Pi}]]

Mathematica graphics

Appendix: Why isn't the amplitude "right"

In the comments, the OP asks why the amplitude of the function 2 Sin[x] appears to be ~2.5 in the transformed data. Let's take a pedagogical approach here, in part to show off how one might use Mathematica to answer these types of questions on their own.

Is there a relationship between the amplitude of the wave and the height of the peak in the transform?

Hopefully, the answer is yes, but let's generate some data, plot it and see.

testdata = 
 Table[{i, 
   Evaluate[
    Abs@FourierTransform[i Sin[x], x, w] /. {DiracDelta -> 
       DiscreteDelta, w -> 1}]}, {i, 1, 10, 1}]

Mathematica graphics

There is a linear relationship - yeah! What is that relationship?

Let's perform a linear least squares analysis on testdata to see what the slope of that line is. I will assume that the plot should go through zero.

LinearModelFit[testdata, x, x]["BestFitParameters"] // Chop
(* {0, 1.25331} *)

So that means that the height of the peak in the transformed data will be 1.25331 times larger than the amplitude of the time-domain function. Where does this 1.25331 come from? Taking a closer look at testdata:

Mathematica graphics

We see a Sqrt[2 Pi]/2 nestled in there. Evaluating N@Sqrt[2 Pi]/2 yields:

(* 1.25331 *)

Nice.

share|improve this answer
    
Oh) So fast answer. But I feels like I am absolutely dummy. In the doc. about functions I see that it is deffers in the coefficiens. But I have no idea for now how was the Sqrt[2 Pi / n] value was reashed? Will it be the same for any function? Or it is different all the time? Looks like in definition the coefficient at the integral/summ is differs all the time on 1/sqrt[2], is it wrom somwhere here? –  user12991 Mar 15 at 13:12
    
@user12991 The 1/Sqrt[n] is in the Fourier equation and the 1/Sqrt[2 Pi] is in the FourierTransform equation. To convert from one to the other you need to multiply by one coefficient and divide by the other, hence the Sqrt[2 Pi/n]. This value should remain the same for all functions you are trying to transform. –  bobthechemist Mar 15 at 13:51
    
Oh thank you. And what about the accuracy of the solving? Looks like now the accurancy of the amplitude is somwhere about 25% o mistake (as the real 2*Sin[x] amplitude is 2). How to increase the accuransy? –  user12991 Mar 15 at 14:01
    
Thank you so much for the evaluation the coefficient of the amplitude/peak height relations that I can use for my transformations of different functions (so as I understand valid for the using fot the different functions by using Fourier discrete transformations?). And even bigger thanks for such big and powerful explanations. That is even more I have ever imagine) –  user12991 Mar 15 at 16:14
    
@user12991 Glad I could help. If the problem is resolved, please consider accepting this answer. –  bobthechemist Mar 15 at 16:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.