@@ -110,6 +110,59 @@ The data is fetched seamlessly on-demand from the audio file(s). The opening/clo
110110
111111Eventual time gap between audio items are filled with ``0. `` values.
112112
113+ Normalization
114+ """""""""""""
115+
116+ The fetched audio data can be normalized according to the presets given by the :class: `osekit.utils.audio_utils.Normalization ` flag:
117+
118+ .. list-table :: Normalization presets
119+ :widths: 10 10
120+ :header-rows: 1
121+
122+ * - Name
123+ - Description
124+ * - ``Normalization.RAW ``
125+ - :math: `x`
126+ * - ``Normalization.DC_REJECT ``
127+ - :math: `x-\overline { x }`
128+ * - ``Normalization.PEAK ``
129+ - :math: `\frac {x}{x_\text {max}}`
130+ * - ``Normalization.ZSCORE ``
131+ - :math: `\frac { x-\overline {x} }{\sigma (x)}`
132+
133+ To normalize the data, simply set the :attr: `osekit.core_api.audio_data.AudioData.normalization ` property to the
134+ requested normalization flag:
135+
136+ .. code-block :: python
137+
138+ from osekit.core_api.audio_data.AudioData import AudioData
139+ from osekit.utils.audio_utils.normalization import Normalization
140+
141+ ad = AudioData(... )
142+ ad.normalization = Normalization.ZSCORE # Note: normalization also is a parameter of the AudioData initializer
143+
144+ v = ad.get_value() # The fetched data will then be normalized
145+
146+ .. note ::
147+
148+ The ``Normalization.DC_REJECT `` normalization can be combined with any single other normalization:
149+
150+ .. code-block :: python
151+
152+ from osekit.utils.audio_utils.normalization import Normalization
153+
154+ dc_peak = Normalization.DC_REJECT | Normalization.PEAK
155+
156+ .. warning ::
157+
158+ Instantiating another combination of normalizations will raise an error:
159+
160+ .. code-block :: python
161+
162+ from osekit.utils.audio_utils.normalization import Normalization
163+
164+ incorrect_normalization = Normalization.RAW | Normalization.PEAK
165+ incorrect_normalization = Normalization.DC_REJECT | Normalization.RAW | Normalization.PEAK
113166
114167 Calibration
115168"""""""""""
@@ -124,8 +177,8 @@ allows for retrieving the data in the shape of the recorded acoustic pressure.
124177
125178.. code-block :: python
126179
127- from osekit.core_api.instrument import Instrument
128180 from osekit.core_api.audio_data import AudioData
181+ from osekit.core_api.instrument import Instrument
129182 import numpy as np
130183
131184 instrument = Instrument(end_to_end_db = 150 ) # The raw 1. WAV value equals 150 dB SPL re 1 uPa
@@ -170,6 +223,7 @@ an ``AudioDataset`` from a given folder containing audio files:
170223
171224 from pathlib import Path
172225 from osekit.core_api.audio_dataset import AudioDataset
226+ from osekit.core_api.instrument import Instrument
173227 from pandas import Timestamp, Timedelta
174228
175229 folder = Path(r " ... " )
@@ -179,7 +233,9 @@ an ``AudioDataset`` from a given folder containing audio files:
179233 strptime_format=" %y_%m_%d _%H_%M_%S" , # To parse the files begin Timestamp
180234 begin=Timestamp(" 2009-01-06 12:00:00" ),
181235 end=Timestamp(" 2009-01-06 14:00:00" ),
182- data_duration=Timedelta(" 10s" )
236+ data_duration=Timedelta(" 10s" ),
237+ instrument=Instrument(end_to_end_db = 150 ),
238+ normalization=" dc_reject"
183239 )
184240
185241 The resulting ``AudioDataset `` will contain 10s-long ``AudioData `` ranging from ``2009-01-06 12:00:00 `` to ``2009-01-06 14:00:00 ``.
@@ -366,4 +422,4 @@ should be provided:
366422 ltas.plot()
367423 plt.show()
368424
369- A ``SpectroData `` object can be turned into a ``LTASData `` thanks to the :meth: `osekit.core_api.ltas_data.LTASData.from_spectro_data ` method.
425+ A ``SpectroData `` object can be turned into a ``LTASData `` thanks to the :meth: `osekit.core_api.ltas_data.LTASData.from_spectro_data ` method.
0 commit comments