In that case, the function returns an array of arrays, the first subarray still contains the indexes of the peaks, the others may present the heights of the found peaks or their left and right thresholds (and all the other information that were previously specified as optional input during the call of the function), as a dictionary.Īfter this brief explanation, let’s see in the following code lines how to call the function and thus finding the peaks. It can return also other information, in the case we had previously specified some options like “height” or “threshold” at the moment of the call. find_peaks() function is an array that contains the indexes of each peak that has been identified. There are then many other options that we can exploit, for example for specifying the minimal width of the peaks etc… Distance: is the required minimal horizontal distance between neighboring peaks it can be really useful in cases in which we have some knowledge about the periodicity of the peaks.Threshold: is the required vertical distance between a peak and its neighboring, very useful in the case of noisy functions where we want to avoid selecting peaks from the noise.
To generate the y array, we make use of the function.linspace() function from Numpy, to define the x array, we call it “x” it consists of an array of 100 equally spaced numbers. This means to create the “x” and “y” arrays that will be then processed and plotted in our script. The first thing that we have to do is to create a function, which should present some peaks. Import matplotlib.pyplot as plt Creating a Function with Peaks Let’s start our script by importing the Python libraries that will be then used in the script. Let’s dive into this code step-by-step! Importing the Needed Python Libraries Min_height = y2] #list of the mirrored minima heightsĪx.scatter(peak_pos, height, color = 'r', s = 15, marker = 'D', label = 'Maxima')Īx.scatter(min_pos, min_height*-1, color = 'gold', s = 15, marker = 'X', label = 'Minima') Min_pos = x] #list of the minima positions Peak_pos = x] #list of the peaks positions Height = peaks #list of the heights of the peaks Peaks = find_peaks(y, height = 1, threshold = 1, distance = 1) find_peaks() from the Scipy.singnal library, to process a specific signal/function and extract the position and intensity of multiple peaks.