def main(): # initialize input/ouput objects ts=time_series() kw=k_omega() for i in range(averages): # initialize time series ts.reset() # Simulate narrow band acoustic data ts.nb_sim() # Simulate colored gaussian noise ts.noise_sim() # Perform k-omega beamforming kw(ts()) # Obtain the result of beamforming gram=kw.get() # rearrange to bring zero-frequency component at the center of spectrum for i in range(gram.size(1)): gram[:,i] = freqswap(gram[:,i]) # Post-process the beamformer output to make it suitable for charting max, idx = reduce.maxval(gram) avg = reduce.meanval(gram) gram = clip(gram,0.0,max,avg/100000.0,max) # plot log-magnitude of beamformed power spectrum gram = elm.log10(gram) min, idx = reduce.minval(gram) gram -= min # Normalize the log-magnitude plot max, idx = reduce.maxval(gram) gram *= 1.0/max fig = pyplot.figure(1,figsize=(10,4)) ax = fig.add_axes([0.10,0.10,0.85,0.80]) ax.set_yticklabels(['0','0','30','60','90','120','150','180']) ax.yaxis.set_ticks_position('right') pyplot.imshow(gram) # Labeling plot axis appropriately pyplot.title(u'K-Ω Beamformer Output') pyplot.xlabel('Frequency') pyplot.ylabel(r'$\frac{cos(\theta)}{\lambda}$',fontsize=16,rotation='horizontal') pyplot.colorbar() # Display the plot pyplot.show()
def noise_sim(self): #sensor-to-sensor travel time d_t=self.d_t * rate # array travel time at end o_0 = d_t * sensors + 1 # angle step a_stp = math.pi/nnoise for j in range(nnoise): a_crct = math.cos(float(j) * a_stp) # Generate white noise self.noise = self.rand.randn(self.noise.length()) # Get it colored by rejecting out-of-band components self.fir(self.noise, self.bl_noise) # Adjust noise variance self.bl_noise *= 12./nnoise for i in range(sensors): offset = int(o_0 + i * d_t * a_crct) # Mix noise with data to model a noisy channel self.data[i,:] += self.bl_noise[offset:offset + nts] # Subtract average value from mixture to remove any biasing self.data -= reduce.meanval(self.data)
# # Copyright (c) 2014 Stefan Seefeld # All rights reserved. # # This file is part of OpenVSIP. It is made available under the # license contained in the accompanying LICENSE.BSD file. import numpy as np from numpy import array from vsip import vector, matrix from vsip.math import reductions as red a = np.arange(16, dtype=float) v = vector(array=a) assert array(red.meanval(v) == np.mean(a)).all() assert array(red.maxval(v)[0] == np.max(a)).all() assert array(red.minval(v)[0] == np.min(a)).all() assert array(red.sumval(v) == np.sum(a)).all()