CHORE: Document fft helper

This commit is contained in:
Valentin Boettcher 2024-05-21 17:03:55 -04:00
parent 8706404b50
commit 393610e0cc

View file

@ -2,12 +2,17 @@ import numpy as np
def fourier_transform(
t: np.ndarray, signal: np.ndarray, window: tuple[float, float] | None = None
t: np.ndarray,
signal: np.ndarray,
window: tuple[float, float] | None = None,
low_cutoff: float = 0,
high_cutoff: float = np.inf,
):
"""
Compute the Fourier transform of a signal from the time array
``t`` and the real signal ``signal``. Optionally, a time window
can be specified through ``window = ([begin], [end])`` .
can be specified through ``window = ([begin], [end])`` . The
``low_cuttof (high_cutoff)`` is the lower (upper) bound of frequencies returned.
:returns: The (linear) frequency array and the Fourier transform.
"""
@ -20,4 +25,5 @@ def fourier_transform(
freq = np.fft.rfftfreq(len(t), t[1] - t[0])
fft = np.fft.rfft(signal)
return freq, fft
mask = (freq > low_cutoff) & (freq < high_cutoff)
return freq[mask], fft[mask]