Beispiel #1
0
 def calcBeamPatternLinearArray(self, w, M, spacing, thetas, steering_angle=0, takePowerAndNormalize=False):
    x_el = np.linspace( -(M-1)/(2.0/spacing), (M-1)/(2.0/spacing), M )
    W_matrix = np.exp(-1j * np.outer(2*np.pi*(np.sin(thetas) - np.sin(steering_angle)), x_el))
    W = np.dot(W_matrix , w)
    if takePowerAndNormalize:
       W = W*W.conj()
       W = W / W.max()
    
    return W
Beispiel #2
0
    def calcBeamPatternLinearArray(self,
                                   w,
                                   M,
                                   spacing,
                                   thetas,
                                   steering_angle=0,
                                   takePowerAndNormalize=False):
        x_el = np.linspace(-(M - 1) / (2.0 / spacing),
                           (M - 1) / (2.0 / spacing), M)
        W_matrix = np.exp(
            -1j *
            np.outer(2 * np.pi *
                     (np.sin(thetas) - np.sin(steering_angle)), x_el))
        W = np.dot(W_matrix, w)
        if takePowerAndNormalize:
            W = W * W.conj()
            W = W / W.max()

        return W
Beispiel #3
0
   def plot(self, axis1, axis2, axis3=None, axis4=None):
      # Display results
      import framework.mypylab as pl
      from framework.mynumpy import abs, db, mean, sin, cos, pi

      self.interpolateData()

      if VERBOSE:
         print 'Start plotting...'

      theta,rad = np.meshgrid(self.angles_intrp, self.ranges_intrp)
      x = 1000 * rad * sin(theta)
      y = 1000 * rad * cos(theta)
      
      ## Start Plotting
      if (axis1 == 0): # stand alone plotting
         pl.figure()
         pl.subplot(1,2,1, aspect=1)
         pl.pcolormesh(x, y, self.img_das_detected, cmap=pl.cm.gray, vmin=self.minDynRange.value, vmax=self.maxDynRange.value)
         pl.gca().invert_yaxis()
      else: # Plotting in given axis
         axis1.pcolormesh(x, y, self.img_das_detected, cmap=pl.cm.gray, vmin=self.minDynRange.value, vmax=self.maxDynRange.value)
         axis1.set_title('Delay-and-sum', fontsize='large')
         axis1.set_xlabel('Width [mm]', fontsize='large')
         axis1.set_ylabel('Depth [mm]', fontsize='large')
         axis1.set_xlim(x.min(), x.max())
         axis1.set_ylim(y.max(), y.min())
      
      if (axis2 == 0):
         ax = 0
         pl.subplot(1,2,2, aspect=1)
         pl.pcolormesh(x, y, self.img_cap_detected, cmap=pl.cm.gray, vmin=self.minDynRangeCapon.value, vmax=self.maxDynRangeCapon.value)
         pl.gca().invert_yaxis()
         pl.show()
      else:
         ax = axis2.pcolormesh(x, y, self.img_cap_detected, cmap=pl.cm.gray, vmin=self.minDynRangeCapon.value, vmax=self.maxDynRangeCapon.value)
         if self.Nb.value > 0:
            axis2.set_title('BS-Capon', fontsize='large')
         else:
            axis2.set_title('ES-Capon', fontsize='large')
         axis2.set_xlabel('Width [mm]', fontsize='large')
         axis2.set_ylabel('Depth [mm]', fontsize='large')
         axis2.set_xlim(x.min(), x.max())
         axis2.set_ylim(y.max(), y.min())
         
      if axis3 is not None:
         # plot axial profile
         #profile_angle = np.arctan( self.profilePos[0] / self.profilePos[1] )
         #if profile_angle < self.angles_intrp[-1] and profile_angle > self.angles_intrp[0]: 
         #   range_slice_idx = round(self.angles_intrp.shape[0] * (profile_angle-self.angles_intrp[0]) / (self.angles_intrp[-1]-self.angles_intrp[0]))
         #   img_das_rslice = img_das_detected[:, range_slice_idx]
         #   img_cap_rslice = img_cap_detected[:, range_slice_idx]
         #
         #   axis3.plot(y[:,range_slice_idx], img_das_rslice, label='DAS')
         #   axis3.plot(y[:,range_slice_idx], img_cap_rslice, '-r', label='Capon')
         #   
         #   axis3.set_ylim([self.minDynRange.value, self.maxDynRange.value])
         #   
         #   axis3.set_title('Radial intensity at %d degrees'%round(profile_angle*180/np.pi))
         #   axis3.set_xlabel('Depth [mm]')
         #   axis3.set_ylabel('Radial intensity [dB]')
         #   axis3.legend(loc=3, markerscale=0.5)
         
         # Plot beampatterns and power spectrums
         profile_range = np.sqrt( self.profilePos[0]**2 + self.profilePos[1]**2 ) / 1000.0
         profile_angle = np.arctan( self.profilePos[0] / self.profilePos[1] )
         
         if profile_range < self.ranges_intrp[-1] and profile_range > self.ranges_intrp[0] and profile_angle < self.angles_intrp[-1] and profile_angle > self.angles_intrp[0]:
            
            range = round(self.ranges_intrp.shape[0] * (profile_range-self.ranges_intrp[0]) / (self.ranges_intrp[-1]-self.ranges_intrp[0]))
            angle = round(self.angles_intrp.shape[0] * (profile_angle-self.angles_intrp[0]) / (self.angles_intrp[-1]-self.angles_intrp[0]))
            
            spacing = 0.5
            
            # plot beamspace data
            x_data = self.Xd_i[angle / (2*self.Kx.value), range / (1*self.Ky.value), :]
            das_beams = self.calcBeamPatternLinearArray(x_data, self.Nm, spacing, self.angles_intrp, self.angles_intrp[angle], takePowerAndNormalize=True)
            axis3.plot(x[range,:], 10*np.log10(das_beams) + self.maxDynRange.value, label='DAS Sample Spectrum')
            
            # make Capon beam pattern
            w_capon = self.capon_weights[angle / (2*self.Kx.value), range / (1*self.Ky.value), :]
            W_capon = self.calcBeamPatternLinearArray(w_capon, self.L.value, spacing, self.angles_intrp, self.angles_intrp[angle])
            W_capon = abs(W_capon*W_capon.conj())
            W_capon = W_capon / W_capon[angle]
            axis3.plot(x[range,:], 10*np.log10(W_capon) + self.maxDynRange.value - 10 , label='Capon Beampattern')
            
            # make DAS beam pattern for subarrays
            W_das = self.calcBeamPatternLinearArray(self.das_w_sub, self.L.value, spacing, self.angles_intrp, self.angles_intrp[angle], takePowerAndNormalize=True)       
            axis3.plot(x[range,:], 10*np.log10(W_das) + self.maxDynRange.value - 10, label='DAS Beampattern')
            
            # make total Capon beam pattern for the whole system (tx and rx)?
            
            # plot selected direction/angle
            axis3.plot([x[range,angle], x[range,angle]], [self.minDynRange.value, self.maxDynRange.value], label='Steering angle')
         
         axis3.set_ylim([self.minDynRange.value, self.maxDynRange.value])
         axis3.set_title('Beam pattern at %d degrees and %d mm range'%(round(profile_angle*180/np.pi), round(profile_range*1000)), fontsize='large') 
         axis3.set_xlabel('Width [mm]', fontsize='large')
         axis3.set_ylabel('Intensity/Gain [dB]', fontsize='large')
         if self.show_legends.value is 1:
            axis3.legend(loc=3, markerscale=0.5)
      
      if axis4 is not None:
         profile_range = np.sqrt(self.profilePos[0]**2 + self.profilePos[1]**2) / 1000.0
         
         if profile_range < self.ranges_intrp[-1] and profile_range > self.ranges_intrp[0]:
            angle_slice_idx = round(self.ranges_intrp.shape[0] * (profile_range-self.ranges_intrp[0]) / (self.ranges_intrp[-1]-self.ranges_intrp[0]))
            self.img_das_aslice = self.img_das_detected[angle_slice_idx, :]
            self.img_cap_aslice = self.img_cap_detected[angle_slice_idx, :]
            self.x_aslice = x[angle_slice_idx,:]
         
            axis4.plot(self.x_aslice, self.img_das_aslice, label='DAS')
            if (self.Nb.value > 0):
               axis4.plot(self.x_aslice, self.img_cap_aslice, '-r', label='BS-Capon')
            else:
               axis4.plot(self.x_aslice, self.img_cap_aslice, '-r', label='ES-Capon')
            
            axis4.set_ylim([self.minDynRange.value, self.maxDynRange.value])
            
            axis4.set_title('Lateral intensity at %d mm range'%round(profile_range*1000), fontsize='large')
            axis4.set_xlabel('Width [mm]', fontsize='large')
            axis4.set_ylabel('Lateral intensity [dB]', fontsize='large')
            if self.show_legends.value is 1:
               axis4.legend(loc=3, markerscale=0.5)
        
      if VERBOSE:   
         print 'done'
         
      return ax
