Findlevels Algorithm

Hello,
I use the function "Findlevels" to treat my signals and it works very well. I wondered if it was possible to have the algorithm of this function because I want to reproduce exactly my program (procedure) in another programming language, C # for example. Is it possible ?
I'm looking for a simple algorithm to do the same work as "findlevels" function?
Many thanks,
Having the exact code is not as important as getting consistent results. I can imagine that a search on a phrase such as "find a value in an array using C++ code" would give you a good starting point. Also, as far as I recall, the code in Igor Pro is referenced often to the handbook Numerical Recipes in C.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Thank you jwiemer.
I would like to have the same code and keep the same parameters used in the function Find Levels such as "Box" and "Level".
I could not find a simple way to do it :(
I would ask first ... Why go outside of Igor Pro when it already does exactly what you need?

As to your ending question ... I suggest you should contact WaveMetrics directly. I imagine that releasing code or even commenting that they might release it is not something they will do on a public forum. Finally, I might suggest that at best, you will get references to literature and still have to develop your own code. In other words, I seriously doubt that you will be handed a "code package" that you can just duplicate and use directly.

Which brings me back to my starting question.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
I come back here to propose a solution, maybe it could help someone.

jjweimer wrote: I would ask first ... Why go outside of Igor Pro when it already does exactly what you need?



@jjweimer : We use Igor Pro for R&D. The goal was to test the algorithm on a large set of data then to make it an embedded software.

Since my last post here I have no longer worked on the issue. But, today I suddenly had a flash ;-).

Here is my solution



#pragma rtGlobals=3		// Use modern global access method and strict wave access.

//-----------------------------------------------------------------------------------------
//					LOOK FOR INDEX 
//-----------------------------------------------------------------------------------------
// 		This function act as the Igor's function "FindLevels"
//-----------------------------------------------------------------------------------------


Function/WAVE LookForIndex(dataWave,level, boxSize) 
	Wave dataWave
	Variable level		// threshold to be crossed
	Variable boxSize 	// box size for sliding average, should preferably be an odd number 
		
	boxSize = ceil((boxSize-1)/2) 	// take the half size of the box
		
	Variable length = numpnts(dataWave)	
	Variable i, j
	Variable slidingAverage	
	Variable lookForRisingEdge = 1
	
	Make/O/N=10000 indexWave // we assume that we have less than 10000 crossing level. If not, change this value. 
	
	for(i = 0; i < length; i+=1)	
		
		slidingAverage =  mean(dataWave,i-boxSize,i+boxSize)	// comput the sliding average  
			
		if ( (slidingAverage > level) && (lookForRisingEdge == 1))	// look for rising edge
			
			indexWave[j] = i			
			lookForRisingEdge = 0			
			j=j+1
			
		elseif ( (slidingAverage) < level && (lookForRisingEdge == 0 ))	// look for falling edge
					
			indexWave[j] = i			
			lookForRisingEdge = 1			
			j=j+1				
		endif
			
	endfor
		
	Redimension /N=(j) indexWave	
	
	return indexWave // All "X" values at which the "level" was crossed
	
End



Here is an example (attached image) with the same parameters on a noisy data:

LookForIndex(myData,1, B=151)
FindLevels/B=151/Q/P/D=levelWave myData,1
LookForIndex.png (11.68 KB)