Generate

This submodule provides the tools for instantiating the measurement and signal objects to be used. We strongly recommend the use of this submodule instead of directly instantiating classes, except when necessary.

The signal generating functions already have set up a few good practices on signal generation and reproduction through audio IO interfaces, like silences at beginning and ending of the signal, as well as fade ins and fade out to avoid abrupt audio currents from flowing and causing undesired peaks at start/ending of reproduction.

On the measurement side, it tries to set up the environment by already giving excitation signals, or by generating a SWEEP from default values

User intended functions:

>>> pytta.generate.sin()
>>> pytta.generate.sweep()
>>> pytta.generate.random_noise()
>>> pytta.generate.impulse()
>>> pytta.generate.measurement()

For further information see the specific function documentation

@authors: - João Vitor Gutkoski Paes, joao.paes@eac.ufsm.br - Matheus Lazarin Alberto, mtslazarin@gmail.com

pytta.generate.sin(Arms=0.5, freq=1000, timeLength=1, phase=6.283185307179586, samplingRate=44100, fftDegree=None)[source]

Generates a sine signal with the traditional parameters plus some PyTTa options.

  • Arms (float) (optional):

    The signal’s RMS amplitude.

    >>> Apeak = Arms*sqrt(2);
    
  • freq (float) (optional):

    Nothing to say;

  • timeLength (float) (optional):

    Sine timeLength in seconds;

  • fftDegree (int) (optional);

    2**fftDegree signal’s number of samples;

  • phase (float) (optional):

    Sine phase in radians;

  • samplingRate (int) (optional):

    Nothing to say;

pytta.generate.sweep(freqMin=None, freqMax=None, samplingRate=None, fftDegree=None, startMargin=None, stopMargin=None, method='logarithmic', windowing='hann')[source]

Generates a chirp signal defined by the “method” input, windowed, with silence interval at the beggining and end of the signal, plus a hanning fade in and fade out.

>>> x = pytta.generate.sweep()
>>> x.plot_time()

Return a signalObj containing a logarithmic chirp signal from 17.8 Hz to 22050 Hz, with a fade in beginning at 17.8 Hz time instant and ending at the 20 Hz time instant; plus a fade out beginning at 20000 Hz time instant and ending at 22050 Hz time instant.

The fade in and the fade out are made with half hanning window. First half for the fade in and last half for the fade out. Different number of points are used for each fade, so the number of time samples during each frequency is respected.

  • freqMin (20), (float)

  • freqMax (20), (float)

  • samplingRate (44100), (int)

  • fftDegree (18), (float)

  • startMargin (0.3), (float)

  • stopMargin (0.7), (float)

  • method (logarithmic’), (string)

  • windowing (‘hann’), (string)

pytta.generate.random_noise(kind='white', samplingRate=None, fftDegree=None, startMargin=None, stopMargin=None, windowing='hann')[source]

See colored_noise.

pytta.generate.colored_noise(color: str = 'white', samplingRate: Optional[int] = None, fftDegree: Optional[int] = None, numChannels: Optional[int] = None, startMargin: Optional[float] = None, stopMargin: Optional[float] = None, windowing: str = 'hann')[source]

Power law noise generator.

Based on the algorithm in: Timmer, J. and Koenig, M.: On generating power law noise. Astron. Astrophys. 300, 707-710 (1995)

Generate random noise with respect to the (1/f)**B rate. f stands for frequency and B is an integer power.

The colors and its spectrum characteristics:

  • Purple | Differentiated:
    • +6.02 dB/octave | +20 dB/decade | B = -2;

    • color: ‘purple’, ‘diff’, ‘differentiated’;

  • Blue | Azure:
    • +3.01 dB/octave | +10 dB/decade | B = -1;

    • color: ‘blue’, ‘azure’

  • White | Flat:
    • +0.00 dB/octave | +0 dB/decade | B = 0;

    • color: ‘white’, ‘flat’;

  • Pink | Flicker:
    • -3.01 dB/octave | -10 dB/decade | B = 1;

    • color: ‘pink’, ‘flicker’, ‘1/f’;

  • Red | Brownian:
    • -6.02 dB/octave | -20 dB/decade | B = 2;

    • color: ‘red’, ‘brown’, ‘brownian’;

The output signal will have startMargin silence at the beginning of the waveform, and stopMargin silence at the end.

There is a fade-in between the starting silence and the noise itself that occurs during 5% of the total noise duration.

@author: Chum4k3r

pytta.generate.impulse(samplingRate=None, fftDegree=None)[source]

Generates a normalized impulse signal at time zero, with zeros to fill the time length

pytta.generate.measurement(kind='playrec', samplingRate=None, freqMin=None, freqMax=None, device=None, inChannels=None, outChannels=None, *args, **kwargs)[source]

Generates a measurement object of type Recording, Playback and Recording, Transferfunction, with the proper initiation arguments, a sampling rate, frequency limits, audio input and output devices and channels

>>> pytta.generate.measurement(kind,
                               [lengthDomain,
                               fftDegree,
                               timeLength,
                               excitation,
                               outputAmplification],
                               samplingRate,
                               freqMin,
                               freqMax,
                               device,
                               inChannels,
                               outChannels,
                               comment)

The parameters between brackets are different for each value of the (kind) parameter.

>>> msRec = pytta.generate.measurement(kind='rec')
>>> msPlayRec = pytta.generate.measurement(kind='playrec')
>>> msFRF = pytta.generate.measurement(kind='frf')

The input arguments may be different for each measurement kind.

Options for (kind=’rec’):

  • lengthDomain: ‘time’ or ‘samples’, defines if the recording length

    will be set by time length, or number of samples;

  • timeLength: [s] used only if (domain=’time’), set the duration of the

    recording, in seconds;

  • fftDegree: represents a power of two value that defines the number of

    samples to be recorded:

    >>> numSamples = 2**fftDegree
    
  • samplingRate: [Hz] sampling frequency of the recording;

  • freqMin: [Hz] smallest frequency of interest;

  • freqMax: [Hz] highest frequency of interest;

  • device: audio I/O device to use for recording;

  • inChannels: list of active channels to record;

  • comment: any commentary about the recording.

Options for (kind=’playrec’):

  • excitation: object of SignalObj class, used for the playback;

  • outputAmplification: output gain in dB;

  • samplingRate: [Hz] sampling frequency of the recording;

  • freqMin: [Hz] smallest frequency of interest;

  • freqMax: [Hz] highest frequency of interest;

  • device: audio I/O device to use for recording;

  • inChannels: list of active channels to record;

  • outChannels: list of active channels to send the playback signal, for

    M channels it is mandatory for the excitation signal to have M columns in the timeSignal parameter.

  • comment: any commentary about the recording.

Options for (kind=’frf’):

  • same as for (kind=’playrec’);

  • regularization: [boolean] option for Kirkeby regularization

pytta.generate.stream(IO='IO', device=None, integration=None, samplingRate=None, inChannels=None, outChannels=None, duration=None, excitation=None, callback=None, *args, **kwargs)[source]