Functions

Set of useful functions of general purpouses when using PyTTa.

Includes reading and writing wave files, seeing the audio IO devices available and few signal processing tools.

Available functions:

>>> pytta.list_devices()
>>> pytta.read_wav(fileName)
>>> pytta.write_wav(fileName, signalObject)
>>> pytta.merge(signalObj1, signalObj2, ..., signalObjN)
>>> pytta.slipt(signalObj)
>>> pytta.fft_convolve(signalObj1, signalObj2)
>>> pytta.find_delay(signalObj1, signalObj2)
>>> pytta.corr_coef(signalObj1, signalObj2)
>>> pytta.resample(signalObj, newSamplingRate)
>>> pytta.peak_time(signalObj1, signalObj2, ..., signalObjN)
>>> pytta.plot_time(signalObj1, signalObj2, ..., signalObjN)
>>> pytta.plot_time_dB(signalObj1, signalObj2, ..., signalObjN)
>>> pytta.plot_freq(signalObj1, signalObj2, ..., signalObjN)
>>> pytta.plot_bars(signalObj1, signalObj2, ..., signalObjN)
>>> pytta.save(fileName, obj1, ..., objN)
>>> pytta.load(fileName)

For further information, check the function specific documentation.

pytta.merge(signal1, *signalObjects)[source]

Gather all channels of the signalObjs given as input arguments into a single SignalObj.

pytta.fft_convolve(signal1, signal2)[source]

Use scipy.signal.fftconvolve() to convolve two time domain signals.

>>> convolution = pytta.fft_convolve(signal1,signal2)
pytta.read_wav(fileName)[source]

Read a wave file into a SignalObj.

pytta.write_wav(fileName, signalIn)[source]

Write a SignalObj into a single wave file.

pytta.list_devices()[source]

Shortcut to sounddevice.query_devices().

Made to exclude the need of importing Sounddevice directly just to find out which audio devices can be used.

>>> pytta.list_devices()
Return type:

A tuple containing all available audio devices.

pytta.get_device_from_user() Union[List[int], int][source]

Print the device list and query for a number input of the device, or devices.

Returns:

Practical interface for querying devices to be used within scripts.

Return type:

Union[List[int], int]

pytta.SPL(signal, nthOct=3, minFreq=100, maxFreq=4000)[source]

Calculate the signal’s Sound Pressure Level

The calculations are made by frequency bands and ranges from minFreq to maxFreq with nthOct bands per octave.

Returns:

Analysis

Return type:

The sound pressure level packed into an Analysis object.

pytta.find_delay(signal1, signal2)[source]

Cross Correlation alternative.

More efficient fft based method to calculate time shift between two signals.

>>> shift = pytta.find_delay(signal1,signal2)
pytta.resample(signal, newSamplingRate)[source]

Resample the timeSignal of the input SignalObj to the given sample rate using the scipy.signal.resample() function

pytta.corr_coef(signal1, signal2)[source]

Finds the correlation coefficient between two SignalObjs using the numpy.corrcoef() function.

pytta.peak_time(signal)[source]

Return the time at signal’s amplitude peak.

pytta.save(fileName: str = 'Fri Oct 21 03:23:19 2022', *PyTTaObjs)[source]

Main save function for .hdf5 and .pytta files.

The file format is chose by the extension applied to the fileName. If no extension is provided choose the default file format (.hdf5).

For more information on saving PyTTa objects in .hdf5 format see pytta.functions._h5_save documentation.

For more information on saving PyTTa objects in .pytta format see pytta.functions.pytta_save’ documentation. (DEPRECATED)

pytta.load(fileName: str)[source]

Main save function for .pytta and .hdf5 files.

pytta.weighting(kind='A', nth=None, freqs=None)[source]

Level weighting curve.

Parameters:
  • kind (TYPE, optional) – DESCRIPTION. The default is ‘A’.

  • nth (TYPE, optional) – DESCRIPTION. The default is None.

  • freqs (TYPE, optional) – DESCRIPTION. The default is None.

