From 0ffeb62954134b81d6fd775bb05a84cf8190f9ab Mon Sep 17 00:00:00 2001 From: William Clark Date: Tue, 21 Nov 2023 16:19:20 +0000 Subject: [PATCH] filter settings --- config.toml | 14 ++++++++------ config/config.go | 20 ++++++++++---------- data/config/data.go | 1 + filter/filter.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/config.toml b/config.toml index c977915..be5e762 100644 --- a/config.toml +++ b/config.toml @@ -1,28 +1,30 @@ +# TH7 demo configuration file. [TH7] -port = 9090 -debug = true +port = 9090 # web port +debug = true # enable to use simulated PCB for development [DB] type = "sqlite3" path = "test.db" freq = 60 +[Channel_1] +type = 'U' +filter.samples = 100 +filter.type = 1 + [Channel_2] type = 'N' -unit = 'C' filter.samples = 20 [Channel_3] type = 'T' -unit = 'C' [Channel_4] type = 'K' -unit = 'C' [Channel_6] type = 'J' -unit = 'C' offset = -23.1 diff --git a/config/config.go b/config/config.go index dc41fa1..559969c 100644 --- a/config/config.go +++ b/config/config.go @@ -12,20 +12,19 @@ import ( var ( ErrConfigBadThermocoupleType = errors.New("unrecognised thermocouple type") - ErrConfigBadTemperatureUnit = errors.New("unrecognised temperature unit") ) var ( thermocoupleTypes = map[string]thermocouple.Type{ - "B": thermocouple.B, - "E": thermocouple.E, - "J": thermocouple.J, - "K": thermocouple.K, - "N": thermocouple.N, - "R": thermocouple.R, - "S": thermocouple.S, - "T": thermocouple.T, - "UV": thermocouple.None, + "B": thermocouple.B, + "E": thermocouple.E, + "J": thermocouple.J, + "K": thermocouple.K, + "N": thermocouple.N, + "R": thermocouple.R, + "S": thermocouple.S, + "T": thermocouple.T, + "U": thermocouple.None, // for uV measurements } ) @@ -100,6 +99,7 @@ func Load() (config.Config, error) { c.Thermo = tc c.Filter.SampleSize = v.GetInt(head + ".filter.samples") + c.Filter.Type = v.GetInt(head + ".filter.type") cfg.Channels = append(cfg.Channels, c) } diff --git a/data/config/data.go b/data/config/data.go index 9a71cd3..eba9d24 100644 --- a/data/config/data.go +++ b/data/config/data.go @@ -6,6 +6,7 @@ import ( type Filter struct { SampleSize int `json:"sample_size"` + Type int `json:"type"` } type Channel struct { diff --git a/filter/filter.go b/filter/filter.go index 19e3a91..6abf08a 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -9,3 +9,33 @@ func AlphaBetaFilter(arr []float64, init float64) float64 { } return value } + +// Simple lag filter. value = old * 0.9 + new * 0.1 +func Lag_1(arr []float64, init float64) float64 { + value := init + for i := range arr { + value = value*0.9 + arr[i]*0.1 + } + + return value +} + +// Simple lag filter. value = old * 0.95 + new * 0.05 +func Lag_2(arr []float64, init float64) float64 { + value := init + for i := range arr { + value = value*0.95 + arr[i]*0.05 + } + + return value +} + +// Simple lag filter. value = old * 0.99 + new * 0.01 +func Lag_3(arr []float64, init float64) float64 { + value := init + for i := range arr { + value = value*0.99 + arr[i]*0.01 + } + + return value +}