Finding period of a square wave with varying sampling frequency I have a square wave (0-1.8V) with a varying sampling frequency (from a circuit simulator). It is also not a perfect square wave (the high and low signal could be very close to but not precisely zero or 1 Volt) and the fall time is slightly slower than the rise time. 

Another factor is that I will retake the data and the period (and possibly duty cycle as well) will change when I alter another parameter, so I am not working with a fixed number of cycles per window. 

I tried autocorrelation but it seems that it gave me double or so the actual period. And fft seems to need a fixed sampling rate.  What would be the best solution to finding the period of this square wave?
Pick a nice center value, say 1.0, scan across looking for crossings from down to up (or the reverse).  Mark the spot of your first crossing, count up some fixed number of crossings, call the count N.  Take your system timer value at your first crossing and your last crossing.  Divide the time interval by N and you'll have a very good estimate of the period.  How uneven the crossings are in the interval is immaterial.  If you can assure the two crossing that you are timing happen in "the same state", you will lose one more level of uncertainty.

You can't do it much simpler than that.  Increased accuracy will come from interpolating the crossing point rather than taking the closest sample's time.

----------------------

Follow up

You'll have to figure the Interpolate routine out yourself.  It's not that hard.

The logic is very straightforward and significantly less computationly heavy than an auto-correlation technique.  More accurate in this case too.

Pseudo-code


    FirstIndex = -1
    N = 0

    For i = 0 to PointCount
      If signal[i] &lt;= 1.0 and signal[i+1] &gt; 1.0 Then
         If FirstIndex &lt; 0 Then
            T1A = System.Time(i)
            T1B = System.Time(i+1)
            FirstIndex = i
         Else        
            TNA = System.Time(i)
            TNB = System.Time(i+1)
            LastIndex = i
            N += 1
         End If
      End If
    Next

    T1 = Interpolate( T1A, T1B, Signal[FirstIndex], Signal[FirstIndex+1] )
    TN = Interpolate( TNA, TNB, Signal[LastIndex], Signal[LastIndex+1] )

    Period = ( TN - T1 ) / N


You may not need to interpolate, (TNA - T1A)/N may be accurate enough.