Skip to content

Commit b0d9f9c

Browse files
committed
rewrite derivatives square wave
1 parent 024f585 commit b0d9f9c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

waveform_editor/tendencies/periodic/sine_wave.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def get_derivative(self, time: np.ndarray) -> np.ndarray:
3737
Returns:
3838
numpy array containing the derivatives
3939
"""
40-
values = self._calc_derivative(time)
41-
return values
40+
derivatives = self._calc_derivative(time)
41+
return derivatives
4242

4343
def _calc_sine(self, time):
4444
"""Returns the value of the sine wave."""

waveform_editor/tendencies/periodic/square_wave.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
import numpy as np
24

35
from waveform_editor.tendencies.periodic.periodic_base import PeriodicBaseTendency
@@ -6,7 +8,9 @@
68
class SquareWaveTendency(PeriodicBaseTendency):
79
"""A tendency representing a square wave."""
810

9-
def generate(self, time=None):
11+
def get_value(
12+
self, time: Optional[np.ndarray] = None
13+
) -> tuple[np.ndarray, np.ndarray]:
1014
"""Generate time and values based on the tendency. If no time array is provided,
1115
a time array will be created from the start to the end of the tendency, where
1216
time points are defined for every peak and trough in the tendency.
@@ -24,21 +28,17 @@ def generate(self, time=None):
2428
values = self._calc_square_wave(time)
2529
return time, values
2630

27-
def get_start_value(self) -> float:
28-
"""Returns the value of the tendency at the start."""
29-
return self._calc_square_wave(self.start)
30-
31-
def get_end_value(self) -> float:
32-
"""Returns the value of the tendency at the end."""
33-
return self._calc_square_wave(self.end)
31+
def get_derivative(self, time: np.ndarray) -> np.ndarray:
32+
"""Get the derivative values on the provided time array.
3433
35-
def get_derivative_start(self) -> float:
36-
"""Returns the derivative of the tendency at the start."""
37-
return 0
34+
Args:
35+
time: The time array on which to generate points.
3836
39-
def get_derivative_end(self) -> float:
40-
"""Returns the derivative of the tendency at the end."""
41-
return 0
37+
Returns:
38+
numpy array containing the derivatives
39+
"""
40+
derivatives = np.zeros(len(time))
41+
return derivatives
4242

4343
def _calc_square_wave(self, time):
4444
"""Calculates the point of the square wave at a given time point or

0 commit comments

Comments
 (0)