pytimbre.spectral.fundamental_frequency.FundamentalFrequencyCalculator¶
- class pytimbre.spectral.fundamental_frequency.FundamentalFrequencyCalculator(f0: float = 10, f1: float = 10000, frequency_window_size: int = 2048, temporal_window: int = 256)¶
Bases:
objectThere are many ways to calculate the fundamental frequency of a waveform. However, many of the methods require information that can easily be combined with the functions and classes that exist within the PyTimbre modules. This class gathers the methods into one system and builds a collection of public and protected elements to access the fundamental frequency calculators.
- __init__(f0: float = 10, f1: float = 10000, frequency_window_size: int = 2048, temporal_window: int = 256)¶
This build the class and initializes the element that are required for the calculation of the fundamental frequency.
- Parameters:
f0 – float the starting frequency for the analysis
f1 – float the ending frequency for the analysis
Methods
__init__([f0, f1, frequency_window_size, ...])This build the class and initializes the element that are required for the calculation of the fundamental frequency.
absolute_thresholding(cmndf, threshold, ...)Absolute thresholding: Set an absolute threshold and choose the smallest value of tau that gives a minimum of d' deeper than that threshold.
aperiodicity(frame, lag_est)Compute aperiodicity of given frame (serves as indicator for reliability or voicing detection).
Computes Cumulative Mean Normalized Difference Function (CMNDF).
fundamental_by_peaks(spectrum)This function attempts to determine the fundamental by first scanning the frequency spectrum for peaks.
fundamental_by_time(wfm)This function calculates the fundamental frequency based on the YIN function that only requires the collection of samples to determine the fundamental frequency
fundamental_swipe(spectrum)parabolic_interpolation(y1, y2, y3)Parabolic interpolation of an extremal value given three samples with equal spacing on the x-axis.
pitch_strength_one(erbs_frequencies, ...)Compute pitch strength for one pitch candidate
primes(n)Returns a set of n prime numbers
Parabolic interpolation between pitch candidates using pitch strength
- static absolute_thresholding(cmndf, threshold, lag_min, lag_max, parabolic_interp=True)¶
Absolute thresholding: Set an absolute threshold and choose the smallest value of tau that gives a minimum of d’ deeper than that threshold. If none is found, the global minimum is chosen instead.
- Parameters:
cmndf (ndarray) – Cumulative Mean Normalized Difference Function
threshold (float) – Threshold
lag_min (float) – Minimal lag
lag_max (float) – Maximal lag
parabolic_interp (bool) – Switch to activate/deactivate parabolic interpolation
- static aperiodicity(frame, lag_est)¶
Compute aperiodicity of given frame (serves as indicator for reliability or voicing detection).
- Parameters:
frame (ndarray) – Frame
lag_est (float) – Estimated lag
- Returns:
ap – Aperiodicity (the lower, the more reliable the estimate)
- Return type:
float
- static cumulative_mean_normalized_difference_function(frame, lag_max)¶
Computes Cumulative Mean Normalized Difference Function (CMNDF).
- Parameters:
frame (ndarray) – Audio frame
lag_max (int) – Maximum expected lag in the CMNDF
- Returns:
cmndf – Cumulative Mean Normalized Difference Function
- Return type:
ndarray
- fundamental_by_peaks(spectrum: Spectrum)¶
This function attempts to determine the fundamental by first scanning the frequency spectrum for peaks. Then the peaks are examined to determine the harmonic relationship between the peaks within the spectrum. If there are insufficient peaks within the spectrum, we return the frequency with the maximum value. Otherwise, we return the value that has the closest set of harmonically related frequencies.
- fundamental_by_time(wfm: Waveform)¶
This function calculates the fundamental frequency based on the YIN function that only requires the collection of samples to determine the fundamental frequency
- Parameters:
wfm – Waveform The PyTimbre object that holds the samples, sample rate and start time of the signal we want to process.
- static parabolic_interpolation(y1, y2, y3)¶
Parabolic interpolation of an extremal value given three samples with equal spacing on the x-axis. The middle value y2 is assumed to be the extremal sample of the three.
- Parameters:
y1 (f(x1))
y2 (f(x2))
y3 (f(x3))
- Returns:
x_interp (Interpolated x-value (relative to x3-x2))
y_interp (Interpolated y-value, f(x_interp))
- static pitch_strength_one(erbs_frequencies, normalized_loudness, pitch_candidate)¶
Compute pitch strength for one pitch candidate
- static primes(n)¶
Returns a set of n prime numbers
- static swipe_parabolic_interpolation(pitch_strength, strength_threshold, pc)¶
Parabolic interpolation between pitch candidates using pitch strength