Sampling an ac waveform on microcontroller

Click For Summary

Discussion Overview

The discussion revolves around the feasibility of sampling an AC waveform using a microcontroller to calculate its frequency, amplitude, and phase. Participants explore various methods and considerations related to sampling rates, the number of samples, and the impact of real-world conditions on measurement accuracy.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a project using DFT for AC power measurement at 50Hz, questioning the possibility of obtaining frequency, amplitude, and phase from 100 samples taken at a sampling frequency of 3.33kHz.
  • Another participant suggests that if the waveform is known to be sinusoidal, four samples can be used to determine the amplitude, phase, and frequency, recommending specific sample indices for precision.
  • A different participant reflects on the challenges faced in designing algorithms for power system protection, emphasizing the trade-off between sampling rate, number of samples, and measurement quality.
  • One participant reiterates the importance of taking samples at the fastest rate possible, sharing their experience of achieving accurate results by knowing the frequency beforehand.
  • Another participant highlights that accuracy requirements and measurement conditions significantly affect the feasibility of using only four samples, suggesting that using all available samples or applying FFT could yield better results.
  • Concerns are raised about the noise in power system waveforms, with a recommendation to measure delays between zero crossings for reliable frequency measurement.

Areas of Agreement / Disagreement

Participants express various viewpoints on the adequacy of using four samples versus a larger number of samples for accurate measurements. There is no consensus on the best approach, and the discussion remains unresolved regarding the optimal method for sampling and analysis.

Contextual Notes

Participants mention limitations related to the accuracy of AD conversion, the effects of noise and disturbances from nearby electrical components, and the need for specific accuracy and reliability requirements to guide the sampling strategy.

cnh1995
Homework Helper
Gold Member
Messages
3,489
Reaction score
1,163
I did a small project on ac power measurement using arduino a few months ago. But it was specifically for 50Hz supply only. I sampled the waveform in a 20ms interval and applied DFT to get the amplitude and phase. This works good when the frequency is between 49.5 Hz to 50.5 Hz. The aim was to demonstrate how dft can be used for measurement of the ac power, so we didn't care much about the frequency. I can use IC LM331 in frequency to voltage converter mode and get the frequency first and set the time for sampling accordingly. This will work for any frequency.
But is it possible to calculate the frequency, amplitude and phase if I just sampled 100 samples with a sampling frequency fs? Say a 50Hz sinusoidal waveform is applied to the ADC and I took 100 samples of the signal in 30ms, which gives a sampling frequency of 3.33k samples/sec. Is it possible to get the fundamental frequency, amplitude and phase using these 100 samples?
 
Engineering news on Phys.org
cnh1995 said:
But is it possible to calculate the frequency, amplitude and phase if I just sampled 100 samples with a sampling frequency fs?
Assuming that you "know" it i s a sine wave you are sampling, the signal can be expressed:

Vn = A * sin( n*Δt * ω + φ ) + DCoffset ( Δt is the sampling period, n is the sample number )

You have 4 unknown which can be determined by 4 samples. So "just" make a program, adjusting the 4 unknown values, so that there will be a match between measured and theoretical values.

I will recommend that you spread out the 4 samples ( n = 1, 15, 35, 69 ) to achieve precision.

Hints: The time between two zero crossings will indicate the signal period.
The signal value of the sample in the middle of the crossings will indicate the amplitude.
In the same way you can guess φ.
Now fine tune.
 
Last edited:
  • Like
Likes   Reactions: cnh1995 and jim mcnamara
I recall struggling with this problem years ago when designing algorithms for digital devices to protect power systems. Obviously, a protection device should decide what it sees, and trigger corrective actions as rapidly as possible. On the other hand, it should have zero false positives where it jumps to the wrong conclusion.

If everything is ideal and perfect, you can do it with 4 samples as @Hesch said, (actually 3 samples if you assume the DC offset is zero). But real life waveforms are far from ideal, especially in transient states.

Bottom line, there is a trade-off between sampling rate, number of samples, and the quality of your calculated result. So unless you specify your accuracy/reliability requirements, and the details of what you are measuring and your apparatus, your question can't be answered.

Having said that, here's a hint. Start with one full cycle of samples taken at the fastest rate you can manage.
 
  • Like
Likes   Reactions: cnh1995
anorlunda said:
Having said that, here's a hint. Start with one full cycle of samples taken at the fastest rate you can manage.
That's what I did in my earlier project. I "knew" the frequency to be 50Hz and I took samples within 20ms using an on-board timer. The results were accurate. I guess I'll have to use the f to v converter IC for frequency measurement. Once the frequency is obtained, DFT gives amplitude and phase of the fundamental harmonic.
 
anorlunda said:
So unless you specify your accuracy/reliability requirements, and the details of what you are measuring and your apparatus, your question can't be answered.
Of course you can specify accuracy requirement, so that the task will be impossible. The resolution of the AD-conversion alone, will limit the accuracy. Use of triacs/thyristors close to the measurement point will disturb the measurement quality enormous, etc. But in principle the use of just 4 samples may be used, though use of all 100 samples by fine tuning ( or use of a FFT ) will give a better and more reliable result ( and longer calculation time ).

As for the hardware ( AD-conversion ), an integrating AD-converter could be used. Have a look at the device: AD652 from Analog Devices. The signal is driving a Voltage Controlled Oscillator, which in turn drives a counter, integrating the mean value of the signal within a sample period. Thereby glitches in the signal will be ignored. The principle of the AD652 may be upgraded, forming a PWM-signal instead of a clock-signal.
 
  • Like
Likes   Reactions: cnh1995
What I had in mind is that power system waveforms can be very noisy, especially with switching surges.

surge-effect-on-power-system.jpg


The most reliable way to measure fundamental frequency via sampling is to measure the delay between zero crossings. You can make a band-pass filter by ignoring crossings except those which occur within a defined time window of the previous crossing.
 
  • Like
Likes   Reactions: cnh1995

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 46 ·
2
Replies
46
Views
6K
  • · Replies 7 ·
Replies
7
Views
4K
Replies
7
Views
4K
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
6
Views
4K