Skip to content

Commit

Permalink
Start documenting the spectral module
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVinyard committed Sep 2, 2017
1 parent aaf1401 commit 7523dc4
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
Binary file removed dist/zounds-0.01.tar.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.doctest',
'sphinx.ext.autosummary'
'sphinx.ext.autosummary',
'sphinx.ext.napoleon'
]

autosummary_generate = True
Expand Down
3 changes: 3 additions & 0 deletions docs/source/core.rst
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.. automodule:: zounds.core



30 changes: 30 additions & 0 deletions docs/source/spectral.rst
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
Spectral
========
.. automodule:: zounds.spectral
.. currentmodule:: zounds.spectral

Representations
---------------
Something here

Nodes
----------------
Something there

Scales
------
.. autoclass:: FrequencyScale
:members:

.. autoclass:: LinearScale
:members:

.. autoclass:: GeometricScale
:members:

.. autoclass:: ExplicitScale
:members:

.. autoclass:: FrequencyBand
:members:


1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ unittest2
requests
tornado
pysoundfile
cython
matplotlib
13 changes: 2 additions & 11 deletions zounds/spectral/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
"""
Spectral
========
Welcome to the spectral stuff
.. autoclass:: FrequencyBand
.. autoclass:: FrequencyScale
.. autoclass:: LinearScale
.. autoclass:: GeometricScale
.. autoclass:: FrequencyDimension
.. autoclass:: ExplicitFrequencyDimension
The spectral module contains classes that aid in dealing with frequency-domain
representations of sound
"""

from sliding_window import \
Expand Down
43 changes: 38 additions & 5 deletions zounds/spectral/frequencyscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
class FrequencyBand(object):
"""
Represents an interval, or band of frequencies in hertz (cycles per second)
Args:
start_hz (float): The lower bound of the frequency band in hertz
stop_hz (float): The upper bound of the frequency band in hertz
Examples::
>>> import zounds
>>> band = zounds.FrequencyBand(500, 1000)
>>> band.center_frequency
750.0
>>> band.bandwidth
500
"""

def __init__(self, start_hz, stop_hz):
"""
:param start_hz: The lower bound for the frequency band, in hertz
:param stop_hz: The upper bound for the frequency band, in hertz
:return: a new FrequencyBand instance
"""
super(FrequencyBand, self).__init__()
if stop_hz <= start_hz:
raise ValueError('stop_hz must be greater than start_hz')
Expand All @@ -34,6 +41,20 @@ def __hash__(self):
return (self.__class__.__name__, self.start_hz, self.stop_hz).__hash__()

def intersect(self, other):
"""
Return the intersection between this frequency band and another.
Args:
other (FrequencyBand): the instance to intersect with
Examples::
>>> import zounds
>>> b1 = zounds.FrequencyBand(500, 1000)
>>> b2 = zounds.FrequencyBand(900, 2000)
>>> intersection = b1.intersect(b2)
>>> intersection.start_hz, intersection.stop_hz
(900, 1000)
"""
lowest_stop = min(self.stop_hz, other.stop_hz)
highest_start = max(self.start_hz, other.start_hz)
return FrequencyBand(highest_start, lowest_stop)
Expand All @@ -47,6 +68,15 @@ def intersection_ratio(self, other):

@staticmethod
def from_start(start_hz, bandwidth_hz):
"""
Produce a :class:`FrequencyBand` instance from a lower bound and
bandwidth
Args:
start_hz (float): the lower bound of the desired FrequencyBand
bandwidth_hz (float): the bandwidth of the desired FrequencyBand
"""
return FrequencyBand(start_hz, start_hz + bandwidth_hz)

@staticmethod
Expand All @@ -57,6 +87,9 @@ def from_center(center_hz, bandwidth_hz):

@property
def bandwidth(self):
"""
The span of this frequency band, in hertz
"""
return self.stop_hz - self.start_hz

@property
Expand Down

0 comments on commit 7523dc4

Please sign in to comment.