Signal Objects

class pytta.SignalObj(signalArray=array([[0.0]], dtype=float32), domain='time', *args, **kwargs)[source]

Signal object class.

Holds real time signals and their FFT spectra, which are symmetric. Therefore only half of the frequency domain signal is stored.

  • signalArray (ndarray | list), (NumPy array):

    signal at specified domain. For ‘freq’ domain only half of the spectra must be provided. The total numSamples should also be provided.

  • domain (‘time’), (str):

    domain of the input array. May be ‘freq’ or ‘time’. For ‘freq’ additional inputs should be provided:

    • numSamples (len(SignalArray)*2-1), (int):

      Total signal’s number of samples. The default value takes into account a signal with even number of samples.

  • samplingRate (44100), (int):

    signal’s sampling rate;

  • signalType (‘power’), (‘str’):

    type of the input signal. ‘power’ for finite power signal (infinite energy) and ‘energy’ for energy signal (power tends to zero);

  • freqMin (20), (int):

    minimum frequency bandwidth limit;

  • freqMax (20000), (int):

    maximum frequency bandwidth limit;

  • comment (‘No comments.’), (str):

    some commentary about the signal or measurement object;

  • timeSignal (), (NumPy ndarray):

    signal at time domain;

  • timeVector (), (NumPy ndarray):

    time reference vector for timeSignal;

  • freqSignal (), (NumPy ndarray):

    signal at frequency domain;

  • freqVector (), (NumPy ndarray):

    frequency reference vector for freqSignal;

  • channels (), (_base.ChannelsList):

    ChannelsList object with info about each SignalObj channel;

  • unit (None), (str):

    signal’s unit. May be ‘V’ or ‘Pa’;

  • channelName (dict), (dict/str):

    channels name dict;

  • lengthDomain (‘time’), (str):

    input array’s domain. May be ‘time’ or ‘samples’;

  • timeLength (seconds), (float):

    signal’s duration;

  • fftDegree (fftDegree), (float):

    2**fftDegree signal’s number of samples;

  • numSamples (samples), (int):

    signal’s number of samples;

  • coordinates (list), (list):

    position in space for the current SignalObj;

  • orientation (list), (list):

    orientation for the current SignalObj;

  • numChannels (int), (int):

    number of channels;

  • crop(startTime, endTime):

    crops the timeSignal within the provided time interval;

  • max_level():

    return the channel’s max levels;

  • rms():

    return the effective value for the entire signal;

  • spl():

    gives the sound pressure level for the entire signal. Calibration is needed;

  • play():

    reproduce the timeSignal with default output device;

  • plot_time():

    generates the signal’s historic graphic;

  • plot_time_dB():

    generates the signal’s historic graphic in dB;

  • plot_freq():

    generates the signal’s spectre graphic;

  • plot_spectrogram():

    generates the signal’s spectrogram graphic;

  • calib_voltage(refSignalObj,refVrms,refFreq):

    voltage calibration from an input SignalObj;

  • calib_pressure(refSignalObj,refPrms,refFreq):

    pressure calibration from an input SignalObj;

  • save_mat(filename):

    save a SignalObj to a .mat file;

For further information on methods see its specific documentation.

property freqSignal

Return half of the RMS spectrum. Normalized in case of a power signal.

split(channels: Optional[list] = None) list[source]

Split the SignalObj channels into several SignalObjs. If the ‘channels’ input argument is given split the specified channel numbers, otherwise split all channels.

  • channels (None), (list):

    specified channels to split from the SignalObj;

  • spltdChs (list):

    a list containing SignalObjs for each specified/all channels;

crop(startTime, endTime)[source]

crop crop the signal duration in the specified interval

Parameters:
  • startTime (int, float) – start time for cropping

  • endTime (int, float or str) – end time for cropping

channelMean()[source]

Returns a signal object with the arithmetic mean channel-wise (column-wise) with same number of samples and sampling rate.

play(channels: Optional[list] = None, mapping: Optional[list] = None, latency='low', **kwargs)[source]

Play method.

Only one SignalObj channel can be played through each sound card output channel. Check the input parameters below

For usage insights, check the examples folder.

  • channels (None), (list):

    list of channel numbers to play. If not specified all existent channels will be chosen;

  • mapping (None), (list):

    list of channel numbers of your sound card (starting with 1) where the specified channels of the SignalObj shall be played back on. Must have the same length as number of SignalObj’s specified channels (except if SignalObj is mono, in which case the signal is played back on all possible output channels). Each channel number may only appear once in mapping;

plot_time(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]

Plots the signal in time domain.

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

  • 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.

plot_time_dB(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]

Plots the signal in decibels in time domain.

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

  • 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.

plot_freq(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]

Plots the signal decibel magnitude in frequency domain.

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

  • smooth (False), (bool):

    option for curve smoothing. Uses scipy.signal.savgol_filter. Preliminar implementation. Needs review.

  • 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.

