Skip to content

Commit

Permalink
Merge 1ff42e1 into 5d52491
Browse files Browse the repository at this point in the history
  • Loading branch information
thangleiter committed Mar 5, 2020
2 parents 5d52491 + 1ff42e1 commit 942cb7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions filter_functions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def symmetrize_spectrum(S: ndarray, omega: ndarray) -> Tuple[ndarray, ndarray]:
S : ndarray, shape (..., n_omega)
The one-sided power spectrum.
omega : ndarray, shape (n_omega,)
The positive frequencies.
The positive and strictly increasing frequencies.
Returns
-------
Expand All @@ -1014,8 +1014,14 @@ def symmetrize_spectrum(S: ndarray, omega: ndarray) -> Tuple[ndarray, ndarray]:
The two-sided power spectral density is in the symmetric case given by
:math:`S^{(1)}(\omega) = 2S^{(2)}(\omega)`.
"""
omega = np.concatenate((-omega[::-1], omega))
S = np.concatenate((S[..., ::-1], S), axis=-1)/2
# Catch zero frequency component
if omega[0] == 0:
ix = 1
else:
ix = 0

omega = np.concatenate((-omega[::-1], omega[ix:]))
S = np.concatenate((S[..., ::-1], S[ix:]), axis=-1)/2
return S, omega


Expand Down
6 changes: 6 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ def test_symmetrize_spectrum(self):
self.assertArrayEqual(S_symmetrized[99::-1], S_symmetrized[100:])
self.assertArrayEqual(S_symmetrized[100:]*2, 1/asym_omega**0.7)

# zero frequency not doubled
omega = np.arange(10)
S_sym, omega_sym = util.symmetrize_spectrum(omega, omega)
self.assertArrayEqual(S_sym, np.abs(np.arange(-9, 10)/2))
self.assertArrayEqual(omega_sym, np.arange(-9, 10))

def test_simple_progressbar(self):
with self.assertRaises(TypeError):
for i in util._simple_progressbar((i for i in range(10))):
Expand Down

0 comments on commit 942cb7e

Please sign in to comment.