# Estimate the wavelength of an oscillatory signal

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.

• have you checked if scipy.signal.find_peaks_cwt works (docs.scipy.org/doc/scipy/reference/generated/…)? – Maximilian Matthé Dec 12 '16 at 16:23
• 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 – Ohm Dec 12 '16 at 16:37
• can you provide the data somewhere on the internet? – Maximilian Matthé Dec 12 '16 at 16:40
• 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? – ruoho ruotsi Dec 12 '16 at 17:08
• @ruohoruotsi: Maybe with only 3 of these peaks a spectral analysis would not show a strong peak at the correct frequency. – Maximilian Matthé Dec 12 '16 at 18:00

## 1 Answer

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(), 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


Output:

[1919 2500 3080]
Period between peaks: 0.145036259065 • Is the any difference in calculating the period with period = int(np.mean(np.diff(peakind))) print "Period between peaks:", X[period]-X instead of np.mean(np.diff(X[peakind])) ? – Ohm Dec 13 '16 at 8:16
• This wont make a difference, it's also possible. – Maximilian Matthé Dec 13 '16 at 8:18