about rms value
The RMS of a waveform is the square root of the mean of the read value squared, or more simply, the area under the function signal divided by time taken for reading. This is easiest found by calculus.
Each wave will generate a different formula because the input function is a different formula - from the simple PWM square wave to complex multiple frequency sinuosidal waveform to random waveforms.
The easiest way to approximate this accurately is to go back to the original formula, sample much higher than the smallest signal period and calculate. Keep in mind a PWM signal of say 1mS repeated every 20 mS in this case is 50Hz but the smallest signal period is 1mS (1000Hz).
Otherwise you need a formula for each waveform and a way to determine which formula to apply.