Go Down

Topic: Got RMS value from PDM data (Read 5908 times) previous topic - next topic

eslavko

Hello...

I need to measure voltage (RMS) from incoming PDM (Pulse Density Modulation) data.
The voltage is actually 50Hz line voltage distorted sine.
For test I do in multiple steps.
I send PDM data to the low pass IIR filter so I got reconstructed vaweform.
After that I accumulate squared samples and finally do the sqrt with samples for one sine wave (20ms)
This works but take too long time. I think there should be better solution but I don't know for that.

Any help?


MarkT

Is this using an Arduino without hardware floating point?  Perhaps rewrite the code to use fixed-point
arithmetic would win significantly.  The algorithm is probably optimal as it stands, you want to reduce
processor cycles...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

eslavko

There was probably some other (faster) method to do that.
For now I need:
1x multiple,add,sub  per sample in IIR filter
1x multiple+add per sample in rms calculation
and at least 1x div and 1x sqrt for sample block.

I wonder if there are some "magic" possible to do that with less computation.
I know that will never catch to be realtime but for now I just skip to many samples.

I use integer math/fixed point.

Paul_KD7HB

There was probably some other (faster) method to do that.
For now I need:
1x multiple,add,sub  per sample in IIR filter
1x multiple+add per sample in rms calculation
and at least 1x div and 1x sqrt for sample block.

I wonder if there are some "magic" possible to do that with less computation.
I know that will never catch to be realtime but for now I just skip to many samples.

I use integer math/fixed point.
The "magic" for speed is to use binary shifts and add for multiply or subtract and binary shifts for divide.

And eliminate all loops, except the main loop of your program. They all take time.

Paul

MarkT

There was probably some other (faster) method to do that.
Can't see how.  PDM has constant RMS value to start with, you have to filter out the high frequencies
to measure the energy content of the low frequency signal, and IIR is usually pretty efficient for that.

And to get the RMS you have to square and add and divide and square-root.

The other approach would be to take the FFT, sum the energy of the low frequencies, but that's O(N log(N)),
as opposed to O(N) for the obvious approach.

You might be able to decimate-in-time after the IIR to reduce the number of samples to sum for the RMS step,
presumably the signal bandwidth is a lot less than the pulse rate.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up