simplecochlea.utils package

Submodules

simplecochlea.utils.utils_cochlea module

simplecochlea.utils.utils_cochlea.erbscale(fs, fmin_hz, fmax_hz, n_filters, q_ear=9.26449, bw_min=24.7, bw_mult=1)[source]

The erbscale gives an approximation of the bandwidth of the filters in human hearing.

Parameters:
fs : float

Sampling Frequency (Hz)

fmin_hz : float

Minimum frequency (Hz)

fmax_hz : float

Maximum frequency (Hz)

n_filters : int

Number of filters in the range [fmin_hz, fmax_hz]

q_ear=9.26449, bw_min=24.7, bw_mult=1

Default Glasberg and Moore parameters.

Returns:
wn : array [n_filters*2]

Normalized cutoff frequencies for all filters to be used for filter design (half-cycle / sample)

cf : array

Center frequency (Hz)

simplecochlea.utils.utils_cochlea.erbspace(fmin_hz, fmax_hz, N, q_ear=9.26449, bw_min=24.7)[source]

Gives the center frequencies of N auditory filters between fmin_hz and fmax_hz using the ERB scale.

Parameters:
fmin_hz : float

Minimum frequency (Hz)

fmax_hz : float

Maximum frequency (Hz)

N : int

Number of filters in the range [fmin_hz, fmax_hz]

q_ear=9.26449, bw_min=24.7

Default Glasberg and Moore parameters.

simplecochlea.utils.utils_cochlea.find_equal_areas_limits(poly_coeff, n_areas, xmin, xmax)[source]

Given a polynomial function defined by its polynomial coefficients poly_coeff, compute the limits of n_areas between the x-coordinate xmin and xmax, so that all these areas are equal. In other words, it divides the area under the curve defined by the polynomial function into n equal areas.

Parameters:
poly_coeff : array | list

Polynomial coefficients

n_areas : int

Number of areas

xmin : float

Minimum x-coordinate

xmax : float

Maximum x-coordinate

Returns:
x_center : array

x-coordinates of the center of the areas

x_start : array

x-coordinates of the left limit of the areas

x_end : array

x-coordinates of the right limit of the areas

simplecochlea.utils.utils_cochlea.linearscale(fs, fmin_hz, fmax_hz, n_filters)[source]

Design n_filters band-pass filters ranging from fmin_hz to fmax with a central frequencies increases linearly and with a fixed bandwidth defined such that the overlap of the frequency responses of adjacent filters is equal to half the bandwidth.

Parameters:
fs : float

Sampling frequency (Hz)

fmin_hz : float

Minimum frequency (Hz)

fmax_hz : float

Maximum frequency (Hz)

n_filters : int

Number of filters in the range [fmin_hz, fmax_hz]

Returns:
wn : array [n_filters*2]

Normalized cutoff frequencies for all filters to be used for filter design (half-cycle / sample)

cf : array

Center frequency (Hz)

simplecochlea.utils.utils_cochlea.musicscale(fs, fmin_hz, fmax_hz, n_filters, poly_coeff=[], bw_mult=10)[source]

Experimental - Try to compute equal-power band in a mean spectrum of music segments - Do not use

simplecochlea.utils.utils_cochlea.normalize_vector(x)[source]

Normalize vector x between -1 and 1

Parameters:
x : array | list

input array

Returns:
x_norm : array

normalized array

simplecochlea.utils.utils_cochlea.plot_input_output(input_sig, output_sig, fs, input_sig_label, output_sig_label, same_colobar=0)[source]
simplecochlea.utils.utils_cochlea.t_spikes_to_spikerate(t_spikes, fs, n_pnts, kernel_duration=0.015)[source]

Compute a mean firing rate over time using a gaussian kernel from the spike times. The kernel duration is set by the kernel_duration parameter.

Parameters:
t_spikes : list |array

Spike times (s)

fs : float

Sampling frequency (Hz)

n_pnts : int

Number of points in the output signal

kernel_duration : float

Duration of the kernel (s). Default: 0.015 s

Returns:
spiking_rate_smooth : array

Smooth firing rate

simplecochlea.utils.utils_freqanalysis module

simplecochlea.utils.utils_freqanalysis.find_peaks(x, thresh_from_baseline, min_dist=1)[source]

Algorithm for detecting peaks above the baseline. A peak should be thresh_from_baseline above the baseline to be detected.

Parameters:
x : array

Input array

thresh_from_baseline : float

Threshold for detecting peaks from the baseline, in dB

min_dist : int

Minimum distance between peak indices - Default : 1

Returns:
peak_indexes_sel : array

Peak indices

peak_amp : array

Peak amplitudes

simplecochlea.utils.utils_freqanalysis.find_spectrum_peaks(x, fs, fmin=[], fmax=[], nfft=4092, thresh_db_from_baseline=6, do_plot=False)[source]

Find the peaks in the Power Spectral Density of signal x between fmin and fmax. A peak is detected if its amplitude is over the threshold defined by thresh_db_from_baseline.

Parameters:
x : array

Input signal

fs : float

Sampling frequency (Hz)

fmin : float

Lower range frequency (Hz)

fmax : float

Upper range frequency (Hz)

nfft : int

Number of points for the FFT - Default : 4092

thresh_db_from_baseline : float

Threshold for detecting peaks from the baseline, in dB - Default: 6

do_plot : bool

If True, plot the PSD and the peaks - Default : False

Returns:
peak_freqs : array

Peaks frequency (Hz)

peak_amps_db : array

Peaks amplitude (dB)

pxx_sel_db : array

Power Spectral Density (dB)

freqs_sel : array

frequency associated with the PSD

simplecochlea.utils.utils_freqanalysis.get_spectral_features(x, fs, fmin=[], fmax=[], nfft=2048, do_plot=False, logscale=True)[source]
Compute some spectral features using the librosa library :
  • Spectrum centroid
  • Spectrum rolloff
  • Peaks in the power spectral density
Parameters:
x : array

Input array. Must be 1D.

fs : float

Sampling frequency (Hz)

fmin : float

Minimum frequency (Hz)

fmax : float

Maximum frequency (Hz)

nfft : int

Number of points for the FFT - Default: 2048

do_plot : bool

If true, plot the spectral features - Default: False

logscale : bool

If True, use a log-scale for the x-axis - Default : True

Returns:
spect_centroid : float

Spetrum centroid. See librosa.feature.spectral_centroid()

spect_rolloff : float

Spectrum rolloff. See librosa.feature.spectral_centroid()

peaks_freq : array

Peak in the spectrum

pxx_db : array

Power Spectral Density (PSD), in dB

freqs : array

Frequency associated with the PSD

Module contents