예제 #1
0
def generate_eye_data(domain, field, scale=None):
    """
    :param object domain: A domain
    :param object field: Current field
    :param double scale: Scale factor by which to divide power
    :return: Temporal array and power matrix
    :rtype: Tuple

    Generates a temporal array and matrix containing eye traces. Each eye
    trace consists of the power array calculated for successive bits.
    """
    # Use the first bit range for the temporal axis:
    t_eye = domain.t[0:domain.samples_per_bit]

    # Calculate power array and normalise if requested:
    P_t = temporal_power(field)
    if(scale is not None):
        P_t /= scale

    # Reshape into matrix with total_bits rows and samples_per_bit columns:
    P_eye = P_t.reshape(domain.total_bits, domain.samples_per_bit)

    # If passed a matrix, pyplot will plot each column as a separate data
    # series. Require each row to be plotted, so transpose the matrix:
    return t_eye, P_eye.T
예제 #2
0
    def calculate(self):
        """ Actual calculation of metrics is performed in this function. """
        maximum_absolute_difference = -1.0
        sample_threshold = -1
        maximum_Q = -1.0
        sample_time = -1.0

        TB = self.domain.total_bits
        SPB = self.domain.samples_per_bit

        for spb in range(SPB):
            data = [temporal_power(self.field[tb * SPB + spb])
                    for tb in range(TB)]

            threshold = np.sum(data) / TB

            zeros = []
            ones = []
            for datum in data:
                if(datum < threshold):
                    zeros.append(datum)
                else:
                    ones.append(datum)

            if((len(zeros) < 4) or (len(ones) < 4)):
                print "Not enough ones and zeros to calculate Q"
                #~raise Exception("Not enough ones and zeros to calculate Q")

            absolute_difference = np.abs(np.mean(ones) - np.mean(zeros))
            if(absolute_difference > maximum_absolute_difference):
                maximum_absolute_difference = absolute_difference
                maximum_Q = \
                    absolute_difference / (np.std(ones) + np.std(zeros))

                sample_time = spb * self.domain.dt
                sample_threshold = threshold

                # Store ones and zeros arrays:
                self.ones = ones
                self.zeros = zeros

        if(maximum_Q < 0.0):
            raise Exception("Unable to calculate maximum Q!")

        self.max_Q_dB = 10.0 * np.log10(maximum_Q)
        self.sample_time = sample_time
        self.sample_threshold = sample_threshold

        self.mean_peak_power_ones = np.mean(self.ones)
        self.mean_peak_power_zeros = np.mean(self.zeros)

        delta_ones = np.max(self.ones) - np.min(self.ones)
        AJ = 0.5 * delta_ones / np.mean(self.ones)
        self.amplitude_jitter = AJ

        ER = np.max(self.zeros) / (np.mean(self.ones) * (1.0 - AJ))
        self.extinction_ratio = -10.0 * np.log10(ER)