diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2023-12-19 14:32:57 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2023-12-19 19:38:32 +0300 |
commit | 664cd1590ecb716b60dc75411eb873b130b2f38b (patch) | |
tree | 28a9a33278acc9c3d6dfdef0de8d7d7748941b3b | |
parent | e983ee7b0760210fdc220364d6c78c92ed8d8479 (diff) | |
download | applause2-664cd1590ecb716b60dc75411eb873b130b2f38b.tar.gz |
fft.lua: added Hann(ing) window function
-rw-r--r-- | fft.lua | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -2,8 +2,6 @@ --- @module applause --- -- TODO: --- Windowing --- Jupyter Notebook -- Documentation local bit = require "bit" local ffi = require "ffi" @@ -302,3 +300,18 @@ function Hamming(samples) return samples end + +-- Also called Hann +function Hanning(samples) + assert(type(samples) == "table") + if samples.is_a_stream then samples = samples:totable() end + + local cos = math.cos + local pi2 = 2*math.pi + + for i = 1, #samples do + samples[i] = samples[i]*(1 - cos((pi2*i)/(#samples-1)))/2; + end + + return samples +end |