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 
117 typedef struct {
121  int32_t mSraw_Minimum;
126  float mIndex_Gain;
130  float mUptime;
131  float mSraw;
132  float mGas_Index;
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_ */
GasIndexAlgorithmParams::mTau_Variance_Hours
float mTau_Variance_Hours
Definition: sensirion_gas_index_algorithm.h:128
GasIndexAlgorithmParams::m_Mean_Variance_Estimator__Gamma_Mean
float m_Mean_Variance_Estimator__Gamma_Mean
Definition: sensirion_gas_index_algorithm.h:141
GasIndexAlgorithmParams::mAlgorithm_Type
int32_t mAlgorithm_Type
Definition: sensirion_gas_index_algorithm.h:118
GasIndexAlgorithmParams
Definition: sensirion_gas_index_algorithm.h:117
GasIndexAlgorithmParams::m_Adaptive_Lowpass___X2
float m_Adaptive_Lowpass___X2
Definition: sensirion_gas_index_algorithm.h:157
GasIndexAlgorithmParams::mSraw_Minimum
int32_t mSraw_Minimum
Definition: sensirion_gas_index_algorithm.h:121
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Gamma_Initial_Mean
float m_Mean_Variance_Estimator___Gamma_Initial_Mean
Definition: sensirion_gas_index_algorithm.h:139
GasIndexAlgorithmParams::m_Sigmoid_Scaled__K
float m_Sigmoid_Scaled__K
Definition: sensirion_gas_index_algorithm.h:150
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Mean
float m_Mean_Variance_Estimator___Mean
Definition: sensirion_gas_index_algorithm.h:134
GasIndexAlgorithm_set_states
void GasIndexAlgorithm_set_states(GasIndexAlgorithmParams *params, float state0, float state1)
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Sraw_Offset
float m_Mean_Variance_Estimator___Sraw_Offset
Definition: sensirion_gas_index_algorithm.h:135
GasIndexAlgorithmParams::m_Mox_Model__Sraw_Mean
float m_Mox_Model__Sraw_Mean
Definition: sensirion_gas_index_algorithm.h:149
GasIndexAlgorithmParams::mSamplingInterval
float mSamplingInterval
Definition: sensirion_gas_index_algorithm.h:119
GasIndexAlgorithmParams::m_Adaptive_Lowpass__A2
float m_Adaptive_Lowpass__A2
Definition: sensirion_gas_index_algorithm.h:154
GasIndexAlgorithm_init_with_sampling_interval
void GasIndexAlgorithm_init_with_sampling_interval(GasIndexAlgorithmParams *params, int32_t algorithm_type, float sampling_interval)
GasIndexAlgorithmParams::m_Sigmoid_Scaled__X0
float m_Sigmoid_Scaled__X0
Definition: sensirion_gas_index_algorithm.h:151
GasIndexAlgorithm_reset
void GasIndexAlgorithm_reset(GasIndexAlgorithmParams *params)
GasIndexAlgorithmParams::mIndex_Gain
float mIndex_Gain
Definition: sensirion_gas_index_algorithm.h:126
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Uptime_Gamma
float m_Mean_Variance_Estimator___Uptime_Gamma
Definition: sensirion_gas_index_algorithm.h:143
GasIndexAlgorithm_process
void GasIndexAlgorithm_process(GasIndexAlgorithmParams *params, int32_t sraw, int32_t *gas_index)
GasIndexAlgorithmParams::mTau_Mean_Hours
float mTau_Mean_Hours
Definition: sensirion_gas_index_algorithm.h:127
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Initialized
int32_t m_Mean_Variance_Estimator___Initialized
Definition: sensirion_gas_index_algorithm.h:133
GasIndexAlgorithmParams::mInit_Duration_Mean
float mInit_Duration_Mean
Definition: sensirion_gas_index_algorithm.h:123
GasIndexAlgorithmParams::m_Adaptive_Lowpass___X1
float m_Adaptive_Lowpass___X1
Definition: sensirion_gas_index_algorithm.h:156
GasIndexAlgorithmParams::mGas_Index
float mGas_Index
Definition: sensirion_gas_index_algorithm.h:132
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Gating_Duration_Minutes
float m_Mean_Variance_Estimator___Gating_Duration_Minutes
Definition: sensirion_gas_index_algorithm.h:145
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Std
float m_Mean_Variance_Estimator___Std
Definition: sensirion_gas_index_algorithm.h:136
GasIndexAlgorithmParams::mSraw
float mSraw
Definition: sensirion_gas_index_algorithm.h:131
GasIndexAlgorithmParams::mGating_Max_Duration_Minutes
float mGating_Max_Duration_Minutes
Definition: sensirion_gas_index_algorithm.h:122
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Gamma_Initial_Variance
float m_Mean_Variance_Estimator___Gamma_Initial_Variance
Definition: sensirion_gas_index_algorithm.h:140
GasIndexAlgorithmParams::m_Sigmoid_Scaled__Offset_Default
float m_Sigmoid_Scaled__Offset_Default
Definition: sensirion_gas_index_algorithm.h:152
GasIndexAlgorithm_get_tuning_parameters
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)
GasIndexAlgorithmParams::mSraw_Std_Initial
float mSraw_Std_Initial
Definition: sensirion_gas_index_algorithm.h:129
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Uptime_Gating
float m_Mean_Variance_Estimator___Uptime_Gating
Definition: sensirion_gas_index_algorithm.h:144
GasIndexAlgorithm_init
void GasIndexAlgorithm_init(GasIndexAlgorithmParams *params, int32_t algorithm_type)
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Sigmoid__X0
float m_Mean_Variance_Estimator___Sigmoid__X0
Definition: sensirion_gas_index_algorithm.h:147
GasIndexAlgorithmParams::mInit_Duration_Variance
float mInit_Duration_Variance
Definition: sensirion_gas_index_algorithm.h:124
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Sigmoid__K
float m_Mean_Variance_Estimator___Sigmoid__K
Definition: sensirion_gas_index_algorithm.h:146
GasIndexAlgorithmParams::m_Adaptive_Lowpass__A1
float m_Adaptive_Lowpass__A1
Definition: sensirion_gas_index_algorithm.h:153
GasIndexAlgorithm_get_states
void GasIndexAlgorithm_get_states(GasIndexAlgorithmParams *params, float *state0, float *state1)
GasIndexAlgorithmParams::m_Mox_Model__Sraw_Std
float m_Mox_Model__Sraw_Std
Definition: sensirion_gas_index_algorithm.h:148
GasIndexAlgorithmParams::m_Adaptive_Lowpass___Initialized
int32_t m_Adaptive_Lowpass___Initialized
Definition: sensirion_gas_index_algorithm.h:155
GasIndexAlgorithmParams::mIndex_Offset
float mIndex_Offset
Definition: sensirion_gas_index_algorithm.h:120
GasIndexAlgorithm_set_tuning_parameters
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)
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Gamma_Mean
float m_Mean_Variance_Estimator___Gamma_Mean
Definition: sensirion_gas_index_algorithm.h:137
GasIndexAlgorithmParams::mGating_Threshold
float mGating_Threshold
Definition: sensirion_gas_index_algorithm.h:125
GasIndexAlgorithmParams::m_Adaptive_Lowpass___X3
float m_Adaptive_Lowpass___X3
Definition: sensirion_gas_index_algorithm.h:158
GasIndexAlgorithmParams::mUptime
float mUptime
Definition: sensirion_gas_index_algorithm.h:130
GasIndexAlgorithm_get_sampling_interval
void GasIndexAlgorithm_get_sampling_interval(GasIndexAlgorithmParams *params, float *sampling_interval)
GasIndexAlgorithmParams::m_Mean_Variance_Estimator___Gamma_Variance
float m_Mean_Variance_Estimator___Gamma_Variance
Definition: sensirion_gas_index_algorithm.h:138
GasIndexAlgorithmParams::m_Mean_Variance_Estimator__Gamma_Variance
float m_Mean_Variance_Estimator__Gamma_Variance
Definition: sensirion_gas_index_algorithm.h:142