Skip to content

Commit

Permalink
Merge pull request #518 from RocketPy-Team/enh/save-filtered-data
Browse files Browse the repository at this point in the history
ENH : Add of a line for saving the filtered dataset
  • Loading branch information
kalounis authored Dec 21, 2023
2 parents 086a924 + cd897a9 commit 14dd0f6
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit 14dd0f6

Please sign in to comment.