コード例 #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal

print('Detect peaks without any filters.')
indexes = scipy.signal.find_peaks_cwt(
    vector,
    np.arange(1, 4),
    max_distances=np.arange(1, 4)*2
)
indexes = np.array(indexes) - 1
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    np.array(indexes),
    algorithm='scipy.signal.find_peaks_cwt'
)
コード例 #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
To install the mlpy, you may read (and run) /tests/install_mlpy.sh
"""
import numpy as np
from vector import vector, plot_peaks
import mlpy

print('Detect peaks without any filters.')
indexes = mlpy.findpeaks_dist(vector)
print('Peaks are: {}'.format(indexes))
plot_peaks(np.array(vector), indexes, algorithm='mlpy.findpeaks_dist')

print('Detect peaks with minimum distance filter.')
mdp = 2.1
indexes = mlpy.findpeaks_dist(vector, mindist=mdp)
print('Peaks are: {}'.format(indexes))
plot_peaks(np.array(vector), indexes, mpd=mdp, algorithm='mlpy.findpeaks_dist')
コード例 #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from oct2py import octave

# Load the Octage-Forge signal package.
octave.eval("pkg load signal")

print("Detect peaks without any filters.")
(_, indexes) = octave.findpeaks(
    np.array(vector), "DoubleSided", "MinPeakHeight", 0, "MinPeakDistance", 0, "MinPeakWidth", 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print("Peaks are: %s" % (indexes))
plot_peaks(np.array(vector), indexes, algorithm="Octave-Forge findpeaks")

print("Detect peaks with minimum height and distance filters.")
(pks, indexes) = octave.findpeaks(
    np.array(vector), "DoubleSided", "MinPeakHeight", 6, "MinPeakDistance", 2, "MinPeakWidth", 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print("Peaks are: %s" % (indexes))
plot_peaks(np.array(vector), indexes, mph=6, mpd=2, algorithm="Octave-Forge findpeaks")
コード例 #4
0
ファイル: peakdetect.py プロジェクト: MonsieurV/py-findpeaks
import numpy as np
from vector import vector, plot_peaks
from libs import peakdetect

print('Detect peaks without any filters.')
peaks = peakdetect.peakdetect(np.array(vector), lookahead=2)
# peakdetect returns two lists, respectively positive and negative peaks,
# with for each peak a tuple of (indexes, values).
indexes = []
for posOrNegPeaks in peaks:
    for peak in posOrNegPeaks:
        indexes.append(peak[0])
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    np.array(indexes),
    algorithm='peakdetect from sixtenbe'
)

print('Detect peaks with distance filters.')
peaks = peakdetect.peakdetect(np.array(vector), lookahead=2, delta=2)
# peakdetect returns two lists, respectively positive and negative peaks,
# with for each peak a tuple of (indexes, values).
indexes = []
for posOrNegPeaks in peaks:
    for peak in posOrNegPeaks:
        indexes.append(peak[0])
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    np.array(indexes),
コード例 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal

print('Detect peaks without any filters.')
indexes, _ = scipy.signal.find_peaks(np.array(vector))
print('Peaks are: {}'.format(indexes))
plot_peaks(np.array(vector), indexes, algorithm='scipy.signal.find_peaks')

print('Detect peaks with minimum height and distance filters.')
indexes, _ = scipy.signal.find_peaks(np.array(vector), height=7, distance=2.1)
print('Peaks are: {}'.format(indexes))
plot_peaks(np.array(vector),
           indexes,
           mph=7,
           mpd=2.1,
           algorithm='scipy.signal.find_peaks')
コード例 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
To install the mlpy, you may read (and run) /tests/install_mlpy.sh
"""
import numpy as np
from vector import vector, plot_peaks
import mlpy

print('Detect peaks without any filters.')
indexes = mlpy.findpeaks_dist(vector)
print('Peaks are: {}'.format(indexes))
plot_peaks(
    np.array(vector),
    indexes,
    algorithm='mlpy.findpeaks_dist'
)

print('Detect peaks with minimum distance filter.')
mdp = 2.1
indexes = mlpy.findpeaks_dist(vector, mindist=mdp)
print('Peaks are: {}'.format(indexes))
plot_peaks(
    np.array(vector),
    indexes,
    mpd=mdp, algorithm='mlpy.findpeaks_dist'
)
コード例 #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal

