{"id":19999211,"url":"https://github.com/mr-addict/digital-filter","last_synced_at":"2026-01-03T12:32:14.211Z","repository":{"id":107623897,"uuid":"487672324","full_name":"MR-Addict/Digital-Filter","owner":"MR-Addict","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-03T01:55:03.000Z","size":571,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-23T08:29:32.088Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/MR-Addict.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-02T00:16:29.000Z","updated_at":"2023-05-01T02:42:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b771a19-d671-40b4-9eeb-5aba4e57c34e","html_url":"https://github.com/MR-Addict/Digital-Filter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FDigital-Filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FDigital-Filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FDigital-Filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FDigital-Filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MR-Addict","download_url":"https://codeload.github.com/MR-Addict/Digital-Filter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243940212,"owners_count":20372050,"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-11-13T05:11:05.665Z","updated_at":"2026-01-03T12:32:14.182Z","avatar_url":"https://github.com/MR-Addict.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Digital Filter\n\n## 1. Preview\n\nTypically, we use **Digital Filter** to process digital signal and sensor data, smoothing or filting data. There are many digital filting algorithm, most popular filters are:\n\n- **FIR Filter**\n- **MAF Filter**\n- **IIR Filter**\n\nFIR Filter is more powerful than MAF and IIR filter, abeling to **stablizie**, **smooth**, and **filt** data, but it comsumes more computing power.\n\nMAF Filter is a simplified FIR Filter that only averaging your singal data, but it's still working very well.\n\nIIR Filter is much more faster, but it's less powerfull than FIR and MAF Filters.\n\nImage below is raw roll and pitch data from MPU6050.\n\n![Raw-Data](Images/RollPitch.png)\n\nAfter filting using MAF Filter, data signal looks like below, and the result is promising.\n\n![Filted-Data](Images/FiltedData.png)\n\n## 2. Drawbacks\n\nThe biggest problem of FIR Filte is that filter will cause **lagging** data. Higher frequeny, more lagger data processing.\n\nYou can clearly see it showing below.\n\n![Drawback](Images/Drawback.png)\n\nLagging problem is less if you're using MAF or IIR Filters. All in all, sensor fusing is really important.\n\n## 3. Filter Implement\n\n### 3.1 FIR Filter\n\n#### 3.1.1 FIR Online Designer\n\nFIR Filter is the most difficult Filters comparing with MAF and IIR Filters, you need to calculating your own filter taps. We often using programmes or Online Designers to do this job.\n\nThere are plenty of FIR online desingers if you google it. What I using is [TFilter](http://t-filter.engineerjs.com). You can specify your design needs on this website. For example, my sampling rate is 100Hz, and my desired frequency is 5 Hz, I want to cutoff 25-50Hz signal, after clicking `DESIGN FILTER` I get my filter taps.\n\n![TFilter](Images/TFilter.png)\n\nGenerated filter taps are use for FIR Filter Implement after.\n\n#### 3.1.2 FIR Filter Implement\n\nYou can directly use FIR Libarary for you own application, which I referred from [Phil’s Lab](https://www.youtube.com/channel/UCVryWqJ4cSlbTSETBHpBUWw) who did a great job on **Control System**.\n\nFirst you need to include FIRFilter in your project.\n\n```c\n#include \"FIRFilter.h\"\n```\n\nThen you need to define a data buffer for storing your data and an arrey of your filter taps.\n\n```c\nfloat buffer[9] = { 0 };\nfloat taps[] = {\n    0.02341152899192398, 0.06471122356467367, 0.12060371719780817,\n    0.16958710211144923, 0.1891554348168665, 0.16958710211144923,\n    0.12060371719780817, 0.06471122356467367, 0.02341152899192398\n};\n```\n\nAnd you need to declear a **FIRFilter** struct and pass above two arreies to it.\n\n```c\nFIRFilter FIRRoll;\nFIRFilter_Init(\u0026FIRRoll, taps, buffer, sizeof(taps)/sizeof(float));\n```\n\nAfter all of this, you can now use FIR Filter in your project. For example, if I need to filt my Roll data, I can do below.\n\n```c\nchar message[50] = { 0 };\nfloat roll = MPU_GetRoll();\nfloat rollFilted = FIRFilter_Update(\u0026FIRRoll, roll);\nsprintf(message, \"%.2f\\t%.2f\\r\\n\", roll, rollFilted);\nHAL_UART_Transmit(\u0026huart1, (uint8_t*) message, sizeof(message), 10);\n```\n\n### 3.2 MAF Filter Implement\n\nMAF Filter usage is much more easier than FIR Filter, you do not need to design filter taps, because you are averaging your data.\n\nSo you just need to including MAFFilter libaray, declear a MAFFilter struct and initilize MAF Filter.\n\n```c\n#include \"MAFFilter.h\"\nMAFFilter MAFRoll;\nMAFFileter_Init(\u0026MAFRoll);\n```\n\nAfter that, you can using MAF Filter just like before.\n\n```c\nchar message[50] = { 0 };\nfloat roll = MPU_GetRoll();\nfloat rollFilted = MAFFilter_Update(\u0026MAFRoll, roll);\nsprintf(message, \"%.2f\\t%.2f\\r\\n\", roll, rollFilted);\nHAL_UART_Transmit(\u0026huart1, (uint8_t*) message, sizeof(message), 10);\n```\n\n### 3.3 IIR Filter Implement\n\nIIR Filter is as easy as MAF Filter, you just need to specify **alpha** you want to use for your filting.\n\n```c\n#include \"IIRFilter.h\"\nIIRFilter IIRRoll;\nIIRFilter_Init(\u0026IIRRoll, 0.5);\n```\n\nThen using IIR Filter.\n\n```c\nchar message[50] = { 0 };\nfloat roll = MPU_GetRoll();\nfloat rollFilted = IIRFilter_Update(\u0026IIRRoll, roll);\nsprintf(message, \"%.2f\\t%.2f\\r\\n\", roll, rollFilted);\nHAL_UART_Transmit(\u0026huart1, (uint8_t*) message, sizeof(message), 10);\n```\n\nHappy Coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-addict%2Fdigital-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmr-addict%2Fdigital-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-addict%2Fdigital-filter/lists"}