Exemple #1
0
 def _to_volts(self, record):
     # convert rec to volts
     bps = self.board_info['bits_per_sample']
     if bps == 12:
         volt_rec = helpers.sample_to_volt_u12(record,
                                               bps,
                                               input_range_volts=0.4)
     else:
         logging.warning('sample to volt conversion does not exist for'
                         ' bps != 12, centered raw samples returned')
         volt_rec = record - np.mean(record)
     return volt_rec
    def _fit(self, rec):
        """
        Applies volts conversion, demodulation fit, low bandpass filter
        and integration limits to samples array

        Args:
            rec (numpy array): record from alazar to be multiplied
                               with the software signal, filtered and limited
                               to integration limits shape = (samples_taken, )

        Returns:
            magnitude (numpy array): shape = (demod_length, records_per_buffer)
            phase (numpy array): shape = (demod_length, records_per_buffer)
        """
        # convert rec to volts
        bps = self.board_info['bits_per_sample']
        if bps == 12:
            volt_rec = helpers.sample_to_volt_u12(rec, bps)
        else:
            logging.warning('sample to volt conversion does not exist for'
                            ' bps != 12, centered raw samples returned')
            volt_rec = rec - np.mean(rec, axis=1)

        # volt_rec to matrix and multiply with demodulation signal matrices
        mat_shape = (self._demod_length, self.buffer_num(), self.record_num(),
                     self.samples_per_record)
        volt_rec_mat = np.outer(np.ones(self._demod_length),
                                volt_rec).reshape(mat_shape)
        re_mat = np.multiply(volt_rec_mat, self.cos_mat)
        im_mat = np.multiply(volt_rec_mat, self.sin_mat)

        # filter out higher freq component
        cutoff = self.get_max_demod_freq() / 10
        if self.filter_settings['filter'] == 0:
            re_filtered = helpers.filter_win(re_mat,
                                             cutoff,
                                             self.sample_rate,
                                             self.filter_settings['numtaps'],
                                             axis=3)
            im_filtered = helpers.filter_win(im_mat,
                                             cutoff,
                                             self.sample_rate,
                                             self.filter_settings['numtaps'],
                                             axis=3)
        elif self.filter_settings['filter'] == 1:
            re_filtered = helpers.filter_ls(re_mat,
                                            cutoff,
                                            self.sample_rate,
                                            self.filter_settings['numtaps'],
                                            axis=3)
            im_filtered = helpers.filter_ls(im_mat,
                                            cutoff,
                                            self.sample_rate,
                                            self.filter_settings['numtaps'],
                                            axis=3)
        elif self.filter_settings['filter'] == 2:
            re_filtered = re_mat
            im_filtered = im_mat

        # apply integration limits
        beginning = int(self.int_delay() * self.sample_rate)
        end = beginning + int(self.int_time() * self.sample_rate)

        re_limited = re_filtered[:, :, beginning:end]
        im_limited = im_filtered[:, :, beginning:end]

        # convert to magnitude and phase
        complex_mat = re_limited + im_limited * 1j
        magnitude = np.mean(abs(complex_mat), axis=3)
        phase = np.mean(np.angle(complex_mat, deg=True), axis=3)

        return magnitude, phase