|
11 | 11 | # Smoothing finite differences # |
12 | 12 | ################################ |
13 | 13 | def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1): |
14 | | - """Perform median smoothing using scipy.signal.medfilt followed by first order finite difference |
| 14 | + """Perform median smoothing using scipy.signal.medfilt followed by second order finite difference |
15 | 15 |
|
16 | 16 | :param np.array[float] x: data to differentiate |
17 | 17 | :param float dt: step size |
@@ -44,7 +44,7 @@ def mediandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1): |
44 | 44 |
|
45 | 45 |
|
46 | 46 | def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1): |
47 | | - """Perform mean smoothing by convolving mean kernel with x followed by first order finite difference |
| 47 | + """Perform mean smoothing by convolving mean kernel with x followed by second order finite difference |
48 | 48 |
|
49 | 49 | :param np.ndarray[float] x: data to differentiate |
50 | 50 | :param float dt: step size |
@@ -74,7 +74,7 @@ def meandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1): |
74 | 74 |
|
75 | 75 |
|
76 | 76 | def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1): |
77 | | - """Perform gaussian smoothing by convolving gaussian kernel with x followed by first order finite difference |
| 77 | + """Perform gaussian smoothing by convolving gaussian kernel with x followed by second order finite difference |
78 | 78 |
|
79 | 79 | :param np.array[float] x: data to differentiate |
80 | 80 | :param float dt: step size |
@@ -103,7 +103,7 @@ def gaussiandiff(x, dt, params=None, options={}, window_size=5, num_iterations=1 |
103 | 103 |
|
104 | 104 |
|
105 | 105 | def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations=1): |
106 | | - """Perform friedrichs smoothing by convolving friedrichs kernel with x followed by first order finite difference |
| 106 | + """Perform friedrichs smoothing by convolving friedrichs kernel with x followed by second order finite difference |
107 | 107 |
|
108 | 108 | :param np.array[float] x: data to differentiate |
109 | 109 | :param float dt: step size |
@@ -132,7 +132,7 @@ def friedrichsdiff(x, dt, params=None, options={}, window_size=5, num_iterations |
132 | 132 |
|
133 | 133 |
|
134 | 134 | def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5, num_iterations=1): |
135 | | - """Perform butterworth smoothing on x with scipy.signal.filtfilt followed by first order finite difference |
| 135 | + """Perform butterworth smoothing on x with scipy.signal.filtfilt followed by second order finite difference |
136 | 136 |
|
137 | 137 | :param np.array[float] x: data to differentiate |
138 | 138 | :param float dt: step size |
@@ -171,7 +171,8 @@ def butterdiff(x, dt, params=None, options={}, filter_order=2, cutoff_freq=0.5, |
171 | 171 |
|
172 | 172 |
|
173 | 173 | def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1): |
174 | | - """Perform spline smoothing on x with scipy.interpolate.UnivariateSpline followed by first order finite difference |
| 174 | + """Find smoothed data and derivative estimates by fitting a smoothing spline to the data with |
| 175 | + scipy.interpolate.UnivariateSpline. |
175 | 176 |
|
176 | 177 | :param np.array[float] x: data to differentiate |
177 | 178 | :param float dt: step size |
@@ -200,6 +201,7 @@ def splinediff(x, dt, params=None, options={}, order=3, s=None, num_iterations=1 |
200 | 201 | spline = scipy.interpolate.UnivariateSpline(t, x_hat, k=order, s=s) |
201 | 202 | x_hat = spline(t) |
202 | 203 |
|
203 | | - x_hat, dxdt_hat = finite_difference(x_hat, dt) |
| 204 | + dspline = spline.derivative() |
| 205 | + dxdt_hat = dspline(t) |
204 | 206 |
|
205 | 207 | return x_hat, dxdt_hat |
0 commit comments