Creating a linear phase from frequency using python and allantools

I’ve tried to create a program that could  calculate the linear phase of the 50 Hz mains in real time. Although there are online excellent Windows  software such as Stable32 from Hamilton Technical Services  and John Miles Timelab I needed a program running under Linux/Unix and Python. Luckly there was  an online  library that came close to what I was looking for : Allantools (  ) , for calculating allan deviation and related time & frequency statistics,  using the frequency to phase function inside allantools from a frequency data file did not create the linear phase. A linear phase slope corresponds to a constant frequency offset, which can be removed using a linear least-squares fit to the phase data or the ordinary arithmetic mean for the frequency. So i wrote a small program in python. You will need Allantools libraries and Numpy . The software come with   GPLv3 license,  you can use it freely just give credit to the author (me). A special thanks to William Riley from Stable32 that helped  to develop the correct mathematical theory behind the code. Here is the overall result expressed in milliseconds. Inside the program i’ve added also a subroutine for Pandas if you need it instead of numpy. (now commented )

You can finde the python code here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s