{"id":15031358,"url":"https://github.com/jlogan03/flaw","last_synced_at":"2025-09-01T19:38:04.785Z","repository":{"id":232018755,"uuid":"779862846","full_name":"jlogan03/flaw","owner":"jlogan03","description":"SISO digital filtering for embedded","archived":false,"fork":false,"pushed_at":"2025-08-31T14:46:34.000Z","size":503,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-31T16:26:16.288Z","etag":null,"topics":["controls","digital-signal-processing","dsp","rust","rust-embedded","rust-lang","rustlang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlogan03.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2024-03-31T01:43:03.000Z","updated_at":"2025-05-25T14:59:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"0aa7ca99-9420-4d7c-ad26-37ac27454ed2","html_url":"https://github.com/jlogan03/flaw","commit_stats":null,"previous_names":["jlogan03/flaw"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/jlogan03/flaw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlogan03%2Fflaw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlogan03%2Fflaw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlogan03%2Fflaw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlogan03%2Fflaw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlogan03","download_url":"https://codeload.github.com/jlogan03/flaw/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlogan03%2Fflaw/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273181993,"owners_count":25059809,"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-09-01T02:00:09.058Z","response_time":120,"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":["controls","digital-signal-processing","dsp","rust","rust-embedded","rust-lang","rustlang"],"created_at":"2024-09-24T20:15:30.861Z","updated_at":"2025-09-01T19:38:04.777Z","avatar_url":"https://github.com/jlogan03.png","language":"Rust","readme":"# flaw\nEmbedded signal filtering, no-std and no-alloc compatible.\n\nThis library provides a simple method for initializing and updating single-input,\nsingle-output infinite-impulse-response filters using 32-bit floats, as well as\ntabulated filter coefficients for some common filters. Filters evaluate in\n4N-1 floating-point operations for a filter of order N.\n\nThe name `flaw` is short for filter-law, but also refers to the fact that\ndigital IIR filtering with small floating-point types is an inherently flawed\napproach, in that higher-order and lower-cutoff filters produce very small\ncoefficients that result in floating-point roundoff error. This library mitigates\nthat problem by providing filter coefficients for a tested\ndomain of validity. The result is a limited, but useful, range of operation\nwhere these filters can achieve both accuracy and performance as well\nas be formulated and initialized in an embedded environment.\n\n## Capabilities\n\n* IIR (f32-only for now)\n  * General IIR filter using state-space canonical form\n  * Interpolated low-pass filters w/ gain error correction\n  * Baked coefficients for Butterworth filters of order 1-6\n* FIR (generic number type)\n  * General FIR filter\n  * Lagrange polynomial fractional-delay filter construction\n\n## Example: Second-Order Butterworth Filter\n\n```rust\n// First, choose a cutoff frequency as a fraction of sampling frequency\nlet cutoff_ratio = 1e-3;\n\n// Construct a filter, interpolating coefficients to that cutoff ratio.\n// Initializes internal state to zero by default.\nlet mut filter = flaw::butter2(cutoff_ratio).unwrap();  // Errors if extrapolating\n\n// Initialize the internal state of the filter\n// to match the steady-state associated with some input value.\nlet initial_steady_measurement = 1.57;  // Some number\nfilter.initialize(initial_steady_measurement);\n\n// Update the filter with a new raw measurement\nlet measurement = 0.3145; // Some number\nlet estimate = filter.update(measurement);  // Latest state estimate\n```\n\n## Coefficient Tables\n\nTabulated filters are tested to enforce\n\n* \u003c0.01% error in converged step response at the minimum cutoff frequency\n* \u003c1ppm error in converged step response at the maximum cutoff frequency\n* \u003c5% error to -3dB attenuation of a sine input at the cutoff frequency at the maximum cutoff ratio\n  * This error appears to be mainly an issue of discretization in test cases, and could be reduced\n    by using a better method for testing (fit a sine curve to the result or do gradient-descent\n    on a cubic interpolator)\n\nEach filter with tabulated coefficients has a minimum and maximum cutoff ratio.\nThe minimum value is determined by floating-point error in convergence of a\nstep response, while the maximum value is determined by the accuracy of attenuation\nat the cutoff frequency as the cutoff ratio approaches the Nyquist frequency.\n\nCoefficients for a given filter are interpolated on these tables using a\ncubic Hermite method with the log10(cutoff_ratio) as the independent variable.\nTabulated values are stored and interpolated as 64-bit floats, and only converted\nto 32-bit floats at the final stage of calculation.\n\nAfter interpolation, the state-space measurement coefficient vector (`C`) is scaled\nto correct steady-state gain for interpolation error, targeting unity gain.\n\nFilter coefficients are extracted from scipy's state-space representations,\nwhich are the result of a bilinear transform of the transfer function polynomials.\n\n| Filter | Min. Cutoff Ratio | Max. Cutoff Ratio |\n|--------|-------------------|-------------------|\n| Butter1| 10^-4             | 0.4               |\n| Butter2| 10^-3             | 0.4               |\n| Butter3| 10^-2             | 0.4               |\n| Butter4| 10^-1.5 (~0.032)  | 0.4               |\n| Butter5| 10^-1.25 (~0.056) | 0.4               |\n| Butter6| 0.1               | 0.4               |\n\n## License\n\nLicensed under either of\n\n* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlogan03%2Fflaw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlogan03%2Fflaw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlogan03%2Fflaw/lists"}