1eurofilter 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![NPM Version](https://badge.fury.io/js/1eurofilter.svg?style=flat)](https://npmjs.org/package/1eurofilter)
2
+ [![npm downloads](https://img.shields.io/npm/dm/1eurofilter.svg?style=flat-square)](https://npm-stat.com/charts.html?package=1eurofilter)
3
+
1
4
  # 1€ filter typescript version
2
5
 
3
6
  Provides a typescript implementation for the [1€ filter](https://gery.casiez.net/1euro/).
@@ -25,6 +28,107 @@ let filtered = f.filter(noisyvalue, timestamp);
25
28
 
26
29
  ```
27
30
 
31
+
32
+ ## Doc
33
+
34
+ ### constructor
35
+
36
+ • **new OneEuroFilter**(`freq`, `mincutoff`, `beta`, `dcutoff`)
37
+
38
+ Constructs a 1 euro filter.
39
+
40
+ #### Parameters
41
+
42
+ | Name | Type | Default value | Description |
43
+ | :------ | :------ | :------ | :------ |
44
+ | `freq` | `number` | `undefined` | An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. |
45
+ | `mincutoff` | `number` | `1.0` | Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. |
46
+ | `beta` | `number` | `0.0` | Parameter to reduce latency (> 0). |
47
+ | `dcutoff` | `number` | `1.0` | Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. |
48
+
49
+
50
+ ### filter
51
+
52
+ ▸ **filter**(`value`, `timestamp`): `number`
53
+
54
+ Returns the filtered value.
55
+
56
+ #### Parameters
57
+
58
+ | Name | Type | Description |
59
+ | :------ | :------ | :------ |
60
+ | `value` | `number` | Noisy value to filter |
61
+ | `timestamp` | `number` | (optional) timestamp in seconds |
62
+
63
+ ### reset
64
+
65
+ ▸ **reset**(): `void`
66
+
67
+ Resets the internal state of the filter.
68
+
69
+ ### setBeta
70
+
71
+ ▸ **setBeta**(`beta`): `void`
72
+
73
+ Sets the Beta parameter
74
+
75
+ #### Parameters
76
+
77
+ | Name | Type | Description |
78
+ | :------ | :------ | :------ |
79
+ | `beta` | `number` | Parameter to reduce latency (> 0). |
80
+
81
+ ### setDerivateCutoff
82
+
83
+ ▸ **setDerivateCutoff**(`dcutoff`): `void`
84
+
85
+ Sets the dcutoff parameter
86
+
87
+ #### Parameters
88
+
89
+ | Name | Type | Description |
90
+ | :------ | :------ | :------ |
91
+ | `dcutoff` | `number` | Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. |
92
+
93
+ ### setFrequency
94
+
95
+ ▸ **setFrequency**(`freq`): `void`
96
+
97
+ Sets the frequency of the signal
98
+
99
+ #### Parameters
100
+
101
+ | Name | Type | Description |
102
+ | :------ | :------ | :------ |
103
+ | `freq` | `number` | An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. |
104
+
105
+ ### setMinCutoff
106
+
107
+ ▸ **setMinCutoff**(`mincutoff`): `void`
108
+
109
+ Sets the filter min cutoff frequency
110
+
111
+ #### Parameters
112
+
113
+ | Name | Type | Description |
114
+ | :------ | :------ | :------ |
115
+ | `mincutoff` | `number` | Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. |
116
+
117
+ ### setParameters
118
+
119
+ ▸ **setParameters**(`freq`, `mincutoff`, `beta`): `void`
120
+
121
+ Sets the parameters of the 1 euro filter.
122
+
123
+ #### Parameters
124
+
125
+ | Name | Type | Description |
126
+ | :------ | :------ | :------ |
127
+ | `freq` | `number` | An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. |
128
+ | `mincutoff` | `number` | Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. |
129
+ | `beta` | `number` | Parameter to reduce latency (> 0). |
130
+
131
+
28
132
  ## Related publication
29
133
 
30
134
  [![DOI](https://img.shields.io/badge/doi-10.1145%2F2207676.2208639-blue)](https://doi.org/10.1145/2207676.2208639)
@@ -36,11 +36,60 @@ export declare class OneEuroFilter {
36
36
  private dx;
37
37
  private lasttime;
38
38
  private alpha;
39
- setFrequency(f: number): void;
40
- setMinCutoff(mc: number): void;
41
- setBeta(b: number): void;
42
- setDerivateCutoff(dc: number): void;
39
+ /**
40
+ * Sets the frequency of the signal
41
+ *
42
+ * @param freq An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
43
+ */
44
+ setFrequency(freq: number): void;
45
+ /**
46
+ * Sets the filter min cutoff frequency
47
+ *
48
+ * @param mincutoff Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
49
+ */
50
+ setMinCutoff(mincutoff: number): void;
51
+ /**
52
+ * Sets the Beta parameter
53
+ *
54
+ * @param beta Parameter to reduce latency (> 0).
55
+ */
56
+ setBeta(beta: number): void;
57
+ /**
58
+ * Sets the dcutoff parameter
59
+ *
60
+ * @param dcutoff Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
61
+ */
62
+ setDerivateCutoff(dcutoff: number): void;
63
+ /**
64
+ * Sets the parameters of the 1 euro filter.
65
+ *
66
+ * @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
67
+ * @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
68
+ * @param beta - Parameter to reduce latency (> 0).
69
+ *
70
+ */
71
+ setParameters(freq: number, mincutoff: number, beta: number): void;
72
+ /**
73
+ * Constructs a 1 euro filter.
74
+ *
75
+ * @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
76
+ * @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
77
+ * @param beta - Parameter to reduce latency (> 0).
78
+ * @param dcutoff - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
79
+ *
80
+ */
43
81
  constructor(freq: number, mincutoff?: number, beta?: number, dcutoff?: number);
82
+ /**
83
+ * Resets the internal state of the filter.
84
+ */
44
85
  reset(): void;
86
+ /**
87
+ * Returns the filtered value.
88
+ *
89
+ * @param value - Noisy value to filter
90
+ * @param timestamp - (optional) timestamp in seconds
91
+ * @returns The filtered value
92
+ *
93
+ */
45
94
  filter(value: number, timestamp: number | undefined): number;
46
95
  }
@@ -77,24 +77,66 @@ class OneEuroFilter {
77
77
  let tau = 1.0 / (2 * Math.PI * cutoff);
78
78
  return 1.0 / (1.0 + tau / te);
79
79
  }
80
- setFrequency(f) {
81
- if (f <= 0)
80
+ /**
81
+ * Sets the frequency of the signal
82
+ *
83
+ * @param freq An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
84
+ */
85
+ setFrequency(freq) {
86
+ if (freq <= 0)
82
87
  console.log("freq should be >0");
83
- this.freq = f;
84
- }
85
- setMinCutoff(mc) {
86
- if (mc <= 0)
88
+ this.freq = freq;
89
+ }
90
+ /**
91
+ * Sets the filter min cutoff frequency
92
+ *
93
+ * @param mincutoff Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
94
+ */
95
+ setMinCutoff(mincutoff) {
96
+ if (mincutoff <= 0)
87
97
  console.log("mincutoff should be >0");
88
- this.mincutoff = mc;
89
- }
90
- setBeta(b) {
91
- this.beta = b;
92
- }
93
- setDerivateCutoff(dc) {
94
- if (dc <= 0)
98
+ this.mincutoff = mincutoff;
99
+ }
100
+ /**
101
+ * Sets the Beta parameter
102
+ *
103
+ * @param beta Parameter to reduce latency (> 0).
104
+ */
105
+ setBeta(beta) {
106
+ this.beta = beta;
107
+ }
108
+ /**
109
+ * Sets the dcutoff parameter
110
+ *
111
+ * @param dcutoff Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
112
+ */
113
+ setDerivateCutoff(dcutoff) {
114
+ if (dcutoff <= 0)
95
115
  console.log("dcutoff should be >0");
96
- this.dcutoff = dc;
116
+ this.dcutoff = dcutoff;
117
+ }
118
+ /**
119
+ * Sets the parameters of the 1 euro filter.
120
+ *
121
+ * @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
122
+ * @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
123
+ * @param beta - Parameter to reduce latency (> 0).
124
+ *
125
+ */
126
+ setParameters(freq, mincutoff, beta) {
127
+ this.setFrequency(freq);
128
+ this.setMinCutoff(mincutoff);
129
+ this.setBeta(beta);
97
130
  }
131
+ /**
132
+ * Constructs a 1 euro filter.
133
+ *
134
+ * @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
135
+ * @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
136
+ * @param beta - Parameter to reduce latency (> 0).
137
+ * @param dcutoff - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
138
+ *
139
+ */
98
140
  constructor(freq, mincutoff = 1.0, beta = 0.0, dcutoff = 1.0) {
99
141
  this.setFrequency(freq);
100
142
  this.setMinCutoff(mincutoff);
@@ -104,11 +146,22 @@ class OneEuroFilter {
104
146
  this.dx = new LowPassFilter(this.alpha(dcutoff));
105
147
  this.lasttime = undefined;
106
148
  }
149
+ /**
150
+ * Resets the internal state of the filter.
151
+ */
107
152
  reset() {
108
153
  this.x.reset();
109
154
  this.dx.reset();
110
155
  this.lasttime = undefined;
111
156
  }
157
+ /**
158
+ * Returns the filtered value.
159
+ *
160
+ * @param value - Noisy value to filter
161
+ * @param timestamp - (optional) timestamp in seconds
162
+ * @returns The filtered value
163
+ *
164
+ */
112
165
  filter(value, timestamp) {
113
166
  // update the sampling frequency based on timestamps
114
167
  if (this.lasttime != undefined && timestamp != undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "1eurofilter",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Algorithm to filter noisy signals for high precision and responsiveness.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",