If you'd like to make the number of samples consistent over time, I'd use the resample() function in a formula. $signal.resample(1min) If you pass resample() a period such as 1min, the result is a signal that will have a sample every 1 minute, regardless of the input sample frequency.
To compute the error, I would create a new signal which is the difference between PV and SP. Then create a periodic condition for which you'd like to sum up this value and use the 'Signal from Condition' tool to sum the new signal over the given condition. To count the number of values in a period, use the 'Signal from Condition' tool to count the number of samples in your signal using whatever periodic condition you'd like as a bounding condition.
For the number of reversals, I'd first use .runningDelta() to create a running delta signal of the signal you'd like to count the number of reversals for. I'd then create a condition using the 'Value Search' tool for anytime the delta signal is greater than or equal to zero, and another condition for anytime the delta signal is less than zero. Then, using the same method as above, create a periodic signal over which you'd like to calculate the number of reversals and use the 'Signal from Condition' tools to count the number of capsules within a given period. The total number of reversals should equal the number of >= 0 capsules plus number of <0 capsules minus 1.
You could do this all in one formula if you'd like.
$delta = $cv.runningDelta()
//Conditions when delta >= 0 & < 0
$gte = $delta >= 0
$lt = $delta < 0
//Condition when to total the number of reversals
$period = periods(10min)
//Signal for total number of $gte/$lt conditions
$gteCount = $gte.aggregate(count(), $period, startKey())
$ltCount = $lt.aggregate(count(), $period, startKey())
//Signal for total number of reversals
$reversals = $gteCount + $ltCount - 1
//Output the reversals signal with Step interpolation
$reversals.toStep()
And here's some of the outputs.
Andrew