Olin Lathrop ha scritto: > No, not with the half wave rectified method. ok, though I don't see an exact... reason. I mean, scaling it differently, it should give some good results all the same. But actually maybe it is no longer needed. > If you make the assumption the input is nearly a sine, then you can get away > with measuring only the peaks. There are various things you can do to get > successively more clever, depending on what performance you really need. ok > First approximation is simply finding the peak of each period, and low pass > filtering those a little. The theoretical error due to missing the peak is > about 1.2%, which is well under your 5% spec, so maybe you can stop there. ok, my idea was to make this peak-measurement every 20mS, and average it with the previous one. Resimulated the peak method, and it fits in the 1.2% error indeed. > If you're worried about spikes and other noise messing up the peak > measurements, you can apply just a little low pass filtering and then look > for the peaks. The next step is to do third order approximation on the > three nearest samples to the peak to find the true peak. Such a small part > of a sine can be approximated quite well with a 3rd order polynomial, so the > 1.2% error will pretty much vanish. I also implemented this, storing 20 samples and grabbing the 3 highest, and averaging them. Still have to try it on both simulation and hardware. What would you suggest, if you can point me to an "algorithm", in depth? > It depends on what characteristics you care about and how much programming > and CPU time you are willing to spend on it. As I said, timing is not critical at all, even making one measure out of 1 second would be more than good (compared to the 50, now). CPU power is indeed in excess (apart from the Ethernet part of it). thx Dario -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist