diff options
author | John Glover <j@johnglover.net> | 2012-10-10 16:46:25 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-10-10 16:46:25 +0200 |
commit | 554309b2fc6a90b0f59ecb5dd4923c97c150ea36 (patch) | |
tree | 9b978bccf829c6d15d2d29de7890381f15bded38 | |
parent | 45074320ccfbde367f41f150cc40fbc5e1a7595d (diff) | |
download | simpl-554309b2fc6a90b0f59ecb5dd4923c97c150ea36.tar.gz simpl-554309b2fc6a90b0f59ecb5dd4923c97c150ea36.tar.bz2 simpl-554309b2fc6a90b0f59ecb5dd4923c97c150ea36.zip |
[mq] Refactor: Simplify peak detection code.
-rw-r--r-- | simpl/mq.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/simpl/mq.py b/simpl/mq.py index 3a4e96f..6cfadf4 100644 --- a/simpl/mq.py +++ b/simpl/mq.py @@ -143,21 +143,18 @@ class MQPeakDetection(simpl.PeakDetection): spectrum = abs(f) # find all peaks in the spectrum - prev_mag = np.abs(spectrum[0]) - current_mag = np.abs(spectrum[1]) - next_mag = 0.0 - for bin in range(2, len(spectrum) - 1): - next_mag = np.abs(spectrum[bin]) + current_mag = spectrum[bin] + prev_mag = spectrum[bin - 1] + next_mag = spectrum[bin + 1] + if (current_mag > prev_mag and current_mag > next_mag): p = simpl.Peak() p.amplitude = current_mag - p.frequency = (bin - 1) * self._fundamental - p.phase = np.angle(f[bin - 1]) + p.frequency = bin * self._fundamental + p.phase = np.angle(f[bin]) self._current_peaks.append(p) - prev_mag = current_mag - current_mag = next_mag # sort peaks, largest amplitude first, and up to a max # of self.num_peaks peaks |