Mercurial > hg > may
changeset 431:f9a954e103db
Cache Kaiser windows
author | Chris Cannam |
---|---|
date | Tue, 08 Oct 2013 08:17:50 +0100 |
parents | 7ee8c2d55e58 |
children | 03c71a35d0eb |
files | src/may/signal/window.yeti |
diffstat | 1 files changed, 16 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/signal/window.yeti Tue Oct 08 07:58:09 2013 +0100 +++ b/src/may/signal/window.yeti Tue Oct 08 08:17:50 2013 +0100 @@ -99,20 +99,17 @@ fi; //!!! if kaiser is going to take a structure, so I guess should sinc and cosineWindow -kaiser { length, beta } = +calculateKaiser { length, beta } = (terms = 20; fact x = fold do x y: x*y done 1 [1..x]; // x! ipow a b = fold do x _: x*a done 1 [1..b]; // a^b where b∈ℕ factorials = array (map fact [1..terms]); bes0 x = - (term x i = - case i of - 0: 1; - _: - f = factorials[i-1]; - (ipow (x/2) (i*2)) / (f * f); - esac; - sum (map (term x) [0..terms])); + 1 + sum + (map do i: + f = factorials[i-1]; + (ipow (x/2) (i*2)) / (f * f); + done [1..terms]); denominator = bes0 beta; kw = vec.fromList (map do i: @@ -121,6 +118,16 @@ done [0..length-1]); kw); +kaisers = [:]; + +kaiser params = + (if not (params in kaisers) + then + k = calculateKaiser params; + kaisers[params] := k; + fi; + kaisers[params]); + /** * Calculate beta and length for a Kaiser window with the given * sidelobe attentuation and either transition width (in samples) or