Friday, April 1, 2011

Quantization Error Redux



Ray says that Sachin & Vaibhav are out of pocket for a little while. We'll wait and work on the board ourselves when we have time. In the meantime, I am reading a book on USB at home in the evenings, which will help us out if we need to debug or make changes in the communication.

My plan for today is to work on the new analysis of how the quantization error affects the Allan deviation by developing a program to do the calculations numerically.

I decided I wanted to first try just writing the new analysis in C/C++ (for faster development since I am most familiar with this language). I liked the NetBeans IDE that Gordon introduced me to, so I will try using it. I already reinstalled it with C/C++ support added a few weeks ago. Today, registered my installation with Oracle. Realized it needed Cygwin for the underlying gcc compiler. There is already a Cygwin environment in the Nios II IDE, but I decided instead of trying to use that one with NetBeans also, it would be cleaner to just install another one for general use. Did that, selecting gcc/make/standard libraries/gdb to install. Also included USB development support in case we need to do any raw USB coding in C. Created a new project "AnalyzeQuantErr"; now ready to start programming...

OK, I got to the core of my calculation, which is the following integral (expressed in Mathematica syntax):

Integrate[PDF[NormalDistribution[mu, sig], Phi2 - Phi1]*
PDF[NormalDistribution[mu, sig], Phi3 - Phi2], {Phi1, -(1/2), 1/2},
{Phi2, x2 - 1/2, x2 + 1/2}, {Phi3, x3 - 1/2, x3 + 1/2}]

Unfortunately, Mathematica is unable to integrate the result over Phi2, although it does manage to do the other two integrals. I tried all possible orders of integration, and did not achieve any better result. So, it looks as if I will have to numerically evaluate the following integral over Phi2:

Integrate[(1/4)*(Erf[(-(1/2) + mu - Phi2)/(Sqrt[2]*sig)] -
Erf[(1/2 + mu - Phi2)/(Sqrt[2]*sig)])*
(Erf[(-1 + 2*mu + 2*Phi2 - 2*x3)/(2*Sqrt[2]*sig)] -
Erf[(1 + 2*mu + 2*Phi2 - 2*x3)/(2*Sqrt[2]*sig)]),
{Phi2, -(1/2) + x2, 1/2 + x2}]

Fortunately, the error function erf() is included in the C math library already, so I don't have to write code to evaluate that as well.

OK, the program is done now, and I ran it and it produced sensible-looking results:

Here's the same graph on a log-log scale, which emphasizes the low end of the scale more:

As we can see, when the inherent frequency variation of the oscillator over the 1-second window size approaches 0, the measured Allan deviation due to quantization error approaches 1/2 cycle. This probably makes some kind of sense, since quantized phase measurements can be off by at most (+/-) 1/2 cycle, and 1/2 is also the RMS error of the quantized deviation that I obtained before by integrating the Dirac delta function under the assumption that the quantization errors of the 3 points x1,x2,x3 are independent & uniformly distributed in the range [-1/2,+1/2] cycle.

And, when the inherent frequency variation of the oscillator (for frequencies averaged over 1-second intervarls) increases well above +/- 1 cycle per second (standard deviation), the Allan deviation asymptotically approaches the actual standard deviation, which is correct since the quantization error then becomes relatively insignificant, and Allan deviation is designed to give the actual deviation in the case of a white noise model of the oscillator frequency fluctuations.

So, this seems like a good, solid theoretical result.

Meanwhile, let's apply this to our data set. We measured a 1-s Allan deviation of 1.7407 cycles. Going backwards through the above curve, we find that the actual standard deviation of frequency is 1.6674. Lo and behold, this is exactly the same as we had computed before by just using a simple quadrature combination of quantization error and inherent frequency variation, using the standard deviation of quantization error of 1/2 cycle that we had already obtained by our simpler analysis (integrating Dirac delta function)! This suggests that the above curve, arrived at by a complicated numerical integration procedure, could have been reproduced using the simple quadrature rule. Indeed, the curve obtained that way is indistinguishable to within 1/1000 cycle, which can be easily accounted for by the imprecision inherent to numerical integration.

This is all a good sanity check of the analysis - the two methods I used (simple quadrature rule & more detailed model) obtain the exact same result. So, I am now confident in this method (either/both method) for accounting for the quantization errors. Of course, it all assumes Gaussian white noise.

No comments:

Post a Comment