{"id":51196836,"url":"https://github.com/maxeq/polyphase-resample","last_synced_at":"2026-06-27T21:05:23.179Z","repository":{"id":365938733,"uuid":"1274415269","full_name":"maxeq/polyphase-resample","owner":"maxeq","description":"Bit-exact, cross-platform polyphase resampling (upfirdn) — matches scipy to float64; no train/serve skew for on-device ML.","archived":false,"fork":false,"pushed_at":"2026-06-19T13:55:09.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-19T15:34:35.002Z","etag":null,"topics":["dsp","edge-ai","on-device-ml","resampling","scipy","signal-processing","typescript","upfirdn"],"latest_commit_sha":null,"homepage":null,"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/maxeq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-19T13:42:18.000Z","updated_at":"2026-06-19T13:55:13.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/maxeq/polyphase-resample","commit_stats":null,"previous_names":["maxeq/polyphase-resample"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/maxeq/polyphase-resample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxeq%2Fpolyphase-resample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxeq%2Fpolyphase-resample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxeq%2Fpolyphase-resample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxeq%2Fpolyphase-resample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxeq","download_url":"https://codeload.github.com/maxeq/polyphase-resample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxeq%2Fpolyphase-resample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34867700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-27T02:00:06.362Z","response_time":126,"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":["dsp","edge-ai","on-device-ml","resampling","scipy","signal-processing","typescript","upfirdn"],"created_at":"2026-06-27T21:05:22.611Z","updated_at":"2026-06-27T21:05:23.166Z","avatar_url":"https://github.com/maxeq.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# polyphase-resample\nn![CI](https://github.com/maxeq/polyphase-resample/actions/workflows/ci.yml/badge.svg) ![license](https://img.shields.io/badge/license-MIT-blue.svg)\n\nBit-exact, cross-platform **polyphase rational resampling** (`upfirdn`) for signal \u0026 on-device-ML preprocessing.\n\nResample a 1-D signal by a rational factor `L/M` — upsample by `L`, FIR-filter, downsample by `M` — with output that is **identical down to float64 on every runtime** (TypeScript, Python, Kotlin, Swift) given the same kernel, and that matches `scipy.signal.upfirdn` to float64 precision.\n\n## Why this exists — the multi-port problem\n\nOn-device ML breaks *silently* when preprocessing differs between platforms. A model trained on signals resampled in Python (say **500 Hz → 300 Hz**) but run on a watch / phone / desktop that resamples even slightly differently sees a shifted input distribution — and accuracy quietly drops. Floating-point drift between a NumPy/SciPy training pipeline and a hand-written mobile resampler is a classic, painful source of **train/serve skew**.\n\nThe fix: implement the resampler **once**, with a single explicit accumulation order, so the same `(kernel, x, up, down)` yields the **same samples on every platform and on the training pipeline** — no drift, no skew. Watch (Kotlin), iOS (Swift), and desktop/browser (TypeScript) all agree with NumPy/SciPy.\n\n## Usage\n```ts\nimport { upfirdn, resamplePoly } from \"./src/upfirdn\";\n\n// Resample 500 Hz -\u003e 300 Hz  (gcd(500,300)=100 -\u003e up=3, down=5)\nconst out = resamplePoly(signal, 3, 5, firKernel); // firKernel = your shared FIR taps\n```\n`upfirdn(h, x, up, down)` has the same semantics as `scipy.signal.upfirdn`.\n\n## Determinism \u0026 verification\n- **Cross-platform:** one fixed accumulation order → bit-identical float64 output on any IEEE-754 runtime.\n- **Vs SciPy:** `scripts/golden.py` runs `scipy.signal.upfirdn` on random inputs and writes golden vectors; `npm run verify` checks **max abs error \u003c 1e-12**.\n\n```bash\npython scripts/golden.py   # needs numpy + scipy\nnpm run verify             # compares TS output against the golden vectors\n```\n\n\u003e Note on \"bit-exact\": within this implementation the output is exact and identical across platforms (fixed op order). Against SciPy the agreement is to ~1e-12 — SciPy's internal polyphase accumulation order differs; the algorithm and result are otherwise the same. Share the FIR kernel across platforms (as JSON) and every port produces the same numbers.\n\n## Why FIR kernel is caller-provided\nSo the resampler is fully deterministic: ship one kernel (e.g. a Kaiser-windowed sinc) as data across all platforms instead of re-designing the filter per language. Same data + same algorithm = same output everywhere.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxeq%2Fpolyphase-resample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxeq%2Fpolyphase-resample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxeq%2Fpolyphase-resample/lists"}