Skip to content

Commit 9aaadbe

Browse files
committed
Document low_pass_filter.h with doxygen docstring
Closes #55
1 parent af9021e commit 9aaadbe

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

include/low_pass_filter.h

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* @file
3+
* @brief Low-pass filter implementation
4+
*
5+
* This module provides a low-pass filter implementation for smoothing sensor readings
6+
* and reducing noise in analog signals. The filter uses an exponential moving average
7+
* algorithm with configurable response time.
8+
*/
9+
110
#ifndef ROCKETLIB_LOW_PASS_FILTER_H
211
#define ROCKETLIB_LOW_PASS_FILTER_H
312

@@ -10,22 +19,58 @@
1019
extern "C" {
1120
#endif
1221

13-
// Inline function to calculate the sample frequency based on the time difference in milliseconds
22+
/**
23+
* @brief Calculate the sample frequency based on the time difference in milliseconds
24+
*
25+
* @param time_diff_ms Time difference between samples in milliseconds
26+
* @return double Sample frequency in Hz
27+
*/
1428
static inline double sample_freq(double time_diff_ms) {
1529
return 1000.0 / time_diff_ms;
1630
}
1731

18-
// Inline function to calculate the alpha value for the low-pass filter based on the response time
32+
/**
33+
* @brief Calculate the alpha value for the low-pass filter based on the response time
34+
*
35+
* The alpha value determines the filter's responsiveness. A higher alpha value results
36+
* in faster response but less filtering, while a lower alpha value provides more filtering
37+
* but slower response.
38+
*
39+
* @param TR Response time constant in milliseconds
40+
* @param time_diff_ms Time difference between samples in milliseconds
41+
* @return double Alpha value (0.0 to 1.0) for the low-pass filter
42+
*/
1943
static inline double low_pass_alpha(double TR, double time_diff_ms) {
2044
double freq = sample_freq(time_diff_ms);
2145
return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0);
2246
}
2347

24-
// Initializes the low-pass filter by calculating and storing the alpha value based on the given
25-
// response time.
48+
/**
49+
* @brief Initializes the low-pass filter by calculating and storing the alpha value
50+
*
51+
* This function calculates the alpha value based on the given response time and stores
52+
* it in the provided pointer. The alpha value is used in subsequent filter updates.
53+
*
54+
* @param alpha Pointer to store the calculated alpha value
55+
* @param response_time Response time constant in milliseconds (must be > 0)
56+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if alpha is NULL or
57+
* response_time is invalid
58+
*/
2659
w_status_t low_pass_filter_init(double *alpha, double response_time);
2760

28-
// Updates the low-pass filter with a new value and returns the operation status
61+
/**
62+
* @brief Updates the low-pass filter with a new value and returns the operation status
63+
*
64+
* This function applies the low-pass filter algorithm to the new input value using the
65+
* provided alpha value. The filtered result is stored in low_pass_value and updated
66+
* in-place for the next iteration.
67+
*
68+
* @param alpha Alpha value (0.0 to 1.0) for the low-pass filter
69+
* @param new_input_value New input value to filter
70+
* @param low_pass_value Pointer to the current filtered value (updated in-place)
71+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if low_pass_value is
72+
* NULL or alpha is out of valid range (0.0 to 1.0)
73+
*/
2974
w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value);
3075

3176
#ifdef __cplusplus

0 commit comments

Comments
 (0)