def get_windows(self): rectangle_windows = [ boxcar(self.rc_lengths[0]), boxcar(self.rc_lengths[1]) ] hanning_windows = hanning(self.hn_length) hamming_windows = hamming(self.hm_length) self.windows = [rectangle_windows, hanning_windows, hamming_windows]
def array_factor(number_of_elements, scan_angle, element_spacing, frequency, theta, window_type, side_lobe_level): """ Calculate the array factor for a linear binomial excited array. :param window_type: The string name of the window. :param side_lobe_level: The sidelobe level for Tschebyscheff window (dB). :param number_of_elements: The number of elements in the array. :param scan_angle: The angle to which the main beam is scanned (rad). :param element_spacing: The distance between elements. :param frequency: The operating frequency (Hz). :param theta: The angle at which to evaluate the array factor (rad). :return: The array factor as a function of angle. """ # Calculate the wavenumber k = 2.0 * pi * frequency / c # Calculate the phase psi = k * element_spacing * (cos(theta) - cos(scan_angle)) # Calculate the coefficients if window_type == 'Uniform': coefficients = ones(number_of_elements) elif window_type == 'Binomial': coefficients = binom(number_of_elements - 1, range(0, number_of_elements)) elif window_type == 'Tschebyscheff': warnings.simplefilter("ignore", UserWarning) coefficients = chebwin(number_of_elements, at=side_lobe_level, sym=True) elif window_type == 'Kaiser': coefficients = kaiser(number_of_elements, 6, True) elif window_type == 'Blackman-Harris': coefficients = blackmanharris(number_of_elements, True) elif window_type == 'Hanning': coefficients = hanning(number_of_elements, True) elif window_type == 'Hamming': coefficients = hamming(number_of_elements, True) # Calculate the offset for even/odd offset = int(floor(number_of_elements / 2)) # Odd case if number_of_elements & 1: coefficients = roll(coefficients, offset + 1) coefficients[0] *= 0.5 af = sum(coefficients[i] * cos(i * psi) for i in range(offset + 1)) return af / amax(abs(af)) # Even case else: coefficients = roll(coefficients, offset) af = sum(coefficients[i] * cos((i + 0.5) * psi) for i in range(offset)) return af / amax(abs(af))
def _update_canvas(self): """ Update the figure when the user changes and input value. :return: """ # Get the parameters from the form x_span = float(self.x_span.text()) y_span = float(self.y_span.text()) z_span = float(self.z_span.text()) nx_ny_nz = self.nx_ny_nz.text().split(',') self.nx = int(nx_ny_nz[0]) self.ny = int(nx_ny_nz[1]) self.nz = int(nx_ny_nz[2]) az_start_end = self.az_start_end.text().split(',') az_start = int(az_start_end[0]) az_end = int(az_start_end[1]) el_start_end = self.el_start_end.text().split(',') el_start = int(el_start_end[0]) el_end = int(el_start_end[1]) # Get the selected window from the form window_type = self.window_type.currentText() # Get the polarization from the form polarization = self.polarization.currentText() x = linspace(-0.5 * x_span, 0.5 * x_span, self.nx) y = linspace(-0.5 * y_span, 0.5 * y_span, self.ny) z = linspace(-0.5 * z_span, 0.5 * z_span, self.nz) self.x_image, self.y_image, self.z_image = meshgrid(x, y, z, indexing='ij') fft_length = 8192 # el 18 - 43 (-1) # az 66 - 115 (-1) # Initialize the image self.bp = 0 # Loop over the azimuth and elevation angles for el in range(el_start, el_end + 1): for az in range(az_start, az_end + 1): print('El {0:d} Az {1:d}'.format(el, az)) filename = '../../Backhoe_CP/3D_Challenge_Problem/3D_K_Space_Data/backhoe_el{0:03d}_az{1:03d}.mat'.format(el, az) b = loadmat(filename) # build a list of keys and values for each entry in the structure vals = b['data'][0, 0] # <-- set the array you want to access. keys = b['data'][0, 0].dtype.descr # Assemble the keys and values into variables with the same name as that used in MATLAB for i in range(len(keys)): key = keys[i][0] val = squeeze(vals[key]) exec(key + '=val', locals(), globals()) # Select the polarization if polarization == 'VV': signal = vv elif polarization == 'HH': signal = hh else: signal = vhhv sensor_az = radians(azim) sensor_el = radians(elev) frequency = FGHz * 1e9 nf = len(frequency) na = len(sensor_az) ne = len(sensor_el) coefficients = ones([nf, ne, na]) # Get the window if window_type == 'Hanning': h1 = hanning(nf, True) h2 = hanning(na, True) h3 = hanning(ne, True) for i in range(nf): for j in range(ne): for k in range(na): coefficients[i, j, k] = (h1[i] * h2[k] * h3[j]) ** (1.0 / 3.0) elif window_type == 'Hamming': h1 = hamming(nf, True) h2 = hamming(na, True) h3 = hamming(ne, True) for i in range(nf): for j in range(ne): for k in range(na): coefficients[i, j, k] = (h1[i] * h2[k] * h3[j]) ** (1.0 / 3.0) # Apply the window coefficients signal *= coefficients # Reconstruct the image self.bp += backprojection.reconstruct3(signal, sensor_az, sensor_el, self.x_image, self.y_image, self.z_image, frequency, fft_length) # Update the image self._update_image_only()
def _update_canvas(self): """ Update the figure when the user changes an input value :return: """ # Get the parameters from the form number_of_steps = int(self.number_of_steps.text()) frequency_step = float(self.frequency_step.text()) prf = float(self.prf.text()) target_range = self.target_range.text().split(',') target_rcs = self.target_rcs.text().split(',') target_velocity = self.target_velocity.text().split(',') t_range = [float(r) for r in target_range] t_rcs = [float(r) for r in target_rcs] t_velocity = [float(v) for v in target_velocity] # Get the selected window from the form window_type = self.window_type.currentText() if window_type == 'Kaiser': coefficients = kaiser(number_of_steps, 6, True) elif window_type == 'Blackman-Harris': coefficients = blackmanharris(number_of_steps, True) elif window_type == 'Hanning': coefficients = hanning(number_of_steps, True) elif window_type == 'Hamming': coefficients = hamming(number_of_steps, True) elif window_type == 'Rectangular': coefficients = ones(number_of_steps) # Calculate the base band return signal s = zeros(number_of_steps, dtype=complex) for rng, rcs, v in zip(t_range, t_rcs, t_velocity): s += [sqrt(rcs) * exp(-1j * 4.0 * pi / c * (i * frequency_step) * (rng - v * (i / prf))) for i in range(number_of_steps)] n = next_fast_len(10 * number_of_steps) sf = ifft(s * coefficients, n) * float(n) / float(number_of_steps) # range_resolution = c / (2.0 * number_of_steps * frequency_step) range_unambiguous = c / (2.0 * frequency_step) range_window = linspace(0, range_unambiguous, n) # Clear the axes for the updated plot self.axes1.clear() # Create the line plot self.axes1.plot(range_window, 20.0 * log10(abs(sf) + finfo(float).eps), '') # Set the x and y axis labels self.axes1.set_xlabel("Range (m)", size=12) self.axes1.set_ylabel("Amplitude (dBsm)", size=12) # Turn on the grid self.axes1.grid(linestyle=':', linewidth=0.5) # Set the plot title and labels self.axes1.set_title('Stepped Frequency Range Profile', size=14) # Set the tick label size self.axes1.tick_params(labelsize=12) # Update the canvas self.my_canvas.draw()
def _update_canvas(self): """ Update the figure when the user changes and input value. :return: """ # Get the parameters from the form x_span = float(self.x_span.text()) y_span = float(self.y_span.text()) nx_ny = self.nx_ny.text().split(',') nx = int(nx_ny[0]) ny = int(nx_ny[1]) az_start_end = self.az_start_end.text().split(',') az_start = float(az_start_end[0]) az_end = float(az_start_end[1]) # Load the selected target target = self.target.currentText() base_path = Path(__file__).parent if target == 'Backhoe Elevation 0': b = loadmat(base_path / "backhoe_0.mat") elif target == 'Backhoe Elevation 30': b = loadmat(base_path / "backhoe_30.mat") elif target == 'Camry Elevation 30': b = loadmat(base_path / "Camry_el30.0000.mat") elif target == 'Camry Elevation 40': b = loadmat(base_path / "Camry_el40.0000.mat") elif target == 'Camry Elevation 50': b = loadmat(base_path / "Camry_el50.0000.mat") elif target == 'Camry Elevation 60': b = loadmat(base_path / "Camry_el60.0000.mat") elif target == 'Tacoma Elevation 30': b = loadmat(base_path / "ToyotaTacoma_el30.0000.mat") elif target == 'Tacoma Elevation 40': b = loadmat(base_path / "ToyotaTacoma_el40.0000.mat") elif target == 'Tacoma Elevation 50': b = loadmat(base_path / "ToyotaTacoma_el50.0000.mat") elif target == 'Tacoma Elevation 60': b = loadmat(base_path / "ToyotaTacoma_el60.0000.mat") elif target == 'Jeep Elevation 30': b = loadmat(base_path / "Jeep99_el30.0000.mat") elif target == 'Jeep Elevation 40': b = loadmat(base_path / "Jeep99_el40.0000.mat") elif target == 'Jeep Elevation 50': b = loadmat(base_path / "Jeep99_el50.0000.mat") elif target == 'Jeep Elevation 60': b = loadmat(base_path / "eep99_el60.0000.mat") # Build a list of keys and values for each entry in the structure vals = b['data'][0, 0] keys = b['data'][0, 0].dtype.descr # Assemble the keys / values into variables with the same name as used in MATLAB for i in range(len(keys)): key = keys[i][0] val = squeeze(vals[key]) exec(key + '=val', locals(), globals()) # Set up the image space self.xi = linspace(-0.5 * x_span, 0.5 * x_span, nx) self.yi = linspace(-0.5 * y_span, 0.5 * y_span, ny) x_image, y_image = meshgrid(self.xi, self.yi) z_image = zeros_like(x_image) # Set the data from the file polarization = self.polarization.currentText() if polarization == 'VV': signal = vv elif polarization == 'HH': signal = hh else: signal = hv # Choose the pulses in the azimuth range sensor_az = [] index = [] i = 0 for az in azim: if az_start <= az <= az_end: sensor_az.append(radians(az)) index.append(i) i += 1 signal1 = signal[:, index] sensor_el = radians(elev) * ones(len(sensor_az)) frequency = FGHz * 1e9 nf = len(frequency) na = len(sensor_az) fft_length = next_fast_len(4 * len(frequency)) # Get the selected window from the form window_type = self.window_type.currentText() if window_type == 'Hanning': h1 = hanning(nf, True) h2 = hanning(na, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Hamming': h1 = hamming(nf, True) h2 = hamming(na, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Rectangular': coefficients = ones([nf, na]) # Apply the selected window signal1 *= coefficients # Reconstruct the image self.bp_image = backprojection.reconstruct2(signal1, sensor_az, sensor_el, x_image, y_image, z_image, frequency, fft_length) # Update the image self._update_image_only()
def _update_canvas(self): """ Update the figure when the user changes an input value :return: """ # Get the parameters from the form bandwidth = float(self.bandwidth.text()) pulsewidth = float(self.pulsewidth.text()) range_window_length = float(self.range_window_length.text()) target_range = self.target_range.text().split(',') target_rcs = self.target_rcs.text().split(',') t_range = [float(r) for r in target_range] t_rcs = [float(r) for r in target_rcs] # Get the selected window from the form window_type = self.window_type.currentText() # Number of samples number_of_samples = int(ceil(4 * bandwidth * range_window_length / c)) if window_type == 'Kaiser': coefficients = kaiser(number_of_samples, 6, True) elif window_type == 'Blackman-Harris': coefficients = blackmanharris(number_of_samples, True) elif window_type == 'Hanning': coefficients = hanning(number_of_samples, True) elif window_type == 'Hamming': coefficients = hamming(number_of_samples, True) elif window_type == 'Rectangular': coefficients = ones(number_of_samples) # Time sampling t, dt = linspace(-0.5 * pulsewidth, 0.5 * pulsewidth, number_of_samples, retstep=True) # Sampled signal after mixing so = zeros(number_of_samples, dtype=complex) for r, rcs in zip(t_range, t_rcs): so += sqrt(rcs) * exp(1j * 2.0 * pi * bandwidth / pulsewidth * (2 * r / c) * t) # Fourier transform so = fftshift(fft(so * coefficients, 4 * number_of_samples)) # FFT frequencies frequencies = fftshift(fftfreq(4 * number_of_samples, dt)) # Range window range_window = 0.5 * frequencies * c * pulsewidth / bandwidth # Clear the axes for the updated plot self.axes1.clear() # Create the line plot self.axes1.plot( range_window, 20.0 * log10(abs(so) / number_of_samples + finfo(float).eps), '') self.axes1.set_xlim(min(t_range) - 5, max(t_range) + 5) self.axes1.set_ylim( -60, max(20.0 * log10(abs(so) / number_of_samples)) + 10) # Set the x and y axis labels self.axes1.set_xlabel("Range (m)", size=12) self.axes1.set_ylabel("Amplitude (dBsm)", size=12) # Turn on the grid self.axes1.grid(linestyle=':', linewidth=0.5) # Set the plot title and labels self.axes1.set_title('Stretch Processor Range Profile', size=14) # Set the tick label size self.axes1.tick_params(labelsize=12) # Update the canvas self.my_canvas.draw()
def pre_processing(self): """ Complete various pre-processing steps for encoded protein sequences before doing any of the DSP-related functions or transformations. Zero-pad the sequences, remove any +/- infinity or NAN values, get the approximate protein spectra and window function parameter names. Parameters ---------- :self (PyDSP object): instance of PyDSP class. Returns ------- None """ #zero-pad encoded sequences so they are all the same length self.protein_seqs = zero_padding(self.protein_seqs) #get shape parameters of proteins seqs self.num_seqs = self.protein_seqs.shape[0] self.signal_len = self.protein_seqs.shape[1] #replace any positive or negative infinity or NAN values with 0 self.protein_seqs[self.protein_seqs == -np.inf] = 0 self.protein_seqs[self.protein_seqs == np.inf] = 0 self.protein_seqs[self.protein_seqs == np.nan] = 0 #replace any NAN's with 0's #self.protein_seqs.fillna(0, inplace=True) self.protein_seqs = np.nan_to_num(self.protein_seqs) #initialise zeros array to store all protein spectra self.fft_power = np.zeros((self.num_seqs, self.signal_len)) self.fft_real = np.zeros((self.num_seqs, self.signal_len)) self.fft_imag = np.zeros((self.num_seqs, self.signal_len)) self.fft_abs = np.zeros((self.num_seqs, self.signal_len)) #list of accepted spectra, window functions and filters all_spectra = ['power', 'absolute', 'real', 'imaginary'] all_windows = [ 'hamming', 'blackman', 'blackmanharris', 'gaussian', 'bartlett', 'kaiser', 'barthann', 'bohman', 'chebwin', 'cosine', 'exponential' 'flattop', 'hann', 'boxcar', 'hanning', 'nuttall', 'parzen', 'triang', 'tukey' ] all_filters = [ 'savgol', 'medfilt', 'symiirorder1', 'lfilter', 'hilbert' ] #set required input parameters, raise error if spectrum is none if self.spectrum == None: raise ValueError( 'Invalid input Spectrum type ({}) not available in valid spectra: {}' .format(self.spectrum, all_spectra)) else: #get closest correct spectra from user input, if no close match then raise error spectra_matches = (get_close_matches(self.spectrum, all_spectra, cutoff=0.4)) if spectra_matches == []: raise ValueError( 'Invalid input Spectrum type ({}) not available in valid spectra: {}' .format(self.spectrum, all_spectra)) else: self.spectra = spectra_matches[0] #closest match in array if self.window_type == None: self.window = 1 #window = 1 is the same as applying no window else: #get closest correct window function from user input window_matches = (get_close_matches(self.window, all_windows, cutoff=0.4)) #check if sym=True or sym=False #get window function specified by window input parameter, if no match then window = 1 if window_matches != []: if window_matches[0] == 'hamming': self.window = hamming(self.signal_len, sym=True) self.window_type = "hamming" elif window_matches[0] == "blackman": self.window = blackman(self.signal_len, sym=True) self.window = "blackman" elif window_matches[0] == "blackmanharris": self.window = blackmanharris(self.signal_len, sym=True) #** self.window_type = "blackmanharris" elif window_matches[0] == "bartlett": self.window = bartlett(self.signal_len, sym=True) self.window_type = "bartlett" elif window_matches[0] == "gaussian": self.window = gaussian(self.signal_len, std=7, sym=True) self.window_type = "gaussian" elif window_matches[0] == "kaiser": self.window = kaiser(self.signal_len, beta=14, sym=True) self.window_type = "kaiser" elif window_matches[0] == "hanning": self.window = hanning(self.signal_len, sym=True) self.window_type = "hanning" elif window_matches[0] == "barthann": self.window = barthann(self.signal_len, sym=True) self.window_type = "barthann" elif window_matches[0] == "bohman": self.window = bohman(self.signal_len, sym=True) self.window_type = "bohman" elif window_matches[0] == "chebwin": self.window = chebwin(self.signal_len, sym=True) self.window_type = "chebwin" elif window_matches[0] == "cosine": self.window = cosine(self.signal_len, sym=True) self.window_type = "cosine" elif window_matches[0] == "exponential": self.window = exponential(self.signal_len, sym=True) self.window_type = "exponential" elif window_matches[0] == "flattop": self.window = flattop(self.signal_len, sym=True) self.window_type = "flattop" elif window_matches[0] == "boxcar": self.window = boxcar(self.signal_len, sym=True) self.window_type = "boxcar" elif window_matches[0] == "nuttall": self.window = nuttall(self.signal_len, sym=True) self.window_type = "nuttall" elif window_matches[0] == "parzen": self.window = parzen(self.signal_len, sym=True) self.window_type = "parzen" elif window_matches[0] == "triang": self.window = triang(self.signal_len, sym=True) self.window_type = "triang" elif window_matches[0] == "tukey": self.window = tukey(self.signal_len, sym=True) self.window_type = "tukey" else: self.window = 1 #window = 1 is the same as applying no window #calculate convolution from protein sequences if self.convolution is not None: if self.window is not None: self.convoled_seqs = signal.convolve( self.protein_seqs, self.window, mode='same') / sum( self.window) if self.filter != None: #get closest correct filter from user input filter_matches = (get_close_matches(self.filter, all_filters, cutoff=0.4)) #set filter attribute according to approximate user input if filter_matches != []: if filter_matches[0] == 'savgol': self.filter = savgol_filter(self.signal_len, self.signal_len) elif filter_matches[0] == 'medfilt': self.filter = medfilt(self.signal_len) elif filter_matches[0] == 'symiirorder1': self.filter = symiirorder1(self.signal_len, c0=1, z1=1) elif filter_matches[0] == 'lfilter': self.filter = lfilter(self.signal_len) elif filter_matches[0] == 'hilbert': self.filter = hilbert(self.signal_len) else: self.filter = "" #no filter
def _update_canvas(self): """ Update the figure when the user changes an input value :return: """ # Get the parameters from the form bandwidth = float(self.bandwidth.text()) pulsewidth = float(self.pulsewidth.text()) target_range = self.target_range.text().split(',') target_rcs = self.target_rcs.text().split(',') t_range = [float(r) for r in target_range] t_rcs = [float(r) for r in target_rcs] # Get the selected window from the form window_type = self.window_type.currentText() # Number of samples N = int(2 * bandwidth * pulsewidth) * 8 if window_type == 'Kaiser': coefficients = kaiser(N, 6, True) elif window_type == 'Blackman-Harris': coefficients = blackmanharris(N, True) elif window_type == 'Hanning': coefficients = hanning(N, True) elif window_type == 'Hamming': coefficients = hamming(N, True) elif window_type == 'Rectangular': coefficients = ones(N) # Set up the time vector t = linspace(-0.5 * pulsewidth, 0.5 * pulsewidth, N) # Calculate the baseband return signal s = zeros(N, dtype=complex) # Chirp slope alpha = 0.5 * bandwidth / pulsewidth for r, rcs in zip(t_range, t_rcs): s += sqrt(rcs) * exp(1j * 2.0 * pi * alpha * (t - 2.0 * r / c)**2) # Transmit signal st = exp(1j * 2 * pi * alpha * t**2) # Impulse response and matched filtering Hf = fft(conj(st * coefficients)) Si = fft(s) so = fftshift(ifft(Si * Hf)) # Range window range_window = linspace(-0.25 * c * pulsewidth, 0.25 * c * pulsewidth, N) # Clear the axes for the updated plot self.axes1.clear() # Create the line plot self.axes1.plot(range_window, 20.0 * log10(abs(so) / N + finfo(float).eps), '') self.axes1.set_xlim(0, max(t_range) + 100) self.axes1.set_ylim(-60, max(20.0 * log10(abs(so) / N)) + 10) # Set the x and y axis labels self.axes1.set_xlabel("Range (m)", size=12) self.axes1.set_ylabel("Amplitude (dBsm)", size=12) # Turn on the grid self.axes1.grid(linestyle=':', linewidth=0.5) # Set the plot title and labels self.axes1.set_title('Matched Filter Range Profile', size=14) # Set the tick label size self.axes1.tick_params(labelsize=12) # Update the canvas self.my_canvas.draw()
def _update_canvas(self): """ Update the figure when the user changes and input value. :return: """ # Get the parameters from the form range_center = float(self.range_center.text()) x_target = self.x_target.text().split(',') y_target = self.y_target.text().split(',') rcs = self.rcs.text().split(',') xt = [] yt = [] rt = [] for x, y, r in zip(x_target, y_target, rcs): xt.append(float(x)) yt.append(float(y)) rt.append(float(r)) x_span = float(self.x_span.text()) y_span = float(self.y_span.text()) nx_ny = self.nx_ny.text().split(',') nx = int(nx_ny[0]) ny = int(nx_ny[1]) start_frequency = float(self.start_frequency.text()) bandwidth = float(self.bandwidth.text()) az_start_end = self.az_start_end.text().split(',') az_start = float(az_start_end[0]) az_end = float(az_start_end[1]) # Set up the azimuth space r = sqrt(x_span**2 + y_span**2) da = c / (2.0 * r * start_frequency) na = int((az_end - az_start) / da) az = linspace(az_start, az_end, na) # Set up the frequency space df = c / (2.0 * r) nf = int(bandwidth / df) frequency = linspace(start_frequency, start_frequency + bandwidth, nf) # Set the length of the FFT fft_length = next_fast_len(4 * nf) # Set up the aperture positions sensor_x = range_center * cos(radians(az)) sensor_y = range_center * sin(radians(az)) sensor_z = zeros_like(sensor_x) # Set up the image space self.xi = linspace(-0.5 * x_span, 0.5 * x_span, nx) self.yi = linspace(-0.5 * y_span, 0.5 * y_span, ny) x_image, y_image = meshgrid(self.xi, self.yi) z_image = zeros_like(x_image) # Calculate the signal (k space) signal = zeros([nf, na], dtype=complex) index = 0 for a in az: r_los = [cos(radians(a)), sin(radians(a))] for x, y, r in zip(xt, yt, rt): r_target = -dot(r_los, [x, y]) signal[:, index] += r * exp( -1j * 4.0 * pi * frequency / c * r_target) index += 1 # Get the selected window from the form window_type = self.window_type.currentText() if window_type == 'Hanning': h1 = hanning(nf, True) h2 = hanning(na, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Hamming': h1 = hamming(nf, True) h2 = hamming(na, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Rectangular': coefficients = ones([nf, na]) # Apply the selected window signal *= coefficients # Reconstruct the image self.bp_image = backprojection.reconstruct(signal, sensor_x, sensor_y, sensor_z, range_center, x_image, y_image, z_image, frequency, fft_length) # Update the image self._update_image_only()
def _update_canvas(self): """ Update the figure when the user changes and input value. :return: """ # Get the parameters from the form squint_angle = radians(float(self.squint_angle.text())) x_center = float(self.range_center.text()) y_center = x_center * tan(squint_angle) x_span = float(self.x_span.text()) y_span = float(self.y_span.text()) nx_ny = self.nx_ny.text().split(',') nx = int(nx_ny[0]) ny = int(nx_ny[1]) aperture_length = float(self.aperture_length.text()) antenna_width = float(self.antenna_width.text()) # Load the selected target target = self.target.currentText() base_path = Path(__file__).parent if target == 'Backhoe Elevation 0': b = loadmat(base_path / "backhoe_0.mat") elif target == 'Backhoe Elevation 30': b = loadmat(base_path / "backhoe_30.mat") elif target == 'Camry Elevation 30': b = loadmat(base_path / "Camry_el30.0000.mat") elif target == 'Camry Elevation 40': b = loadmat(base_path / "Camry_el40.0000.mat") elif target == 'Camry Elevation 50': b = loadmat(base_path / "Camry_el50.0000.mat") elif target == 'Camry Elevation 60': b = loadmat(base_path / "Camry_el60.0000.mat") elif target == 'Tacoma Elevation 30': b = loadmat(base_path / "ToyotaTacoma_el30.0000.mat") elif target == 'Tacoma Elevation 40': b = loadmat(base_path / "ToyotaTacoma_el40.0000.mat") elif target == 'Tacoma Elevation 50': b = loadmat(base_path / "ToyotaTacoma_el50.0000.mat") elif target == 'Tacoma Elevation 60': b = loadmat(base_path / "ToyotaTacoma_el60.0000.mat") elif target == 'Jeep Elevation 30': b = loadmat(base_path / "Jeep99_el30.0000.mat") elif target == 'Jeep Elevation 40': b = loadmat(base_path / "Jeep99_el40.0000.mat") elif target == 'Jeep Elevation 50': b = loadmat(base_path / "Jeep99_el50.0000.mat") elif target == 'Jeep Elevation 60': b = loadmat(base_path / "eep99_el60.0000.mat") # Build a list of keys and values for each entry in the structure vals = b['data'][0, 0] keys = b['data'][0, 0].dtype.descr # Assemble the keys / values into variables with the same name as used in MATLAB for i in range(len(keys)): key = keys[i][0] val = squeeze(vals[key]) exec(key + '=val', locals(), globals()) # Set the data from the file polarization = self.polarization.currentText() if polarization == 'VV': signal = vv elif polarization == 'HH': signal = hh else: signal = hv # Frequency (Hz) frequency = FGHz * 1e9 # Set up the image space self.xi = linspace(-0.5 * x_span + x_center, 0.5 * x_span + x_center, nx) self.yi = linspace(-0.5 * y_span + y_center, 0.5 * y_span + y_center, ny) x_image, y_image = meshgrid(self.xi, self.yi) z_image = zeros_like(x_image) # Calculate the wavelength at the start frequency (m) wavelength = c / frequency[0] # Calculate the number of frequencies bandwidth = frequency[-1] - frequency[0] number_of_frequencies = len(frequency) # Set the length of the FFT fft_length = next_fast_len(4 * number_of_frequencies) # Calculate the element spacing (m) element_spacing = wavelength / 4.0 # Calculate the number of elements number_of_elements = int(ceil(antenna_width / element_spacing + 1)) # Calculate the spacing on the synthetic aperture (m) aperture_spacing = tan( c / (2 * y_span * frequency[0])) * x_center # Based on y_span # Calculate the number of samples (pulses) on the aperture number_of_samples = int(ceil(aperture_length / aperture_spacing + 1)) # Create the aperture synthetic_aperture = linspace(-0.5 * aperture_length, 0.5 * aperture_length, number_of_samples) # Calculate the sensor location sensor_x = zeros_like(synthetic_aperture) sensor_y = synthetic_aperture sensor_z = zeros_like(synthetic_aperture) # Calculate the signal (k space) # Initialize the signal signal1 = zeros([number_of_frequencies, number_of_samples], dtype=complex) # Initialize the range center (m) range_center = zeros_like(synthetic_aperture) # For calculating sensor height te = tan(radians(elev)) index = 0 for sa in synthetic_aperture: # Calculate the sensor z location sensor_z[index] = sqrt(x_center**2 + (y_center - sa)**2) * te # Calculate the range to the center of the scene range_center[index] = sqrt(x_center**2 + (y_center - sa)**2 + sensor_z[index]**2) # Calculate the target azimuth (rad) target_azimuth = arctan((y_center - sa) / x_center) target_azimuth = target_azimuth % (2 * pi) # Find the antenna pattern at the target azimuth antenna_pattern = array_factor( number_of_elements, 0.5 * pi - squint_angle, element_spacing, frequency[0], target_azimuth, 'Uniform', 0) * cos(squint_angle) # Calculate the return signal signal1[:, index] = antenna_pattern**2 * signal[:, ( abs(degrees(target_azimuth) - azim)).argmin()] index += 1 # Get the selected window from the form window_type = self.window_type.currentText() if window_type == 'Hanning': h1 = hanning(number_of_frequencies, True) h2 = hanning(number_of_samples, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Hamming': h1 = hamming(number_of_frequencies, True) h2 = hamming(number_of_samples, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Rectangular': coefficients = ones([number_of_frequencies, number_of_samples]) # Apply the selected window signal1 *= coefficients # Reconstruct the image self.bp_image = backprojection.reconstruct(signal1, sensor_x, sensor_y, sensor_z, range_center, x_image, y_image, z_image, frequency, fft_length) # Update the image self._update_image_only()
def _update_canvas(self): """ Update the figure when the user changes and input value. :return: """ # Get the parameters from the form squint_angle = radians(float(self.squint_angle.text())) x_center = float(self.range_center.text()) y_center = x_center * tan(squint_angle) x_target = self.x_target.text().split(',') y_target = self.y_target.text().split(',') rcs = self.rcs.text().split(',') xt = [] yt = [] rt = [] for x, y, r in zip(x_target, y_target, rcs): xt.append(float(x)) yt.append(float(y)) rt.append(float(r)) x_span = float(self.x_span.text()) y_span = float(self.y_span.text()) nx_ny = self.nx_ny.text().split(',') nx = int(nx_ny[0]) ny = int(nx_ny[1]) start_frequency = float(self.start_frequency.text()) bandwidth = float(self.bandwidth.text()) aperture_length = float(self.aperture_length.text()) antenna_width = float(self.antenna_width.text()) # Set up the image space self.xi = linspace(-0.5 * x_span + x_center, 0.5 * x_span + x_center, nx) self.yi = linspace(-0.5 * y_span + y_center, 0.5 * y_span + y_center, ny) x_image, y_image = meshgrid(self.xi, self.yi) z_image = zeros_like(x_image) # Calculate the wavelength at the start frequency (m) wavelength = c / start_frequency # Calculate the number of frequencies df = c / (2.0 * sqrt(x_span**2 + y_span**2)) number_of_frequencies = int(ceil(bandwidth / df)) # Set up the frequency space frequency = linspace(start_frequency, start_frequency + bandwidth, number_of_frequencies) # Set the length of the FFT fft_length = next_fast_len(4 * number_of_frequencies) # Calculate the element spacing (m) element_spacing = wavelength / 4.0 # Calculate the number of elements number_of_elements = int(ceil(antenna_width / element_spacing + 1)) # Calculate the spacing on the synthetic aperture (m) aperture_spacing = tan( c / (2 * y_span * start_frequency)) * x_center # Based on y_span # Calculate the number of samples (pulses) on the aperture number_of_samples = int(ceil(aperture_length / aperture_spacing + 1)) # Create the aperture synthetic_aperture = linspace(-0.5 * aperture_length, 0.5 * aperture_length, number_of_samples) # Calculate the sensor location sensor_x = zeros_like(synthetic_aperture) sensor_y = synthetic_aperture sensor_z = zeros_like(synthetic_aperture) # Calculate the signal (k space) # Initialize the signal signal = zeros([number_of_frequencies, number_of_samples], dtype=complex) # Initialize the range center (m) range_center = zeros_like(synthetic_aperture) # Phase term for the range phase (rad) phase_term = -1j * 4.0 * pi * frequency / c index = 0 for sa in synthetic_aperture: range_center[index] = sqrt(x_center**2 + (y_center - sa)**2) for x, y, r in zip(xt, yt, rt): # Antenna pattern at each target target_range = sqrt( (x_center + x)**2 + (y_center + y - sa)**2) - range_center[index] target_azimuth = arctan((y_center + y - sa) / (x_center + x)) antenna_pattern = array_factor( number_of_elements, 0.5 * pi - squint_angle, element_spacing, start_frequency, 0.5 * pi - target_azimuth, 'Uniform', 0) * cos(squint_angle) signal[:, index] += r * antenna_pattern**2 * exp( phase_term * target_range) index += 1 # Get the selected window window_type = self.window_type.currentText() if window_type == 'Hanning': h1 = hanning(number_of_frequencies, True) h2 = hanning(number_of_samples, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Hamming': h1 = hamming(number_of_frequencies, True) h2 = hamming(number_of_samples, True) coefficients = sqrt(outer(h1, h2)) elif window_type == 'Rectangular': coefficients = ones([number_of_frequencies, number_of_samples]) # Apply the selected window signal *= coefficients # Reconstruct the image self.bp_image = backprojection.reconstruct(signal, sensor_x, sensor_y, sensor_z, range_center, x_image, y_image, z_image, frequency, fft_length) # Update the image self._update_image_only()
from scipy.signal import iirdesign, filtfilt, convolve import pandas as pd #### FILTER STARTS HERE freq = 909090893.1880873 nyq = freq / 2 wp = 1.1e8 / nyq ws = 0.3 b, a = iirdesign(wp, ws, 1, 40) filt = filtfilt(b, a, data) # filt is the filtered data #### FILTER ENDS HERE import scipy.signal.windows as win #w = win.tukey(7) w = win.hanning(7) w = w / sum(w) conv = convolve(w, data) conv = conv[3:] data.plot() pd.Series(filt).plot() pd.Series(conv).plot() # for E, S, convolve with hanning window of size 7, shift signal 3 samples to # the left #%% Plots df.acoustic_data.plot()
def _update_canvas(self): """ Update the figure when the user changes and input value. :return: """ # Get the parameters from the form x_target = self.x_target.text().split(',') y_target = self.y_target.text().split(',') z_target = self.z_target.text().split(',') rcs = self.rcs.text().split(',') xt = [] yt = [] zt = [] rt = [] for x, y, z, r in zip(x_target, y_target, z_target, rcs): xt.append(float(x)) yt.append(float(y)) zt.append(float(z)) rt.append(float(r)) x_span = float(self.x_span.text()) y_span = float(self.y_span.text()) z_span = float(self.z_span.text()) nx_ny_nz = self.nx_ny_nz.text().split(',') self.nx = int(nx_ny_nz[0]) self.ny = int(nx_ny_nz[1]) self.nz = int(nx_ny_nz[2]) start_frequency = float(self.start_frequency.text()) bandwidth = float(self.bandwidth.text()) az_start_end = self.az_start_end.text().split(',') az_start = float(az_start_end[0]) az_end = float(az_start_end[1]) el_start_end = self.el_start_end.text().split(',') el_start = float(el_start_end[0]) el_end = float(el_start_end[1]) # Set up the azimuth space r = sqrt(x_span**2 + y_span**2) da = c / (2.0 * r * start_frequency) na = int((az_end - az_start) / da) az = linspace(az_start, az_end, na) # Set up the elevation space r = sqrt(x_span**2 + z_span**2) de = c / (2.0 * r * start_frequency) ne = int((el_end - el_start) / de) el = linspace(el_start, el_end, ne) # Set up the angular grid az_grid, el_grid = meshgrid(az, el) # Set up the frequency space df = c / (2.0 * r) nf = int(bandwidth / df) frequency = linspace(start_frequency, start_frequency + bandwidth, nf) # Set the length of the FFT fft_length = next_fast_len(4 * nf) # Set up the image space xi = linspace(-0.5 * x_span, 0.5 * x_span, self.nx) yi = linspace(-0.5 * y_span, 0.5 * y_span, self.ny) zi = linspace(-0.5 * z_span, 0.5 * z_span, self.nz) self.x_image, self.y_image, self.z_image = meshgrid(xi, yi, zi, indexing='ij') signal = zeros([nf, ne, na], dtype=complex) # Calculate the signal (k space) i1 = 0 for a in az: i2 = 0 for e in el: r_los = [ cos(radians(e)) * cos(radians(a)), cos(radians(e)) * sin(radians(a)), sin(radians(e)) ] for x, y, z, r in zip(xt, yt, zt, rt): r_target = dot(r_los, [x, y, z]) signal[:, i2, i1] += r * exp( -1j * 4.0 * pi * frequency / c * r_target) i2 += 1 i1 += 1 # Get the selected window from the form window_type = self.window_type.currentText() coefficients = ones([nf, ne, na]) if window_type == 'Hanning': h1 = hanning(nf, True) h2 = hanning(na, True) h3 = hanning(ne, True) for i in range(nf): for j in range(ne): for k in range(na): coefficients[i, j, k] = (h1[i] * h2[k] * h3[j])**(1.0 / 3.0) elif window_type == 'Hamming': h1 = hamming(nf, True) h2 = hamming(na, True) h3 = hamming(ne, True) for i in range(nf): for j in range(ne): for k in range(na): coefficients[i, j, k] = (h1[i] * h2[k] * h3[j])**(1.0 / 3.0) # Apply the selected window signal *= coefficients # Reconstruct the image self.bp = backprojection.reconstruct3(signal, radians(az_grid), radians(el_grid), self.x_image, self.y_image, self.z_image, frequency, fft_length) # Update the image self._update_image_only()