imptube

GitHub repository

This library provides an implementation of transfer function impedance tube measurements according to ISO 10534-2:1998.

It requires several Python packages to be installed:

  • sounddevice
  • soundfile
  • scipy
  • numpy
  • pandas

Installation

It is currently not possible to install this library using pip or conda, please use the latest released package instead and install using pip locally.

Usage

The library currently provides two ways to perform a measurement.

Method 1: Direct measurement without saving any data

This method shows the inner logic of the whole measurement. In contrast to the second method, this method does not work with any folder/file structure.

import imptube as imp

temp = 29  # Temperature in degrees Celsius
humidity = 30  # Relative humidity in percent
atm_pressure = 101300  # Atmospheric pressure in Pascal

tube = imp.Tube(
    further_mic_dist=0.4,
    closer_mic_dist=0.1,
    freq_limit=1000
)

measurement = imp.Measurement(device=15)  # Create an instance of the Measurement class

# Perform the configuration 1 measurement
data, fs = measurement.measure(export=False, thd_filter=True)  
p11, p12 = imp.stereo_to_spectra(data.T)
freqs = imp.frequencies(p11, fs)

input("Ready to measure in the second configuration?") 

# Perform the configuration 2 measurement
data, fs = measurement.measure(export=False, thd_filter=True)
p21, p22 = imp.stereo_to_spectra(data.T)

# Calculate the calibration factor based on the spectra
cf = imp.calibration_factor(p11, p12, p21, p22)
# Calculate the transfer function based on the spectra
# of the first configuration
tf = imp.transfer_function(p11, p12)  

# Correct the transfer function using the calibration factor
tf_corrected = tf / cf  
tf_I, tf_R = imp.tf_i_r(temp, freqs, tube.mic_spacing)

# Calculate the reflection factor, absorption coefficient and 
# surface impedance based on the transfer function and other parameters
refl_factor = imp.reflection_factor(tf_I, tf_R, tf_corrected, temp, freqs, tube.closer_mic_dist)  

absorption_coeff = imp.absorption_coefficient(refl_factor)

surf_impedance = imp.surface_impedance(refl_factor, temp, atm_pressure)

Method 2: Using the Sample class and autosaving the captured and processed data to a specific folder structure

import imptube as imp

tube = imp.Tube(
    further_mic_dist=0.3,
    closer_mic_dist=0.1,
    freq_limit=1000)

measurement = imp.Measurement(device=15)

sample = imp.Sample("test1",
    temperature=29,
    rel_humidity=30,
    tube=tube)

imp.calibration(
    sample=sample,
    measurement=measurement
)

imp.single_measurement(
    sample=sample,
    measurement=measurement,
    depth=160
)

Acknowledgments

This library was created thanks to the FAST-J-22-7880 project.

Special thanks to prof. Christ Glorieux for his help with the theory.

Github Copilot was used to generate parts of the documentation and code.

Author

Contributing

Pull requests are welcome. For any changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

  1"""
  2[GitHub repository](https://github.com/vyhyb/imptube)
  3
  4This library provides an implementation of transfer function impedance tube measurements according to [ISO 10534-2:1998](https://www.iso.org/standard/22851.html).
  5
  6
  7It requires several Python packages to be installed:
  8
  9- sounddevice
 10- soundfile
 11- scipy
 12- numpy
 13- pandas
 14
 15## Installation
 16
 17It is currently not possible to install this library using `pip` or `conda`, please use the latest [released package](https://github.com/vyhyb/imptube/releases) instead and install using [`pip` locally](https://packaging.python.org/en/latest/tutorials/installing-packages/).
 18
 19## Usage
 20
 21The library currently provides two ways to perform a measurement.
 22
 23### Method 1: Direct measurement without saving any data
 24
 25This method shows the inner logic of the whole measurement. In contrast to the second method, this method does not work with any folder/file structure.
 26
 27```python
 28import imptube as imp
 29
 30temp = 29  # Temperature in degrees Celsius
 31humidity = 30  # Relative humidity in percent
 32atm_pressure = 101300  # Atmospheric pressure in Pascal
 33
 34tube = imp.Tube(
 35    further_mic_dist=0.4,
 36    closer_mic_dist=0.1,
 37    freq_limit=1000
 38)
 39
 40measurement = imp.Measurement(device=15)  # Create an instance of the Measurement class
 41
 42# Perform the configuration 1 measurement
 43data, fs = measurement.measure(export=False, thd_filter=True)  
 44p11, p12 = imp.stereo_to_spectra(data.T)
 45freqs = imp.frequencies(p11, fs)
 46
 47input("Ready to measure in the second configuration?") 
 48
 49# Perform the configuration 2 measurement
 50data, fs = measurement.measure(export=False, thd_filter=True)
 51p21, p22 = imp.stereo_to_spectra(data.T)
 52
 53# Calculate the calibration factor based on the spectra
 54cf = imp.calibration_factor(p11, p12, p21, p22)
 55# Calculate the transfer function based on the spectra
 56# of the first configuration
 57tf = imp.transfer_function(p11, p12)  
 58
 59# Correct the transfer function using the calibration factor
 60tf_corrected = tf / cf  
 61tf_I, tf_R = imp.tf_i_r(temp, freqs, tube.mic_spacing)
 62
 63# Calculate the reflection factor, absorption coefficient and 
 64# surface impedance based on the transfer function and other parameters
 65refl_factor = imp.reflection_factor(tf_I, tf_R, tf_corrected, temp, freqs, tube.closer_mic_dist)  
 66
 67absorption_coeff = imp.absorption_coefficient(refl_factor)
 68
 69surf_impedance = imp.surface_impedance(refl_factor, temp, atm_pressure)
 70```
 71
 72### Method 2: Using the `Sample` class and autosaving the captured and processed data to a specific folder structure
 73
 74```python
 75import imptube as imp
 76
 77tube = imp.Tube(
 78    further_mic_dist=0.3,
 79    closer_mic_dist=0.1,
 80    freq_limit=1000)
 81
 82measurement = imp.Measurement(device=15)
 83
 84sample = imp.Sample("test1",
 85    temperature=29,
 86    rel_humidity=30,
 87    tube=tube)
 88
 89imp.calibration(
 90    sample=sample,
 91    measurement=measurement
 92)
 93
 94imp.single_measurement(
 95    sample=sample,
 96    measurement=measurement,
 97    depth=160
 98)
 99```
100## Acknowledgments
101
102This library was created thanks to the [FAST-J-22-7880](https://www.vut.cz/vav/projekty/detail/33840) project.
103
104Special thanks to prof. Christ Glorieux for his help with the theory.
105
106Github Copilot was used to generate parts of the documentation and code.
107
108## Author
109
110- [David Jun](https://www.fce.vutbr.cz/o-fakulte/lide/david-jun-12801/)
111  
112  PhD student at [Brno University of Technology](https://www.vutbr.cz/en/)
113
114## Contributing
115
116Pull requests are welcome. For any changes, please open an issue first
117to discuss what you would like to change.
118
119Please make sure to update tests as appropriate.
120
121## License
122
123[MIT](https://choosealicense.com/licenses/mit/)
124
125"""
126from .tube import (
127    Tube, 
128    Measurement, 
129    Sample, 
130    single_measurement, 
131    calculate_alpha, 
132    calibration
133)
134
135from .processing.signal_proc import (
136    read_audio, 
137    separate_mono, 
138    stereo_to_spectra, 
139    calibration_factor, 
140    transfer_function, 
141    tf_i_r, 
142    frequencies, 
143    reflection_factor, 
144    absorption_coefficient, 
145    surface_impedance
146)
147
148from .processing.files import read_file