public double getMeanPeriod (double tmin, double tmax, double minimumPeriod, double maximumPeriod, double maximumPeriodFactor){
        
        if (tmax <= tmin){tmin = this.xmin; tmax = this.xmax;}   /* Autowindowing. */
	
        Triple<Integer,Integer,Integer> tri = getWindowPoints (tmin, tmax);
        int numberOfPeriods = tri.first - 1;
        int imin = tri.second;
        int imax = tri.third;
        
        if (numberOfPeriods < 1) return Pitch.NUMundefined;
        double sum = 0.0;
        for (int i = imin; i < imax; i ++) {
            if (isPeriod (i, minimumPeriod, maximumPeriod, maximumPeriodFactor)) {
                sum += this.t [i + 1] - this.t [i];   /* This interval counts as a period. */
            } else {
                numberOfPeriods --;   /* This interval does not count as a period. */
            }
        }
        return numberOfPeriods > 0 ? sum / numberOfPeriods : Pitch.NUMundefined;
    }