environment4 2.1.0.0
sensirion_gas_index_algorithm.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022, Sensirion AG
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of Sensirion AG nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef GASINDEXALGORITHM_H_
33#define GASINDEXALGORITHM_H_
34
35#include <stdint.h>
36
37#ifndef __cplusplus
38
39#if __STDC_VERSION__ >= 199901L
40#include <stdbool.h>
41#else
42
43#ifndef bool
44#define bool int
45#define true 1
46#define false 0
47#endif // bool
48
49#endif // __STDC_VERSION__
50
51#endif // __cplusplus
52
53// Should be set by the building toolchain
54#ifndef LIBRARY_VERSION_NAME
55#define LIBRARY_VERSION_NAME "3.2.0"
56#endif
57
58#define GasIndexAlgorithm_ALGORITHM_TYPE_VOC (0)
59#define GasIndexAlgorithm_ALGORITHM_TYPE_NOX (1)
60#define GasIndexAlgorithm_DEFAULT_SAMPLING_INTERVAL (1.f)
61#define GasIndexAlgorithm_INITIAL_BLACKOUT (45.f)
62#define GasIndexAlgorithm_INDEX_GAIN (230.f)
63#define GasIndexAlgorithm_SRAW_STD_INITIAL (50.f)
64#define GasIndexAlgorithm_SRAW_STD_BONUS_VOC (220.f)
65#define GasIndexAlgorithm_SRAW_STD_NOX (2000.f)
66#define GasIndexAlgorithm_TAU_MEAN_HOURS (12.f)
67#define GasIndexAlgorithm_TAU_VARIANCE_HOURS (12.f)
68#define GasIndexAlgorithm_TAU_INITIAL_MEAN_VOC (20.f)
69#define GasIndexAlgorithm_TAU_INITIAL_MEAN_NOX (1200.f)
70#define GasIndexAlgorithm_INIT_DURATION_MEAN_VOC ((3600.f * 0.75f))
71#define GasIndexAlgorithm_INIT_DURATION_MEAN_NOX ((3600.f * 4.75f))
72#define GasIndexAlgorithm_INIT_TRANSITION_MEAN (0.01f)
73#define GasIndexAlgorithm_TAU_INITIAL_VARIANCE (2500.f)
74#define GasIndexAlgorithm_INIT_DURATION_VARIANCE_VOC ((3600.f * 1.45f))
75#define GasIndexAlgorithm_INIT_DURATION_VARIANCE_NOX ((3600.f * 5.70f))
76#define GasIndexAlgorithm_INIT_TRANSITION_VARIANCE (0.01f)
77#define GasIndexAlgorithm_GATING_THRESHOLD_VOC (340.f)
78#define GasIndexAlgorithm_GATING_THRESHOLD_NOX (30.f)
79#define GasIndexAlgorithm_GATING_THRESHOLD_INITIAL (510.f)
80#define GasIndexAlgorithm_GATING_THRESHOLD_TRANSITION (0.09f)
81#define GasIndexAlgorithm_GATING_VOC_MAX_DURATION_MINUTES ((60.f * 3.f))
82#define GasIndexAlgorithm_GATING_NOX_MAX_DURATION_MINUTES ((60.f * 12.f))
83#define GasIndexAlgorithm_GATING_MAX_RATIO (0.3f)
84#define GasIndexAlgorithm_SIGMOID_L (500.f)
85#define GasIndexAlgorithm_SIGMOID_K_VOC (-0.0065f)
86#define GasIndexAlgorithm_SIGMOID_X0_VOC (213.f)
87#define GasIndexAlgorithm_SIGMOID_K_NOX (-0.0101f)
88#define GasIndexAlgorithm_SIGMOID_X0_NOX (614.f)
89#define GasIndexAlgorithm_VOC_INDEX_OFFSET_DEFAULT (100.f)
90#define GasIndexAlgorithm_NOX_INDEX_OFFSET_DEFAULT (1.f)
91#define GasIndexAlgorithm_LP_TAU_FAST (20.0f)
92#define GasIndexAlgorithm_LP_TAU_SLOW (500.0f)
93#define GasIndexAlgorithm_LP_ALPHA (-0.2f)
94#define GasIndexAlgorithm_VOC_SRAW_MINIMUM (20000)
95#define GasIndexAlgorithm_NOX_SRAW_MINIMUM (10000)
96#define GasIndexAlgorithm_PERSISTENCE_UPTIME_GAMMA ((3.f * 3600.f))
97#define GasIndexAlgorithm_TUNING_INDEX_OFFSET_MIN (1)
98#define GasIndexAlgorithm_TUNING_INDEX_OFFSET_MAX (250)
99#define GasIndexAlgorithm_TUNING_LEARNING_TIME_OFFSET_HOURS_MIN (1)
100#define GasIndexAlgorithm_TUNING_LEARNING_TIME_OFFSET_HOURS_MAX (1000)
101#define GasIndexAlgorithm_TUNING_LEARNING_TIME_GAIN_HOURS_MIN (1)
102#define GasIndexAlgorithm_TUNING_LEARNING_TIME_GAIN_HOURS_MAX (1000)
103#define GasIndexAlgorithm_TUNING_GATING_MAX_DURATION_MINUTES_MIN (0)
104#define GasIndexAlgorithm_TUNING_GATING_MAX_DURATION_MINUTES_MAX (3000)
105#define GasIndexAlgorithm_TUNING_STD_INITIAL_MIN (10)
106#define GasIndexAlgorithm_TUNING_STD_INITIAL_MAX (5000)
107#define GasIndexAlgorithm_TUNING_GAIN_FACTOR_MIN (1)
108#define GasIndexAlgorithm_TUNING_GAIN_FACTOR_MAX (1000)
109#define GasIndexAlgorithm_MEAN_VARIANCE_ESTIMATOR__GAMMA_SCALING (64.f)
110#define GasIndexAlgorithm_MEAN_VARIANCE_ESTIMATOR__ADDITIONAL_GAMMA_MEAN_SCALING \
111 (8.f)
112#define GasIndexAlgorithm_MEAN_VARIANCE_ESTIMATOR__FIX16_MAX (32767.f)
113
117typedef struct {
130 float mUptime;
131 float mSraw;
160
169 int32_t algorithm_type);
170
181 GasIndexAlgorithmParams* params, int32_t algorithm_type,
182 float sampling_interval);
183
191
203 float* state0, float* state1);
204
218 float state1);
219
257 GasIndexAlgorithmParams* params, int32_t index_offset,
258 int32_t learning_time_offset_hours, int32_t learning_time_gain_hours,
259 int32_t gating_max_duration_minutes, int32_t std_initial,
260 int32_t gain_factor);
261
268 GasIndexAlgorithmParams* params, int32_t* index_offset,
269 int32_t* learning_time_offset_hours, int32_t* learning_time_gain_hours,
270 int32_t* gating_max_duration_minutes, int32_t* std_initial,
271 int32_t* gain_factor);
272
277 GasIndexAlgorithmParams* params, float* sampling_interval);
278
288 int32_t* gas_index);
289
290#endif /* GASINDEXALGORITHM_H_ */
void GasIndexAlgorithm_reset(GasIndexAlgorithmParams *params)
void GasIndexAlgorithm_init(GasIndexAlgorithmParams *params, int32_t algorithm_type)
void GasIndexAlgorithm_get_states(GasIndexAlgorithmParams *params, float *state0, float *state1)
void GasIndexAlgorithm_process(GasIndexAlgorithmParams *params, int32_t sraw, int32_t *gas_index)
void GasIndexAlgorithm_set_tuning_parameters(GasIndexAlgorithmParams *params, int32_t index_offset, int32_t learning_time_offset_hours, int32_t learning_time_gain_hours, int32_t gating_max_duration_minutes, int32_t std_initial, int32_t gain_factor)
void GasIndexAlgorithm_get_tuning_parameters(GasIndexAlgorithmParams *params, int32_t *index_offset, int32_t *learning_time_offset_hours, int32_t *learning_time_gain_hours, int32_t *gating_max_duration_minutes, int32_t *std_initial, int32_t *gain_factor)
void GasIndexAlgorithm_set_states(GasIndexAlgorithmParams *params, float state0, float state1)
void GasIndexAlgorithm_init_with_sampling_interval(GasIndexAlgorithmParams *params, int32_t algorithm_type, float sampling_interval)
void GasIndexAlgorithm_get_sampling_interval(GasIndexAlgorithmParams *params, float *sampling_interval)
Definition sensirion_gas_index_algorithm.h:117
float mIndex_Gain
Definition sensirion_gas_index_algorithm.h:126
int32_t m_Adaptive_Lowpass___Initialized
Definition sensirion_gas_index_algorithm.h:155
float m_Sigmoid_Scaled__K
Definition sensirion_gas_index_algorithm.h:150
float m_Mean_Variance_Estimator__Gamma_Variance
Definition sensirion_gas_index_algorithm.h:142
float mSraw
Definition sensirion_gas_index_algorithm.h:131
float m_Adaptive_Lowpass___X3
Definition sensirion_gas_index_algorithm.h:158
float mTau_Variance_Hours
Definition sensirion_gas_index_algorithm.h:128
float m_Mox_Model__Sraw_Mean
Definition sensirion_gas_index_algorithm.h:149
float m_Sigmoid_Scaled__Offset_Default
Definition sensirion_gas_index_algorithm.h:152
float m_Mean_Variance_Estimator___Sraw_Offset
Definition sensirion_gas_index_algorithm.h:135
float mGating_Threshold
Definition sensirion_gas_index_algorithm.h:125
float m_Adaptive_Lowpass__A1
Definition sensirion_gas_index_algorithm.h:153
float m_Mean_Variance_Estimator___Uptime_Gating
Definition sensirion_gas_index_algorithm.h:144
int32_t mAlgorithm_Type
Definition sensirion_gas_index_algorithm.h:118
float mGating_Max_Duration_Minutes
Definition sensirion_gas_index_algorithm.h:122
float m_Mean_Variance_Estimator___Gamma_Variance
Definition sensirion_gas_index_algorithm.h:138
int32_t mSraw_Minimum
Definition sensirion_gas_index_algorithm.h:121
float m_Mean_Variance_Estimator___Std
Definition sensirion_gas_index_algorithm.h:136
float m_Sigmoid_Scaled__X0
Definition sensirion_gas_index_algorithm.h:151
float m_Mean_Variance_Estimator___Gamma_Initial_Variance
Definition sensirion_gas_index_algorithm.h:140
float m_Mean_Variance_Estimator__Gamma_Mean
Definition sensirion_gas_index_algorithm.h:141
float mUptime
Definition sensirion_gas_index_algorithm.h:130
float mIndex_Offset
Definition sensirion_gas_index_algorithm.h:120
float m_Mean_Variance_Estimator___Gating_Duration_Minutes
Definition sensirion_gas_index_algorithm.h:145
float m_Mean_Variance_Estimator___Gamma_Initial_Mean
Definition sensirion_gas_index_algorithm.h:139
float mTau_Mean_Hours
Definition sensirion_gas_index_algorithm.h:127
float mSraw_Std_Initial
Definition sensirion_gas_index_algorithm.h:129
float mInit_Duration_Mean
Definition sensirion_gas_index_algorithm.h:123
float mInit_Duration_Variance
Definition sensirion_gas_index_algorithm.h:124
float m_Mean_Variance_Estimator___Uptime_Gamma
Definition sensirion_gas_index_algorithm.h:143
float m_Adaptive_Lowpass___X1
Definition sensirion_gas_index_algorithm.h:156
float m_Mox_Model__Sraw_Std
Definition sensirion_gas_index_algorithm.h:148
float m_Mean_Variance_Estimator___Sigmoid__X0
Definition sensirion_gas_index_algorithm.h:147
float m_Mean_Variance_Estimator___Sigmoid__K
Definition sensirion_gas_index_algorithm.h:146
float m_Mean_Variance_Estimator___Mean
Definition sensirion_gas_index_algorithm.h:134
int32_t m_Mean_Variance_Estimator___Initialized
Definition sensirion_gas_index_algorithm.h:133
float mGas_Index
Definition sensirion_gas_index_algorithm.h:132
float m_Adaptive_Lowpass___X2
Definition sensirion_gas_index_algorithm.h:157
float mSamplingInterval
Definition sensirion_gas_index_algorithm.h:119
float m_Mean_Variance_Estimator___Gamma_Mean
Definition sensirion_gas_index_algorithm.h:137
float m_Adaptive_Lowpass__A2
Definition sensirion_gas_index_algorithm.h:154