# Lowpass with Hann window

**URL:** <https://discourse.julialang.org/t/lowpass-with-hann-window/100227>\
**Category:** Signal and Image Processing\
**Created:** [June 12, 2023, 12:18pm UTC](https://discourse.julialang.org/t/lowpass-with-hann-window/100227 "2023-06-12T12:18:45Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [June 14, 2023, 5:32am UTC](https://discourse.julialang.org/t/lowpass-with-hann-window/100227/21 "2023-06-14T05:32:09Z")

</div>

> [@mbaz](#):
>
> I think it’s reasonable to expect the window functions to return values according to their [mathematical definition](https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows)

You assume that there were only one definition for each window. Even if the wikipedia article showed a normalized form, that would be **a** correct definition.

Indeed, let’s look at the wikipedia entry about Julius von Hann, the inventor of the Hann filter:

> **[Julius von Hann](https://en.wikipedia.org/wiki/Julius_von_Hann)**
>
> Julius Ferdinand von Hann (23 March 1839 in Wartberg ob der Aist near Linz – 1 October 1921 in Vienna) was an Austrian meteorologist. He is seen as a father of modern meteorology.
> He was educated at the gymnasium of Kremsmünster and then studied mathematics, chemistry and physics at the University of Vienna, then geology and paleontology under Eduard Suess and physical geography under Friedrich Simony. From 1865 to 1868, he was master at the Oberrealschule at Linz, and in 1865 was invited by Kar...

His original filter window was [1/4, 1/2, 1/4], which was normalized! (He was from my field: meteorology, oceanography, climate science, etc.)

We can see what happened to normalization in this article about the Hann function:

> **[Hann function](https://en.wikipedia.org/wiki/Hann_function)**
>
> The Hann function is named after the Austrian meteorologist Julius von Hann. It is a window function used to perform Hann smoothing. The function, with length 
>   
>     
>       
> L
>       
>     
> {\\displaystyle L}
>   
> and amplitude 
>   
>     
>       
> 1
>         
> /
>         
> L
> ,
>       
>     
> {\\displaystyle 1/L,}
>   
> is given by:
> For digital signal processing, the function is sampled symmetrically (with spacing 
>   
>     
>       
> L
>         
> /
> ...

It first shows the continuous form, which is normalized; that is

integral H(x) dx = 1

When converting this integral form to a discrete form, one would normally put dx = L/N and then

integral H(x) dx = sum\_n H(x\_n) L / N = sum\_n G(n),

where G(n) = (L /N) H(x\_n) is **a** discrete form of the Hann window. If this were the definition, we would have

sum\_n G(n) = 1.

Instead, the above Wikipedia article ignores N and defines F(n) = L H(x\_n) to be the discrete version of the Hann window. Under this definition,

sum\_n F(n) = N

instead of 1. Apparently, this is the definition people in the field of digital signal use.

I’m _not_ saying that the definition of the window in your discipline is wrong. You must have your own reason. But, the reason shouldn’t be that it is _the_ correct definition.

> Maybe a boolean keyword `normalized` that defaults to `false` would be a good idea.

_I_ would appreciate that, but I guess that the current user base of the `DPS` package is dominated by people from the digital signal field and then `normalized` may not be widely used even if implemented.

On the other hand, I’m discovering other julia packages that directly talk about “local filter”, moving average, smoothing, etc. One of them (I forgot which one) includes the capability of plugging in one’s own window functions. Maybe I should go with such a package.

But, what worries me is this proliferation of similar packages. One of the packages I looked at explicitly mentions that it has a large overlap with `DSP`.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [June 15, 2023, 2:42am UTC](https://discourse.julialang.org/t/lowpass-with-hann-window/100227/22 "2023-06-15T02:42:38Z")

</div>

> [@ryofurue](#):
>
> You assume that there were only one definition for each window.

You’re right – what I meant is, the definition most commonly accepted in DSP. Definitely not the only one, nor the most useful in other contexts. And thanks for sharing your dive into the window’s history, quite interesting.

I still think a `normalize` keyword could be useful. I use it myself when generating pulse signals (see for example [here](https://github.com/mbaz/WaveformCommunications.jl/blob/5f5a66d679dfae1e9b97c08e22e6efaa57938d1e/src/pulses.jl#L13)).

[Previous page](https://discourse.julialang.org/t/lowpass-with-hann-window/100227.md?page=1)
