Skip to content

Commit 88276aa

Browse files
committed
feat: add MATLAB CI workflow and unit test for OneEuroFilter
1 parent b37e1d8 commit 88276aa

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: MATLAB CI
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
name: Run Tests
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out repository
11+
uses: actions/checkout@v4
12+
13+
- name: Set up MATLAB
14+
uses: matlab-actions/setup-matlab@v2
15+
16+
- name: Run Unit Tests
17+
uses: matlab-actions/run-tests@v2
18+
with:
19+
source-folder: .

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![View OneEuroFilter on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/183059-oneeurofilter)
44
[![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=cuixing158/OneEuroFilter&file=ExampleOneEuroFilter)
5+
[![MATLAB CI](https://github.com/cuixing158/OneEuroFilter/actions/workflows/ci.yml/badge.svg)](https://github.com/cuixing158/OneEuroFilter/actions/workflows/ci.yml)
56

67
A MATLAB implementation of the **1 Euro Filter**[^1], a simple algorithm for filtering noisy signals for high precision and responsiveness.
78

@@ -75,5 +76,5 @@ title('1 Euro Filter Result');
7576
## References
7677

7778
[^1]: **1 € Filter: A Simple Speed-based Low-pass Filter for Noisy Input in Interactive Systems** Géry Casiez, Nicolas Roussel, and Daniel Vogel. CHI 2012.
78-
> <http://cristal.univ-lille.fr/~casiez/1euro/> <br>
79+
> <https://gery.casiez.net/1euro/> <br>
7980
> <https://www.mathworks.com/matlabcentral/fileexchange/129829-smooth-data>

testValidGroundTruthData.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
classdef testValidGroundTruthData < matlab.unittest.TestCase
2+
% testValidGroundTruthData 验证 OneEuroFilter 是否符合标准 Ground Truth 数据
3+
% 数据来源: https://github.com/casiez/OneEuroFilter
4+
5+
methods (Test)
6+
function testGroundTruthValues(testCase)
7+
% 1. 读取 Ground Truth 数据
8+
url = "https://raw.githubusercontent.com/casiez/OneEuroFilter/main/groundTruth.csv";
9+
try
10+
data = readtable(url);
11+
catch ME
12+
testCase.verifyFail("Can't read from URL: " + ME.message);
13+
return;
14+
end
15+
16+
% 2. 设置滤波器参数
17+
% 这些是生成 Ground Truth 数据时使用的标准参数
18+
freq = 120;
19+
mincutoff = 1.0;
20+
beta = 0.1;
21+
dcutoff = 1.0;
22+
23+
one_euro = OneEuroFilter(freq, ...
24+
'mincutoff', mincutoff, ...
25+
'beta_', beta, ...
26+
'dcutoff', dcutoff);
27+
28+
% 3. 逐点滤波并验证
29+
% 注意:Ground Truth 数据包含 timestamp, signal, noisy, filtered
30+
for i = 1:height(data)
31+
t = data.timestamp(i);
32+
noisy_val = data.noisy(i);
33+
expected_val = data.filtered(i);
34+
35+
% 执行滤波
36+
actual_val = one_euro.filter(noisy_val, t);
37+
38+
% 验证结果 (使用 1e-4 的绝对误差容限,因为 CSV 精度有限)
39+
testCase.verifyEqual(actual_val, expected_val, 'AbsTol', 1e-4, ...
40+
sprintf('Mismatch at index %d (t=%.4f)', i, t));
41+
end
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)