Pytta: Open Source Toolbox For Acoustic Measurements and Signal Processing
Pytta: Open Source Toolbox For Acoustic Measurements and Signal Processing
Pytta: Open Source Toolbox For Acoustic Measurements and Signal Processing
signal processing
(1) Federal University of Santa Maria, Acoustical Engineering, Santa Maria, RS, Brazil,
{will.fonseca, joao.paes, matheus.lazarin, marcos.reis, paulo.mareze, eric.brandao}@eac.ufsm.br
Abstract
Python is a high-level programming language that has gained strength in the international community. This
mainly occurs because it is open-source nature, that is, any user is entitled to its use, whether for scientific,
commercial or hobby purposes. Another important feature is that Python is OS-independent. This means that
no matter what OS the code was written, it can be run by any operating system. In addition, access to AD/DA
acquisition interfaces allows interaction with real systems for their estimation and control. These features
enable its use as a powerful signal processing tool, whether for acoustics or general purpose. The Federal Uni-
versity of Santa Maria (UFSM), in Brazil, has created a group of developers, who are working cooperatively
on a toolbox for acoustic, audio and vibration signal processing. The project is named PyTTa, standing for
Python in Technical Acoustics. It is object-oriented programmed, enabling the easy use of variables, classes,
and functions. The collection of codes inside the toolbox creates an environment that facilitates the acquisi-
tion/measurement, pre/post-processing, I/O operations and plotting/documenting. This is a continuing work
that relies on the collaborative effort to provide free access to information and work/research tools.
Keywords: Signal Processing, Toolbox, Computer Science, Acoustics.
1 INTRODUCTION
Aiming to create acoustics, audio, vibration and general signal processing tools, the Acoustical Engineering
Department, at the Federal University of Santa Maria (UFSM), in Brazil, has created a group of developers
who are working cooperatively on a toolbox. The project is named PyTTa, standing for Python in Technical
Acoustics (since Python [1] is the chosen programming language). PyTTa is a continuing work that relies on
collaborative efforts to provide free access to information and work/research tools.
The collection of codes inside the toolbox creates an environment that facilitates the acquisition/measurement,
pre/post-processing, I/O operations and plotting/documenting. This work presents the ideas and developments
carried out during the first two years of the PyTTa project.
1.1 Motivation
The engineering pre- and/or post-processing tools usually rely on paid software. This yields the problem
that enthusiasts and students may face costly situations to start studying/testing. Thus, looking forward to
circumventing this circumstance and motivated by the excellent experience of using ITA Toolbox [2] (written in
Matlab), students, professors and coders have started a joint work for a freeware and open source tools.
2 PYTHON
Python1 is an already established high-level programming language. It was published during the 1990s by Guido
van Rossum [4]. He has released the first public version of the code in the forum alt.sources (this version was
known as 0.9.0). Version 1.0 was released in 1994 and just in 1995 (version 1.4) [5] the language won native
1 Excerpt fom General Python FAQ [3]: “When he began implementing Python, Guido van Rossum was also reading the published scripts from
’Monty Python’s Flying Circus’, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly
mysterious, so he decided to call the language Python”.
support for complex numbers. In version 2.2, Python types and classes were unified in only one hierarchy. This
feature has enabled the Python object model consistently object-oriented. If compared, Python 3 has new syntax
and keywords; fresh modules in the standard library; reliability improvements and dozen of fixes that made it
easier to develop high-quality software. Version 3.73 is the most recent, until the closing of this paper.
Python is a free and open source language, that is, any user may use it for scientific, commercial or hobby
applications. It is classified as a scripting language2 , i.e. it does not require the compilation step and is rather
interpreted. Another important point is that Python is platform independent. This means that whatever operating
system (OS) the code was written. It will probably run smoothly in any OS.
The language is commonly used for web application, game development and database interface. Recently,
it has expanded to scientific and statistical analysis. This happened due to a collaborative community that
develops and delivers new modules for these purposes. These modules are libraries with implemented functions,
which add features/resources to the user/programmer. Some notable ones are NumPy [6] (for data manipulation
of homogeneous vectors); Pandas [7] (for data manipulation of heterogeneous vectors), SciPy [8] (for daily
scientific applications), Matplotlib [9] (for quality plots), among others.
Developed to be an easy-to-read language, the indentation is mandatory. Given that aspects and presenting an
easy syntax, it is considered as an easy learning language. It is used by universities, private companies and
computer coders. Furthermore, Python may be an excellent choice to learn about programming logic [10].
2 For the record, all scripting languages are programming languages. For example, Matlab is also a scripting language.
3 Git is a distributed version control system.
4 For example, Impulse Response (IR) measurement [14] or Frequency Response Function (FRF), see Section 4.1.
The attributes in a class can be other classes, indeed Python sees everything as a class instance, even the
numerical types, this is called a composition, and it is the preferable way of combining different classes and its
attributes and methods. Another way of sharing those is inheriting a class, which consists of creating another
class, often called a subclass, that holds its superclass attributes and methods but can also have its own.
The inheritance brings to light another feature of the OOP, the polymorphism. Any class can have the same
attributes or methods, and they all can behave differently from class to class. A subclass can reimplement any
method provided by the superclass and can change the values of the attributes without affecting the superclass.
Finally, there is the encapsulation, which is to hide the actual data and provide only methods that either show
or change the data – in a way to check if the new data suits the role that attribute have within the class or the
code.
3 PyTTa FEATURES
By now, PyTTa has several features and can be seen as a core package for measurement applications. There
are ways to generate and handle audio signals for playback, recording, visualization and processing.
The codebase is separated into modules, python scripts, that were made as the code grew in lines. Thus they
are not perfectly designed to have interchangeability of information, but everything made up to this point works.
There are four modules that compose the measurement core, and the fifth is the room acoustics application
(under development). They can be observed in Figure 1 and are presented in the following sections.
3.1 Classes
Classes is the first module created, all the PyTTa classes are written in this file. They are:
• SignalObj;
• ChannelObj;
• ImpulsiveResponse;
• RecMeasure;
• PlayRecMeasure;
• FRFMeasure.
The SignalObj class is the main audio handler. It holds data of the discrete time amplitudes; discrete magnitudes
and phases in the frequency domain; a list of active channels for audio acquisition (or reproduction) in the
form of ChannelObj (that holds information about each channel’s identification, calibration factor and units).
The ImpulsiveResponse is a container class that holds three SignalObj, one for the excitation audio, one for
the recorded audios and the third for the processed impulsive responses (IRs).
On the measurement side, the classes’ roles are identified by their names. The RecMeasure class is used for
record-only purposes. Both the PlayRecMeasure and the FRFMeasure are used for playback and record. The
main difference is that the FRFMeasure is being developed to return ImpulsiveResponse objects, assuming that
the out/in relation will be analyzed.
3.2 Properties
Every PyTTa class has several attributes that are used for measurement or signal configuration. The package
comes with a set of default values that are held by the Default class (which is inside the properties module).
These parameters are passed down to every function that needs some sort of PyTTa-like object parameters.
They range from sampling rate, to the number of channels, to commentaries about the audios or measurements.
3.3 Generate
This module provides user-end functions that are fully default parameterized to return pre-configured signals
and measurements (setup to run out of the box). There are two main kinds of functions inside the module,
a group of signal generators and a unique measurement generator. The signal generators are named after the
signals they generate (e.g., sweep, impulse, noise). The measurement generator is named measurement and a
parameter is passed down to choose which of the measure classes will be used.
3.4 Functions
The functions module has several utility functions like merging N signal objects (SignalObj) of M channels
into one (containing the total number of channels); estimating the delay between two signals; finding the signal’s
peak’s time from each channel; listing available audio I/O5 devices; export and import audio files; resampling;
correlation and convolution.
3.5 Rooms
This is the latest addition and is still under development. The module is being designed to provide a bundle
of room acoustic parameters like reverberation time, center time, clarity, definition, interaural cross-correlation,
speech transmission index and many others. This module will also be the first application of the package.
20
Magnitude in dB
30
40
50
60
102 103 104
Frequency [Hz]
Figure 2. Frequency Response Function (FRF) between a loudspeaker and a microphone, including a loopback
between input and output.
80
Magnitude in dB
100
120
140
102 103 104
Frequency [Hz]
(a) Mics. of the test bench (b) FRF: PyTTa vs. ITA Toolbox
Figure 3. Testing audio acquisition and processing using PyTTa vs. ITA on mufflers insertion loss test bench.
The test was performed using a test bench for insertion loss. The tested object is a reference tube with
approximately 42 cm long. The microphone that the yellow arrow points (see Figure 3 (a)) is placed into an
opening at the beginning of the tube (closer to the sound source and linked to the first channel of the audio
I/O device). The microphone that the pink arrow points (see Figure 3 (a)) is aiming to the center point of the
tube outlet (and is linked to the second channel of the audio I/O device).
The evaluation of the tube transfer-function is the ratio between microphone at channel 2 over microphone at
channel 1. Two data sets were acquired, one using ITA Toolbox via Matlab, and another using PyTTa via
Anaconda Python. The data post-processing was accomplished with Matlab and Python for both acquisitions.
The Figure 3 (b) depicts only the comparison between the ITA Toolbox measurement and the PyTTa mea-
surement, both processed, in this case6 , by PyTTa ImpulsiveResponse class, using the H1 statistical method
– as proposed by Shin and Hammond [17]. It is possible to notice that the differences are quite small, even
considering a statistical method (and for different measurements).
This set of commands will print the available audio I/O devices (such as sound cards) and the default parameters
(as they are in the default class object).
To read everything present inside the package, and assuming the use of Spyder IDE (see Figure 4), the user
can press ctrl+i with the cursor in front of the module, submodule, class, methods or function names (see
Code 4 below). This action will open the help menu with the documentation of the respective item.
Code 4: PyTTA installed package.
pytta |
pytta . properties |
pytta . generate |
pytta . functions |
pytta . classes |
The “ | ” sign represents the cursor position to press ctrl+i in order to use the Spyder help widget. Inside
each submodule the user will find instructions on the available tools, and how to access them.
7 CONCLUSIONS
PyTTa is a collaborative effort and a tool under development to aid acousticians to measure, get results,
do analysis and find solutions with a trusted, easy to run, community software, capable of expansion and
customization. Every class, module and application is in constant improvement to be more user and developer
friendly. This is a long journey to walk alone, the engagement of users on helping to improve and create more
tools is essential for the continuity of the work.
The next steps to be followed are the development of the room acoustics module (and application), an environ-
mental noise application, a loudspeaker alignment application, and means to provide an auralization application.
It is also in development an end-user application that can be setup and started using a graphical user interface
(GUI), returning fully processed data and real-time monitoring. Plus a full documentation covering all the end
user functionalities and a reference guide for developers. All this development is based upon the research group
at the Federal University of Santa Maria, but also includes, and hopes for, community contributors and users
feedback.
ACKNOWLEDGEMENTS
The authors would like to express deep gratitude to the Federal University of Santa Maria [22]; Acoustic
Engineering Department, classmates and professors [23]; and the Institute of Technical Acoustics of the RWTH
Aachen University [24] for the countless support and inspiration. Finally, we wish to acknowledge the help
provided by the Python developer community and the people who maintain websites, forums, blogs and YouTube
channels with tutorials.
REFERENCES
[1] Python Programming Language. https://www.python.org, accessed March 2019.
[2] P. Dietrich, B. Masiero, M. Müller-Trapet, M. Pollow, and R. Scharrer. Matlab toolbox for the comprehen-
sion of acoustic measurement and signal processing. In Fortschritte der Akustik – DAGA, 2010.
[3] Python - General Python FAQ. https://docs.python.org/3/faq/general.html, accessed May 2019.
[4] John V. Guttag. Introduction to Computation and Programming Using Python. The MIT Press, 2 edition,
2016. ISBN 9780262525008.
[5] G. van Rossum. Python tutorial - CWI Report CS-R9525. 1995.
[6] NumPy. http://www.numpy.org, accessed April 2019.
[7] Pandas - Python Data Analysis Library. https://pandas.pydata.org/, accessed April 2019.
[8] SciPy. https://scipy.org, accessed April 2019.
[9] Matplotlib: Python plotting. https://matplotlib.org, accessed April 2019.
[10] edX | Introduction to Python: Fundamentals (by Microsoft). https://www.edx.org/course/
introduction-to-python-fundamentals-0, accessed April 2019.
[11] Jeff Atwood and Joel Spolsky. Stack Overflow http://pt.stackoverflow.com, accessed April 2019.
[12] GitHub. http://github.com, accessed March 2019.
[13] Wikipedia - GitHub. https://pt.wikipedia.org/wiki/GitHub, accessed March 2019.
[14] Swen Müller and Paulo Massarani. Transfer-function Measurement with Sweeps (Director’s Cut Including
Previously Unreleased Material and Some Corrections). Original published in Journal of the Audio Engineer-
ing Society, 49(6):443–471, 2001. URL http://www.aes.org/e-lib/browse.cfm?elib=10189.
[15] Sounddevice - Play and Record Sound with Python. http://pypi.org/project/sounddevice, accessed
May 2019.
[16] PortAudio - an Open-Source Cross-Platform Audio API. http://www.portaudio.com, accessed March
2019.
[17] Kihong Shin and Joseph Hammond. Fundamentals of signal processing for sound and vibration engineers.
John Wiley & Sons, 2008.
[18] Anaconda Distribution. https://www.anaconda.com/distribution/, accessed April 2019.
[19] Spyder IDE. http://pythonhosted.org/spyder, accessed April 2019.
[20] PyPI - Python Package Index. https://pypi.org/project/pip/, accessed May 2019.
[21] PyTTa Master. GitHub - PyTTA https://github.com/pyttamaster/pytta, accessed May 2019.
[22] Federal University of Santa Maria. Official website https://ufsm.br, 2019. acessed May 2019.
[23] Course of Acoustical Engineering (UFSM). Official website https://eac.ufsm.br, 2019. acessed May
2019.
[24] ITA Toolbox. http://www.ita-toolbox.org and http://git.rwth-aachen.de/ita/toolbox, ac-
cessed April 2019.