Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Skyward Boardcore
Commits
4579a450
Commit
4579a450
authored
1 year ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
[MedFilter] now uses SlidingWindow class
parent
582439cf
No related branches found
No related tags found
1 merge request
!227
FFT and other Utilities (Filters and Windows)
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shared/algorithms/Filters/MedFilter.h
+14
-27
14 additions, 27 deletions
src/shared/algorithms/Filters/MedFilter.h
with
14 additions
and
27 deletions
src/shared/algorithms/Filters/MedFilter.h
+
14
−
27
View file @
4579a450
...
...
@@ -22,6 +22,8 @@
#pragma once
#include
<utils/SlidingWindow.h>
#include
<array>
namespace
Boardcore
...
...
@@ -30,15 +32,15 @@ namespace Boardcore
/**
* @brief Implementation of a Median Filter
*
* @tparam
windowSize
The size of the window
* @note WARNING: should be noted that the first
windowSize
- 1 outputs will be
* @tparam
WIN_SIZE
The size of the window
* @note WARNING: should be noted that the first
WIN_SIZE
- 1 outputs will be
* wrong because the window is not full yet (consider using a Shadow Mode)
*/
template
<
size_t
windowSize
>
template
<
size_t
WIN_SIZE
>
class
MedFilter
{
//
windowSize
must be odd
static_assert
(
windowSize
%
2
==
1
,
"
windowSize
must be odd"
);
//
WIN_SIZE
must be odd
static_assert
(
WIN_SIZE
%
2
==
1
,
"
WIN_SIZE
must be odd"
);
public:
/**
...
...
@@ -46,49 +48,34 @@ public:
*
* @note WARNING: Initialize output at 0 at first
*/
explicit
MedFilter
()
:
window
(
{}
)
{}
explicit
MedFilter
()
:
window
()
{}
/**
* @brief Filter the input
*
* @param input The input to filter
* @note WARNING: should be noted that the first
windowSize
- 1 outputs will
* @note WARNING: should be noted that the first
WIN_SIZE
- 1 outputs will
* be wrong because the window is not full yet (consider using a Shadow
* Mode)
*/
float
filter
(
float
input
)
{
slideWindow
(
input
);
window
.
push
(
input
);
return
median
();
}
private
:
/**
* @brief Slide the window by one position to the left and add the new input
* to the right
*
* @param input The input to add to the window
*/
void
slideWindow
(
float
input
)
{
for
(
size_t
i
=
0
;
i
<
windowSize
-
1
;
i
++
)
{
window
[
i
]
=
window
[
i
+
1
];
}
window
[
windowSize
-
1
]
=
input
;
}
/**
* @brief Calculate the median of the window
*/
float
median
()
{
std
::
array
<
float
,
windowSize
>
sorted
W
indow
=
window
;
std
::
sort
(
sorted
W
indow
.
begin
(),
sorted
W
indow
.
end
());
return
sorted
W
indow
[
windowSize
/
2
];
std
::
array
<
float
,
WIN_SIZE
>
sorted
_w
indow
=
window
.
all
()
;
std
::
sort
(
sorted
_w
indow
.
begin
(),
sorted
_w
indow
.
end
());
return
sorted
_w
indow
[
WIN_SIZE
/
2
];
}
std
::
array
<
float
,
windowSize
>
window
;
SlidingWindow
<
float
,
WIN_SIZE
>
window
;
};
}
// namespace Boardcore
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment