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

Added a band-pass method #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions src/waveresponse/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,40 @@ def reshape(
new._freq, new._dirs, new._vals = freq_new, dirs_new, vals_new
return new

def bandpassed(self, freq_min = None, freq_max = None):
"""
Apply a bandpass filter to keep only the energy between the given frequencies [Hz].

A new object is returned where the grid is modified such that
- the bandpassed frequencies are included
- the frequencies outside the bandpass are removed

"""

freq_hz = self.freq(freq_hz=True)

if freq_min is None:
freq_min = min(freq_hz)
if freq_max is None:
freq_max = max(freq_hz)

assert freq_min < freq_max, "freq_min must be less than freq_max"
assert freq_min >= min(freq_hz), "freq_min must be greater than or equal to the minimum frequency in the grid"
assert freq_max <= max(freq_hz), "freq_max must be less than or equal to the maximum frequency in the grid"

new_freq = np.unique([*freq_hz, freq_min, freq_max])
new_freq.sort()
new_freq = new_freq[(new_freq >= freq_min) & (new_freq <= freq_max)]

return self.reshape(freq = new_freq,
dirs = self.dirs(degrees=True),
freq_hz = True,
degrees = True)





def __mul__(self, other):
"""
Multiply values (element-wise).
Expand Down