Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ROS2 DSP Filters
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Dzmitry Maladzenkau
ROS2 DSP Filters
Commits
431cdbe0
Commit
431cdbe0
authored
7 months ago
by
Eric Schoeneberg
Browse files
Options
Downloads
Patches
Plain Diff
[ADD] low-pass tested and work. high-pass added, but not tested
parent
377e65df
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
filter_signal/config/filter.yaml
+1
-1
1 addition, 1 deletion
filter_signal/config/filter.yaml
filter_signal/filter_signal/filters.py
+25
-0
25 additions, 0 deletions
filter_signal/filter_signal/filters.py
sample_signal/config/sample_signal.yaml
+2
-2
2 additions, 2 deletions
sample_signal/config/sample_signal.yaml
with
28 additions
and
3 deletions
filter_signal/config/filter.yaml
+
1
−
1
View file @
431cdbe0
/**/filter_signal
:
/**/filter_signal
:
ros__parameters
:
ros__parameters
:
lowpass_cuttoff_frequency
:
5
.0
lowpass_cuttoff_frequency
:
20
.0
signal_topic
:
sample_wave
signal_topic
:
sample_wave
use_sim_time
:
false
use_sim_time
:
false
This diff is collapsed.
Click to expand it.
filter_signal/filter_signal/filters.py
+
25
−
0
View file @
431cdbe0
...
@@ -21,3 +21,28 @@ class LowPassFilter():
...
@@ -21,3 +21,28 @@ class LowPassFilter():
filtered_signal
=
current_signal
*
(
self
.
sample_time
/
(
self
.
tau
+
self
.
sample_time
))
+
self
.
past_filtered_signal
*
(
self
.
tau
/
(
self
.
tau
+
self
.
sample_time
))
filtered_signal
=
current_signal
*
(
self
.
sample_time
/
(
self
.
tau
+
self
.
sample_time
))
+
self
.
past_filtered_signal
*
(
self
.
tau
/
(
self
.
tau
+
self
.
sample_time
))
self
.
past_filtered_signal
=
filtered_signal
self
.
past_filtered_signal
=
filtered_signal
return
filtered_signal
return
filtered_signal
class
HighPassFilter
():
def
__init__
(
self
,
cuttoff_frequency
,
sample_time
):
"""
Implements a first-order low-pass filter.
y_k = alpha*(y_{k-1} + x_k - x_{k-1})
where:
delta_t = sample_time
tau = 1/(2*pi*cuttoff_frequency)
alpha = tau/(tau + delta_t)
according to: https://en.wikipedia.org/wiki/High-pass_filter
"""
self
.
cuttoff_frequency
=
cuttoff_frequency
self
.
sample_time
=
sample_time
self
.
tau
=
1
/
(
2
*
np
.
pi
*
self
.
cuttoff_frequency
)
self
.
alpha
=
self
.
tau
/
(
self
.
tau
+
self
.
sample_time
)
self
.
past_filtered_signal
=
0.0
self
.
past_signal
=
0.0
def
filter
(
self
,
current_signal
):
filtered_signal
=
self
.
alpha
*
(
self
.
past_filtered_signal
+
current_signal
-
self
.
past_signal
)
self
.
past_signal
=
current_signal
self
.
past_filtered_signal
=
filtered_signal
return
filtered_signal
\ No newline at end of file
This diff is collapsed.
Click to expand it.
sample_signal/config/sample_signal.yaml
+
2
−
2
View file @
431cdbe0
/**/sample_signal
:
/**/sample_signal
:
ros__parameters
:
ros__parameters
:
publisher_frequency
:
5
0.0
# Hz
publisher_frequency
:
20
0.0
# Hz
base_signal
:
false
base_signal
:
false
base_signal_initial_value
:
0.0
base_signal_initial_value
:
0.0
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
# To satisfy Shannon-Nyquist sampling theorem -> 2*signal_frequency < publisher_frequency.
# To satisfy Shannon-Nyquist sampling theorem -> 2*signal_frequency < publisher_frequency.
sine_wave
:
true
sine_wave
:
true
sine_wave_components
:
[
2.0
,
20.0
,
0.0
,
# Frequency, amplitude, phase shift(radians) pairs
sine_wave_components
:
[
2.0
,
20.0
,
0.0
,
# Frequency, amplitude, phase shift(radians) pairs
1
0.0
,
10.0
,
1.57
,
# Add as much as needed
8
0.0
,
10.0
,
1.57
,
# Add as much as needed
#5.0, 3.0, 3.14
#5.0, 3.0, 3.14
]
]
...
...
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