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

biquadjs

v1.1.0

Published

Create arbitrary biquad filters to apply to signals. Created for real time biosensing, works in most general cases.

Downloads

17

Readme

BiquadFilters.js

npm i biquadjs

A simple javascript adaptation of a set of useful Biquad filters from an obscure arachnoid.com python tutorial. See the example html for usage. I combed the internet for this and I use these for EEG signal filtering. These will work in nodejs with imports, or just paste it into your html page and delete the exports.

Features:

  • Low pass
  • High pass
  • Band pass
  • Notch
  • Peak
  • High shelf
  • Low shelf

Set Q-factor and other parameters as needed, you will want to experiment a bit for the notch, peak, and bandpass filters, the defaults otherwise are butterworth (1/root(2)) Q factors while I set relatively effective values for the aforementioned special cases. dbGain only applies to the shelf filters, which provide amplification above or below the set frequency.

Main class: Biquad


let lowpass = new Biquad('lowpass',20,512); //20Hz lowpass at 512Hz. 
//let notch = makeNotchFilter(...) //macros
//let bandpass = makeBandpassFilter(...) //macros

Secondary class: BiquadChannelFilterer - bundles biquad presets in a configurable way for easy device stream transforming.

There is a ready-made macro to use a list of filters, preset for getting biosignal data like EEG and ECG by applying notch and bandpass etc.

let filterer = new BiquadChannelFilterer({
    sps:512,
    useBandpass:true,
    bandpassLower:3, //hz
    bandpassUpper:45 //hz
});
let result = filterer.apply(signal_step);

All settings:

export type FilterSettings = {
  sps:number, //required
  useSMA4?:boolean,
  useNotch50?:boolean,
  useNotch60?:boolean,
  useLowpass?: boolean,
  lowpassHz?:number,
  useHighpass?:boolean,
  highpassHz?:number,
  useBandpass?: boolean,
  bandpassLower?:number,
  bandpassUpper?:number,
  useDCBlock?: boolean,
  DCBresonance?: number,
  useScaling?: boolean,
  scalar?:number,
  offset?:number, //+=
  trimOutliers?:boolean,
  outlierTolerance?:number
}
  • Scaling factor just applies a scalar e.g. ADC -> Voltage conversion.
  • Filtering toggles whether the filter is applied when looping over it in a bigger program
  • Samplerate is fixed, calculate correctly or it won't work very well. You can start/stop streams just fine and the filters will correct otherwise.
  • Returns the result with filterer.apply(signal_step), where the signal step is the latest amplitude in a time domain sequence (which can be real time, see https://app.brainsatplay.com)

Functions:

let classinstance = new Biquad(type,freq,sps,Q,dbGain) Create a new filter, these keep the latest sample and filter values so make a new one for each additional filter. types: 'lowpass','highpass','bandpass','notch','peak','lowshelf','highshelf'. Set the frequency and sample rate, with default butterworth Q values. dBGain only applies to the shelf filters. See below for notch and bandpass filter macros. I should add a peak filter macro..

let output = classinstance.applyFilter(signal_step) Apply the filter to the next sample in the sequence. Returns the filtered amplitude.

let z = classinstance.zResult(freq) Returns the z-transfer function values (i.e. how much each frequency amplitude gets multiplied/reduced by the filter)

let dcblocker = new class DCBlocker(r) Create a DC blocking filter which better highlights oscillations. Default r = 0.995. Use output = dcblocker.applyFilter(y) for each signal step.

makeNotchFilter(frequency,sps,bandwidth) Macro to generate a notch filter with the correct Q factor for the specified bandwidth. Returns a Biquad class instance.

makeBandpassFilter(freqStart,freqEnd,sps,resonance) Macro to generate a bandpass filter. Returns a Biquad class instance. The resonance value has a default setting that works pretty well, but I recommend experimenting. Having the resonance value being around 10^floor(log10(center frequency)) works well at least at low frequencies, I used 1 and 9.75 for a 3-45Hz bandpass filter in different cases while experimenting, for example. Applying 4 in a row seems to work well to get much sharper cancellation, though for some reason the output gets scaled by 1/n filters so you just need to multiply by how many filters you used to restore the amplitudes to the right values.

capture