#pragma rtGlobals=1 // Use modern global access method. Proc Second (Threshold) // Returns numeric value for level in analysis macro Variable Threshold setLevel= Threshold End Macro Mini_anal (ywave) String ywave Prompt ywave, "wave name?", popup, WaveList ("*", ";", "") Variable PointLoc, PointMin, Pointmax Variable npoints Variable ampli Variable xstart, xend Silent 1 Duplicate $ywave, test Smooth /B/E=0 11, test Differentiate test Smooth /B/E=0 21, test Display /W=(0,0,1000,400) test ModifyGraph nticks=30, grid=1 Variable/G setLevel Second () // Calls numeric value for test Level from Second above SetDrawEnv xcoord=prel, ycoord=left DrawLine 0, setLevel, 1, setLevel // Draws line to mark the selected level FindLevels /M=50 Test, setLevel // Finds points that cross the line WaveStats W_FindLevels do PointLoc=W_FindLevels(i) xstart=PointLoc-10 xend=PointLoc+490 Duplicate /R=(xstart,xend) $ywave 'newave 1' += 1 sum +=i i +=1 While (i < npoints) Make /N=(V_npnts) mini_ampl // Makes a wave to store the y pos of the detected points AppendToGraph mini_ampl vs W_FindLevels ModifyGraph rgb (mini_ampl)=(0,0,0), marker (mini_ampl)=2, mode (mini_ampl)=3 Duplicate $ywave amplitudes Smooth /B/E=0 5, amplitudes Display amplitudes MoveWindow 0,400,1000,700 Make /N=(V_npnts) pointampl AppendToGraph pointampl vs W_FindLevels ModifyGraph rgb (pointampl)=(0,0,0), marker (pointampl)=2, mode (pointampl)=3 Variable i, sum=0 // i is the loop variable npoints=V_npnts do PointLoc=W_FindLevels(i) PointMin=PointLoc-10 PointMax=PointLoc+50 WaveStats /R=[PointMin,Pointmax] amplitudes ampli=V_min-V_max mini_ampl(i)=ampli pointampl(i)=V_min sum += i i += 1 while (i < npoints) // as long as condition is true Make /N=(npoints) time_ms time_ms = W_FindLevels*0.2 Edit time_ms, mini_ampl KillVariables setLevel End