Fix typo (inversion between freq and values)

This commit is contained in:
linarphy 2024-05-27 15:20:01 +02:00
parent f42fdc131a
commit caf973cbba
No known key found for this signature in database
GPG key ID: E61920135EFF2295
2 changed files with 13 additions and 3 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.env .env
__pycache__

View file

@ -66,10 +66,14 @@ class Signal:
cos(self.y), 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 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)) indexes = where(logical_and(self.x > start, self.x < end))
return Signal( return Signal(
self.x[indexes], self.x[indexes],
@ -105,11 +109,16 @@ class Signal:
) )
def filter( def filter(
self, start: None | float, end: None | float self, start: None | float = None, end: None | float = None
) -> "Signal": ) -> "Signal":
freq_x = rfftfreq(len(self), self.sampling) freq_x = rfftfreq(len(self), self.sampling)
freq_y = rfft(self.y) 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( index_to_remove = where(
logical_and(abs(freq_x) < start, abs(freq_x) > end) logical_and(abs(freq_x) < start, abs(freq_x) > end)
) )
@ -124,7 +133,7 @@ class Signal:
""" """
Compute psd of a given signal Compute psd of a given signal
""" """
psd, freq = welch( freq, psd = welch(
self.y, self.y,
self.rate, self.rate,
nperseg=fft_length * self.rate, nperseg=fft_length * self.rate,