예제 #1
0
 def test_interval(self):
     emin = 1.0
     emax = 4.0
     f = np.logspace(emin, emax, 50)
     
     o = Octave(interval=f)
     
     self.assertEqual(o.fmin, 10.0**emin)
     self.assertEqual(o.fmax, 10.0**emax)
     self.assertEqual(len(o.n), len(o.center))
     
     o.unique = True
     self.assertEqual(len(o.n), len(f))
예제 #2
0
    def test_interval(self):
        emin = 1.0
        emax = 4.0
        f = np.logspace(emin, emax, 50)

        o = Octave(interval=f)

        assert (o.fmin == 10.0**emin)
        assert (o.fmax == 10.0**emax)
        assert (len(o.n) == len(o.center))

        o.unique = True
        assert (len(o.n) == len(f))
예제 #3
0
 def test_minmax(self):
     fmin = 250.0
     fmax = 1000.0
     
     o = Octave(fmin=fmin, fmax=fmax)
     
     self.assertEqual(len(o.center), 3) # 250, 500, and 1000 Hz
     self.assertEqual(len(o.n), 3)
예제 #4
0
    def test_minmax(self):
        fmin = 250.0
        fmax = 1000.0

        o = Octave(fmin=fmin, fmax=fmax)

        assert (len(o.center) == 3)  # 250, 500, and 1000 Hz
        assert (len(o.n) == 3)
예제 #5
0
def main():

    """We happen to have the following frequency vector."""
    f = np.logspace(2, 4, 100)

    """And we want to get some 1/3-octave results, so we set octave to 3."""
    o = Octave(interval=f, fraction=3)

    """We can now print the center frequencies of the 1/3 octave bands belonging
    to this frequency vector."""
    print(o.center)

    """
    Since by default ``unique=True`` in :class:`Auraliser.Octave.Octave` we get
    a value for every value in ``interval``. If we only want to obtain unique
    values, it is fastest to set ``unique=True`. This could be done during
    initialization but also now.
    """
    o.unique = True

    """Now we should only get the unique center frequencies."""
    print(o.center)

    """We can also calculate the bandwidth of each band."""
    print(o.bandwidth)

    """As well as the lower limits of the frequency limits..."""
    print(o.lower)

    """...and the upper frequency limits."""
    print(o.upper)

    """
    So far we used a frequency interval. Sometimes you have a lower frequency
    and an upper frequency.
    Instead of requiring to generate a frequency vector you can just give these
    boundary values as well.
    """
    o = Octave(fmin=100.0, fmax=20000, fraction=6)

    print(o.center)
예제 #6
0
def octsmooth(amps, freq_vals, noct=24, st_freq=20, en_freq=20000):
    """Smooth magnitude spectrum values using octave bands for easier subtractions and viz.

    Args
    ----------
    amps : array
        Magnitude spectrum values for smoothing

    freq_vals : array
        Magnitude spectrum frequency values

    Parameters
    ----------
    noct : int, optional
        Number of octaves to smooth over (default is 24)

    st_freq : int, optional
        Start frequency for octave bands (default is 20)

    en_freq : int, optional
        End frequency for octave bands (default is 20000)

    Returns
    -------
    array
        Octave smoothed magnitude spectrum array
    array
        Octave smoothed magnitude spectrum array frequency bins
            """
    o = Octave(fmin=st_freq, fmax=en_freq, fraction=noct)
    octbins = np.zeros(len(o.center))
    for i in range(0, len(o.center)):
        st = (np.abs(freq_vals - o.lower[i])).argmin()
        en = (np.abs(freq_vals - o.upper[i])).argmin()
        if en - st > 0:
            octbinvec = amps[st:en]
        else:
            octbinvec = amps[st:en + 1]
        octbins[i] = np.max(octbinvec)
    return octbins, o.center
예제 #7
0
import sys, json
from acoustics.octave import Octave
import numpy as np

f = sys.argv[1]
f = json.loads(f)

o = Octave(interval=f, fraction=3)

print(json.dumps(o.center.tolist()))