[med-svn] [python-mne] 337/353: ENH : new stft_norm2 to compute stft norm taking into account negative freqs
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:25:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to tag 0.4
in repository python-mne.
commit 0d0bf8cc34372872497a65cbee20fea3c89132cd
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Wed Aug 1 18:15:16 2012 +0200
ENH : new stft_norm2 to compute stft norm taking into account negative freqs
---
mne/time_frequency/stft.py | 22 ++++++++++++++++++++++
mne/time_frequency/tests/test_stft.py | 9 +++------
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/mne/time_frequency/stft.py b/mne/time_frequency/stft.py
index 4b9c949..917a0d2 100644
--- a/mne/time_frequency/stft.py
+++ b/mne/time_frequency/stft.py
@@ -201,3 +201,25 @@ def stftfreq(wsize, sfreq=None):
if sfreq is not None:
freqs *= float(sfreq)
return freqs
+
+
+def stft_norm2(X):
+ """Compute L2 norm of STFT transform
+
+ It takes into account that stft only return positive frequencies.
+ As we use tight frame this quantity is conserved by the stft.
+
+ Parameters
+ ----------
+ X : 3D complex array
+ The STFT transforms
+
+ Returns
+ -------
+ norms2 : array
+ The squared L2 norm of every raw of X.
+ """
+ X2 = np.abs(X) ** 2
+ # compute all L2 coefs and remove freq zero once.
+ norms2 = (2. * X2.sum(axis=2).sum(axis=1) - np.sum(X2[:, 0, :], axis=1))
+ return norms2
diff --git a/mne/time_frequency/tests/test_stft.py b/mne/time_frequency/tests/test_stft.py
index 11d08f3..42b3c08 100644
--- a/mne/time_frequency/tests/test_stft.py
+++ b/mne/time_frequency/tests/test_stft.py
@@ -3,7 +3,7 @@ from scipy import linalg
from numpy.testing import assert_almost_equal, assert_array_almost_equal
from nose.tools import assert_true
-from ..stft import stft, istft, stftfreq
+from ..stft import stft, istft, stftfreq, stft_norm2
def test_stft():
@@ -29,12 +29,9 @@ def test_stft():
assert_array_almost_equal(x, xp, decimal=6)
- # Symmetrize X to get also negative frequencies to guarantee
# norm conservation thanks to tight frame property
- X = np.concatenate([X[:, 1:, :][:, ::-1, :], X], axis=1)
-
- assert_almost_equal(linalg.norm(X.ravel()), linalg.norm(x.ravel()),
- decimal=2)
+ assert_almost_equal(np.sqrt(stft_norm2(X)),
+ map(linalg.norm, x), decimal=2)
# Try with empty array
x = np.zeros((0, T))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git
More information about the debian-med-commit
mailing list