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] [TH7]
port = 9090 port = 9090 # web port
debug = true debug = true # enable to use simulated PCB for development
[DB] [DB]
type = "sqlite3" type = "sqlite3"
path = "test.db" path = "test.db"
freq = 60 freq = 60
[Channel_1]
type = 'U'
filter.samples = 100
filter.type = 1
[Channel_2] [Channel_2]
type = 'N' type = 'N'
unit = 'C'
filter.samples = 20 filter.samples = 20
[Channel_3] [Channel_3]
type = 'T' type = 'T'
unit = 'C'
[Channel_4] [Channel_4]
type = 'K' type = 'K'
unit = 'C'
[Channel_6] [Channel_6]
type = 'J' type = 'J'
unit = 'C'
offset = -23.1 offset = -23.1

View File

@ -12,7 +12,6 @@ import (
var ( var (
ErrConfigBadThermocoupleType = errors.New("unrecognised thermocouple type") ErrConfigBadThermocoupleType = errors.New("unrecognised thermocouple type")
ErrConfigBadTemperatureUnit = errors.New("unrecognised temperature unit")
) )
var ( var (
@ -25,7 +24,7 @@ var (
"R": thermocouple.R, "R": thermocouple.R,
"S": thermocouple.S, "S": thermocouple.S,
"T": thermocouple.T, "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.Thermo = tc
c.Filter.SampleSize = v.GetInt(head + ".filter.samples") c.Filter.SampleSize = v.GetInt(head + ".filter.samples")
c.Filter.Type = v.GetInt(head + ".filter.type")
cfg.Channels = append(cfg.Channels, c) cfg.Channels = append(cfg.Channels, c)
} }

View File

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

View File

@ -9,3 +9,33 @@ func AlphaBetaFilter(arr []float64, init float64) float64 {
} }
return value 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
}