filter settings

This commit is contained in:
William Clark 2023-11-21 16:19:20 +00:00
parent e2d57edf45
commit 0ffeb62954
4 changed files with 49 additions and 16 deletions

View File

@ -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

View File

@ -12,7 +12,6 @@ import (
var (
ErrConfigBadThermocoupleType = errors.New("unrecognised thermocouple type")
ErrConfigBadTemperatureUnit = errors.New("unrecognised temperature unit")
)
var (
@ -25,7 +24,7 @@ var (
"R": thermocouple.R,
"S": thermocouple.S,
"T": thermocouple.T,
"UV": thermocouple.None,
"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)
}

View File

@ -6,6 +6,7 @@ import (
type Filter struct {
SampleSize int `json:"sample_size"`
Type int `json:"type"`
}
type Channel struct {

View File

@ -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
}