OptFROG - Analytic signal spectrograms with optimized time-frequency resolution

A Python package for the calculation of spectrograms with optimized time and frequency resolution for application in the analysis of numerical simulations on ultrashort pulse propagation is presented. Gabor's uncertainty principle prevents both resolutions from being optimal simultaneously for a given window function employed in the underlying short-time Fourier analysis. Our aim is to yield a time-frequency representation of the input signal with marginals that represent the original intensities per unit time and frequency similarly well. As use-case we demonstrate the implemented functionality for the analysis of simulations on ultrashort pulse propagation in a nonlinear waveguide.

The spectrogram, providing a particular timefrequency representation of signals that vary in time [1], represents an inevitable tool in the analysis of the characteristics of ultrashort optical pulses.E.g., allowing to monitor the change in frequency of pulse features as function of time permits to determine quantities that cannot be obtained from either the time or frequency domain representation of the optical pulse alone.The applicability of the spectrogram to both, data retrieved from experiments [2,3,4,5] where it is referred to as frequency resolved optical gating (FROG) analysis, as well as from numerical simulations [6,7,8], carried out to complement experiments and to provide a basis for the interpretation of the observed effects, highlights the relevance of signal processing in the field of nonlinear optics and demonstrates the need to be able to compute such spectrograms in the first place.Here, we consider the Email address: oliver.melchert@hot.uni-hannover.de(O.Melchert) issue of obtaining optimal time-frequency representations of signals for the interpretation of numerical experiments on ultrashort pulse propagation in nonlinear waveguides.
In principle, a spectrogram measures the properties of the signal under scrutiny as well as those of a userspecified window function for localizing parts of the signal during analysis.Exhibiting features of both, the interpretation of the spectrogram is strongly affected by the particular function used for windowing.Different window functions estimate different signal properties, e.g., if a given function achieves a good approximation of the intensities per unit time of the underlying signal, its approximation of the intensities per unit frequency might be bad.Consequently, the spectrogram might suffer from distortion yielding an unreasonable characterization of the timefrequency features of the signal under scrutiny.The usual approach for deciding on a particular window function is by trial-and-error and guided by the liking and experience of the individual.
Here we present a software tool that aims at minimizing the mismatch between the intensities per unit time and frequency and their corresponding estimates based on the spectrogram itself, obtained for a user-supplied parame-terized window function.The resulting spectrograms are "optimal" in the sense that their visual inspection exhibits a minimal amount of distortion and thus allow for a reliable interpretation of the time-frequency composition of the input signal.Such an approach was previously shown to result in a reasonable characterization of the underlying time-frequency features [9].It is further independent of the experience of the individual user and thus yields reproducible results.

Software description
The presented package facilitates the construction of spectrograms for the analytic signal (AS) [10] E(t) of the real field E(t).In the Fourier domain, the angular frequency components of both are related via Ê(ω) = [1 + sgn(ω)] Ê(ω) [11].Due to its one-sided spectral definition the time-domain representation of the AS is complex, further satisfying E(t) = Re[E(t)].The construction of an AS spectrogram relies on the repeated calculation of the spectrum of the modified signal E(t)h(t−τ) at different delay times τ in terms of the short-time Fourier transform wherein h(t) specifies a narrow window function centered at t = 0 and decaying to zero for increasing |t|.The latter allows to selectively filter parts of the AS and to estimate its local frequency content.Scanning over a range of delay times then yields the spectrogram as , providing a joint time-frequency distribution of both, the AS and the window function [12].For assessing the approximation quality of P S we utilize its time and frequency marginals Note that in the limit where h(t) approaches a delta function, the time marginal will approach the intensity per unit time |E(t)| 2 but the frequency marginal will represent the intensity per unit frequency | Ê(ω)| 2 only poorly.As a result, time resolution will be good and frequency resolution will be bad, see the discussion in section 3 below.The time-frequency uncertainty principle prevents both resolutions from being optimal simultaneously [1].
The aim of the presented package is to obtain a timefrequency representation of the input signal for which the integrated absolute error (IAE) between its normalized marginals and the original intensities per unit time and frequency are minimal.We consider a single parameter window function h(t, σ), e.g. a Gaussian function with mean t and root-mean-square (rms) width σ, and solve for Above, the underlying spectrogram is computed via h(t, σ), indicated by the superscript σ on the marginals, and we assume normalization to |E(t)| 2 dt = 1 and a total signal energy E S = P S (τ, ω) dτ dω in terms of the spectrogram.For a good agreement of the marginals and the original intensities, the objective function Q assumes a small value.The additional parameter α might be adjusted to give more weight to frequency resolution (α < 0) or time resolution (α > 0) if appropriate.The particular choice α = 0 yields a balanced time-frequency representation, see the example provided in section 3. The optimized spectrogram is then computed by using h(t) ≡ h(t, σ ) for windowing.

Software Architecture
OptFROG, following the naming convention [13] for Python packages implemented as optfrog, uses the Python programming language [14] and depends on the functionality of numpy and scipy [15].It further follows a procedural programming paradigm.

Software Functionalities
The current version of optfrog comprises five software units having the subsequent responsibilities: For a more detailed description of function parameters and return values we refer to the documentation provided within the code [16].

