2
$\begingroup$

I need to estimate the dominant wavelength of a signal that is looking like this:enter image description here 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.

$\endgroup$
  • 1
    $\begingroup$ have you checked if scipy.signal.find_peaks_cwt works (docs.scipy.org/doc/scipy/reference/generated/…)? $\endgroup$ – Maximilian Matthé Dec 12 '16 at 16:23
  • $\begingroup$ Yes, I tried to use it, but I still don't make a lot of sense to it...I will keep on reading in this direction, so thanks $\endgroup$ – Ohm Dec 12 '16 at 16:37
  • 2
    $\begingroup$ can you provide the data somewhere on the internet? $\endgroup$ – Maximilian Matthé Dec 12 '16 at 16:40
  • $\begingroup$ Shouldn't a (log) spectral analysis work? The reciprocal value of the dominant frequency should give you the dominant wavelength no? What am I missing? $\endgroup$ – ruoho ruotsi Dec 12 '16 at 17:08
  • $\begingroup$ @ruohoruotsi: Maybe with only 3 of these peaks a spectral analysis would not show a strong peak at the correct frequency. $\endgroup$ – Maximilian Matthé Dec 12 '16 at 18:00
4
$\begingroup$

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

enter image description here

$\endgroup$
  • $\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 of np.mean(np.diff(X[peakind])) ? $\endgroup$ – Ohm Dec 13 '16 at 8:16
  • 1
    $\begingroup$ This wont make a difference, it's also possible. $\endgroup$ – Maximilian Matthé Dec 13 '16 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.