Skip to content

Commit 6e28ddf

Browse files
committed
Merge branch 'master' of https://github.com/neurosity/eeg-pipes
2 parents 3fa2bea + 1e15612 commit 6e28ddf

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"dependencies": {
4949
"dsp.js": "^1.0.1",
5050
"fili": "^2.0.1",
51-
"rxjs": "^6.3.1"
51+
"rxjs": "^6.6.3"
5252
},
5353
"devDependencies": {
5454
"@types/node": "^10.12.10",

src/pipes/frequency/absolutePower.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { pipe } from "rxjs";
2+
import { map } from "rxjs/operators";
3+
4+
import { sum } from "../../utils/stats";
5+
import { IPSD } from "../../types/psd";
6+
7+
/**
8+
* Takes a stream of PSDs and returns a stream of arrays, containing the absolute power in each channel
9+
* @method absolutePower
10+
* @example eeg$.pipe(epoch({ duration: 256, interval: 100, samplingRate: 256 }), fft({ bins: 256 }), sliceFFT(10, 20), absolutePower())
11+
* @returns {Observable} band powers array
12+
*/
13+
export const absolutePower = () =>
14+
pipe(
15+
map((inputPSD: IPSD) =>
16+
inputPSD.psd.reduce(
17+
(acc, channel) => [...acc, sum(channel)],
18+
[]
19+
)
20+
)
21+
);

src/pipes/frequency/averagePower.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { average } from "../../utils/stats";
55
import { IPSD } from "../../types/psd";
66

77
/**
8-
* Takes a stream of PSDs and returns a sream of arrays, containing the average power in each channel
8+
* Takes a stream of PSDs and returns a stream of arrays, containing the average power in each channel
99
* @method averagePower
1010
* @example eeg$.pipe(epoch({ duration: 256, interval: 100, samplingRate: 256 }), fft({ bins: 256 }), sliceFFT(10, 20), averagePower())
1111
* @returns {Observable} band powers array

src/pipes/frequency/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./absolutePower";
12
export * from "./alphaPower";
23
export * from "./averagePower";
34
export * from "./betaPower";

src/pipes/frequency/powerByBand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import { FREQUENCY_BANDS as defaultBands } from "../../constants";
1111
* @method powerByBand
1212
* @example eeg$.pipe(epoch({ duration: 256, interval: 100, samplingRate: 256 }), fft({ bins: 256 }), powerByBand())
1313
* @param {Object} [bands] Custom bands object containing corresponding names and frequency ranges
14+
* @param {Function} [powerMapper] Custom mapping function to compute band power (default = averagePower)
1415
* @returns {Observable<Array<number>>}
1516
*/
16-
export const powerByBand = (bands = defaultBands) =>
17+
export const powerByBand = (bands = defaultBands, powerMapper = averagePower) =>
1718
pipe(
1819
flatMap(inputPSD => {
1920
const entries = Object.entries(bands);
2021
const bandPowers = entries.map(([_, range]) =>
2122
of(inputPSD).pipe(
2223
sliceFFT(range),
23-
averagePower()
24+
powerMapper()
2425
)
2526
);
2627
const zipPowers = (...powers) =>

src/pipes/utility/addSignalQuality.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ export const addSignalQuality = ({ dataProp = defaultDataProp } = {}) =>
2121
: epoch[dataProp].map((_, i) => i);
2222
return {
2323
...epoch,
24-
signalQuality: epoch[dataProp].reduce(
25-
(acc, curr, index) => ({
26-
...acc,
27-
[names[index]]: standardDeviation(curr)
28-
}),
29-
{}
30-
)
24+
info: {
25+
...epoch.info,
26+
signalQuality: epoch[dataProp].reduce(
27+
(acc, curr, index) => ({
28+
...acc,
29+
[names[index]]: standardDeviation(curr)
30+
}),
31+
{}
32+
)
33+
}
3134
};
3235
})
3336
);

0 commit comments

Comments
 (0)