I need to estimate the dominant wavelength of a signal that is looking like this:
My first attempt was using scipy.signal.argrelmin
in Python in order to detect the minima of the signal, but it detects also very small local minima. Is there any useful method for this that I should look into? (The wavelength that I would like to measure is the one between the pronounced minima in the above figure)
The data for this solution can be downloaded from here.
$\begingroup$
$\endgroup$
6
1 Answer
$\begingroup$
$\endgroup$
2
Consider the code snippet below to find the three peaks in the graph. Note, that peak search usually only searches for positive peaks. Hence, I negated the signal to search for the down-peaks. Also, I adapt the SNR threshold in the code to detect only the very strong peaks.
import urllib2
import scipy.signal as signal
url = 'https://raw.githubusercontent.com/Omer80/wavelength/master/oscillations.dat'
response = urllib2.urlopen(url)
cr = np.loadtxt(response)
X = cr[0,:]
Y = cr[1,:]
plt.subplot(2,2,1)
plt.plot(Y)
plt.subplot(2,2,2)
plt.plot(X, Y)
peakind = signal.find_peaks_cwt(-Y, np.array([100]), min_snr=5)
peakind = np.array(peakind)
print peakind
plt.stem(X[peakind], 1+0*peakind);
period = int(np.mean(np.diff(peakind)))
print "Period between peaks:", X[period]-X[0]
Output:
[1919 2500 3080]
Period between peaks: 0.145036259065
-
$\begingroup$ Is the any difference in calculating the period with
period = int(np.mean(np.diff(peakind))) print "Period between peaks:", X[period]-X[0]
instead ofnp.mean(np.diff(X[peakind]))
? $\endgroup$– OhmDec 13, 2016 at 8:16 -
1$\begingroup$ This wont make a difference, it's also possible. $\endgroup$ Dec 13, 2016 at 8:18
scipy.signal.find_peaks_cwt
works (docs.scipy.org/doc/scipy/reference/generated/…)? $\endgroup$