| 1 | #cxx . . $ `<file>/fon/Function.h`/ifndef _Function_h_ |
| 2 | #define _Function_h_cxx . . $ `fon/Function.h:2:9`! |
| 3 | /* Function.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2012,2015-2018,2020,2023-2025 Paul Boersma |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | * See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "Collection.h"cxx . . $ `<file>/sys/Collection.h`/ |
| 22 | |
| 23 | #include "Function_def.h"cxx . . $ `<file>/fon/Function_def.h`/ |
| 24 | |
| 25 | Collection_definecxx . . $ structFunctionList# (FunctionList, OrderedOf, Function) { |
| 26 | }; |
| 27 | |
| 28 | /* |
| 29 | An object of type Function represents a function f (x, ...) on the domain [xmin, xmax] * .... |
| 30 | Class invariants: |
| 31 | xmax >= xmin; |
| 32 | xmin, xmax are constant; |
| 33 | */ |
| 34 | |
| 35 | void Function_initcxx . . $ Function_init(ac72a71dd6ac1bfb). (Functioncxx . . $ Function# me, double xmin, double xmax); |
| 36 | /* |
| 37 | Preconditions: |
| 38 | xmin <= xmax; |
| 39 | Postconditions: |
| 40 | result -> xmin == xmin; |
| 41 | result -> xmax == xmax; |
| 42 | */ |
| 43 | |
| 44 | int Function_getDomainQuantitycxx . . $ Function_getDomainQuantity(1f467e71fce55133). (constFunctioncxx . . $ constFunction# me); // as input for MelderQuantity_getXXX |
| 45 | |
| 46 | /* |
| 47 | A function value is often expressed in some unit, such as: |
| 48 | Pa, Hz, dB, sones. |
| 49 | In the following, `ilevel` is for multidimensional functions; it could be the row number of a matrix, |
| 50 | or pitch height (Hz) vs. pitch strength (dimensionless), and so on. |
| 51 | `unit` is an enumerated type that has to be defined in the header files of the descendant class, |
| 52 | starting from 0, which should be the default unit; e.g. for pitch: 0 = Hz, 1 = logHz, 2 = semitones, 3 = mel. |
| 53 | */ |
| 54 | int Function_getMinimumUnitcxx . . $ Function_getMinimumUnit(3ca9094f3c2853b9). (constFunctioncxx . . $ constFunction# me, integercxx . . $ integer# ilevel); |
| 55 | int Function_getMaximumUnitcxx . . $ Function_getMaximumUnit(3ca9094f3c2853b9). (constFunctioncxx . . $ constFunction# me, integercxx . . $ integer# ilevel); |
| 56 | |
| 57 | #define Function_UNIT_TEXT_SHORTcxx . . $ `fon/Function.h:57:9`! 0x0000'0001 |
| 58 | #define Function_UNIT_TEXT_GRAPHICALcxx . . $ `fon/Function.h:58:9`! 0x0000'0002 |
| 59 | #define Function_UNIT_TEXT_MENUcxx . . $ `fon/Function.h:59:9`! 0x0000'0004 |
| 60 | conststring32cxx . . $ conststring32# Function_getUnitTextcxx . . $ Function_getUnitText(a97c80dc386b9edb). (constFunctioncxx . . $ constFunction# me, integercxx . . $ integer# level, int unit, uint32cxx . . $ uint32# flags); |
| 61 | |
| 62 | bool Function_isUnitLogarithmiccxx . . $ Function_isUnitLogarithmic(a5dfd34c63a2afb0). (constFunctioncxx . . $ constFunction# me, integercxx . . $ integer# level, int unit); |
| 63 | |
| 64 | double Function_convertStandardToSpecialUnitcxx . . $ Function_convertStandardToSpecialUnit(2ac20cd4dc1e204c). (constFunctioncxx . . $ constFunction# me, double value, integercxx . . $ integer# level, int unit); |
| 65 | double Function_convertSpecialToStandardUnitcxx . . $ Function_convertSpecialToStandardUnit(2ac20cd4dc1e204c). (constFunctioncxx . . $ constFunction# me, double value, integercxx . . $ integer# level, int unit); |
| 66 | double Function_convertToNonlogarithmiccxx . . $ Function_convertToNonlogarithmic(2ac20cd4dc1e204c). (constFunctioncxx . . $ constFunction# me, double value, integercxx . . $ integer# level, int unit); |
| 67 | |
| 68 | /* |
| 69 | The domain of a function can be changed by windowing. |
| 70 | Here follow some window functions. |
| 71 | */ |
| 72 | |
| 73 | #define Function_RECTANGULARcxx . . $ `fon/Function.h:73:9`! 0 |
| 74 | #define Function_TRIANGULARcxx . . $ `fon/Function.h:74:9`! 1 |
| 75 | #define Function_PARABOLICcxx . . $ `fon/Function.h:75:9`! 2 |
| 76 | #define Function_HANNINGcxx . . $ `fon/Function.h:76:9`! 3 |
| 77 | #define Function_HAMMINGcxx . . $ `fon/Function.h:77:9`! 4 |
| 78 | #define Function_POTTERcxx . . $ `fon/Function.h:78:9`! 5 |
| 79 | #define Function_KAISER12cxx . . $ `fon/Function.h:79:9`! 6 |
| 80 | #define Function_KAISER20cxx . . $ `fon/Function.h:80:9`! 7 |
| 81 | #define Function_GAUSSIANcxx . . $ `fon/Function.h:81:9`! 8 |
| 82 | |
| 83 | double Function_windowcxx . . $ Function_window(f7856f627868a823). (double tim, int windowType); |
| 84 | /* |
| 85 | Return value: |
| 86 | a number between 0 and 1, zero outside the "domain": |
| 87 | domain [-0.5, 0.5]: rectangular, triangular, parabolic, hanning, hamming; |
| 88 | domain [-0.77, 0.77]: potter, kaiser12; |
| 89 | domain [-1, 1]: kaiser20; |
| 90 | domain [-inf, +inf]: gaussian. |
| 91 | Rectangular: 1; |
| 92 | Triangular ("Parzen"): 1 - tim / 0.5 |
| 93 | Parabolic ("Welch"): 1 - (tim / 0.5) ^ 2 |
| 94 | Hanning (raised cosine): 0.5 + 0.5 * cos (2 * pi * tim) |
| 95 | Hamming (raised cosine): 0.54 + 0.46 * cos (2 * pi * tim) |
| 96 | Gaussian: exp (- (pi * tim) ^ 2) |
| 97 | Kaiser12: besselI0 (12 * sqrt (1 - (tim / 0.77) ^ 2)) / besselI0 (12) |
| 98 | Kaiser20: besselI0 (20.24 * sqrt (1 - tim ^ 2)) / besselI0 (20.24) |
| 99 | Usage: |
| 100 | the preferred window for almost every application is Kaiser20; |
| 101 | its only shortcoming is the usual double computation time. |
| 102 | Properties: |
| 103 | Highest sidelobe: |
| 104 | Rectangular: -10 dB |
| 105 | Hanning: -30 dB |
| 106 | Hamming: -40 dB |
| 107 | Potter, Kaiser12: -90 dB |
| 108 | Kaiser20: -180 dB |
| 109 | Gaussian: -inf dB |
| 110 | Height at 'tim' is +0.5 or -0.5 (limit from below): |
| 111 | Rectangular: 1 |
| 112 | Triangular, Parabolic, Hanning: 0 |
| 113 | Hamming: 0.08 |
| 114 | Gaussian: 0.085 |
| 115 | Kaiser20: 0.0715 |
| 116 | Potter: ... |
| 117 | Area: |
| 118 | Rectangular: 1 |
| 119 | Parabolic: 2/3 |
| 120 | Gaussian: 1 / sqrt (pi) |
| 121 | Kaiser20: 0.9813318115591122859 / sqrt (pi) |
| 122 | Hamming: 0.54 |
| 123 | Triangular, Hanning: 1/2 |
| 124 | Bandwidth (-20 dB): |
| 125 | ... |
| 126 | */ |
| 127 | |
| 128 | /* |
| 129 | Procedures to adapt a range to the extent of the function domain. |
| 130 | */ |
| 131 | void Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). ( |
| 132 | constFunctioncxx . . $ constFunction# me, |
| 133 | double *xmin, |
| 134 | double *xmax |
| 135 | ); |
| 136 | void Function_bidirectionalAutowindowcxx . . $ Function_bidirectionalAutowindow(88b7840c59a57eaf). ( |
| 137 | constFunctioncxx . . $ constFunction# me, |
| 138 | double *x1, |
| 139 | double *x2 |
| 140 | ); |
| 141 | bool Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). ( |
| 142 | constFunctioncxx . . $ constFunction# me, |
| 143 | double *x1, |
| 144 | double *x2 |
| 145 | ); |
| 146 | |
| 147 | void Function_shiftXBycxx . . $ Function_shiftXBy(730db58827849a4c). ( |
| 148 | mutableFunctioncxx . . $ mutableFunction# me, |
| 149 | double shift |
| 150 | ); |
| 151 | void Function_shiftXTocxx . . $ Function_shiftXTo(ac72a71dd6ac1bfb). (mutableFunctioncxx . . $ mutableFunction# me, double xfrom, double xto); |
| 152 | void Function_scaleXBycxx . . $ Function_scaleXBy(730db58827849a4c). (mutableFunctioncxx . . $ mutableFunction# me, double factor); |
| 153 | void Function_scaleXTocxx . . $ Function_scaleXTo(ac72a71dd6ac1bfb). (mutableFunctioncxx . . $ mutableFunction# me, double xminto, double xmaxto); |
| 154 | |
| 155 | /* End of file Function.h */ |
| 156 | #endif |