Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH : Add of a line for saving the filtered dataset #518

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def to_frequency_domain(self, lower, upper, sampling_frequency, remove_dc=True):
extrapolation="zero",
)

def low_pass_filter(self, alpha):
def low_pass_filter(self, alpha, file_path=None):
"""Implements a low pass filter with a moving average filter

Parameters
Expand All @@ -1097,6 +1097,9 @@ def low_pass_filter(self, alpha):
filtered function returned will match the function the smaller
alpha is, the smoother the filtered function returned will be
(but with a phase shift)
file_path : string
File path or file name of the CSV to save. Don't save any CSV if
if no argument is passed. Initiated to None.

Returns
-------
Expand All @@ -1112,6 +1115,10 @@ def low_pass_filter(self, alpha):
alpha * self.source[i] + (1 - alpha) * filtered_signal[i - 1]
)

# Save the new csv file with filtered data
if isinstance(file_path, str):
np.savetxt(file_path, filtered_signal, delimiter=",")

return Function(
source=filtered_signal,
interpolation=self.__interpolation__,
Expand Down