Beispiel #4
0
    def plot(self, axis1, axis2, axis3=None, axis4=None):
        # Display results
        import framework.mypylab as pl
        from framework.mynumpy import abs, db, mean, sin, cos, pi

        self.interpolateData()

        if VERBOSE:
            print 'Start plotting...'

        theta, rad = np.meshgrid(self.angles_intrp, self.ranges_intrp)
        x = 1000 * rad * sin(theta)
        y = 1000 * rad * cos(theta)

        ## Start Plotting
        if (axis1 == 0):  # stand alone plotting
            pl.figure()
            pl.subplot(1, 2, 1, aspect=1)
            pl.pcolormesh(x,
                          y,
                          self.img_das_detected,
                          cmap=pl.cm.gray,
                          vmin=self.minDynRange.value,
                          vmax=self.maxDynRange.value)
            pl.gca().invert_yaxis()
        else:  # Plotting in given axis
            axis1.pcolormesh(x,
                             y,
                             self.img_das_detected,
                             cmap=pl.cm.gray,
                             vmin=self.minDynRange.value,
                             vmax=self.maxDynRange.value)
            axis1.set_title('Delay-and-sum', fontsize='large')
            axis1.set_xlabel('Width [mm]', fontsize='large')
            axis1.set_ylabel('Depth [mm]', fontsize='large')
            axis1.set_xlim(x.min(), x.max())
            axis1.set_ylim(y.max(), y.min())

        if (axis2 == 0):
            ax = 0
            pl.subplot(1, 2, 2, aspect=1)
            pl.pcolormesh(x,
                          y,
                          self.img_cap_detected,
                          cmap=pl.cm.gray,
                          vmin=self.minDynRangeCapon.value,
                          vmax=self.maxDynRangeCapon.value)
            pl.gca().invert_yaxis()
            pl.show()
        else:
            ax = axis2.pcolormesh(x,
                                  y,
                                  self.img_cap_detected,
                                  cmap=pl.cm.gray,
                                  vmin=self.minDynRangeCapon.value,
                                  vmax=self.maxDynRangeCapon.value)
            if self.Nb.value > 0:
                axis2.set_title('BS-Capon', fontsize='large')
            else:
                axis2.set_title('ES-Capon', fontsize='large')
            axis2.set_xlabel('Width [mm]', fontsize='large')
            axis2.set_ylabel('Depth [mm]', fontsize='large')
            axis2.set_xlim(x.min(), x.max())
            axis2.set_ylim(y.max(), y.min())

        if axis3 is not None:
            # plot axial profile
            #profile_angle = np.arctan( self.profilePos[0] / self.profilePos[1] )
            #if profile_angle < self.angles_intrp[-1] and profile_angle > self.angles_intrp[0]:
            #   range_slice_idx = round(self.angles_intrp.shape[0] * (profile_angle-self.angles_intrp[0]) / (self.angles_intrp[-1]-self.angles_intrp[0]))
            #   img_das_rslice = img_das_detected[:, range_slice_idx]
            #   img_cap_rslice = img_cap_detected[:, range_slice_idx]
            #
            #   axis3.plot(y[:,range_slice_idx], img_das_rslice, label='DAS')
            #   axis3.plot(y[:,range_slice_idx], img_cap_rslice, '-r', label='Capon')
            #
            #   axis3.set_ylim([self.minDynRange.value, self.maxDynRange.value])
            #
            #   axis3.set_title('Radial intensity at %d degrees'%round(profile_angle*180/np.pi))
            #   axis3.set_xlabel('Depth [mm]')
            #   axis3.set_ylabel('Radial intensity [dB]')
            #   axis3.legend(loc=3, markerscale=0.5)

            # Plot beampatterns and power spectrums
            profile_range = np.sqrt(self.profilePos[0]**2 +
                                    self.profilePos[1]**2) / 1000.0
            profile_angle = np.arctan(self.profilePos[0] / self.profilePos[1])

            if profile_range < self.ranges_intrp[
                    -1] and profile_range > self.ranges_intrp[
                        0] and profile_angle < self.angles_intrp[
                            -1] and profile_angle > self.angles_intrp[0]:

                range = round(self.ranges_intrp.shape[0] *
                              (profile_range - self.ranges_intrp[0]) /
                              (self.ranges_intrp[-1] - self.ranges_intrp[0]))
                angle = round(self.angles_intrp.shape[0] *
                              (profile_angle - self.angles_intrp[0]) /
                              (self.angles_intrp[-1] - self.angles_intrp[0]))

                spacing = 0.5

                # plot beamspace data
                x_data = self.Xd_i[angle / (2 * self.Kx.value),
                                   range / (1 * self.Ky.value), :]
                das_beams = self.calcBeamPatternLinearArray(
                    x_data,
                    self.Nm,
                    spacing,
                    self.angles_intrp,
                    self.angles_intrp[angle],
                    takePowerAndNormalize=True)
                axis3.plot(x[range, :],
                           10 * np.log10(das_beams) + self.maxDynRange.value,
                           label='DAS Sample Spectrum')

                # make Capon beam pattern
                w_capon = self.capon_weights[angle / (2 * self.Kx.value),
                                             range / (1 * self.Ky.value), :]
                W_capon = self.calcBeamPatternLinearArray(
                    w_capon, self.L.value, spacing, self.angles_intrp,
                    self.angles_intrp[angle])
                W_capon = abs(W_capon * W_capon.conj())
                W_capon = W_capon / W_capon[angle]
                axis3.plot(x[range, :],
                           10 * np.log10(W_capon) + self.maxDynRange.value -
                           10,
                           label='Capon Beampattern')

                # make DAS beam pattern for subarrays
                W_das = self.calcBeamPatternLinearArray(
                    self.das_w_sub,
                    self.L.value,
                    spacing,
                    self.angles_intrp,
                    self.angles_intrp[angle],
                    takePowerAndNormalize=True)
                axis3.plot(x[range, :],
                           10 * np.log10(W_das) + self.maxDynRange.value - 10,
                           label='DAS Beampattern')

                # make total Capon beam pattern for the whole system (tx and rx)?

                # plot selected direction/angle
                axis3.plot([x[range, angle], x[range, angle]],
                           [self.minDynRange.value, self.maxDynRange.value],
                           label='Steering angle')

            axis3.set_ylim([self.minDynRange.value, self.maxDynRange.value])
            axis3.set_title(
                'Beam pattern at %d degrees and %d mm range' % (round(
                    profile_angle * 180 / np.pi), round(profile_range * 1000)),
                fontsize='large')
            axis3.set_xlabel('Width [mm]', fontsize='large')
            axis3.set_ylabel('Intensity/Gain [dB]', fontsize='large')
            if self.show_legends.value is 1:
                axis3.legend(loc=3, markerscale=0.5)

        if axis4 is not None:
            profile_range = np.sqrt(self.profilePos[0]**2 +
                                    self.profilePos[1]**2) / 1000.0

            if profile_range < self.ranges_intrp[
                    -1] and profile_range > self.ranges_intrp[0]:
                angle_slice_idx = round(
                    self.ranges_intrp.shape[0] *
                    (profile_range - self.ranges_intrp[0]) /
                    (self.ranges_intrp[-1] - self.ranges_intrp[0]))
                self.img_das_aslice = self.img_das_detected[angle_slice_idx, :]
                self.img_cap_aslice = self.img_cap_detected[angle_slice_idx, :]
                self.x_aslice = x[angle_slice_idx, :]

                axis4.plot(self.x_aslice, self.img_das_aslice, label='DAS')
                if (self.Nb.value > 0):
                    axis4.plot(self.x_aslice,
                               self.img_cap_aslice,
                               '-r',
                               label='BS-Capon')
                else:
                    axis4.plot(self.x_aslice,
                               self.img_cap_aslice,
                               '-r',
                               label='ES-Capon')

                axis4.set_ylim(
                    [self.minDynRange.value, self.maxDynRange.value])

                axis4.set_title('Lateral intensity at %d mm range' %
                                round(profile_range * 1000),
                                fontsize='large')
                axis4.set_xlabel('Width [mm]', fontsize='large')
                axis4.set_ylabel('Lateral intensity [dB]', fontsize='large')
                if self.show_legends.value is 1:
                    axis4.legend(loc=3, markerscale=0.5)

        if VERBOSE:
            print 'done'

        return ax