# pyewt.ewt1d module

pyewt.ewt1d.dual_filterbank(mfb)

  Build the dual filterbank

  Parameters:

    mfb (-) – List containing the original empirical wavelet filters.

  Returns:

    - dualmfb – List which elements are the dual filters of each filter of the input filterbank.

  Return type:

    list

  Notes

  This function builds the dual filterbank used for the reconstruction.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.ewt1d(f, params)

  1D Empirical Wavelet Transform

  Parameters:

    - f (-) – input signal.

    - params (-) – must be set properly accordingly to the options described in the notes section below.

  Returns:

    - - ewt (list) – each element of that list is a ndarray containing the corresponding components of the EWT (note, they could be either real of complex depending on the used mother wavelet).

    - - mfb (list) – each element of that list is a ndarray containing the different filters built accordingly to the detected supports and the chosen mother wavelet.

    - - boundaries (ndarray) – list of boundaries normalized in [0,pi) if f is real, or [0,2pi) if f is complex (i.e. no fftshift has been applied).

  Notes

  This function performs the 1D Empirical Wavelet Transform (EWT) of the input signal f, using the parameters provided in params. It has three main steps: 1) detect the supports boundaries, 2) build the wavelet filter bank, 3) perform the transform itself. The options for steps 1) and 2) are described hereafter.

  ## STEP 1): boundary detection

  If params[“log”] is set to True, then the detection is performed on the logarithm of f, otherwise it will be on f itself.

  Two types of preprocessing are available to “clean” the spectrum:

  - A global trend remover method is set via params[“globtrend”]:

      - “none” : does nothing, returns f

      - “powerlaw”uses a power law to estimate the trend, returns

          f - powerlaw(f)

      - “polylaw”: uses a polynomial interpolation of degree specified
          by params[“degree”] to estimate the trend, returns

            f - polynomial(f)

      - “morpho”uses morphological operators, returns

          f - (opening(f)+closing(f))/2

      - “tophat”uses morphological operators, returns

          f - opening(f)

      - “opening”returns

          opening(f)

  - A regularization method is set via params[“reg”]:

      - “none” : does nothing, returns f

      - “gaussian”convolve f with a Gaussian of length and standard

          deviation given by params[“lengthfilter”] and params[“sigmafilter”], respectively

      - “average”: convolve f with a constant filter of length given

          by params[“lengthfilter”]

      - “closing”applies the morphological closing operator of length

          given by params[“lengthfilter”]

  The wanted boundary detection method must be set in params[“detect”]. The available options are: - “localmax” : select the mid-point between consecutive maxima.

  > params[“N”] must be set to the expected number of modes.

  - “localmaxmin”select the lowest minima between consecutive

      maxima of the preprocessed spectrum. params[“N”] must be set to the expected number of modes.

  - “localmaxminf”select the lowest minima between consecutive

      maxima where the minima are detected on the original spectrum instead of the preprocessed one. params[“N”] must be set to the expected number of modes.

  - “adaptivereg”this method re-adjust a set of provided initial

      boundaries based on the actual lowest minima of the preprocessed spectrum params[“InitBounds”] must be set with a vector of initial boundaries

  - “adaptive”this method re-adjust a set of provided initial

      boundaries based on the actual lowest minima of the original spectrum params[“InitBounds”] must be set with a vector of initial boundaries

  - “scalespace”uses the scale-space detection technique to

      automatically find the boundaries (including their number) params[“typeDetect”] must be set to the wanted classification method. The available options are: - “otsu” : uses Otsu’s technique - “halfnormal” : uses a half-normal law to model the problem - “empiricallaw” : uses the data itself to build a model of the problem - “mean” : threshold is fixed as the mean of the data - “kmeans” : uses kmeans to classify

  For the automatic detection methods, a completion step is available is the number of detected modes is lower than an expected value params[“N”]. If needed, the last high frequency support is evenly splitted. This step is performed if params[“Completion”] is set to True.

  STEP 2): construction of the wavelet filter bank The name of the wanted mother wavelet must be given in params[“wavname”]. The available options are:

  > - “littlewood-paley”

  > - “meyer”

  > - “shannon”

  > - “gabor1”

  > - “gabor 2”

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.gabor1_filterbank(boundaries, N, cpx)

  Gabor wavelet filters - Option 1

  Parameters:

    - boundaries (-) – It is expected that these boundaries lie in [0,pi) for a real case, and [0,2pi) for a complex case.

    - N (-) – Should correspond to the length of the Fourier transform of the signal used to detect the boundaries

    - cpx (-)

  Returns:

    - mfb – Each element of that list is a ndarray corresponding to each filter

  Return type:

    list

  Notes

  This function builds the set of Gabor filters corresponding to the given set of boundaries. This option build the last filter as a full Gabor filter.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.gabor2_filterbank(boundaries, N, cpx)

  Gabor wavelet filters - option 2

  Parameters:

    - boundaries (-) – It is expected that these boundaries lie in [0,pi) for a real case, and [0,2pi) for a complex case.

    - N (-) – Should correspond to the length of the Fourier transform of the signal used to detect the boundaries

    - cpx (-)

  Returns:

    - mfb – Each element of that list is a ndarray corresponding to each filter

  Return type:

    list

  Notes

  This function builds the set of Gabor filters corresponding to the given set of boundaries. This option build the last filter as half a Gabor filter and the other half as a constant.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.iewt1d(ewt, mfb, cpx)

  Inverse 1D Empirical Wavelet Transform

  Parameters:

    - -ewt (List) – Each element in that list is a ndarray containing the empirical wavelet components.

    - -mfb (List) – Each element in that list is a ndarray containing the empirical wavelet filters used to extract ewt

    - -cpx (True is the original signal was complex, False otherwise)

  Returns:

    Reconstructed signal

  Return type:

    - rec ndarray

  Notes

  This function performs the inverse empirical wavelet transform from the empirical components stored in ewt.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.ifcleaning(fin, lb, ub)

  Instantaneous frequencies cleaning

  Parameters:

    - fin (-) – contains the set of frequencies to clean

    - lb (-)

    - ub (-)

  Returns:

    - f – contains the cleaned frequencies

  Return type:

    ndarray

  Notes

  This function removes outliers (i.e. frequencies that are not in [lb,ub]) using interpolation.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.instantaneous_components(ewt, boundaries)

  Extract instantaneous amplitude and frequencies

  Parameters:

    - ewt (-) – wavelet components

    - boundaries (-) – wavelet filters.

  Returns:

    - - HilbA (list that contains ndarray with the instantaneous amplitude)

    - - HilbF (list that contains ndarray with the instantaneous frequencies)

  Notes

  This function extracts the instantaneous amplitude and frequencies for each empirical wavelet component using the Hilbert transform.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.lp_filterbank(boundaries, N, cpx)

  Littlewood-Paley wavelet filters

  Parameters:

    - boundaries (-) – It is expected that these boundaries lie in [0,pi) for a real case, and [0,2pi) for a complex case.

    - N (-) – Should correspond to the length of the Fourier transform of the signal used to detect the boundaries

    - cpx (-)

  Returns:

    - mfb – Each element of that list is a ndarray corresponding to each filter

  Return type:

    list

  Notes

  This function builds the set of Littlewood-Paley filters corresponding to the given set of boundaries.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.meyer_filterbank(boundaries, N, cpx)

  Meyer wavelet filters

  Parameters:

    - boundaries (-) – It is expected that these boundaries lie in [0,pi) for a real case, and [0,2pi) for a complex case.

    - N (-) – Should correspond to the length of the Fourier transform of the signal used to detect the boundaries

    - cpx (-)

  Returns:

    - mfb – Each element of that list is a ndarray corresponding to each filter

  Return type:

    list

  Notes

  This function builds the set of Meyer filters corresponding to the given set of boundaries.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.plot_ewt1d(ewt, indep=False, SamplingRate=6.283185307179586)

  Plot the empirical wavelet components

  ## Parameter

  - ewt: list

      contains the 1D numpy arrays corresponding to each emprical wavelet components

  - indep: True of False (default)

      if False the components are plotted in different subplots. If True, they are plotted in different figures

  - SamplingRate: Sampling frequency

      if known we can indicate the used sampling frequency. If unknown, set it to 2*np.pi (default) to have a normalized frequancy axis, i.e. [-pi,pi)

  Notes

  This function plots the empirical wavelet components extracted by the EWT. If the components are complex, it plot the real and imaginary parts separately.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.plot_filterBank1d(mfb, spectrum=[], Grouped=False, SamplingRate=6.283185307179586)

  Plot 1D empirical wavelet filterbank

  Parameters:

    - mfb (-) – contains the 1D numpy arrays corresponding to each filter

    - spectrum (-) – we assume it has not been fftshift.

    - Grouped (-) – if False, each filter is plotted on a different subplot, otherwise they are all plotted on the same figure.

    - SamplingRate (-) – if known we can indicate the used sampling frequency. If unknown, set it to 2*np.pi (default) to have a normalized frequancy axis, i.e. [-pi,pi)

  Notes

  This function plots the filter bank on top of the spectrum (if provided). If the filters are complex, it plots the magnitude.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.shannon_filterbank(boundaries, N, cpx)

  Shannon wavelet filters

  Parameters:

    - boundaries (-) – It is expected that these boundaries lie in [0,pi) for a real case, and [0,2pi) for a complex case.

    - N (-) – Should correspond to the length of the Fourier transform of the signal used to detect the boundaries

    - cpx (-)

  Returns:

    - mfb – Each element of that list is a ndarray corresponding to each filter

  Return type:

    list

  Notes

  This function builds the set of Shannon filters corresponding to the given set of boundaries.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)

pyewt.ewt1d.timefrequency_plot(ewt, boundaries, sig, color=True, SamplingRate=6.283185307179586, GlobalNorm=True, Logmag=False)

  Time-Frequency plot

  Parameters:

    - ewt (-) – contains the 1D numpy arrays corresponding to each emprical wavelet components

    - boundaries (-) – contains the boundaries used in the construction of the empirical wavelet filters.

    - sig (-) – original signal

    - color (-) – indicate if the plot must be done in color (True) or grayscale (False)

    - SamplingRate (-) – if known we can indicate the used sampling frequency. If unknown, set it to 2*np.pi (default) to have a normalized frequancy axis, i.e. [-pi,pi)

    - GlobalNorm (-) – indicate if the magnitude of each time-frequency curve must be normalized globally (i.e. by the maximum across all component) or individually (i.e by its own maximum). Note: if individual normalization tends to provide a more visually appealing plot, be aware the maxima for each curve (despite having the same color) are different!

    - Logmag (-) – indicate if we plot the logarithm of the magnitude.

  Notes

  This function extract the time-frequency information from the empirical wavelet components and plot them in the time-frequency domain. This function works only for real signals.

  Author: Jerome Gilles Institution: San Diego State University Version: 1.0 (01/07/2025)