Wave Folding

This small snippet allows one to efficiently fold and average a 1D wave containing periodic data, for instances, a wave of 100 points containing ten cycles of 10-point data. 

The end result is a 10-point 1D wave containing the averaged results of the ten cycles originally contained by the 100-point 1D wave.

function foldWave(foldedWave, waveToFold)
    wave foldedWave, waveToFold
    variable numRowfW = numpnts(foldedWave)
    variable numRowwTF = numpnts(waveToFold)
    variable numFold = floor(numRowwTF/numRowfw)
    duplicate/o/R=[0,numFold*numRowfW] waveToFold, fWMatrix
    redimension/N=(numRowfW, numFold,0,0) fWMatrix

    multithread foldedWave = meanRow(fwMatrix,p)

threadsafe static Function MeanRow (wave2D, whichRow)
    wave wave2D
    variable whichRow      
    MatrixOP/O/free w=row(wave2D,whichRow)^t
   return mean(w)


Two quick suggestions:

1. You may want to add /FREE to your duplicate command.  This should clean out the fWMatrix which you should not really need when execution completes.

2. You could simplify

  multithread foldedWave = meanRow(fwMatrix,p)


MatrixOP/O/FREE aa=averageCols(fwMatrix^t)^t






Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More