Forums

Best way to estimate amplitude and phase

Started by Mimar July 9, 2013
Kevin Neilson <kevin.neilson@xilinx.com> wrote:
> Is this just a 60Hz wave with noise? > If so, some sort of DFT sounds like overkill. > Why can't you just find the peaks (with an early-late loop, > or Muller-Mueller or something like that) and measure the peaks, > averaging over a few to cancel out noise effects? > I may be missing something here.
If you know the frequency well enough, linear least squares, if not, then non-linear least squares (including the frequency as a fit parameter). -- glen
On 7/9/13 4:14 AM, Mimar wrote:

> > I need to estimate amplitude and phase of power line voltage.
i'll repeat everyone else "phase relative to what?" if you have a reference sinusoid of exactly the same frequency of your unknown sinusoid (unknown amplitude and phase, but known frequency), then it shouldn't be too hard to come up with another reference that is exactly 90 degrees outa phase with the first given reference (use a hilbert transformer, if you must). we'll call that a "quadrature reference". so you have these two reference sinusoids: reference: r[n] = cos(w0*n) quadrature reference: q[n] = sin(w0*n) and your input signal with *exactly* the same frequency and with unknown amplitude and phase is x[n] = A*cos(w0*n + phi) and you want to know what A and phi are. so first multiply the input against the two references: x[n]*r[n] = A*cos(w0*n+phi) * cos(w0*n) x[n]*q[n] = A*cos(w0*n+phi) * sin(w0*n) toss in a couple of trig identities and you get: x[n]*r[n] = A/2*( cos(phi) + cos(2*w0*n+phi) ) x[n]*q[n] = A/2*( -sin(phi) + sin(2*w0*n+phi) ) note that in both, there is a DC component and a high frequency component at a frequency of 2*w0. next, low-pass filter out the components at frequency 2*w0 LPF{ x[n]*r[n] } = A/2 * cos(phi) LPF{ x[n]*q[n] } = -A/2 * sin(phi) you will see that A = 2*sqrt( (LPF{x[n]*r[n]})^2 + (LPF{x[n]*r[n]})^2 ) and phi = arg{ LPF{x[n]*r[n]} - j*LPF{x[n]*q[n]} } where arg{} is the complex angle. if you know that |phi| < pi/2, then you can say phi = arctan( -LPF{x[n]*q[n]} / LPF{x[n]*r[n]} ) otherwise you need the 4-quadrant arctan() function commonly called atan2() in most math libraries. for the definition, look up http://en.wikipedia.org/wiki/Atan2#Definition_and_computation the low-pass filter should have a gain at DC of 1 (0 dB), otherwise you will have to compensate for that in evaluating A. a simple LPF with DC gain of 1 is: y[n] = (1-p)*x[n] + p*y[n-1] where p is the pole and should be 0 < 1-p << 1 . as long as you have a reference sinusoid (and can turn that into a reference cosinusoid), that's all that's to it. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Take your real samples and run them through a Hilbert Transformer (FIR) to
get complex values. Take ATAN2 of complex values. Check phase values for
wrap around and unwrap by adding 2*pi. Find least squares fit to line of
phases. The slope will be the frequency, the y intercept will be the phase.
	 

_____________________________		
Posted through www.DSPRelated.com
On 7/9/2013 6:14 AM, Mimar wrote:
> Hello, > > as Tim Wescott wrote in his last followup it will be better to create new > thread instead to continue in "Sliding Goertzel problem" thread. > > I need to estimate amplitude and phase of power line voltage. My boss has > said me recently we have to compute these values quickly and accurately.
The best method is the one that you can master. What about may be not the very top but really bohemian method, that even your boss could understand and appreciate. Find zero crossings in the signal; this immediately tells frequency and phase. Amplitude is what happens with the signal right between zero crossings. "A" graders in elementary math could elaborate further by adding averaging into the algorithm. An interpolation to refine zero crossing positions would be advanced PhD level work. //---------- Q: Why it is impossible to have sex in Red Square in Moscow ? A: Because every bystander idiot would be trying to give his invaluable advice. Vladimir Vassilevsky DSP and Mixed Signal Designs www.abvolt.com
Since the OP has mentioned he is measuring power-line  frequencies, it's safe to assume he has a voltage channel and a current channel, so the phase difference between them is what's important. 

Bob

Ps, excellent opportunity for jokes about "imaginary power"
radams2000@gmail.com writes:
> [...] > Ps, excellent opportunity for jokes about "imaginary power"
Apparently. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
On Wednesday, July 10, 2013 8:57:24 AM UTC-4, Randy Yates wrote:
> writes: > > > [...] > > > Ps, excellent opportunity for jokes about "imaginary power" > > > > Apparently. > > -- > > Randy Yates > > Digital Signal Labs > > http://www.digitalsignallabs.com
Re: Imaginary power and related poorly worded/named concepts. The state of Georgia used to always ask near the end of the individual annual tax return "Did you file an intangible tax return? If not, why not?" I used to always answer "No, because if it is intangible, it doesn't relate to anything!" I never had a problem with the state for this answer. Of course an "intangible tax return" was for declaring dividend payments and paying income tax on them. The state no longer asks that question. But yes, one still shows dividends as income and pays tax on it! Clay
On Wed, 10 Jul 2013 07:54:26 -0700 (PDT), clay@claysturner.com
wrote:

>Re: Imaginary power and related poorly worded/named concepts. > > >The state of Georgia used to always ask near the end of the individual annual tax return "Did you file an intangible tax return? If not, why not?"
Would it have been so difficult to call it a "tax on intangibles", and avoid the ambiguity? People pronounce "Empire State Building" as "empire STATE building", as though it is the "'STATE Building' of the Empire". It should be pronounced "(EMPIRE state) building", as "Building of the 'Empire State'". Same goes for Madison Square Garden. It is not a "square garden" on Madison Avenue, it is a garden at Madison Square.
Yes; this sounds much simpler to me than some type of DFT.  I don't know if the poster said what his sample rate is.  If it's low (compared to the fundamental freq) he'll need to interpolate, but a cubic interpolator based on four samples is pretty easy to make.
On 7/10/2013 12:49 PM, Kevin Neilson wrote:
> Yes; this sounds much simpler to me than some type of DFT. I don't > know if the poster said what his sample rate is. If it's low > (compared to the fundamental freq) he'll need to interpolate, but a > cubic interpolator based on four samples is pretty easy to make. >
It is about AC mains frequency; how could sample rate be slow? Oh, I forgot: OP is in Bohemia. They do things without haste. Starting project in March, no result by now. Perhaps, this slowness applies to sample rate, too. VLV