def subtruction(ssignal,ksignal,window,winsize,method): nf = len(ssignal)/(winsize/2) - 1 out=sp.zeros(len(ssignal),sp.float32) for no in xrange(nf): s = get_frame(ssignal, winsize, no) k = get_frame(ksignal, winsize, no) add_signal(out, method.compute(s,k), winsize, no) return out
def _get_amplitude(self, signal, l): if self._amplitude.has_key(l): return self._amplitude[l] else: amp = sp.absolute(sp.fft(get_frame(signal, self._winsize, l) * self._window)) self._amplitude[l] = amp return amp
def _compute_noise_avgspectrum(self, nsignal): windownum = len(nsignal) / (self._winsize / 2) - 1 avgamp = sp.zeros(self._winsize) for l in xrange(windownum): avgamp += sp.absolute( sp.fft(get_frame(nsignal, self._winsize, l) * self._window)) return avgamp / float(windownum)
def _compute_noise_avgspectrum(self, nsignal): windownum = int(len(nsignal)/(self._winsize/2) - 1) avgamp = np.zeros(int(self._winsize/2) + 1) for l in xrange(windownum): frame = get_frame(nsignal, self._winsize, l) avgamp += np.absolute(np.fft.rfft(frame * self._window)) return avgamp/float(windownum)
def noise_reduction(signal,params,winsize,window,ss,ntime): out=sp.zeros(len(signal),sp.float32) n_pow = compute_avgpowerspectrum(signal[0:winsize*int(params[2] /float(winsize)/(1000.0/ntime))],winsize,window)#maybe 300ms nf = len(signal)/(winsize/2) - 1 for no in xrange(nf): s = get_frame(signal, winsize, no) add_signal(out, ss.compute_by_noise_pow(s,n_pow), winsize, no) return out
def _get_amplitude(self, signal, l): if self._amplitude.has_key(l): return self._amplitude[l] else: amp = sp.absolute( sp.fft(get_frame(signal, self._winsize, l) * self._window)) self._amplitude[l] = amp return amp
def _compute_noise_avgspectrum(self, nsignal): windownum = int(len(nsignal) / (self._winsize / 2) - 1) avgamp = sp.zeros(self._winsize) for l in range(windownum): avgamp += sp.absolute( sp.fft(get_frame(nsignal, self._winsize, l) * self._window) ) return avgamp / float(windownum)
def noise_reduction(signal, params, winsize, window, ss, ntime): out = sp.zeros(len(signal), sp.float32) # maybe 300ms n_pow = compute_avgpowerspectrum(signal[0:winsize*int(params[2]/float(winsize)/(1000.0/ntime))], winsize, window) nf = int(len(signal)/(winsize/2)) - 1 for no in xrange(nf): s = get_frame(signal, winsize, no) add_signal(out, ss.compute_by_noise_pow(s, n_pow), winsize, no) return out
def vad(vas,signal,winsize,window): out=sp.zeros(len(signal),sp.float32) for va in vas: for i in range(va[0],va[1]): add_signal(out,get_frame(signal, winsize, i)*window,winsize,i) for va in vas: out[(va[0])*winsize/2:(va[0]+4)*winsize/2] = fin(winsize*2,out[(va[0])*winsize/2:(va[0]+4)*winsize/2]) out[(va[1]-4)*winsize/2:(va[1])*winsize/2] = fout(winsize*2,out[(va[1]-4)*winsize/2:(va[1])*winsize/2]) return out
def _get_amplitude(self, signal, l): if l in self._amplitude: return self._amplitude[l] else: frame = get_frame(signal, self._winsize, l) spec = np.fft.rfft(frame * self._window) amp = np.absolute(spec) # amp = sp.absolute(sp.fft(frame * self._window)) self._amplitude[l] = amp return amp
def hmm_filter(mhmm, nhmm, signal, vas, winsize, window): ret = [] for va in vas: ls = [] for i in range(va[0], va[1] + 2): s = get_frame(signal, winsize, i) s_spec = sp.fft(s * window) ls.append(sp.absolute(s_spec)) print mhmm.score(ls) print nhmm.score(ls) if mhmm.score(ls) > nhmm.score(ls): ret.append(va) return ret
def _get_amplitude(self, signal, l): if l in self._amplitude: return self._amplitude[l] else: frame = sp.zeros((self._winsize,)) sig_frame = get_frame(signal, self._winsize, l) if sig_frame.shape[0] < self._winsize: frame[: sig_frame.shape[0]] = sig_frame else: frame = sig_frame amp = sp.absolute(sp.fft(frame * self._window)) self._amplitude[l] = amp return amp
def noise_reduction(signal,params,winsize,window,ss,ntime): out=sp.zeros(len(signal),sp.float32) ms = MinimumStatistics(winsize,window,params[2]) NP_lambda = compute_avgpowerspectrum(signal[0:winsize*int(params[2] /float(winsize)/(1000.0/ntime))],winsize,window)#maybe 300ms ms.init_noise_profile(NP_lambda) nf = int(len(signal)/(winsize/2)) - 1 for no in xrange(nf): frame = get_frame(signal, winsize, no) n_pow = ms.compute(frame,no) if int(params[2] /float(winsize)/3.0)*2>no: n_pow = NP_lambda res = ss.compute_by_noise_pow(frame,n_pow) add_signal(out, res, winsize, no) #ms.show_debug_result() return out
def vad(vas, signal, winsize, window): out = np.zeros(len(signal), np.float32) for va in vas: for i in range(va[0], va[1]+2): add_signal(out, get_frame(signal, winsize, i)*window, winsize, i) return out