Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
low_pass_zoh_filter.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Justin Dubois <j.p.g.dubois@student.tudelft.nl>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
24#ifndef LOW_PASS_ZOH_FILTER_H
25#define LOW_PASS_ZOH_FILTER_H
26
27#include "std.h"
29
30
43
56static inline void init_first_order_zoh_low_pass(struct FirstOrderZOHLowPass *filter, const float tau,
57 const float sample_time,
58 float value)
59{
60 filter->discrete_time_constant = exp(-sample_time / tau);
61 filter->last_in = value;
62 filter->last_out = value;
63}
64
72static inline float update_first_order_zoh_low_pass(struct FirstOrderZOHLowPass *filter, const float value)
73{
74 float out = (1.0f - filter->discrete_time_constant) * value + filter->discrete_time_constant * filter->last_out;
75 filter->last_in = value;
76 filter->last_out = out;
77 return out;
78}
79
87static inline float reset_first_order_zoh_low_pass(struct FirstOrderZOHLowPass *filter, const float value)
88{
89 filter->last_in = value;
90 filter->last_out = value;
91 return value;
92}
93
100static inline float get_first_order_zoh_low_pass(const struct FirstOrderZOHLowPass *filter)
101{
102 return filter->last_out;
103}
104
110static inline void update_first_order_zoh_low_pass_tau(struct FirstOrderZOHLowPass *filter, const float tau,
111 const float sample_time)
112{
113 filter->discrete_time_constant = exp(-sample_time / tau);
114}
115
116#endif // LOW_PASS_ZOH_FILTER_H
static void update_first_order_zoh_low_pass_tau(struct FirstOrderZOHLowPass *filter, const float tau, const float sample_time)
Update time constant (tau parameter) for first order ZOH low pass filter.
static float update_first_order_zoh_low_pass(struct FirstOrderZOHLowPass *filter, const float value)
Update first order ZOH low pass filter state with a new value.
static float get_first_order_zoh_low_pass(const struct FirstOrderZOHLowPass *filter)
Get current value of the first order ZOH low pass filter.
static float reset_first_order_zoh_low_pass(struct FirstOrderZOHLowPass *filter, const float value)
Reset the first order ZOH low-pass filter to a specific value.
static void init_first_order_zoh_low_pass(struct FirstOrderZOHLowPass *filter, const float tau, const float sample_time, float value)
Init first order ZOH low pass filter.
Zero Order Hold (ZOH) discrete first order low pass filter structure.
uint16_t foo
Definition main_demo5.c:58
Paparazzi fixed point algebra.