Skip to content

Commit

Permalink
typescript: setParameters function + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Géry Casiez committed Oct 8, 2023
1 parent b2edd49 commit 4655962
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 12 deletions.
101 changes: 101 additions & 0 deletions typescript/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,107 @@ let filtered = f.filter(noisyvalue, timestamp);
```


## Doc

### constructor

**new OneEuroFilter**(`freq`, `mincutoff`, `beta`, `dcutoff`)

Constructs a 1 euro filter.

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `freq` | `number` | `undefined` | An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. |
| `mincutoff` | `number` | `1.0` | Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. |
| `beta` | `number` | `0.0` | Parameter to reduce latency (> 0). |
| `dcutoff` | `number` | `1.0` | Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. |


### filter

**filter**(`value`, `timestamp`): `number`

Returns the filtered value.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value` | `number` | Noisy value to filter |
| `timestamp` | `number` | (optional) timestamp in seconds |

### reset

**reset**(): `void`

Resets the internal state of the filter.

### setBeta

**setBeta**(`beta`): `void`

Sets the Beta parameter

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `beta` | `number` | Parameter to reduce latency (> 0). |

### setDerivateCutoff

**setDerivateCutoff**(`dcutoff`): `void`

Sets the dcutoff parameter

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `dcutoff` | `number` | Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. |

### setFrequency

**setFrequency**(`freq`): `void`

Sets the frequency of the signal

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `freq` | `number` | An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. |

### setMinCutoff

**setMinCutoff**(`mincutoff`): `void`

Sets the filter min cutoff frequency

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `mincutoff` | `number` | Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. |

### setParameters

**setParameters**(`freq`, `mincutoff`, `beta`): `void`

Sets the parameters of the 1 euro filter.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `freq` | `number` | An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. |
| `mincutoff` | `number` | Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. |
| `beta` | `number` | Parameter to reduce latency (> 0). |


## Related publication

[![DOI](https://img.shields.io/badge/doi-10.1145%2F2207676.2208639-blue)](https://doi.org/10.1145/2207676.2208639)
Expand Down
2 changes: 1 addition & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "1eurofilter",
"version": "1.1.1",
"version": "1.2.0",
"description": "Algorithm to filter noisy signals for high precision and responsiveness.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
81 changes: 70 additions & 11 deletions typescript/src/OneEuroFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,71 @@ export class OneEuroFilter {
return 1.0 / (1.0 + tau/te);
}

public setFrequency(f : number) {
if (f<=0) console.log("freq should be >0") ;
this.freq = f;

/**
* Sets the frequency of the signal
*
* @param freq An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
*/

public setFrequency(freq : number) {
if (freq<=0) console.log("freq should be >0") ;
this.freq = freq;
}

public setMinCutoff(mc : number) {
if (mc<=0) console.log("mincutoff should be >0");
this.mincutoff = mc;
/**
* Sets the filter min cutoff frequency
*
* @param mincutoff Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
*/
public setMinCutoff(mincutoff : number) {
if (mincutoff<=0) console.log("mincutoff should be >0");
this.mincutoff = mincutoff;
}

public setBeta(b : number) {
this.beta = b;
/**
* Sets the Beta parameter
*
* @param beta Parameter to reduce latency (> 0).
*/
public setBeta(beta : number) {
this.beta = beta;
}

public setDerivateCutoff(dc : number) {
if (dc<=0) console.log("dcutoff should be >0") ;
this.dcutoff = dc;
/**
* Sets the dcutoff parameter
*
* @param dcutoff Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*/
public setDerivateCutoff(dcutoff : number) {
if (dcutoff<=0) console.log("dcutoff should be >0") ;
this.dcutoff = dcutoff;
}

/**
* Sets the parameters of the 1 euro filter.
*
* @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
* @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
* @param beta - Parameter to reduce latency (> 0).
*
*/
public setParameters(freq : number, mincutoff : number, beta : number) {
this.setFrequency(freq);
this.setMinCutoff(mincutoff);
this.setBeta(beta);
}

/**
* Constructs a 1 euro filter.
*
* @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
* @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
* @param beta - Parameter to reduce latency (> 0).
* @param dcutoff - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*
*/

constructor(freq : number, mincutoff : number = 1.0, beta : number = 0.0, dcutoff : number = 1.0) {
this.setFrequency(freq) ;
this.setMinCutoff(mincutoff) ;
Expand All @@ -128,12 +174,25 @@ export class OneEuroFilter {
this.lasttime = undefined ;
}

/**
* Resets the internal state of the filter.
*/

public reset() {
this.x.reset();
this.dx.reset();
this.lasttime = undefined;
}

/**
* Returns the filtered value.
*
* @param value - Noisy value to filter
* @param timestamp - (optional) timestamp in seconds
* @returns The filtered value
*
*/

public filter(value : number, timestamp : number | undefined) : number {
// update the sampling frequency based on timestamps
if (this.lasttime!=undefined && timestamp!=undefined)
Expand Down

0 comments on commit 4655962

Please sign in to comment.