From 1ba25f78909aa152ff8eb2f0fd56a4e05fa0abd5 Mon Sep 17 00:00:00 2001 From: ezra Date: Thu, 28 May 2020 21:10:55 -0700 Subject: [PATCH 1/2] small fix to filters.smoother --- lua/lib/filters.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/lib/filters.lua b/lua/lib/filters.lua index b97d08d61..8746b7413 100644 --- a/lua/lib/filters.lua +++ b/lua/lib/filters.lua @@ -15,7 +15,10 @@ end --- clear a filter's history function f:clear() - for i=1,self.bufsize do self.buf[i]=0 end + for i=1,self.bufsize do + print('clearing index: '..i) + self.buf[i]=0 + end end -- debug function to print the buffer @@ -159,6 +162,7 @@ function smoother.new(time, sr) new.bufsize = 1 new:clear() new.x = 0 + new.a = 1 new.sr = sr new.t = time new:calc_coeff() @@ -168,8 +172,8 @@ end function smoother:calc_coeff() - self.b = math.exp(-6.9 / (self.t * self.sr)) - print(self.b) + self.a = 1 - math.exp(-6.9 / (self.t * self.sr)) + print(self.a) end -- set convergence time @@ -195,12 +199,12 @@ function smoother:next(x) if x == nil then x = self.x else self.x = x end - local d = self.buf[1] - x + local d = x - self.buf[1] if math.abs(d) < smoother.EPSILON then self.buf[1] = x else - self.buf[1] = x + (self.b * d) + self.buf[1] = self.buf[1] + (self.a * d) end return self.buf[1] end @@ -209,7 +213,6 @@ end -- @param new value function smoother:set_value(x) self.buf[1] = x - self.y = x end -- set target without updating From e949588414b305c9ab56c0f55174d67011ea8ed9 Mon Sep 17 00:00:00 2001 From: ezra Date: Thu, 28 May 2020 21:12:33 -0700 Subject: [PATCH 2/2] clean print --- lua/lib/filters.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/lib/filters.lua b/lua/lib/filters.lua index 8746b7413..a4f9d5c5f 100644 --- a/lua/lib/filters.lua +++ b/lua/lib/filters.lua @@ -16,7 +16,6 @@ end --- clear a filter's history function f:clear() for i=1,self.bufsize do - print('clearing index: '..i) self.buf[i]=0 end end