-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProportionalIntegral.hpp
More file actions
48 lines (46 loc) · 1.84 KB
/
ProportionalIntegral.hpp
File metadata and controls
48 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* *
* * Filename: ProportionalIntegral.hpp
* *
* * Description:
* * Proportional-Integral (PI) Loop Filter for Costas Loop and Gardner Timing Recovery.
* * - Simple discrete-time PI filter with configurable gains.
* * - Used in CostasLoop and GardnerTimingRecovery classes.
* *
* * Author:
* * JEP, J. Enrique Peraza
* * Organization:
* * Trivium Solutions LLC, 9175 Guilford Rd, Suite 220, Columbia, MD 21046
* *
*/
#pragma once
#include <complex>
#include <cmath>
namespace sdr::mdm
{
template<typename T=float>
struct PILoopFilter // Proportional-Integral Loop Filter
{
T kp{T(0.05)}; // Proportional gain
T ki{T(0.001)}; // Integral gain
T acc{T(0)}; // Integrator accumulator
PILoopFilter (void)=default;
inline void Assemble (
T p, // Proportional gain
T i) // Integrator gain
{ // ~~~~~~~~~~ Assemble ~~~~~~~~~~ //
kp=p; // Set proportional gain
ki=i; // Set integrator gain
} // ~~~~~~~~~~ Assemble ~~~~~~~~~~ //
inline void Reset (void)
{ // ~~~~~~~~~~ Reset ~~~~~~~~~~ //
acc=T(0); // Clear integrator accumulator
} // ~~~~~~~~~~ Reset ~~~~~~~~~~ //
inline T Step (
T err) // Time step
{ // ~~~~~~~~~~ Step ~~~~~~~~~~ //
acc+=ki*err; // Integrate error
return kp*err+acc; // Return PI output
} // ~~~~~~~~~~ Step ~~~~~~~~~~ //
}; // PILoopFilter
}