plot_spectrogram(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 a signal spectrogram.

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

  • 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.

calib_voltage(chIndex, refSignalObj, refVrms=1, refFreq=1000)[source]

Use informed SignalObj with a calibration voltage signal, and the reference RMS voltage to calculate and apply the Correction Factor.

>>> SignalObj.calibVoltage(chIndex,refSignalObj,refVrms,refFreq)
  • chIndex (), (int):

    channel index for calibration. Starts in 0;

  • refSignalObj (), (SignalObj):

    SignalObj with the calibration recorded signal;

  • refVrms (1.00), (float):

    the reference voltage provided by the voltage calibrator;

  • refFreq (1000), (int):

    the reference sine frequency provided by the voltage calibrator;

calib_pressure(chIndex, refSignalObj, refPrms=1.0, refFreq=1000)[source]

Use informed SignalObj, with a calibration acoustic pressure signal, and the reference RMS acoustic pressure to calculate and apply the Correction Factor.

>>> SignalObj.calibPressure(chIndex,refSignalObj,refPrms,refFreq)
  • chIndex (), (int):

    channel index for calibration. Starts in 0;

  • refSignalObj (), (SignalObj):

    SignalObj with the calibration recorded signal;

  • refPrms (1.00), (float):

    the reference pressure provided by the acoustic calibrator;

  • refFreq (1000), (int):

    the reference sine frequency provided by the acoustic calibrator;

__truediv__(other)[source]

Frequency domain division method

For deconvolution divide by a SignalObj. For gain operation divide by a number.

__mul__(other)[source]

Gain apply method/FFT convolution

__add__(other)[source]

Time domain addition method

__sub__(other)[source]

Time domain subtraction method

class pytta.ImpulsiveResponse(excitation=None, recording=None, method='linear', winType=None, winSize=None, overlap=None, regularization=True, ir=None, *args, **kwargs)[source]

This class is a container of SignalObj, intended to calculate impulsive responses and store them.

The access to this class is provided by itself and as an output of the FRFMeasure.run() method.

  • excitation (SignalObj) (optional)::

    The signal-like object used as excitation signal on the measurement-like object. Optional if ‘ir’ is provided;

  • recording (SignalObj) (optional)::

    The recorded signal-like object, obtained directly from the audio interface used on the measurement-like object. Optional if ‘ir’ is provided;

  • method (str):

    The way that the impulsive response should be computed, accepts “linear”, “H1”, “H2” and “Ht” as values:

    • “linear”:

      Computes using the spectral division of the signals;

    • “H1”:

      Uses power spectral density Ser divided by See, with “e” standing for “excitation” and “r” for “recording;

    • “H2”:

      uses power spectral density Srr divided by Sre, with “e” standing for “excitation” and “r” for “recording;

    • “Ht”:

      uses the formula: TODO;

  • winType (str | tuple) (optional):

    The name of the window used by the scipy.signal.csd function to compute the power spectral density, (only for method=”H1”, method=”H2” and method=”Ht”). The possible values are:

    >>> boxcar, triang, blackman, hamming, hann, bartlett,
        flattop, parzen, bohman, blackmanharris, nuttall,
        barthann, kaiser (needs beta), gaussian (needs standard
        deviation), general_gaussian (needs power, width),
        slepian (needs width), dpss (needs normalized half-
        bandwidth), chebwin (needs attenuation), exponential
        (needs decay scale), tukey (needs taper fraction).
    

    If the window requires no parameters, then window can be a string.

    If the window requires parameters, then window must be a tuple with the first argument the string name of the window, and the next arguments the needed parameters.

  • winSize (int) (optional):

    The size of the window used by the scipy.signal.csd function to compute the power spectral density, (only for method=”H1”, method=”H2” and method=”Ht”);

  • overlap (float) (optional):

    the overlap ratio of the window used by the scipy.signal.csd function to compute the power spectral density, (only for method =”H1”, method=”H2” and method=”Ht”).

  • regularization (bool), (True):

    Do Kirkeby regularization with a packing filter for the impulsive response’s time signature. Details in ‘Advancements in impulsive response measurements by sine sweeps’ Farina, 2007.

  • ir (SignalObj) (optional):

    An calculated impulsive response. Optional if ‘excitation’ and ‘recording’ are provided;

The class’s attribute are described next:

  • irSignal | IR | tfSignal | TF | systemSignal:

    All names are valid, returns the computed impulsive response signal-like object;

  • methodInfo:

    Returns a dict with the “method”, “winType”, “winSize” and “overlap” parameters.

  • plot_time():

    generates the systemSignal historic graphic;

  • plot_time_dB():

    generates the systemSignal historic graphic in dB;

  • plot_freq():

    generates the systemSignal spectral magnitude graphic;