From 16e2bb090f9f805afefcd58e73f21b20c9be822e Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 26 Oct 2018 19:19:49 +0200 Subject: [PATCH] [python] improve docstrings for window --- python/ext/py-musicutils.h | 89 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/python/ext/py-musicutils.h b/python/ext/py-musicutils.h index 2c6836d9..02415e42 100644 --- a/python/ext/py-musicutils.h +++ b/python/ext/py-musicutils.h @@ -2,16 +2,95 @@ #define PY_AUBIO_MUSICUTILS_H static char Py_aubio_window_doc[] = "" -"window(string, integer) -> fvec\n" +"window(window_type, size)\n" +"\n" +"Create a window of length `size`. `window_type` should be one\n" +"of the following:\n" +"\n" +"- `default` (same as `hanningz`).\n" +"- `ones`\n" +"- `rectangle`\n" +"- `hamming`\n" +"- `hanning`\n" +"- `hanningz` [1]_\n" +"- `blackman`\n" +"- `blackman_harris`\n" +"- `gaussian`\n" +"- `welch`\n" +"- `parzen`\n" "\n" -"Create a window\n" +"Parameters\n" +"----------\n" +"window_type : str\n" +" Type of window.\n" +"size : int\n" +" Length of window.\n" "\n" -"Example\n" +"Returns\n" "-------\n" +"fvec\n" +" Array of shape `(length,)` containing the new window.\n" +"\n" +"See Also\n" +"--------\n" +"pvoc, fft\n" +"\n" +"Examples\n" +"--------\n" +"Compute a zero-phase Hann window on `1024` points:\n" "\n" -">>> window('hanningz', 1024)\n" +">>> aubio.window('hanningz', 1024)\n" "array([ 0.00000000e+00, 9.41753387e-06, 3.76403332e-05, ...,\n" -" 8.46982002e-05, 3.76403332e-05, 9.41753387e-06], dtype=float32)"; +" 8.46982002e-05, 3.76403332e-05, 9.41753387e-06], dtype=float32)\n" +"\n" +"Plot different window types with `matplotlib `_:\n" +"\n" +">>> import matplotlib.pyplot as plt\n" +">>> modes = ['default', 'ones', 'rectangle', 'hamming', 'hanning',\n" +"... 'hanningz', 'blackman', 'blackman_harris', 'gaussian',\n" +"... 'welch', 'parzen']; n = 2048\n" +">>> for m in modes: plt.plot(aubio.window(m, n), label=m)\n" +"...\n" +">>> plt.legend(); plt.show()\n" +"\n" +"Note\n" +"----\n" +"The following examples contain the equivalent source code to compute\n" +"each type of window with `NumPy `_:\n" +"\n" +">>> n = 1024; x = np.arange(n, dtype=aubio.float_type)\n" +">>> ones = np.ones(n).astype(aubio.float_type)\n" +">>> rectangle = 0.5 * ones\n" +">>> hanning = 0.5 - 0.5 * np.cos(2 * np.pi * x / n)\n" +">>> hanningz = 0.5 * (1 - np.cos(2 * np.pi * x / n))\n" +">>> hamming = 0.54 - 0.46 * np.cos(2.*np.pi * x / (n - 1))\n" +">>> blackman = 0.42 \\\n" +"... - 0.50 * np.cos(2 * np.pi * x / (n - 1)) \\\n" +"... + 0.08 * np.cos(4 * np.pi * x / (n - 1))\n" +">>> blackman_harris = 0.35875 \\\n" +"... - 0.48829 * np.cos(2 * np.pi * x / (n - 1)) \\\n" +"... + 0.14128 * np.cos(4 * np.pi * x / (n - 1)) \\\n" +"... + 0.01168 * np.cos(6 * np.pi * x / (n - 1))\n" +">>> gaussian = np.exp( - 0.5 * ((x - 0.5 * (n - 1)) \\\n" +"... / (0.25 * (n - 1)) )**2 )\n" +">>> welch = 1 - ((2 * x - n) / (n + 1))**2\n" +">>> parzen = 1 - np.abs((2 * x - n) / (n + 1))\n" +">>> default = hanningz\n" +"References\n" +"----------\n" +#if 0 +"`Window function `_ on\n" +"Wikipedia.\n" +"\n" +#endif +".. [1] Amalia de Götzen, Nicolas Bernardini, and Daniel Arfib. Traditional\n" +" (?) implementations of a phase vocoder: the tricks of the trade.\n" +" In *Proceedings of the International Conference on Digital Audio\n" +" Effects* (DAFx-00), pages 37–44, University of Verona, Italy, 2000.\n" +" (`online version <" +"https://www.cs.princeton.edu/courses/archive/spr09/cos325/Bernardini.pdf" +">`_).\n" +""; PyObject * Py_aubio_window(PyObject *self, PyObject *args); -- 2.11.0