TCL procedure is the solution to make a measurement during each period of a signal: proc avg_period { wave0 wave1 } { wfc " myxup = xup($wave0,0) myavg=\[\] for i in range(0,length(myxup)-1) : xtmp=myxup\[i\]\; ytmp=(avg($wave1, myxup\[i\], myxup\[i+1\])) \; myavg.append(\[xtmp,ytmp\]) wf1 = datatowf(myavg) " return wf1 }
The TCL code defines a procedure called "avg_period" that needs 2 waves as argument. The first one (wave0) is the reference to define the window for average computation. This wave could be the output of the oscillator for instance. XUP function returns a vector "myxup" that contains the X values each time this wave cross 0. Then a "for" loop is used to compute the average value of wave1 (that could be the current of a source if wanted to extract the consumption of the oscillator) by specifying the computation window based on "myxup" previously extracted. For all X values, average on Wave1 is computed between x(i) and x(i+1). [xtmp,ytmp] is added in "myavg". And finally this vector is converted in wave "wf1" with datatowf function.
Note: language used in Waveform Calculator is Python so the for loop syntax is also in Python because it is embedded inside the wfc.
This TCL procedure is called in Eldo with .TCL_WAVE command: