apollon.signal.tools module

apollon/signal/tools.py (c) Michael Blaß 2016

Signal processing tools

acf Normalized autocorrelation. acf_pearson Normalized Pearson acf. amp2db Transform amplitude to dB. corr_coef_pearson Correlation coefficient after Pearson. freq2mel Transform frequency to mel. mel2freq Transform mel to frequency. frq2bark Transform frequency to Bark scale. maxamp Maximal amplitude of signal. minamp Minimal amplitude of signal. normalize Scale data betwee -1.0 and 1.0. noise Generate withe noise. sinusoid Generate sinusoidal signal. zero_padding Append array with zeros. trim_spectrogram Trim spectrogram to a frequency range.

Normalized estimate of the autocorrelation function of inp_sig by means of cross correlation.


Normalized estimate of the autocorrelation function of inp_sig by means of pearson correlation coefficient.

apollon.signal.tools.amp2db(amp, ref: float = 2e-05) → numpy.ndarray

Transform amplitude to dB.

Return a copy of amp in dB scaling regarding a reference pressure ref. The reference pressure is commonly the human hearing treshold at 20 micro Pa.

amp is supposed to be a inon-negative scalar or numpy.array taken from a magnitude spectrum.

This function set all values of amp smaller then ref to ref, hence eliminating inaudible singnal energy in the log domain.

amp (array-like or number) Given amplitude values.
Returns:(ndarray) values in dB.
apollon.signal.tools.corr_coef_pearson(x, y)

Fast perason correlation coefficient.


Transforms Hz to Mel-Frequencies.

f: (real number) Frequency in Hz
Returns:(real number) Mel-Frequency

Maximal absolute elongation within the signal.

sig (array-like) Input signal.
Returns:(scalar) Maximal amplitude.

Transforms Mel-Frequencies to Hz.

z: (real number) Mel-Frequency.
Returns:(real number) Frequency in Hz.

Minimal absolute elongation within the signal.

sig (array-like) Input signal.
Returns:(scalar) Maximal amplitude.
apollon.signal.tools.noise(level, n=9000)

Generate withe noise.

level (float) Noise level as standard deviation of a gaussian. n (int) Length of noise signal in samples.
Returns:(ndarray) White noise signal.

Normlize a signal to [-1.0, 1.0].

sig (np.nadarray) Signal to normalize.
Returns:(np.ndarray) Normalized signal.
apollon.signal.tools.sinusoid(f, amps=1, fs=9000, length=1, retcomps=False)

Generate sinusoidal signal.


f (iterable) Component frequencies. amps (int or interable) Amplitude of each component in f.

If amps is an integer each component of f will be scaled according to amps. If amps is an iterable each frequency will be scaled with the respective amplitude.

fs (int) Sample rate. length (number) Length of signal in seconds. retcomps(bool) If True return the components of the signal,

otherwise return the sum.
Returns:(ndarray) Sinusoidal signal.
apollon.signal.tools.trim_spectrogram(inp: numpy.ndarray, frqs: numpy.ndarray, low: float, high: float) → numpy.ndarray

Trim spectrogram and frequency array to the frequency range [low, high].

  • inp (ndarray) –
  • frqs (ndarray) –
  • low (float) –
  • high (float) –

(tuple) (trimmed_spectrogram, trimmed_frqs)

apollon.signal.tools.zero_padding(sig, n)

Append n zeros to signal. sig must be 1D array.

sig (np.ndarray) a list of data points. n (int) number of zeros to be appended.
Returns:(array) zero-padded input signal.