{'fraction_non_alphanumeric': 0.023805770140312155, 'fraction_numerical': 0.006936780703137317, 'mean_word_length': 4.803751143641354, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Simple empirical algorithm to obtain signal envelope in three steps

Signal amplitude envelope allows to obtain information on the signal features for different applications. It is commonly agreed that the envelope is a signal that varies slowly and it should pass the prominent peaks of the data smoothly. It has been widely used in sound analysis and also in different variables of physiological data for animal and human studies. In order to get signal envelope, a simple algorithm is proposed based on peak detection and it was implemented with python libraries. This method can be used for different applications in sound or in general in time series analysis for signals of different origin or frequency content. As well, some aspects on the parameter selection are discussed here to adapt the same method for different applications and some traditional methods are also revisited.


Introduction
In audio signals, envelope is usually defined together with temporal fine structure. The amplitude modulations of animal sounds, speech or musical instruments are important characteristics used to understand the physics of different process. Accurate estimation of the amplitude, or equivalently energy, or envelope of a time-domain signal (waveform) is not a trivial task. Ideally, the amplitude envelope should outline the waveform connecting the main peaks and avoiding over fitting [1].
The definition of envelope is ambiguous and lack of an exact mathematical definition. It is commonly agreed that envelope varies slowly and in some empirical view it should pass the prominent peaks of the data smoothly [2].
Amplitude envelope allows to get a reliable estimation that follows closely sudden variations in amplitude and avoids ripples in more stable regions with near optimal order selection depending on the fundamental frequency of the signal. Amplitude variations depending on the application allows to obtain information on the signal patterns or features. i. e. peaks, maximum, signal sudden variations, etc.
In addition to sound signals, the signal envelope is useful in many application of signal analysis in different fields from biology or medicine, to geology or material sciences [3,4,5,6,7,8,9]. A simple algorithm together with a code implementation could became a useful tool to be provide for experimental analysis for different disciplines.
Currently there is a diversity of methods already implemented in different programming languages to obtain signal envelope. Most of them do not allow to obtain a not attenuated envelope. A review the most popular techniques are presented and implemented them with python libraries in Section 2. Also a comment on the more sophisticated novel algorithms is presented.
The main purpose of this works is to propose a simple algorithm to get the amplitude signal envelope. The algorithm is presented in Section 3.1 and the description of the implementation in Section 3.2. This method can be adjusted to be used for digitalized signals of different frequency content, sample rate, and duration. Some examples of application are presented in Section 3.3. Also this section includes the discussion of how to change the parameters in order to adapt the method for different signals and some cues to lead to good practices in signal analysis. Finally in Section 4 the conclusions are presented.
2 Current envelope techniques

Clasical techniques
The classical approach for the estimation of the amplitude envelope of a time-domain signal is the technique known as envelope follower [10,11]. This method has been widely used. It consists basically in rectifying the waveform and then low-pass filtering it. This can be implemented in either the analog or digital domains. With programming tools, the algorithm consist of taking the absolute value of the digitalized signal, and then use a digital low-pass filter. Several programing languages has libraries with build-in filters such as MATLAB [12] or Python [13]. For the comparison presented in further in Section 3 we used python libraries.
Another interesting algorithm is to calculate the instantaneous root mean square (RMS) value of the waveform through a sliding window with finite support [14]. Some authors have proposed other techniques to obtain a more reliable estimation of the amplitude envelope of waveforms. An early attempt [11] consisted of a piece-wise linear approximation of the waveform. The amplitude envelope is created by finding and connecting the peaks of the waveform in a window that moves through the data. Again we used python libraries to generate a function for smooth the signal via RMS together with the sliding window and compare with the other methods in Section 3.
Other technique consists of using the analytic signal from Hilbert Transform. Notably, if the Hilbert transform of S(t) is equal to its quadrature signal [10], then the estimates are equal to the actual information signals [10]. Synthetic signals (i.e. AM) can be constructed to have this property, but there is no reason to expect that animal sounds, acoustic musical instrument sounds or speech also present it. A more realistic condition is verified when we are dealing with narrow-band signals [15].
Finally another classical approach is an algorithm that directly use the prominent peaks and finally get the envelope by interpolation. A detail of this method can be found in [2].

More sophisticated techniques
A more recent method developed with not attenuated envelope is called Cepstral Smoothing [1]. It uses the real cepstrum defined as the inverse Fourier transform of the log magnitude spectrum. Implementation for this method is more sophisticated and it was discussed in detail in [1].
Another novel method called empirical mode decomposition (EMD) [16] allows to obtain the envelope as a result of an optimization precess and sought as a minimum of a quadratic cost function. A closed form solution of this optimization problem is obtained and it is shown that by choosing free parameters, where they can fine-tune the frequency resolution or the number of intrinsic mode functions (IMFs) as well as the shape of the envelopes, the method could be widely implemented.
3 Envelope based on a peak detection algorithm 3

.1 The three-step algorithm
To get an envelope output that will not be attenuated, a possible approach is to use a peak detection algorithm combined with a moving window. Later it is possible to lowpass-filter the resulting signal afterwards to get rid of the remaining staircase. This process is summarized in the schematic presented in Figure 1. In more detail, the method implemented in present work to get signal envelope consist of a three simple steps: • The first step is to take absolute value of signal S(t) meaning |S(t)| as it is shown in Figure 2 top panel. • The third step consist in a lowpass-filter applied to the resulted signal R(t) to get rid of the remaining staircase ripple to obtainŜ(t) , as illustrated in the2 bottom panel. Figure 1: Algorithm schema. Input signal is called S(t) and the envelope obtained isŜ(t).
The signal obtained with this technique has the same sample rate that the original signal. This could be very useful in order to compare the envelope with other simultaneous measurements related to the original signal.
By using this three step method the envelope obtained follows the signal amplitude variations, without attenuation if the parameters are carefully selected as shown in Fig.2. In this example the filter cutoff frequency is chosen between 100 − 150 Hz to ensure that the signal envelope follows signal variations as rapid as 10 mS combined with the bunch size of 35 samples. These two variables could be adjusted to follow variations as rapid as needed.
A comparison between the classical implementations of envelope methods and the one proposed in this work are presented in Figure 3. The frequency cut for the envelope follower is 150 Hz. For the RMS slide window is 50 samples. For the three-step algorithm parameters are selected as in Figure 3.

Software implementation
The previous section is a general description of the method. Some particular considerations have to be taken into account for the code implementation and are presented in this section. The libraries and parameters used in the code are presented here as well as the arguments for the choices made.
The language used for the implementation was Python [13]. The main reason to use python is the expansive library of open source data analysis tools, web frameworks and testing instruments that make one of the largest current programming community. Python is an accessible language for new programmers because the community provides many introductory resources.
With respect of the implementation, first of all it is necessary to determinate the size of the bunch for the signal to be divided. It will mainly depend first of all of the sampling rate.
For the examples presented here sample rate is 44.100 KHz. In this case a proper bunch size is between 20 − 200 samples. Since we have available audio files to analyze , the Scipy Signal processing library functions was used to get the audio sample rate and signal vector and write a code with these input variables.
Second, it is necessary to choose a digital filter that do not produce face differences (a zero-phase filtering), which does not shift the signal as it filters. Since the phase is zero at all frequencies, it is also linear-phase. Filtering backwards in time requires to predict the future signal value. This kind of filters can not be used for "online" real-life applications, only for off-line processing of recordings of signals.
The scipy signal library [17] has two kinds of functions to use for filter design. One is called scipy.signal.lfilter and the other scipy.signal.filtfilt. The first one (lfilter ) is causal forward-intime filtering only, similar to a real-life electronic filter. It cannot be zero-phase. It usually adds different amounts of delay at different frequencies. The appropriated method for the off-line application is to use filtfilt with no shift in the signal as it filters.
The following step consist of choosing the type of filter as well as the frequency behavior. In this case we used a Butterworth low pass filter type scipy.signal.butter of fourth order. Frequency attenuation (behavior) of this filter is elsewhere [18]. The key point to obtain the envelope appropriate for the specific application is to choose the frequency cut of the low pass filter. Depending on this value you can obtain as many detail on the amplitude as it is required. Some examples for the same signal and different frequency cuts are presented in Section 3.3. Additionally the method proposed here is not computational expensive, so it can be applied in different systems.

Examples of different kind of sounds and parameter selection
A good method must be flexible enough to be applied to all kinds of signals. Here the envelope result from the method implemented is shown over different kinds of sound segments with or without rapid variations. Audio files was selected from public data sets: two sounds of very different animals presented in Figure 4 (canary song and a whale song), human speech (English language) and an instrument recording of piano song presented with corresponding spectrogram in Figure 5.

Conclusions
In this work it is proposed a simple and novel technique for envelope estimation. This algorithm it is very simple to implement and it is another empirical method which can be applied in signal with different spectral content. The time scaling parameter can be adjusted by the researcher in order to select the smoothness of the estimated envelope. Experimental applications presented shows that the algorithm can achieve good performance on the temporal envelope estimation of data. It was observed that the estimated envelope can track quite well the changing trend of input data. This algorithm can be implemented in off-line processing applications, e.g. animal sounds (particularly bird songs), musical instrument sound analysis, heart sound analysis, vibration signal analysis, and etc. In this paper, temporal audio signals were used as examples. However,there are no requirements on the specific domain of the data. It is appropriate for one dimensional data in any domain (e.g. time domain, frequency domain, space domain, etc.).

Funding
This work was supported by the following institutions: CONICET and UNQ. The software was developed on python language. Code is available at University local repository: http : //ceciliajarne.web.unq.edu.ar/investigacion/envelope c ode/ with password envelope.