def svd_fft_fft(self, input_array, framesize, hopsize, window_function=signal.hanning, number_of_vectors_used=256): pbar = Progressbar(number_of_vectors_used) self.feature_vectors = None interesting_parts = input_array[:, :number_of_vectors_used] interesting_parts = transpose(interesting_parts) for row in interesting_parts: # print "row shape:", shape(row) pbar.update() #fft = parent.feature_vectors specspectrum = calculate_spectrogram( row, framesize=framesize, hopsize=hopsize, window_function=window_function, show_progressbar=0) #z, lambdas, EOFs = svdeofs.svdeofs(fft) #svd_fft_fft_vectors = transpose(z[:, :15]) svd_fft_fft_vectors = transpose(svd_eofs(specspectrum)[0]) if self.feature_vectors is None: self.feature_vectors = transpose(svd_fft_fft_vectors) else: self.feature_vectors = concatenate( (self.feature_vectors, transpose(svd_fft_fft_vectors)), 1) #print "svd_fft_fft_vectors shapes:", shape(svd_fft_fft_vectors), shape(self.feature_vectors) pbar.finish()
def different_kernel_sizes(self, arr, l = 20): a = zeros((l, len(arr)), Float) pb = Progressbar(l) print "b" for i in range(0, l): # a[l - 1 - i] = diag(sim_matrix_find_segments(arr, i, 2)) a[l - 1 - i] = diag(sim_matrix_find_segments(arr, i, 2)) print "b" pb.update() print "c" pb.finish() return a
def OLD_vertical_structure_filter(arr, delta = 10, boundary = 10): new_arr = copy.copy(arr) arr_binary = greater(arr, 0) l = len(arr) pb = Progressbar(l) for x in range(l): pb.update() for y in range(delta, l - x - delta): if sum(arr_binary[y - delta : y + delta, x]) < boundary: new_arr[y, x] = 0 pb.finish() return new_arr
def OLD_calculate_distance_matrix(self): """Calculate the similarity matrix.""" W = Numeric.array(self.feature_vectors) length = W.shape[0] S = zeros((length, length)) * 1.0 pbar = Progressbar(length) for i in range(length): pbar.update() for j in range(i): S[j, i] = S[i, j] = self.distance_function(W[i], W[j]) pbar.finish() return S
def window_for_window(self, window): arr = zeros((self.parent_segmentation.number_of_frames), Float) a = 0 b = len(window) w = self.window_function(self.framesize) w *= self.hopsize / sum(w) pb = Progressbar(len(window)) for i in range(len(window)): # print len(arr[i * self.hopsize : (i + 1) * self.hopsize - 1]), len(window[i] * w) pb.update() part = arr[i * self.hopsize : i * self.hopsize + self.framesize] part += (window[i] * w)[:len(part)] pb.finish() # assert alltrue(greater_equal(arr, 0)) return arr
def calculate_spectrogram(input_array, framesize, hopsize, window_function, keep_bands_until = 0, axis = 0, show_progressbar = 0 ): # TODO Segmentation should be determined here! #Segmentations.Frames(self, # len(self. # print "Calculating FFT..." do_fft = lambda arr: abs(FFT.real_fft(arr, axis = axis))[:keep_bands_until] keep_bands_until = keep_bands_until or int(framesize / 2) input_shape = map(None, shape(input_array)) window = window_function(framesize) if len(input_shape) > 1: window = transpose(array([list(window)] * input_shape[1])) # print "input_shape:", shape(input_array) zeros_shape = input_shape # this allows for both 1 and 2 dim inputs zeros_shape[0] = framesize / 2 input_array_plus_zeros = concatenate((zeros(zeros_shape), input_array, zeros(zeros_shape))) fft_range = range(0, len(input_array) - framesize, hopsize) fft_array = zeros(([len(fft_range)] + map(None, shape(do_fft(window)))), # do_fft(window) is used here because it gives the right shape Float32) * 1.0 # this *1.0 is necessary! # print shape(fft_array) if show_progressbar: pbar = Progressbar(len(fft_range)) output_counter = 0 for i in fft_range: frame = window * input_array_plus_zeros[i : i + framesize] fft_array[output_counter] = 10 * log10(0.1 + do_fft(frame)) output_counter += 1 if show_progressbar: divmod(output_counter, 128)[1] or pbar.update(output_counter) if show_progressbar: pbar.finish() # print "outputshape:", shape(fft_array) return fft_array
def __init__(self, parent_processor, parent_borders): parent = parent_processor Parts.__init__(self, parent) self.parent_borders = parent_borders bp = parent_borders.get_border_points() l = [] pb = Progressbar(len(bp)) for cur_pos, parent_weight in bp: start, end = parent_borders.segmentation.parent_segments(cur_pos) sv = sum(calculate_distance_band(parent_processor.feature_vectors[start : end], 150)) # MAYBE TODO: sum -> cumsum # MAYBE TODO: multiply sv with window_function(framesize)... am = argmax(sv) own_weight = sqrt(sv[am] / 1024 / 50) b = MorePreciseBorder(self, start + am, parent_weight, own_weight) l.append([start + am, parent_weight, own_weight]) self.append(b) pb.update() pb.finish() self.feature_vectors = array(l)
def OLD_calc_fft(input_array, hopsize, framesize, window_function=signal.hanning): keep_bands_until = keep_bands_until or int(framesize / 2) do_fft = lambda arr: abs(FFT.real_fft(arr))[:keep_bands_until] input_shape = map(None, shape(input_array)) window = window_function(framesize) if len(input_shape) > 1: window = transpose(array([list(window)] * input_shape[1])) print "input_shape:", shape(input_array) zeros_shape = input_shape # this allows for both 1 and 2 dim inputs zeros_shape[0] = framesize input_array_plus_zeros = concatenate((input_array, zeros(zeros_shape))) fft_range = range(0, len(input_array) - framesize, hopsize) if show_progressbar: pbar = Progressbar(len(fft_range)) output_counter = 0 fft_array = zeros(([len(fft_range)] + map(None, shape(do_fft(window)))), Float32) * 1.0 # this *1.0 is necessary! print shape(fft_array) for i in fft_range: frame = window * input_array_plus_zeros[i:i + framesize] fft_array[output_counter] = 10 * log10(0.1 + do_fft(frame)) if show_progressbar: divmod(output_counter, 128)[1] or pbar.update(output_counter) output_counter += 1 if show_progressbar: pbar.finish() return fft_array