Mercurial > hg > cm
diff equalLoudness.py @ 10:c5e7162fb8ea
* A bit of commenting
author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
---|---|
date | Tue, 22 Apr 2014 01:20:56 +0100 |
parents | ef62cca13f36 |
children | ca98f5f26bcb |
line wrap: on
line diff
--- a/equalLoudness.py Tue Apr 22 00:55:19 2014 +0100 +++ b/equalLoudness.py Tue Apr 22 01:20:56 2014 +0100 @@ -12,6 +12,14 @@ def get_elc_range(xtol=0.0000005, verbose=False): """ Plot the prediction of the equal loudness contours of frequencies for a range of SPL levels from 10 to 120dB, intervals of 10dB. + + Parameters: + * xtol (type: float) - x tolerance of fsolve + * verbose (type: boolean) - I tell you what I know + + Returns: + * elc (type: numpy array of floats) - SPL at which each frequency in fArray is equal to i*10 phons, where i is the first dimension index + """ levels = range(20, 100, 20) elc = np.zeros((len(levels), len(fArray))) @@ -29,6 +37,14 @@ def get_elc(SPL = 90, xtol=0.0000005, verbose=False): """ Plot the prediction of the equal loudness contours for specified level. + + Parameters: + * SPL (type: float) - SPL of the reference, or the loudness level + * xtol (type: float) - x tolerance of fsolve + * verbose (type: boolean) - I tell you what I know if you give me True + + Returns: + * elc (type: numpy array of floats) - SPL at which each frequency in fArray is equal to SPL phons """ fs = 44100 t = np.array(range(44100)) @@ -53,7 +69,14 @@ def get_temporal_descrimination(verbose=False): """ - Return the prediction of STL and peak of STL for tones with short durations. + Return the prediction of STL and peak of STL for tones with short duration. + + Parameters + * verbose (type: boolean) - I tell you what I know if you give me True + + Returns: + * STLMax (type: array-like of floats) - peak short term loudness for each duration + * STL (type: array-like of floats) - short term loudness function for each duration """ @@ -107,7 +130,10 @@ * fs (type: int) - sampling frequency * SPL (type: float) - the level to start searching at * xtol (type: float) - x tolerance of fsolve - * verbose (type: boolean) - tell me everything I need to know + * verbose (type: boolean) - I tell you what I know if you give me True + + Returns: + x (type: float) - sound pressure level at equal loudness """ x = opt.fsolve(getLoudnessDifference, SPL, (input, fs, refL, verbose), factor=0.1, xtol=xtol) @@ -122,6 +148,9 @@ * SPL (type: float) - the level to set input to * input (type: array-like of floats) - input signal * fs (type: int) - sampling frequency + + Returns: + difference (type: float) - difference in loudness """ if(verbose): print "SPL: ", SPL @@ -136,18 +165,28 @@ def rms(input): """ RMS of the input + + Parameters: + * input (type: array-like of floats): input array + + Returns: + * output (type: float): the rms """ - output = np.sqrt(np.mean(input**2)) + output = np.sqrt(np.mean(input**2, -1)) return output -def plot_elc(ppOut, show = True): +def plot_elc(elc, show = True): """ Plot an equal loudness contour + + Parameters: + * elc (type: array-like of floats) - equal loudness contour x, obtained from get_elc + * show (type: boolean) - show the figure or turn hold on """ plt.gca().set_xscale('log') plt.ylim((0,170)) - plt.plot(fArray, ppOut, 'x-') + plt.plot(fArray, elc, 'x-') if(show): plt.show() else: