{"id":15483359,"url":"https://github.com/hackergrrl/goertzel","last_synced_at":"2025-09-13T17:33:08.055Z","repository":{"id":57251803,"uuid":"50683843","full_name":"hackergrrl/goertzel","owner":"hackergrrl","description":":microphone: Fast frequency detection using the Goertzel algorithm.","archived":false,"fork":false,"pushed_at":"2016-06-10T17:07:52.000Z","size":12,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-03T00:42:24.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackergrrl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-29T18:54:04.000Z","updated_at":"2022-12-09T11:01:55.000Z","dependencies_parsed_at":"2022-09-04T23:10:40.249Z","dependency_job_id":null,"html_url":"https://github.com/hackergrrl/goertzel","commit_stats":null,"previous_names":["noffle/goertzel"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgoertzel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgoertzel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgoertzel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgoertzel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackergrrl","download_url":"https://codeload.github.com/hackergrrl/goertzel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232897216,"owners_count":18593522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T05:14:16.822Z","updated_at":"2025-01-07T14:53:14.636Z","avatar_url":"https://github.com/hackergrrl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goertzel\n\n\u003e Fast frequency detection using the Goertzel algorithm\n\n## Background\n\nThe [Goertzel algorithm](https://en.wikipedia.org/wiki/Goertzel_algorithm) is a\nfast alternative to the [Fast Fourier Transform]() that is optimized for\ndetecting the presence of a single frequency in a buffer of signal samples\n(radio waves, sound, light).\n\n## Usage\n\nLet's detect a sine wave with a frequency of 2 kHz:\n\n```js\nvar goertzel = require('goertzel')\n\nvar detect = goertzel({\n  targetFrequency: 2000,  // 2 kHz\n  sampleRate: 10000,      // 1000 samples per second\n  samplesPerFrame: 100    // 100 samples per buffer\n})\n\n// Generates a sine wave at some Hz and time (ms)\nfunction sin (hz, t) {\n  return Math.sin(Math.PI * 2 * t * hz)\n}\n\n// Populate a buffer with a sine wave at 2 kHz for 100 samples\nvar sin2 = []\nfor (var i = 0; i \u003c 100; i++) {\n  var v = sin(2, i / 100)\n  sin2.push(v)\n}\n\n// Populate a buffer with a sine wave at 19 kHz for 100 samples\nvar sin19 = []\nfor (var i = 0; i \u003c 100; i++) {\n  var v = sin(19, i / 100)\n  sin19.push(v)\n}\n\nconsole.log(detect(sin19))\nconsole.log(detect(sin2))\n```\n\nThis will output\n\n```\nfalse\ntrue\n```\n\n## API\n\n```js\nvar goertzel = require('goertzel')\n```\n\n### var detect = goertzel(opts={})\n\nReturns a function set to detect a single frequency.\n\n`opts` is mandatory, and has some required and optional parameters:\n\n- `opts.targetFrequency` (required) - the frequency, in Hertz, to detect.\n- `opts.sampleRate` (required) - how many samples are taken per second. For best\n  results, this should be at least twice the [Nyquist\n  frequency](https://en.wikipedia.org/wiki/Nyquist_frequency). 2.5x works well.\n- `opts.samplesPerFrame` (required) - how many samples will be included in each\n  frame to be tested.\n- `opts.threshold` (optional) - The Goertzel algorithm returns a relative\n  magnitude of how well the samples match the `targetFrequency`. Set this to\n  control the threshold. In general, the default value can be used safely.\n\n## detect(data)\n\nGiven a buffer of floating point audio samples (-1..1), returns a `boolean`:\n`true` if the `targetFrequency` is present in the samples, and `false`\notherwise.\n\n## Install\n\nWith [npm](https://npmjs.org/) installed, run\n\n```\n$ npm install goertzel\n```\n\n## Acknowledgments\n\nAn understanding of the algorithm was gleaned from\nhttps://en.wikipedia.org/wiki/Goertzel_algorithm and\nhttp://www.embedded.com/design/configurable-systems/4024443/The-Goertzel-Algorithm.\n\n## Works Great With\n\n- [noffle/mic-stream](https://github.com/noffle/mic-stream)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackergrrl%2Fgoertzel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackergrrl%2Fgoertzel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackergrrl%2Fgoertzel/lists"}