Home > Community > FPScript > calculate the true RMS value > Antwort auf: calculate the true RMS value

#9273
Bernhard KantzBernhard Kantz
Teilnehmer

The RMS value is a mean value, for a good estimation it is sufficient to average over enough full periods of the signal.
To compute the RMS over single periods, one can use the FPScript function LevelCrossings() to determine the indices of upward zero crossings as boundaries in the signal to compute one RMS value per period.

// indices of upward zero crossings (with 5 % hysteresis)
Dim idx = LevelCrossings(IA, 0, 0.05 * Range(IA), EVENT_POSITIVE, EVENT_INDEX)

// prepare output datasets in the desired length
Dim rms_y = IA.Y[0L] # Shape(idx[1L,-1L])
Dim rms_x = IA.X[0L] # Shape(idx[1L,-1L])

Dim i_begin, i_end

For Each Row i In idx[1L,-1L] Do
	// extract a full period
	i_begin = idx
	i_end   = idx - 1L
	// use x (time) of the interval center
	rms_x = IA.X[(i_begin + i_end) / 2L]
	rms_y = Mean(IA[i_begin, i_end], MEAN_SQUARE)
End

Signal(rms_y, rms_x)