pyyeti.psd.get_freq_oct¶
- pyyeti.psd.get_freq_oct(n, frange=(1.0, 10000.0), exact=False, trim='outside', anchor=None)[source]¶
Get frequency vector on an octave scale.
- Parameters:
n (scalar) – Specify octave band: 1 for full octave, 3 for 1/3 octave, 6 for 1/6, etc.
frange (1d array_like; optional) – Specifies bounds for the frequencies according to input trim. Only the first and last elements are used. If the first element <= 0.0, 1.0 is used instead. See also the trim input.
trim (string; optional) – Specify how to trim frequency vector to frange:
trim
Description
‘inside’
- All frequencies inside frange:
F_lower[0] >= frange[0];F_upper[-1] <= frange[-1]
‘center’
- Center frequencies inside frange:
F[0] >= frange[0];F[-1] <= frange[-1]
‘outside’
First band includes
frange[0]and last band includesfrange[-1]‘band’
Same as ‘outside’
exact (bool; optional) – If False, return an approximate octave scale so that it hits the power of 10s, achored at 1 Hz by default (see anchor). If True, return an exact octave scale, anchored at 1000 Hz by default.
anchor (scalar or None; optional) – If scalar, it specifies the anchor. If None, the anchor used is specified under exact above (1 or 1000).
- Returns:
F (1d ndarray) – Contains the band center frequencies on an octave scale.
F_lower (1d ndarray) – Same size as F, band lower frequencies.
F_upper (1d ndarray) – Same size as F, band upper frequencies.
Notes
If exact is False, the center, lower, and upper frequencies are computed from (where \(i\) and \(j\) are integers according to frange and trim):
\[\begin{split}\begin{aligned} F &= anchor \cdot 10^{3 [i, i+1, i+2, ..., j] / (10 n)} \\ F_{lower} &= F/10^{3/(20 n)} \\ F_{upper} &= F \cdot 10^{3/(20 n)} \end{aligned}\end{split}\]If exact is True:
\[\begin{split}\begin{aligned} F &= anchor \cdot 2^{[i, i+1, i+2, ..., j] / n} \\ F_{lower} &= F/2^{1/(2 n)} \\ F_{upper} &= F \cdot 2^{1/(2 n)} \end{aligned}\end{split}\]Examples
>>> import numpy as np >>> from pyyeti import psd >>> np.set_printoptions(precision=4, linewidth=75) >>> np.array(psd.get_freq_oct(3, [505, 900])) array([[ 501.1872, 630.9573, 794.3282, 1000. ], [ 446.6836, 562.3413, 707.9458, 891.2509], [ 562.3413, 707.9458, 891.2509, 1122.0185]]) >>> np.array(psd.get_freq_oct(3, [505, 900], trim='center')) array([[ 630.9573, 794.3282], [ 562.3413, 707.9458], [ 707.9458, 891.2509]]) >>> np.array(psd.get_freq_oct(3, [505, 900], exact=True)) array([[ 500. , 629.9605, 793.7005, 1000. ], [ 445.4494, 561.231 , 707.1068, 890.8987], [ 561.231 , 707.1068, 890.8987, 1122.462 ]]) >>> psd.get_freq_oct(6, [.8, 2.6])[0] array([ 0.7943, 0.8913, 1. , 1.122 , 1.2589, 1.4125, 1.5849, 1.7783, 1.9953, 2.2387, 2.5119]) >>> psd.get_freq_oct(6, [.8, 2.6], anchor=2)[0] array([ 0.7962, 0.8934, 1.0024, 1.1247, 1.2619, 1.4159, 1.5887, 1.7825, 2. , 2.244 , 2.5179]) >>> psd.get_freq_oct(6, [.8, 2.6], exact=True)[0] array([ 0.7751, 0.87 , 0.9766, 1.0962, 1.2304, 1.3811, 1.5502, 1.74 , 1.9531, 2.1923, 2.4608]) >>> psd.get_freq_oct(6, [.8, 2.6], exact=True, anchor=2)[0] array([ 0.7937, 0.8909, 1. , 1.1225, 1.2599, 1.4142, 1.5874, 1.7818, 2. , 2.2449, 2.5198])