"Vectorizing" a custom skill function

S

Stephen Greenwood

Guest
I'm writing a SKILL function to count the number of crossings in a
waveform object. After some poking around in the SKILL ADE Reference,
I managed to write the following:

procedure( crossCount( inWave crosspt edgeType )
crossWave = cross(inWave crosspt 0 edgeType t "time")
numberOfCrossings = drVectorLength(drGetWaveformYVec(crossWave))
)

where the arguments are as follows:

inWave (waveform)
crosspt (float)
edgeType (string ["rising" | "falling" | "either"] )

The idea is to use the cross function to capture all crossings of a
user-defined threshold "crosspt", then get the length of one of the
vectors returned from that cross() function. (In this case I chose the
YVec.) So numberOfCrossings returns an integer, and it works fine when
"inWave" is a single waveform.

However, when "inWave" is a family of waveforms, the function does not
do what I want it to. It returns a single integer, whereas I want it
to return a vector of integers. Can anyone suggest a way to accomplish
this? I'm not so concerned about the type of the data returned
(integer or float), as long as I can get the information somehow.

Thanks for any help you can provide,
Stephen Greenwood
 
On Jan 18, 4:59 pm, Stephen Greenwood <stephen.greenw...@gmail.com>
wrote:
I'm writing a SKILL function to count the number of crossings in a
waveform object. After some poking around in the SKILL ADE Reference,
I managed to write the following:

  procedure( crossCount( inWave crosspt edgeType )
    crossWave = cross(inWave crosspt 0 edgeType t "time")
    numberOfCrossings = drVectorLength(drGetWaveformYVec(crossWave))
  )

where the arguments are as follows:

  inWave (waveform)
  crosspt (float)
  edgeType (string ["rising" | "falling" | "either"] )

The idea is to use the cross function to capture all crossings of a
user-defined threshold "crosspt", then get the length of one of the
vectors returned from that cross() function. (In this case I chose the
YVec.) So numberOfCrossings returns an integer, and it works fine when
"inWave" is a single waveform.

However, when "inWave" is a family of waveforms, the function does not
do what I want it to. It returns a single integer, whereas I want it
to return a vector of integers. Can anyone suggest a way to accomplish
this? I'm not so concerned about the type of the data returned
(integer or float), as long as I can get the information somehow.

Thanks for any help you can provide,
Stephen Greenwood
Bump.

Anyone? Thank you.
 
Stephen Greenwood wrote, on 01/26/11 18:12:
On Jan 18, 4:59 pm, Stephen Greenwood<stephen.greenw...@gmail.com
wrote:
I'm writing a SKILL function to count the number of crossings in a
waveform object. After some poking around in the SKILL ADE Reference,
I managed to write the following:

procedure( crossCount( inWave crosspt edgeType )
crossWave = cross(inWave crosspt 0 edgeType t "time")
numberOfCrossings = drVectorLength(drGetWaveformYVec(crossWave))
)

where the arguments are as follows:

inWave (waveform)
crosspt (float)
edgeType (string ["rising" | "falling" | "either"] )

The idea is to use the cross function to capture all crossings of a
user-defined threshold "crosspt", then get the length of one of the
vectors returned from that cross() function. (In this case I chose the
YVec.) So numberOfCrossings returns an integer, and it works fine when
"inWave" is a single waveform.

However, when "inWave" is a family of waveforms, the function does not
do what I want it to. It returns a single integer, whereas I want it
to return a vector of integers. Can anyone suggest a way to accomplish
this? I'm not so concerned about the type of the data returned
(integer or float), as long as I can get the information somehow.

Thanks for any help you can provide,
Stephen Greenwood

Bump.

Anyone? Thank you.
Stephen,

The way this is normally done is something like this (i.e. have a cond which
checks the type, and then use famMap if it's a family):

procedure(ABEyeHisto(waveform start stop period threshold bins @optional
(edgeType "either"))
cond(
;---------------------------------------------------------------------
; Handle ordinary waveform
;---------------------------------------------------------------------
(drIsWaveform(waveform)
let((xVec len clipped crosses cycleNum edgePos binArray binWidth bin
outXVec outYVec)
xVec=drGetWaveformXVec(waveform)
len=drVectorLength(xVec)
binArray=makeVector(bins+1 0)
binWidth=period/bins
;---------------------------------------------------------------
; if no start given (start less or equal to 0), use first time point
;---------------------------------------------------------------
when(start<=0
start=drGetElem(xVec 0))
;---------------------------------------------------------------
; if no stop given (stop less or equal to 0), use last time point
;---------------------------------------------------------------
when(stop<=0
stop=drGetElem(xVec len-1))
;---------------------------------------------------------------
; cast everything to floats, just to make sure
;---------------------------------------------------------------
start=float(start)
stop=float(stop)
period=float(period)
;---------------------------------------------------------------
; clip the waveform
;---------------------------------------------------------------
clipped=clip(waveform start stop)
;---------------------------------------------------------------
; And find the crossing points, and then bin them
;---------------------------------------------------------------
crosses=cross(clipped threshold 0 edgeType)
foreach(cross crosses
cross=cross-start
cycleNum=floor(cross/period)
edgePos=cross-cycleNum*period
bin=floor(edgePos/binWidth)
binArray[bin]=binArray[bin]+1
)
;---------------------------------------------------------------
; Build the waveform
;---------------------------------------------------------------
outXVec=drCreateVec('double bins)
outYVec=drCreateVec('intlong bins)
for(binNum 0 bins-1
drSetElem(outXVec binNum binWidth*(binNum+0.5))
drSetElem(outYVec binNum binArray[binNum])
)
drCreateWaveform(outXVec outYVec)
))
;---------------------------------------------------------------------
; Handle family
;---------------------------------------------------------------------
(famIsFamily(waveform)
famMap('ABEyeHisto waveform start stop period threshold bins edgeType)
) ; family
(t
error("ABEyeHisto - can't handle %L\n" waveform)
)
) ; cond
) ; procedure

Regards,

Andrew.
 

Welcome to EDABoard.com

Sponsor

Back
Top