1 // (c) 1999-2003, Pawel Jalocha
2 // (c) 2019, David Freese, W1HKJ
3 
4 #ifndef __LOWPASS3_H__
5 #define __LOWPASS3_H__
6 
7 // ==========================================================================
8 
9 // IIR low pass filter for integration (averaging) purposes
10 // Overshoot is about 1% for Feedback=0.5, and about 1e-6 for Feedback=0.1
11 // Weight is 1 / PeakingTime
12 
13 template <class Type>
14 class LowPass3_Filter {
15 public:
16 	Type Out1, Out2, Output;
17 	template <class InpType, class WeightType>
18 	void Process(InpType Inp, WeightType Weight, WeightType Feedback = 0.1) {
19 		Weight *= 2.0;
20 		Type DiffI1 = Inp;  DiffI1 -= Out1;
21 		Type Diff12 = Out1; Diff12 -= Out2;
22 		Type Diff23 = Out2; Diff23 -= Output;
23 		DiffI1 *= Weight;   Out1   += DiffI1;
24 		Diff12 *= Weight;   Out2   += Diff12;
25 		Diff23 *= Weight;   Output += Diff23;
26 		Diff23 *= Feedback; Out2   += Diff23;
27 	}
28 
29 	template <class LevelType>
30 	void operator = (LevelType Level) {
31 		Out1 = Level;
32 		Out2 = Level;
33 		Output=Level;
34 	}
35 
36 	template <class LevelType>
37 	void Set(LevelType Level = 0) {
38 		Out1 = Level;
39 		Out2 = Level;
40 		Output=Level;
41 	}
42 };
43 
44 
45 // ==========================================================================
46 
47 #endif // of __LOWPASS3_H__
48 
49