Reflect the values in matrix *x* about the scalar values *minx* and *maxx*. Hence a vector *x* containing a long linearly increasing series is converted into a waveform which ramps linearly up and down between *minx* and *maxx*. If *x* contains integers and *minx* and *maxx* are (in
(x, minx, maxx)
| 1240 | |
| 1241 | |
| 1242 | def reflect(x, minx, maxx): |
| 1243 | """Reflect the values in matrix *x* about the scalar values *minx* and |
| 1244 | *maxx*. Hence a vector *x* containing a long linearly increasing series is |
| 1245 | converted into a waveform which ramps linearly up and down between *minx* |
| 1246 | and *maxx*. If *x* contains integers and *minx* and *maxx* are (integers + |
| 1247 | 0.5), the ramps will have repeated max and min samples. |
| 1248 | |
| 1249 | .. codeauthor:: Rich Wareham <rjw57@cantab.net>, Aug 2013 |
| 1250 | .. codeauthor:: Nick Kingsbury, Cambridge University, January 1999. |
| 1251 | |
| 1252 | """ |
| 1253 | x = np.asanyarray(x) |
| 1254 | rng = maxx - minx |
| 1255 | rng_by_2 = 2 * rng |
| 1256 | mod = np.fmod(x - minx, rng_by_2) |
| 1257 | normed_mod = np.where(mod < 0, mod + rng_by_2, mod) |
| 1258 | out = np.where(normed_mod >= rng, rng_by_2 - normed_mod, normed_mod) + minx |
| 1259 | return np.array(out, dtype=x.dtype) |
| 1260 |