Socket
Book a DemoInstallSign in
Socket

goertzel

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

goertzel

Fast frequency detection using the Goertzel algorithm

latest
Source
npmnpm
Version
3.0.1
Version published
Weekly downloads
6
-62.5%
Maintainers
2
Weekly downloads
 
Created
Source

goertzel

Implements the Goertzel algorithm for efficient frequency detection.

example

var goertzel = require('goertzel')

var opts = {
  // 1 kHz
  targetFrequency: 1000,
  // samples per second
  sampleRate: 10000,
  // samples per frame
  samplesPerFrame: 100
}

var detect = goertzel(opts)

// generate sine wave at some Hz and time (ms)
function sin (hz, t) {
  return Math.sin(Math.PI * 2 * t * hz)
}

// sine at 1 kHz for 100 samples
var data = []
for (var i = 0; i < opts.samplesPerFrame; i++) {
  var v = sin(opts.targetFrequency, i / opts.sampleRate)
  data.push(v)
}

console.log(detect(data))
true

methods

var detect = goertzel(opts={})

Returns a function set to detect a single frequency.

opts is mandatory, and has some required and optional parameters:

  • opts.targetFrequency (required) - the frequency, in Hertz, to detect the presence of
  • opts.sampleRate (required) - how many samples are taken per second. For best results, this should be at least twice the Nyquist frequency. 2.5x works well.
  • opts.samplesPerFrame (required) - how many samples will be included in each frame to be tested.
  • opts.threshold (optional) - The Goertzel algorithm returns a relative magnitude of how well the samples match the targetFrequency. Set this to control the threshold. In general, the default value can be used safely.

detect(data)

Returns a boolean: true if the targetFrequency is present in the samples, and false otherwise.

data is expected to be compatible with a Float32Array.

install

With npm installed, run

$ npm install goertzel

license

MIT

Keywords

goertzel

FAQs

Package last updated on 05 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts