Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/neurosity/eeg-pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcastillo committed Nov 9, 2020
2 parents 3fa2bea + 1e15612 commit 6e28ddf
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"dsp.js": "^1.0.1",
"fili": "^2.0.1",
"rxjs": "^6.3.1"
"rxjs": "^6.6.3"
},
"devDependencies": {
"@types/node": "^10.12.10",
Expand Down
21 changes: 21 additions & 0 deletions src/pipes/frequency/absolutePower.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { pipe } from "rxjs";
import { map } from "rxjs/operators";

import { sum } from "../../utils/stats";
import { IPSD } from "../../types/psd";

/**
* Takes a stream of PSDs and returns a stream of arrays, containing the absolute power in each channel
* @method absolutePower
* @example eeg$.pipe(epoch({ duration: 256, interval: 100, samplingRate: 256 }), fft({ bins: 256 }), sliceFFT(10, 20), absolutePower())
* @returns {Observable} band powers array
*/
export const absolutePower = () =>
pipe(
map((inputPSD: IPSD) =>
inputPSD.psd.reduce(
(acc, channel) => [...acc, sum(channel)],
[]
)
)
);
2 changes: 1 addition & 1 deletion src/pipes/frequency/averagePower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { average } from "../../utils/stats";
import { IPSD } from "../../types/psd";

/**
* Takes a stream of PSDs and returns a sream of arrays, containing the average power in each channel
* Takes a stream of PSDs and returns a stream of arrays, containing the average power in each channel
* @method averagePower
* @example eeg$.pipe(epoch({ duration: 256, interval: 100, samplingRate: 256 }), fft({ bins: 256 }), sliceFFT(10, 20), averagePower())
* @returns {Observable} band powers array
Expand Down
1 change: 1 addition & 0 deletions src/pipes/frequency/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./absolutePower";
export * from "./alphaPower";
export * from "./averagePower";
export * from "./betaPower";
Expand Down
5 changes: 3 additions & 2 deletions src/pipes/frequency/powerByBand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import { FREQUENCY_BANDS as defaultBands } from "../../constants";
* @method powerByBand
* @example eeg$.pipe(epoch({ duration: 256, interval: 100, samplingRate: 256 }), fft({ bins: 256 }), powerByBand())
* @param {Object} [bands] Custom bands object containing corresponding names and frequency ranges
* @param {Function} [powerMapper] Custom mapping function to compute band power (default = averagePower)
* @returns {Observable<Array<number>>}
*/
export const powerByBand = (bands = defaultBands) =>
export const powerByBand = (bands = defaultBands, powerMapper = averagePower) =>
pipe(
flatMap(inputPSD => {
const entries = Object.entries(bands);
const bandPowers = entries.map(([_, range]) =>
of(inputPSD).pipe(
sliceFFT(range),
averagePower()
powerMapper()
)
);
const zipPowers = (...powers) =>
Expand Down
17 changes: 10 additions & 7 deletions src/pipes/utility/addSignalQuality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ export const addSignalQuality = ({ dataProp = defaultDataProp } = {}) =>
: epoch[dataProp].map((_, i) => i);
return {
...epoch,
signalQuality: epoch[dataProp].reduce(
(acc, curr, index) => ({
...acc,
[names[index]]: standardDeviation(curr)
}),
{}
)
info: {
...epoch.info,
signalQuality: epoch[dataProp].reduce(
(acc, curr, index) => ({
...acc,
[names[index]]: standardDeviation(curr)
}),
{}
)
}
};
})
);

0 comments on commit 6e28ddf

Please sign in to comment.