print('Detect peaks without any filters (maxima).')
indexes = scipy.signal.argrelextrema(
    np.array(vector),
    comparator=np.greater
)
print('Peaks are: %s' % (indexes[0]))
plot_peaks(
    np.array(vector),
    indexes[0],
    algorithm='scipy.signal.argrelmax'
)

print('Detect peaks without any filters (minima).')
indexes = scipy.signal.argrelextrema(
    np.array(vector),
    comparator=np.less
)
print('Peaks are: %s' % (indexes[0]))
plot_peaks(
    np.array(vector),
    indexes[0],
    algorithm='scipy.signal.argrelmax'
)

print('Detect peaks with order (distance) filter.')
コード例 #8
0
# only dependencies required
import numpy as np
from math import sqrt

# threshold used to discard peaks too small
def detect_peaks(signal, threshold=0.5):
	# compute root mean square
	root_mean_square = sqrt(np.sum(np.square(signal) / len(signal)))

	# compute peak to average ratios
	ratios = np.array([pow(x / root_mean_square, 2) for x in signal])

	# apply first order logic
	peaks = (ratios > np.roll(ratios, 1)) & (ratios > np.roll(ratios, -1)) & (ratios > threshold)

	# optional: return peak indices
	peak_indexes = []
	
	for i in range(0, len(peaks)):
		if peaks[i]:
			peak_indexes.append(i)

	return peak_indexes

# example
from vector import vector, plot_peaks

indexes = detect_peaks(vector, 1.5)
print indexes
plot_peaks(np.array(vector), np.array(indexes), mph=1.5, algorithm='lightweight standalone peaks')
コード例 #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import peakutils.peak

print('Detect peaks without any filters.')
indexes = peakutils.peak.indexes(np.array(vector), thres=0, min_dist=0)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector), indexes,
    algorithm='peakutils.peak.indexes')

print('Detect peaks with minimum height and distance filters.')
indexes = peakutils.peak.indexes(np.array(vector),
    thres=7.0/max(vector), min_dist=2)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector), indexes, mph=7, mpd=2,
    algorithm='peakutils.peak.indexes')
コード例 #10
0
# Load the Octage-Forge signal package.
octave.eval("pkg load signal")

print('Detect peaks without any filters.')
(_, indexes) = octave.findpeaks(
    np.array(vector),
    'DoubleSided', 'MinPeakHeight', 0, 'MinPeakDistance', 0, 'MinPeakWidth', 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    indexes,
    algorithm='Octave-Forge findpeaks'
)

print('Detect peaks with minimum height and distance filters.')
(pks, indexes) = octave.findpeaks(
    np.array(vector),
    'DoubleSided', 'MinPeakHeight', 6, 'MinPeakDistance', 2, 'MinPeakWidth', 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
コード例 #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from libs.findpeaks import findpeaks

print('Detect peaks without any filters.')
indexes = findpeaks(np.array(vector), spacing=1)
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    np.array(indexes),
    algorithm='findpeaks from Janko Slavic'
)

print('Detect peaks with distance and height filters.')
indexes = findpeaks(np.array(vector), spacing=2, limit=7)
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    np.array(indexes), mph=7, mpd=2,
    algorithm='findpeaks from Janko Slavic'
)
コード例 #12
0
ファイル: peakdetect.py プロジェクト: wocclyl/py-findpeaks
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from libs import peakdetect

print('Detect peaks without any filters.')
peaks = peakdetect.peakdetect(np.array(vector), lookahead=2)
# peakdetect returns two lists, respectively positive and negative peaks,
# with for each peak a tuple of (indexes, values).
indexes = []
for posOrNegPeaks in peaks:
    for peak in posOrNegPeaks:
        indexes.append(peak[0])
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           algorithm='peakdetect from sixtenbe')

print('Detect peaks with distance filters.')
peaks = peakdetect.peakdetect(np.array(vector), lookahead=2, delta=2)
# peakdetect returns two lists, respectively positive and negative peaks,
# with for each peak a tuple of (indexes, values).
indexes = []
for posOrNegPeaks in peaks:
    for peak in posOrNegPeaks:
        indexes.append(peak[0])
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           mph=None,
           mpd=2,
