Programming help for new user

Hi all,

I'm new to Igor (and programming!) and want to apologize in advance for the basic question. I've just started going through the manual but have a somewhat urgent deadline and would be very grateful for some help pointing me in the right direction.

I have two waves, x and V. I need to find the maximum V for every group of 32 points. These maxima would ideally be interpolated, and I should note that every group of points takes the shape of a smooth, yet antisymmetric peak. I then need to make a wave of the x-values corresponding to these maximum V-values. Because I'm working with a high volume of data, manually plotting/calculating this is not feasible. Every set of 32 x-values is identical.

Where would be the best place to start in order to figure this out quickly? I got Igor today and have been going through the tutorial and programming section to get started. I still feel like I'm a long way away from being able to write a program from scratch and am not sure how to go about my main task.

Thanks!
Here is something to get you started:


// FindSegmentPeaks(wIn, segmentLength)
// Finds the peak in each segment.
// Output waves are named after input wave. For example, if the input wave
// is wave0, the output waves are wave0_spx and wave0_spy.
// Example:
// Make/O/N=1000 wave0
// SetScale/P x 0, .1, "s", wave0
// wave0 = abs(sin(x))
// Display wave0
// FindSegmentPeaks(wave0, 32)
// AppendToGraph wave0_spy vs wave0_spx
// ModifyGraph rgb(wave0_spy)=(0,0,65535)
// ModifyGraph mode(wave0_spy)=2, lsize(wave0_spy)=3
// Edit wave0_spx, wave0_spy
Function FindSegmentPeaks(wIn, segmentLength)
	Wave wIn					// e.g., wave0
	Variable segmentLength		// e.g., 32
	
	Variable numPoints = numpnts(wIn)
	Variable numSegments = trunc(numPoints / segmentLength)	// Partial segment at end is ignored
	if (numSegments  <= 0)
		Abort "Not enough input points"
	endif
	
	String wOutNameX = NameOfWave(wIn) + "_spx"
	Make/O/D/N=(numSegments) $wOutNameX
	Wave wOutX = $wOutNameX
	
	String wOutNameY = NameOfWave(wIn) + "_spy"
	Make/O/D/N=(numSegments) $wOutNameY
	Wave wOutY = $wOutNameY
	
	Variable i
	for(i=0; i<numSegments; i+=1)
		Variable startPoint = segmentLength*i, startX = pnt2x(wIn, startPoint)
		Variable endPoint = startPoint+segmentLength-1, endX = pnt2x(wIn, endPoint)
		
		// FindPeak sets V_PeakLoc and V_PeakVal
		FindPeak /Q/R=(startX,endX) wIn		// Find peak for this segment
		if (V_flag == 0)							// Success
			wOutX[i] = V_PeakLoc
			wOutY[i] = V_PeakVal
		else
			wOutX[i] = NaN
			wOutY[i] = NaN
		endif
	endfor	
End

Function DemoFindSegmentPeaks()
	Make/O/N=1000 wave0
	SetScale/P x 0, .1, "s", wave0
	wave0 = abs(sin(x))
	Display wave0
	FindSegmentPeaks(wave0, 32)
	AppendToGraph wave0_spy vs wave0_spx
	ModifyGraph rgb(wave0_spy)=(0,0,65535)
	ModifyGraph mode(wave0_spy)=2, lsize(wave0_spy)=3
	Edit wave0_spx, wave0_spy
End
hrodstein wrote: Here is something to get you started:


Wow, thank you so much. I really appreciate it!!