Returns:

The weighting curve in dB.

Return type:

np.ndarray

pytta.fft_degree(*args, **kwargs)[source]

Being replaced by pytta.utils.maths.fft_degree on version 0.1.0.

Power-of-two value that can be used to calculate the total number of samples of the signal.

>>> numSamples = 2**fftDegree
Parameters:
  • 0) (* timeLength (float =) – Value, in seconds, of the time duration of the signal or recording.

  • 1) (* samplingRate (int =) – Value, in samples per second, that the data will be captured or emitted.

Returns:

Power of 2 that can be used to calculate number of samples.

Return type:

fftDegree (float = 0)

pytta.plot_time(*sigObjs, xLabel: Optional[str] = None, yLabel: Optional[str] = None, yLim: Optional[list] = None, xLim: Optional[list] = None, title: Optional[str] = None, decimalSep: str = ',', timeUnit: str = 's')[source]

Plot provided SignalObjs togheter in time domain.

Saves xLabel, yLabel, and title when provided for the next plots.

  • sigObjs (), (SignalObj):

    non-keyworded input arguments with N SignalObjs.

  • xLabel (None), (str):

    x axis label.

  • yLabel (None), (str):

    y axis label.

  • yLim (None), (list):

    inferior and superior limits.

    >>> yLim = [-100, 100]
    
  • xLim (None), (str):

    left and right limits.

    >>> xLim = [0, 15]
    
  • title (None), (str):

    plot title.

  • decimalSep (‘,’), (str):

    may be dot or comma.

    >>> decimalSep = ',' # in Brazil
    
  • timeUnit (‘s’), (str):

    ‘ms’ or ‘s’.

matplotlib.figure.Figure object.

pytta.plot_time_dB(*sigObjs, xLabel: Optional[str] = None, yLabel: Optional[str] = None, yLim: Optional[list] = None, xLim: Optional[list] = None, title: Optional[str] = None, decimalSep: str = ',', timeUnit: str = 's')[source]

Plot provided SignalObjs togheter in decibels in time domain.

  • sigObjs (), (SignalObj):

    non-keyworded input arguments with N SignalObjs.

  • xLabel (‘Time [s]’), (str):

    x axis label.

  • yLabel (‘Amplitude’), (str):

    y axis label.

  • yLim (), (list):

    inferior and superior limits.

    >>> yLim = [-100, 100]
    
  • xLim (), (list):

    left and right limits

    >>> xLim = [0, 15]
    
  • title (), (str):

    plot title

  • decimalSep (‘,’), (str):

    may be dot or comma.

    >>> decimalSep = ',' # in Brazil
    
  • timeUnit (‘s’), (str):

    ‘ms’ or ‘s’.

matplotlib.figure.Figure object.

pytta.plot_freq(*sigObjs, smooth: bool = False, xLabel: Optional[str] = None, yLabel: Optional[str] = None, yLim: Optional[list] = None, xLim: Optional[list] = None, title: Optional[str] = None, decimalSep: str = ',')[source]

Plot provided SignalObjs magnitudes togheter in frequency domain.

  • sigObjs (), (SignalObj):

    non-keyworded input arguments with N SignalObjs.

  • xLabel (‘Time [s]’), (str):

    x axis label.

  • yLabel (‘Amplitude’), (str):

    y axis label.

  • yLim (), (list):

    inferior and superior limits.

    >>> yLim = [-100, 100]
    
  • xLim (), (list):

    left and right limits

    >>> xLim = [15, 21000]
    
  • title (), (str):

    plot title

  • decimalSep (‘,’), (str):

    may be dot or comma.

    >>> decimalSep = ',' # in Brazil
    

matplotlib.figure.Figure object.

pytta.plot_bars(*analyses, xLabel: Optional[str] = None, yLabel: Optional[str] = None, yLim: Optional[list] = None, xLim: Optional[list] = None, title: Optional[str] = None, decimalSep: str = ',', barWidth: float = 0.75, errorStyle: Optional[str] = None, forceZeroCentering: bool = False, overlapBars: bool = False, color: Optional[list] = None)[source]

Plot the analysis data in fractinal octave bands.

  • analyses (), (SignalObj):

    non-keyworded input arguments with N SignalObjs.

  • xLabel (‘Time [s]’), (str):

    x axis label.

  • yLabel (‘Amplitude’), (str):

    y axis label.

  • yLim (), (list):

    inferior and superior limits.

    >>> yLim = [-100, 100]
    
  • xLim (), (list):

    bands limits.

    >>> xLim = [100, 10000]
    
  • title (), (str):

    plot title

  • decimalSep (‘,’), (str):

    may be dot or comma.

    >>> decimalSep = ',' # in Brazil
    
  • barWidth (0.75), float:

    width of the bars from one fractional octave band. 0 < barWidth < 1.

  • errorStyle (‘standard’), str:

    error curve style. May be ‘laza’ or None/’standard’.

  • forceZeroCentering (‘False’), bool:

    force centered bars at Y zero.

  • overlapBars (‘False’), bool:

    overlap bars. No side by side bars of different data.

  • color (None), list:

    list containing the color of each Analysis.

matplotlib.figure.Figure object.

pytta.plot_spectrogram(*sigObjs, winType: str = 'hann', winSize: int = 1024, overlap: float = 0.5, xLabel: Optional[str] = None, yLabel: Optional[str] = None, yLim: Optional[list] = None, xLim: Optional[list] = None, title: Optional[str] = None, decimalSep: str = ',')[source]

Plots provided SignalObjs spectrogram.

  • sigObjs (), (SignalObj):

    non-keyworded input arguments with N SignalObjs.

  • winType (‘hann’), (str):

    window type for the time slicing.

  • winSize (1024), (int):

    window size in samples

  • overlap (0.5), (float):

    window overlap in %

  • xLabel (‘Time [s]’), (str):

    x axis label.

  • yLabel (‘Frequency [Hz]’), (str):

    y axis label.

  • yLim (), (list):

    inferior and superior frequency limits.

    >>> yLim = [20, 1000]
    
  • xLim (), (list):

    left and right time limits

    >>> xLim = [1, 3]
    
  • title (), (str):

    plot title

  • decimalSep (‘,’), (str):

    may be dot or comma.

    >>> decimalSep = ',' # in Brazil
    

List of matplotlib.figure.Figure objects for each item in curveData.

pytta.plot_waterfall(*sigObjs, step=512, n=8192, fmin=None, fmax=None, pmin=None, pmax=None, tmax=None, xaxis='linear', time_tick=None, freq_tick=None, mag_tick=None, tick_fontsize=None, fpad=1, delta=60, dBref=2e-05, fill_value='pmin', fill_below=True, overhead=3, winAlpha=0, plots=['waterfall'], show=True, cmap='jet', alpha=[1, 1], saveFig=False, figRatio=[1, 1, 1], figsize=(950, 950), camera=[2, 1, 2])[source]

This function was gently sent by Rinaldi Polese Petrolli.

# TO DO

Keyword Arguments:
  • (default (filtered {bool} -- [description]) – {10})

  • (default – {None})

  • (default – {20})

  • (default – {None})

  • (default – {0})

  • (default – {None})

  • (default – {-72})

  • (default – {14})

  • (default – {‘jet’})

  • (default – {False})

  • (default – {True})

  • (default – {True})

  • (default – {False})

  • (default – {1})

  • (default – {(20, 8)})

  • (default – {0})

  • (default – {False})

  • (default – {False})

  • (default – {False})

  • (default – {0.70})

  • (default – {3})

  • (default – {None})

  • (default – {True})

Returns:

[type] – [description]