コード例 #13
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from libs.findpeaks import findpeaks

print('Detect peaks without any filters.')
indexes = findpeaks(np.array(vector), spacing=1)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           algorithm='findpeaks from Janko Slavic')

print('Detect peaks with distance and height filters.')
indexes = findpeaks(np.array(vector), spacing=2, limit=7)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           mph=7,
           mpd=2,
           algorithm='findpeaks from Janko Slavic')
コード例 #14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from libs import detect_peaks

print('Detect peaks without any filters.')
indexes = detect_peaks.detect_peaks(vector)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector), indexes,
    algorithm='detect_peaks from Marcos Duarte')

print('Detect peaks with minimum height and distance filters.')
indexes = detect_peaks.detect_peaks(vector, mph=7, mpd=2)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector), indexes, mph=7, mpd=2,
    algorithm='detect_peaks from Marcos Duarte')
コード例 #15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from libs.tony_beltramelli_detect_peaks import detect_peaks

print('Detect peaks without any filters.')
indexes = detect_peaks(vector)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector), np.array(indexes),
    algorithm='detect_peaks from Tony Beltramelli')

print('Detect peaks with height threshold.')
indexes = detect_peaks(vector, 1.5)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector), np.array(indexes), mph=1.5,
	algorithm='detect_peaks from Tony Beltramelli')
コード例 #16
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal

print('Detect peaks without any filters (maxima).')
indexes = scipy.signal.argrelextrema(np.array(vector), comparator=np.greater)
print('Peaks are: %s' % (indexes[0]))
# To get number of peaks:
# print("{} peaks".format(len(indexes[0])))
plot_peaks(np.array(vector), indexes[0], algorithm='scipy.signal.argrelmax')

print('Detect peaks without any filters (minima).')
indexes = scipy.signal.argrelextrema(np.array(vector), comparator=np.less)
print('Peaks are: %s' % (indexes[0]))
plot_peaks(np.array(vector), indexes[0], algorithm='scipy.signal.argrelmax')

print('Detect peaks with order (distance) filter.')
indexes = scipy.signal.argrelextrema(np.array(vector),
                                     comparator=np.greater,
                                     order=2)
print('Peaks are: %s' % (indexes[0]))
plot_peaks(np.array(vector),
           indexes[0],
           mpd=2,
           algorithm='scipy.signal.argrelmax')
コード例 #17
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
from libs.tony_beltramelli_detect_peaks import detect_peaks

print('Detect peaks without any filters.')
indexes = detect_peaks(vector)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           algorithm='detect_peaks from Tony Beltramelli')

print('Detect peaks with height threshold.')
indexes = detect_peaks(vector, 1.5)
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           mph=1.5,
           algorithm='detect_peaks from Tony Beltramelli')
コード例 #18
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal

print('Detect peaks without any filters.')
indexes = scipy.signal.find_peaks_cwt(vector,
                                      np.arange(1, 4),
                                      max_distances=np.arange(1, 4) * 2)
indexes = np.array(indexes) - 1
print('Peaks are: %s' % (indexes))
plot_peaks(np.array(vector),
           np.array(indexes),
           algorithm='scipy.signal.find_peaks_cwt')
コード例 #19
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
To install the mlpy, you may read (and run) /tests/install_mlpy.sh
"""
import numpy as np
from vector import vector, plot_peaks
import mlpy

span = 3
print('Detect peaks with a sliding window of {} (minimum possible).'.format(
    span))
indexes = mlpy.findpeaks_win(vector, span=span)
print('Peaks are: {}'.format(indexes))
plot_peaks(np.array(vector), indexes, mpd=span, algorithm='mlpy.findpeaks_win')

span = 5
print('Detect peaks with a sliding window of {}.'.format(span))
indexes = mlpy.findpeaks_win(vector, span=span)
print('Peaks are: {}'.format(indexes))
plot_peaks(np.array(vector), indexes, mpd=span, algorithm='mlpy.findpeaks_win')