You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An EMA (**Exponential Moving Average**) filter behaves like an RC lowpass filter with RC = SamplePeriod((1-alpha)/alpha) see [here](https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter).<br/>
13
+
An EMA filter is implemented by e.g. the following statement:
The alpha's for the implemented **ultrafast EMA filters** are 1/2, 1/4, 1/8, 1/16, 1/32 and 1/256 corresponding to the shift values of 1, 2, 3, 4, 5 and 8.
21
+
22
+
#### For a 1 kHz sampling rate (1/1000s sampling interval) we get the following equivalent cutoff (-3db) frequencies:
23
+
- For alpha 1/2 (shift 1) -> 160 Hz
24
+
- 1/4 -> 53 Hz (160 Hz / 3)
25
+
- 1/8 -> 22.7 Hz (160 Hz / 7)
26
+
- 1/16 -> 10.6 Hz (160 Hz / 15)
27
+
- 1/32 -> 5.13 Hz (160 Hz / 31)
28
+
- 1/256 -> 0.624 Hz (160 Hz / 255)
29
+
30
+
### The SimpleEMAFilters.hpp contains:
31
+
- A fixed set of 6 **ultrafast** EMA (Exponential Moving Average) filters which require only **1 to 2 microseconds**.
13
32
- 3 derived filters (highpass and 2 bandpasses) by just subtracting one lowpass from input (highpass) or from another lowpass (bandpass).
14
33
- Display routines for Arduino Plotter.
15
-
An EMA filter behaves like an RC lowpass filter with RC = SamplePeriod((1-alpha)/alpha) see [here](https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter).<br/>
16
-
The alpha's for the implemented **ultrafast EMA filters** are 1/2, 1/4, 1/8, 1/16, 1/32, and 1/256.
17
-
#### For a 1 kHz sampling rate (1/1000s sampling interval) we get the following equivalent cutoff (-3db) frequencies:
18
-
- 1/2 -> 160 Hz
19
-
- 1/4 -> 53 Hz (160 / 3)
20
-
- 1/8 -> 22.7 Hz (160 / 7)
21
-
- 1/16 -> 10.6 Hz
22
-
- 1/32 -> 5.13 Hz
23
-
- 1/256 -> 0.624 Hz (160 / 255)
34
+
35
+
All implemented filters are applied at once to the input test signal calling `doFiltersStep(int16_t aInput)` and the results can in turn easily be displayed in the Arduino Plotter.
24
36
25
37
#### Plotter output representing e.g. a 20 Hz square / sine wave at a sample rate of 1 ms (or 40 Hz at 0.5 ms and so on)
26
38
Arduino Plotter output for a rectangle input signal with a amplitude of +/- 100. E.g. Lowpass3 is the one with alpha 1/8 implemented by `>> 3`.
@@ -32,21 +44,23 @@ Arduino Plotter output for a sine input signal with a amplitude of +/- 100. Note
32
44
Arduino Plotter output for a triangle input signal with a amplitude of +/- 100. Note that Lowpass5 is almost a perfect sine.
***Attention!** The 16 bit implementations are limited to a **maximum input value of +/- 16383** for rectangular input (which is the worst input case). The reason is, that the term `InputValue - Lowpass3` must always fit into a 16 bit signed integer.
36
-
37
47
The floating point implementation of the 1/32 EMA filter takes 24 to 34 µs.<br/>
38
48
39
-
All filters are applied to your test signal calling `doFiltersStep(int16_t)` and the results can in turn easily be displayed in the Arduino Plotter.<br/>
40
49
There is no function implemented for one EMA filter, since it is better to implement it directly by e.g.
Lowpass5_int32 += ((((int32_t) InputValue) << 8) - Lowpass5_int32) >> 5; // Fixed point 4.2 us, value is Lowpass5_int32 >> 8
48
59
Lowpass8_int32 += ((((int32_t) InputValue) << 16) - Lowpass8_int32) >> 8; // Fixed point 2.0 us because of fast shift, value is Lowpass8_int32 >> 16
49
60
```
61
+
62
+
***Attention!** The 16 bit implementations are limited to a **maximum input value of +/- 16383** for rectangular input (which is the worst input case). The reason is, that the term `InputValue - Lowpass3` must always fit into a 16 bit signed integer.
@@ -129,14 +143,15 @@ library available as an Arduino library.
129
143
130
144
### The very useful *digitalWriteFast.h* file from [Watterott electronic](https://github.com/watterott/Arduino-Libs).
131
145
132
-
### Modifying compile options with Arduino IDE
146
+
### Changing include (*.h) files with Arduino IDE
133
147
First, use *Sketch > Show Sketch Folder (Ctrl+K)*.<br/>
134
-
If you did not yet stored the example as your own sketch, then you are instantly in the right library folder.<br/>
148
+
If you have not yet saved the example as your own sketch, then you are instantly in the right library folder.<br/>
135
149
Otherwise you have to navigate to the parallel `libraries` folder and select the library you want to access.<br/>
136
-
In both cases the library files itself are located in the `src` directory.<br/>
150
+
In both cases the library source and include files are located in the libraries `src` directory.<br/>
151
+
The modification must be renewed for each new library version!
137
152
138
153
### Modifying compile options with Sloeber IDE
139
-
If you are using Sloeber as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
154
+
If you are using [Sloeber](https://eclipse.baeyens.it) as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
0 commit comments