From the documentation

f = FourierTransform[HannWindow[x], x, w];
Plot[Log10@Abs[f], {w, -80, 80}, PlotRange -> All]

which produces

enter image description here

Now I was trying to do the same for a discrete case using $1/n$ normalization

    T = 1.;
    num = 1000;
    funx = Table[i, {i, -T/2, T/2, T/(num - 1)}];
    funHann = HannWindow /@ (funx/T);
    frek = Most@Range[-num/2, num/2, 1]/T;
    DFT = Fourier[funHann, FourierParameters -> {-1, 1}]~
    ListLogPlot[Transpose[{frek, Abs@DFT}], PlotRange -> All]

which instead of produces something totally different enter image description here

Does anybody have an idea why?

EDIT: I think I managed to get to a working case, but not via implemented Fourier instead I defined DFT

    xfft = With[{N = num - 1}, 
   Compile[{{k, _Real}, {fun1, _Real, 1}}, (1/N)*
     fun1.Exp[-2*Pi*I*Range[0, N - 1]*k/N]]];
frek = Join[Most@Range[0, num/2, 1], Most@Range[-num/2, 0, 1]]/(10.0);
XHann = (xfft[#, Most@funHann]) & /@ (Most@frek);
out = ListLogPlot[{Transpose[{Most@frek, Abs[XHann]}]}, 
  PlotRange -> {{-20, 20}, All}, Joined -> {True, True}, 
  Frame -> True, PlotMarkers -> {\[FilledCircle], 6}, Joined -> True, 
  ImageSize -> Large, 
  BaseStyle -> {FontFamily -> "Courier New", FontSize -> 10}]

enter image description here

I really don't understand the implemented Fourier and what is correct or what is wrong.


1 Answer 1


You have sampled too small a range in x, so you don't have sufficient resolution in frequency space to see the structure. With a larger x range:

data = Array[HannWindow, 1024, {-20, 20}];
ListLogPlot[Abs@Fourier[data] ~RotateRight~ 512,
  Joined -> True, DataRange -> {-1, 1} 1024 π/40]

enter image description here

  • 1
    $\begingroup$ I have a more theoretical question than. I is obvious from your and my code that the maximum amplitude in the spectrum depends on the range in x. Im not so sure I understand that part. The greater the range, the smaller the amplitude of Main lobe. $\endgroup$
    – skrat
    Dec 24, 2016 at 18:19
  • 1
    $\begingroup$ @skrat I faced exactly the same problem recently. I had some peaks in my PSD that would simply disappear when using smaller x intervals. $\endgroup$ Jan 12, 2017 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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