Sample code snippet
In our research work we use optfrog mainly in script mode.An exemplary data postprocessing script, reproducing Fig. 1(b) discussed in section 3 below, is shown in listing 1. Therein, after importing the functionality of numpy, optfrog, and a custom figure generating routine in lines 1-3, the location of the input data (line 5) and filter options for the spectrogram output-data (lines 6p) are specified.Note that the user defined window function (lines 9p) does not need to be normalized.After loading the input data (lines 12p) the routine optFrog is used to compute an optimized spectrogram in line 15.Finally, a visual account of the latter is prepared by the routine spectrogramFigure in line 17.

Illustrative Examples
So as to demonstrate the functionality of optfrog we consider the numerical propagation of a short and intense few-cycle optical pulse in presence of the refractive index profile of an "endlessly single mode" (ESM) photonic crystal fiber [17,18].The underlying unidirectional propagation model includes the Kerr effect and a delayed Raman response of Hollenbeck-Cantrell type [19].For the preparation of the initial condition we considered a single soliton with duration t 0 = 7 fs, i.e. approximately 3.8 cycles, and soliton order N s = 8, prepared at a center frequency ω = 1.7 rad/fs.See Refs.[20,21] for a detailed account of the propagation model and Ref. [22] for a more thorough discussion of the particular problem setup.In Fig. 1 we illustrate the time-frequency characteristics of the pulse at propagation distance z = 0.12 m by using a Gaussian window function h(t, σ) centered at t = 0 and having rms-width σ.Note that the delay time τ has to be interpreted as being relative to the origin of a co-moving frame of reference in which the soliton is initially at rest.
In Figs.1(a,c) we demonstrate an inevitable drawback of a trial-and-error choice of a window function used for calculating a spectrogram.As discussed earlier, the properties of the window implies a trade-off in resolution that might be achieved.I.e., if the user opts for a window function that is either too wide or too narrow in comparison to the signal features in the time domain, only one marginal will approximate its underlying original intensity well and, as a result, the spectrogram will appear distorted.This is shown in Fig. 1(a), where a vanillaFrog trace using σ = 140 fs demonstrates a good frequency resolution and a bad time resolution.Conversely, as evident from Fig. 1(c), a vanillaFrog trace using σ = 10 fs yields a good time resolution and a bad frequency resolution.In contrast, if the IAEs of both marginals are minimized simultaneously by aid of a numerical algorithm, both marginals of the optimized spectrogram are found to approximate the original intensities per unit time and frequency similarly well.Consequently, the resulting spectrogram provides a most reasonable time-frequency representation of the underlying signal.To demonstrate this, the balanced (α = 0) optFrog trace for the optimized window function, obtained for σ = 39.1 fs with Q = 0.39, is shown in Fig. 1(b).

Impact
Computing reliable spectrograms represents an integral part in the analysis of the characteristics of ultrashort optical pulses.The publicly available and free Python package optfrog performs the nontrivial task of computing such spectrograms with optimized time-frequency resolution.It is based on a computational approach to parameter optimization in opposition to common trial-and-error approaches, helping to save time and effort and yielding reproducible results independent of the skill of the individual user.It addresses researchers in the field of ultrashort pulse propagation and related disciplines where signal analysis in terms of short-time Fourier transforms is of relevance.As independent software postprocessing tool it is ideally suited for the analysis of output data obtained by existing pulse propagation codes, as, e.g., the open source LaserFOAM (Python) [23] and gnlse (Matlab) [24] solver for the generalized nonlinear Schrödinger equation.

Conclusions
The optfrog Python package provides easy-to-use tools that yield a time-frequency representation of a real valued input signal and allow to quantify how well the resulting spectrogram approximates the signal under scrutiny for a user supplied window function.
We have shown how optfrog can be used to calculate analytic signal based spectrograms that are optimal in the sense that their visual inspection exhibits a minimal amount of distortion, allowing for a reliable interpretation of the time-frequency composition of the input signal.
The optfrog software tool, including scripts that implement the exemplary use-cases illustrated in section 3, is available for download and installation under Ref. [16].

vanillaFrog
Compute a standard spectrogram P S (τ, ω) for the normalized time-domain analytic signal for a particular window function h(t, σ).optFrog Compute a time-frequency resolution optimized spectrogram for the normalized time-domain analytic signal using the window function h(t, σ ) that minimizes the total IAE of both marginals.Note: for the minimization of the scalar function Q(σ, α) in the variable σ, the scipy native function scipy.optimize.minimizescalar is employed in bounded mode.timeMarginal Compute the marginal distribution in time P 1 based on the spectrogram.frequencyMarginal Compute the marginal distribution in frequency P 2 based on the spectrogram.totalEnergy Compute the total energy E S provided by the spectrogram approximation of the timefrequency characteristics of the signal.

Listing 1 :
Exemplary Python script using optfrog for the calculation of a time-frequency resolution optimized spectrogram.

1
i m p o r t numpy as np from optfrog i m p o r t optFrog 3 from figure i m p o r t s p e c t r o g r a m F i g u r e 5 fName = ' ./data / e x a m p l e D a t a _ p u l s e P r o p a g a t i o n .npz '

Figure 1 :
Figure 1: Analytic signal spectrograms allowing for the time-frequency characterization of a real optical field obtained from the numerical propagation of an ultrashort pulse in an ESM photonic crystal fiber.(a) vanillaFrog-trace for a Gaussian window function with rms-width σ = 140 fs, (b) balanced optFrog-trace for σ = 39.1 fs, and, (c) vanillaFrog-trace for a Gaussian window function at σ = 10 fs.

Table 1 :
Ancillary data table required for subversion of the codebase.Kindly replace examples in right column with the correct information about your current code, and leave the left column as it is.Code metadata (mandatory)