diff --git a/.gitignore b/.gitignore index 4c49bd7..3b72af0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env +__pycache__ diff --git a/src/science_signal/signal.py b/src/science_signal/signal.py index 878ae05..e0d2953 100644 --- a/src/science_signal/signal.py +++ b/src/science_signal/signal.py @@ -66,10 +66,14 @@ class Signal: cos(self.y), ) - def cut(self, start: float, end: float) -> "Signal": + def cut(self, start: None | float = None, end: None | float = None) -> "Signal": """ Cut signal from a start x to an end x """ + if start is None: + start = min(self.x) + if end is None: + end = max(self.x) indexes = where(logical_and(self.x > start, self.x < end)) return Signal( self.x[indexes], @@ -105,11 +109,16 @@ class Signal: ) def filter( - self, start: None | float, end: None | float + self, start: None | float = None, end: None | float = None ) -> "Signal": freq_x = rfftfreq(len(self), self.sampling) freq_y = rfft(self.y) + if start is None: + start = min(abs(freq_x)) + if end is None: + end = max(abs(freq_x)) + index_to_remove = where( logical_and(abs(freq_x) < start, abs(freq_x) > end) ) @@ -124,7 +133,7 @@ class Signal: """ Compute psd of a given signal """ - psd, freq = welch( + freq, psd = welch( self.y, self.rate, nperseg=fft_length * self.rate,