npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bcijs

v1.8.0

Published

EEG signal processing and machine learning

Downloads

88

Readme

BCI.js is a library for EEG-based brain computer interface (BCI) design with JavaScript and Node.js. It allows for the creation of BCI enabled web apps or Node.js applications, with features such as:

  • Signal processing and machine learning (Bandpower, PSD, LDA, CSP, ICA, etc.)
  • Data manipulation (MATLAB style array subscripting, data windowing, CSV file support, etc.)
  • Networking (data collection, streaming via OSC, etc.)

You can view all available methods in the docs

Latest release is v1.7.1. You can view the release notes at releases

Getting Started

Node.js

npm install bcijs

Browser

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bci.min.js"></script>

Tutorials

Examples

More examples can be found in the examples directory

Signal Processing

const bci = require('bcijs');

// Generate 1 second of sample data
let sampleRate = 512;
let duration = 1;
let amplitudes = [8, 4, 2, 1];
let frequencies = [
	1, // 1 Hz, delta range
	5, // 5 Hz, theta range
	8, // 8 Hz, alpha range
	17 // 17 Hz, beta range
];

let signal = bci.generateSignal(amplitudes, frequencies, sampleRate, duration);

// Compute relative power in each frequency band
let bandpowers = bci.bandpower(
	signal,
	sampleRate,
	['delta', 'theta', 'alpha', 'beta'],
	{relative: true}
);

console.log(bandpowers);
/*
[
  0.7171876695851037, 
  0.22444067394892755,
  0.04489131763080717,
  0.013469490282877555
]
*/

Machine Learning

Check out https://bci.js.org/examples/lda for a visual demo of how LDA works

const bci = require('bcijs');

// Training set
let class1 = [
	[0, 0],
	[1, 2],
	[2, 2],
	[1.5, 0.5]
];
let class2 = [
	[8, 8],
	[9, 10],
	[7, 8],
	[9, 9]
];

// Testing set
let unknownPoints = [
	[-1, 0],
	[1.5, 2],
	[3, 3],
	[5, 5],
	[7, 9],
	[10, 12]
];

// Learn an LDA classifier
let ldaParams = bci.ldaLearn(class1, class2);

// Test classifier
let predictions = bci.ldaClassify(ldaParams, unknownPoints);

console.log(predictions); // [ 0, 0, 0, 1, 1, 1 ]

Data Manipulation and Feature Extraction

const bci = require('bcijs');

// Some random numbers
let data = [3, 2, 3, 0, 4, 0, 0, 5, 4, 0];

// Partition into training and testing sets
let [training, testing] = bci.partition(data, 0.6, 0.4);

console.log(training); // [3, 2, 3, 0, 4, 0]
console.log(testing); // [0, 5, 4, 0]

// Traverse the data array with windows of size 3 and a step of 2 (overlap of 1 item per window)
bci.windowApply(data, window => console.log(window), 3, 2);
/*
[ 3, 2, 3 ]
[ 3, 0, 4 ]
[ 4, 0, 0 ]
[ 0, 5, 4 ]
*/

// Find the log of the variance of these windows (feature extraction)
let features = bci.windowApply(data, bci.features.logvar, 3, 2);
console.log(features); // [-1.099, 1.466, 1.674, 1.946]

// Colon notation for array subscripting
let arr = [
  [1, 2, 3, 4],
  [5, 6, 7, 8],
  [9, 10, 11, 12]
];
let subarr = bci.subscript(arr, '1 3', '2:4'); // rows 1 and 3, columns 2 through 4
console.log(subarr);
/*
[[2, 3, 4],
 [10, 11, 12]]
*/

Usage in the web

BCI.js can be loaded from the jsDelivr CDN with

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bci.min.js"></script>

You can also find bci.js and bci.min.js in the /dist directory.

BCI.js methods are accessible via the global object bci.

If building a web distributable using a tool such as browserify or webpack, require bcijs/browser.js to load only methods that are browser compatible. Node.js specific methods such as networking and file system methods will not be included.

const bci = require('bcijs/browser.js');

Requiring specific methods

You can require specific methods as well. For example, if you only need fastICA, you can use

const fastICA = require('bcijs/lib/math/fastICA.js');

BCI.js methods can be found in the lib/ directory.

Documentation

Documentation can be found at https://bci.js.org/docs or by viewing api.md

Deprecated methods can be found at deprecated.md

Building

See dev.md for info on how to modify and build BCI.js

Reference

BCI.js began as WebBCI, a library developed to aid in my research at the Human Technology Interaction Lab at the University of Alabama Department of Computer Science. If you use BCI.js in a published work, please reference this paper

P. Stegman, C. Crawford, and J. Gray, "WebBCI: An Electroencephalography Toolkit Built on Modern Web Technologies," in Augmented Cognition: Intelligent Technologies, 2018, pp. 212–221.

Logo uses icon from Font Awesome.

Contact

If you have a commercial use case for BCI.js and would like to discuss working together, contact me at [email protected]