{"id":13768458,"url":"https://github.com/scijs/periodic-function","last_synced_at":"2025-10-04T16:46:21.122Z","repository":{"id":56681099,"uuid":"95086222","full_name":"scijs/periodic-function","owner":"scijs","description":"List of periodic functions normalized to 0..1 range","archived":false,"fork":false,"pushed_at":"2020-10-25T17:00:47.000Z","size":25,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-22T04:53:49.465Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scijs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-22T07:16:50.000Z","updated_at":"2024-02-22T06:29:05.000Z","dependencies_parsed_at":"2022-08-15T23:10:42.196Z","dependency_job_id":null,"html_url":"https://github.com/scijs/periodic-function","commit_stats":null,"previous_names":["dfcreative/periodic-function"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scijs/periodic-function","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijs%2Fperiodic-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijs%2Fperiodic-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijs%2Fperiodic-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijs%2Fperiodic-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scijs","download_url":"https://codeload.github.com/scijs/periodic-function/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijs%2Fperiodic-function/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278343073,"owners_count":25971399,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08-03T16:01:21.637Z","updated_at":"2025-10-04T16:46:21.084Z","avatar_url":"https://github.com/scijs.png","language":"JavaScript","readme":"# periodic-function [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dfcreative/periodic-function.svg)](https://travis-ci.org/dfcreative/periodic-function)\n\nCollection of periodic functions with period normalized to turns.\n\n## Usage\n\n[![npm install periodic-function](https://nodei.co/npm/periodic-function.png?mini=true)](https://npmjs.org/package/periodic-function/)\n\n```js\nconst fn = require('periodic-function/\u003cfn\u003e')\n\n//π radians\nlet halfTurn = fn(.5)\n\n//2π radians\nlet fullTurn = fn(1)\n```\n\n## API\n\n### let fn = require('periodic-function/\\\u003cfn\\\u003e')\n\nThe `fn` takes the amount of turn `t` as the first argument and optional parameters. The list of available functions:\n\n| Signature | Waveform | Meaning |\n---|:---:|---|\n| \u003ccode\u003esine(t,\u0026nbsp;phase=0)\u003c/code\u003e | ![sine](img/sine.png) | `Math.sin` normalized to `0..1` rather than radians `0..2π`. To turn into cos, set `phase=.25`. |\n| \u003ccode\u003etriangle(t,\u0026nbsp;ratio=0.5)\u003c/code\u003e | ![triangle](img/triangle.png) | Triangular waveform with regulated ratio. To turn into sawtooth set `ratio=0` or `ratio=1`. |\n| \u003ccode\u003esawtooth(t,\u0026nbsp;inverse=false)\u003c/code\u003e | ![sawtooth](img/sawtooth.png) | Edge case of triangular waveform, whether descending or ascending. |\n| \u003ccode\u003esquare(t,\u0026nbsp;ratio=0.5)\u003c/code\u003e | ![square](img/square.png) | Rectangular waveform with regulated ratio. To turn into pulse set `ratio=0`. |\n| \u003ccode\u003epulse(t,\u0026nbsp;tlr=0)\u003c/code\u003e | ![pulse](img/pulse.png) | Delta-pulse, which is `1` at `0` and `0` anywhere else. Pass `tlr` as a precision tolerance, ie. `1e-5`. |\n| \u003ccode\u003efourier(t,\u0026nbsp;real,\u0026nbsp;imag?, normalize=false)\u003c/code\u003e | ![fourier](img/fourier.png) | [Fourier Series](https://en.wikipedia.org/wiki/Fourier_series) coefficients, ie. harmonics. `0` harmonic is static level, `1`st is base frequency, `2`nd is double base frequency, `3`rd is triple etc. Set `normalize=true` to bring max harmonic to `1`. |\n| \u003ccode\u003eclausen(t,\u0026nbsp;limit=10)\u003c/code\u003e | ![clausen](img/clausen.png) | [Clausen function](https://en.wikipedia.org/wiki/Clausen_function). Pass `limit` to indicate number of iterations, precision/performance tradeoff. |\n| \u003ccode\u003estep(t, samples)\u003c/code\u003e | ![step](img/step.png) | [Step function](https://en.wikipedia.org/wiki/Step_function), picks closest sample value out of a set. |\n| \u003ccode\u003einterpolate(t, samples)\u003c/code\u003e | ![interpolate](img/interpolate.png) | Interpolates between closest values in a sample set. |\n| \u003ccode\u003enoise(t)\u003c/code\u003e | ![noise](img/noise.png) | Repeated sample of noise. |\n\nIf you feel like it is not complete list of you know example of a good periodic function, suitable for dsp, welcome to [contribute](https://github.com/dfcreative/periodic-function/issues).\n\n## Related\n\n* [audio-oscillator](https://github.com/audiojs/audio-oscillator)\n* [createPeriodicWave](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)\n* [List of periodic functions](https://en.wikipedia.org/wiki/List_of_periodic_functions)\n\n## Credits\n\n© 2017 Dima Yv. MIT License\n","funding_links":[],"categories":["Sound creation"],"sub_categories":["Low frequency oscillators (\"LFOs\"):"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscijs%2Fperiodic-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscijs%2Fperiodic-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscijs%2Fperiodic-function/lists"}