3 * \brief 1st and 2nd order filter implementation
4 * \author Jean Baptiste Lanfrey <jean-baptiste.lanfrey@parrot.com>
11 #include <VP_Os/vp_os_types.h>
14 #define NB_FIRST_ORDER 1
15 #define NB_SECOND_ORDER 2
16 #define NB_THIRD_ORDER 3
17 #define NB_FOURTH_ORDER 4
18 #define NB_SIXTH_ORDER 6
19 #define DEFAULT_DELAY_STEP_TIME_DELAY TWENTY_STEP_TIME_DELAY
20 #define FORTY_STEP_TIME_DELAY 40
21 #define THIRTY_TWO_STEP_TIME_DELAY 32
22 #define TWENTY_STEP_TIME_DELAY 20
24 ///////////////////////////////////////////////
29 * \struct _first_order_filter_
30 * \brief First order filter states using Matlab notation.
33 float32_t old_outputs[NB_FIRST_ORDER]; //< filter output history
34 float32_t old_inputs [NB_FIRST_ORDER]; //< filter input history
35 } first_order_filter_t;
39 * \struct _second_order_filter_
40 * \brief Second order filter states using Matlab notation.
43 float32_t old_outputs[NB_SECOND_ORDER]; //< filter output history
44 float32_t old_inputs [NB_SECOND_ORDER]; //< filter input history
45 } second_order_filter_t;
49 * \struct _third_order_filter_
50 * \brief Third order filter states using Matlab notation.
53 float32_t old_outputs[NB_THIRD_ORDER]; //< filter output history
54 float32_t old_inputs [NB_THIRD_ORDER]; //< filter input history
55 } third_order_filter_t;
59 * \struct _fourth_order_filter_
60 * \brief Fourth order filter states using Matlab notation.
63 float32_t old_outputs[NB_FOURTH_ORDER]; //< filter output history
64 float32_t old_inputs [NB_FOURTH_ORDER]; //< filter input history
65 } fourth_order_filter_t;
68 float32_t old_outputs[NB_SIXTH_ORDER]; //< filter output history
69 float32_t old_inputs [NB_SIXTH_ORDER]; //< filter input history
70 } sixth_order_filter_t;
73 typedef struct _deriv_param_t {
78 float32_t internal_state;
84 * \brief m sampling step time delay.
87 float32_t old_inputs[FORTY_STEP_TIME_DELAY]; //< input history
90 ///////////////////////////////////////////////
95 * \fn Digital filter initialization.
96 * \brief This function is used to initialize previous values in digital filter.
97 * \param Filter order.
98 * \param address of previous inputs list.
99 * \param initial input value.
100 * \param address of previous outputs list.
101 * \param initial output value.
106 * \par date: 2007-06-25 author: <florian.pantaleao.ext\@parrot.com> <jean-baptiste.lanfrey\@parrot.com>
109 void filter_init(uint32_t n, float32_t *old_input, float32_t initial_input, float32_t *old_output, float32_t initial_output);
114 * \fn Filter a value.
115 * \brief This function uses the same notation as Matlab except that array indices start at 0
116 * \brief a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na)
117 * \brief This function automatically shifts old inputs and outputs.
118 * \param Filter order
119 * \param address of B coefficients list.
120 * \param address of A coefficients list.
121 * \param input value.
122 * \param address of previous inputs list.
123 * \param address of previous outputs list.
124 * \return filtered value.
128 * \par date: 2007-06-25 author: <florian.pantaleao.ext\@parrot.com> <jean-baptiste.lanfrey\@parrot.com>
131 float32_t filter(uint32_t n, const float32_t *b, const float32_t *a, float32_t input, float32_t *old_input, float32_t *old_output);
134 * \fn Derivative filter
135 * \brief Y/U = kd;p/(1+Td.p)
136 * \param Kd, Td, Te, previous values (state and input)
137 * \return filtered value.
141 * \par date: 2007-10-15 author: <jean-baptiste.lanfrey\@parrot.com>
144 float32_t deriv(deriv_param_t *param, float32_t input);
147 * \fn Digital delay initialization
148 * \brief This function is used to initialize previous inputs of the digital delay.
149 * \param m number of sampling step time delay.
154 * \par date: 2008-5-13 author: <yannick.foloppe.ext\@parrot.com>
157 void delay_init(uint32_t m, float32_t *old_input, float32_t initial_input);
161 * \brief y(k)=u(k-m).
162 * \param m number of sampling step time delay, previous values (state and input).
163 * \return delayed input.
167 * \par date: 2008-5-13 author: <yannick.foloppe.ext\@parrot.com>
170 float delay(uint32_t m, float32_t input, float32_t *old_input);
173 // rate_max is the highest rate allowed in one sample time
174 // warning : rate_max must be positive
177 * \brief limit the rate of an input.
178 * \param rate_max is the highest rate allowed in one sample time. Warning : rate_max must be positive
179 * \return rate limiter output.
183 * \par date: 2008-7-24 author: <yannick.foloppe.ext\@parrot.com>
186 float32_t rate_limiter(float32_t input, float32_t old_output, float32_t rate_max);