latest matlab code.  Still need to implement better square wave frequency estimation logic