# Findpeaks function Classic List Threaded 8 messages Reply | Threaded
Open this post in threaded view
|

## Findpeaks function

 Hello I have two signals x and y ploted versus time vector t (please refer to function below). I am trying to create two result vectors named result1 and result2. The vector result1 should find local peaks (max values). Function "findpeaks" rejects the inputs since they include negative values so I am kind a stuck. It should find the local max values and give back the value and its index. The vector result2 should give back index of crossing of x and y, where these are zero (or close to zero). On the chart you can see that not all crossings of x and y fullfill this condition. Am I using the "findpeaks" function wrong? Is there a way to accept the signals with negative values as well? For result2 is there a function to do this? Any help is much appreciated. Thanks   Wave_peaks.png   -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 Forgot to mention, the findpeaks function input vector is x. [poc,loc]=findpeaks(x); -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 In reply to this post by Blaz Am 24.02.21 um 18:28 schrieb Blaz: > The vector result1 should find local peaks (max values). Function > "findpeaks" rejects the inputs since they include negative values so I am > kind a stuck. you can either move the values like x = sin(0:0.1:10); [~, LOC] = findpeaks (x - min(x)) or remove the negative part x(x<0) = 0; > The vector result2 should give back index of crossing of x and y, where > these are zero (or close to zero). On the chart you can see that not all > crossings of x and y fullfill this condition. I don't understand this, perhaps you should also upload the data and show some code what you already did. You might also find "peakdet" interesting https://github.com/gnu-octave/macgyver_utils/blob/master/peakdet.cc-- Andy
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 Thanks andy. The negative parts removal is simple and ideal solution. I feel so silly, not remembering that myself. For the second part I have come up to defining zerocrossing t values for both signals separately. Now I would need to crossreference them and leave in result2 only those who are the same in both vectors (indx and indy). indx=zerocrossing(t,x); indy=zerocrossing(t,y); result2 = ?? -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 Am 24.02.21 um 19:23 schrieb Blaz: > For the second part I have come up to defining zerocrossing t values for > both signals separately. Now I would need to crossreference them and leave > in result2 only those who are the same in both vectors (indx and indy). > > indx=zerocrossing(t,x); > indy=zerocrossing(t,y); > > result2 = ?? help intersect
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 I have written some code to solve this although it is not quite what I was looking for. If somoeone can make a use of it, here it is a=dlmread('C:\Users\pblaz\Documents\MEGAsync\Octave\data.dat','', 0,0); t=a(:,1); x=a(:,2); y=a(:,3); c=abs(x+y); index=[]; ic=1; for i=1:length(c)   if c(i) < 600 && c(i) > 200 && x(i) < 500 && y(i) < 500     index(ic)=i;     ic=ic+1;   end end clf plot(t,x,t,y,t(index),x(index),'orb') -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 On Thursday, February 25, 2021 11:33:04 AM WET Blaz wrote: > index=[]; > ic=1; > for i=1:length(c) >   if c(i) < 600 && c(i) > 200 && x(i) < 500 && y(i) < 500 >     index(ic)=i; >     ic=ic+1; >   end > end This part can probably be reduced to: index = c < 600 && c > 200 && x < 500 && y < 500; and that is it. :-) -- José Matos
Reply | Threaded
Open this post in threaded view
|

## Re: Findpeaks function

 In reply to this post by Blaz Hi, The first step is always to read the documentation clearly. This is written in the help of the function "DoubleSided"           Tells the function that data takes positive and negative           values.  The base-line for the peaks is taken as the mean           value of the function.  This is equivalent as passing the           absolute value of the data after removing the mean. Also check the demos (none with negative data, but shows other aspects of the function)