File:Window function (comparsion).png

Summary

Description
English: Comparison of different window functions
Date
Source Own Work by user Marcel Müller
Author Marcel Müller
Permission
(Reusing this file)
Marcel Müller at the English-language Wikipedia, the copyright holder of this work, hereby publishes it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. Subject to disclaimers.
Attribution: Marcel Müller at the English-language Wikipedia
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This licensing tag was added to this file as part of the GFDL licensing update.
Category:CC-BY-SA-3.0-migrated-with-disclaimers#Window%20function%20(comparsion).pngCategory:License migration completed#Window%20function%20(comparsion).png
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. Subject to disclaimers.
Category:GFDL-en
Category:Self-published work
This graph image could be re-created using vector graphics as an SVG file. This has several advantages; see Commons:Media for cleanup for more information. If an SVG form of this image is available, please upload it and afterwards replace this template with {{vector version available|new image name}}.
It is recommended to name the SVG file “Window function (comparsion).svg”—then the template Vector version available (or Vva) does not need the new image name parameter.
Category:Graph images that should use vector graphics#%20Window%20function%20(comparsion).pngCategory:PNG that should use vector graphics

Image details and source code

The image is created with Mathematica 3.0 and some beautifications with CorelDraw 7.0. Due to the old versions no SVG export is available.

Init

<< Graphics`Graphics`
<< Graphics`Legend`

Parameters

Len = 4096;   (* Window length *)
Oversamp = 8; (* Oversampling *)

Helper functions

CreateWindow[winfn_] := Table[winfn[p/Len], {p,0,Len}]

DoFFT[data_] := Chop@Take[
  Fourier[RotateLeft[Join[data, Table[0, {Oversamp*(Length[data]-1)-Length[data]}]], (Length[data]-1)/2]],
  (Length[data]-1)*Oversamp/2+1]

GetEnvelope[data_] := Block[
  {min = 1, max, last = data[[1]]},
  While[data[[min+1]] < last*1.001, last=data[[++min]]];
  Map[
    {#,data[[#]]}&,
    {Range[min], Select[Range[2, Length[data]-1], # > min && data[[#-1]] < data[[#]] > data[[#+1]]&]},
    {2}]
]

PlotWin[winfo_,opt___] := Block[
  {fft = Abs@DoFFT@CreateWindow@winfo[[2]]},
  ListPlot[
    20*Log[10, fft/fft[[1]]+1*^-12],
    GridLines->Automatic, PlotJoined->True, Frame->True, PlotRange->All, opt]
]

PlotWin2[winfo_,opt___] := Block[
  {fft = GetEnvelope@Abs@DoFFT@CreateWindow@winfo[[2]]},
  {LogLinearListPlot[
     {#[[1]]/Oversamp, 20*Log[10,#[[2]]/fft[[1,1,2]]+1*^-12]}& /@ fft[[1]],
     GridLines->Automatic, PlotJoined->True, Frame->True, PlotRange->All, opt],
   LogLinearListPlot[
     {#[[1]]/Oversamp, 20*Log[10,#[[2]]/fft[[1,1,2]]+1*^-12]}& /@ fft[[2]],
     GridLines->Automatic, PlotJoined->True, Frame->True, PlotRange->All, opt]}
]

Colors = Apply[
  RGBColor,
  {{0,0,0}, {1,0,0}, {0,0,1}, {0,.7,0}, {.8,0,.8}, {0,.6,.6}, {.6,.6,0}, {.5,.5,.5}},
  {1}];

Dashings = AbsoluteDashing/@(2{{} (*, {4,2}, {4,2,2,2}*)});

GetStyle[i_] :=
  {Colors[[Mod[i-1,Length[Colors]]+1]],
   Dashings[[Mod[Quotient[i-1,Length[Colors]], Length[Dashings]]+1]]}

Window Functions

GaussWin[sigma_] = Exp[-.5 * ((2#-1)/sigma)^2]&;

CosWin[a__] = Apply[Plus, {a} * Table[(-1)^p Cos[2 Pi p #], {p, 0, Length[{a}]-1}]]&;

KaiserWin[alpha_] = BesselI[0, Pi alpha Sqrt[1 - (2#-1)^2]] / BesselI[0, Pi alpha]&;

WinFN = {
  {"Recangular",        1&,                                          1.},
  {"Gauss \[Sigma]=.4", GaussWin[.4],                                1.45},
  {"Hamming",           CosWin[.53836,.46164],                       1.37},
  {"Hann",              CosWin[.5,.5],                               1.5},
  {"Bartlett",          1-Abs[2#-1]&,                                1.33},
  {"Bartlett-Hann",     .62-.48Abs[#-.5]-.38Cos[2Pi#]&,              1.46},
  {"Blackman",          CosWin[.42,.5,.08],                          1.73},
  {"Kaiser \[Alpha]=1", KaiserWin[1],                                1.2},
  {"Kaiser \[Alpha]=2", KaiserWin[2],                                1.5},
  {"Kaiser \[Alpha]=3", KaiserWin[3],                                1.8},
  {"Nutall",            CosWin[.355768,.487396,.144232,.012604],     2.01},
  {"Blackman-Harris",   CosWin[.35875,.48829,.14128,.01168],         2.01},
  {"Blackman-Nutall",   CosWin[.3635819,.4891775,.1365995,.0106411], 1.98},
  {"Flat top",          CosWin[1,1.93,1.29,.388,.032],               3.77}
};

Test Results

PlotWin[WinFN[[-1]]];

PlotWin2[WinFN[[-1]]];

ListPlot@CreateWindow[WinFN[[-1,2]]];

LogLogListPlot[DoFFT@CreateWindow[WinFN[[-1,2]]],
  PlotRange->All, PlotJoined->True, GridLines->Automatic];

DoFFT@CreateWindow[WinFN[[-1,2]]]

GetEnvelope[Abs@DoFFT[CreateWindow[WinFN[[1,2]]]]]

Results

gr = Show[MapIndexed[
  PlotWin2[#, DisplayFunction->Identity, PlotStyle->GetStyle[#2[[1]]]&, WinFN],
  DisplayFunction->$DisplayFunction, PlotRange->{All, {-145,5}}];

gr2 = ShowLegend[
  gr, {MapIndexed[{Graphics[Append[GetStyle[#2[[1]]], Line[{{0,0},{1,0}}]]],#[[1]]}&, WinFN],
  LegendShadow->{0,0}, LegendPosition->{-.8,-.5}, LegendSize->{.4,.55}, LegendTextSpace->5}];

Licensing

Marcel Müller at the English-language Wikipedia, the copyright holder of this work, hereby publishes it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. Subject to disclaimers.
Attribution: Marcel Müller at the English-language Wikipedia
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This licensing tag was added to this file as part of the GFDL licensing update.
Category:CC-BY-SA-3.0-migrated-with-disclaimers#Window%20function%20(comparsion).pngCategory:License migration completed#Window%20function%20(comparsion).png
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. Subject to disclaimers.
Category:GFDL-enCategory:Self-published work

Original upload log

The original description page was here. All following user names refer to en.wikipedia.
  • 2007-01-19 20:25 Marcel Müller 988×726×??? (82239 bytes) Frequency response of the window functions. The double logarithmic plot shows the magnitude in dB over the normalized frequency. Besides the main lobe only the envelope of the frequency response is shown. This is more clearly and allows a quick comparsion
Category:Window function
Category:CC-BY-SA-3.0-migrated-with-disclaimers Category:GFDL-en Category:Graph images that should use vector graphics Category:License migration completed Category:PNG that should use vector graphics Category:Self-published work Category:Window function