1. 程式人生 > 其它 >基於python原始碼的嘯叫抑制演算法解析

基於python原始碼的嘯叫抑制演算法解析

一 原理解析 從下圖一中可以看出,該演算法的原理也是先檢測出來嘯叫,然後通過陷波器來進行嘯叫抑制的,和筆者以前分析的所用方法基本耦合。  二 原始碼分析   函式PAPR:計算峰值功率和平均功率的比值  
def papr(frame, threshold):
    """Peak-to-Avarage Power Ratio (PAPR)
    Returns all frequency indices where power is greater than avarage power + threshold,
    which are possible candidates 
where howling occurs.

 

函式PTPR:計算峰值功率和閾值功率的比值,這裡的閾值功率是系統可以產生嘯叫的功率閾值,根實際環境有關係。  
def ptpr(frame, threshold):
    """Peak-to-Threshold Power Ratio (PTPR)

 

函式PNPR:計算峰值功率和相鄰頻段功率的比值  
def pnpr(frame, threshold):
    """Peak-to-Neighboring Power Ratio (PNPR)
    Returns all frequency indices of power peaks,
    which are greater than neighboring frequency bins by a threshold.

 

函式howling_detect該函式是檢測出嘯叫頻點,是最重要的部分,嘯叫抑制的難點就是怎麼檢出嘯叫抑制的頻點:這裡通過三個維度來篩選,找出共同的頻點,認為共同的頻點就是嘯叫的頻點。  
def howling_detect(frame, win, nFFT, Slen, candidates, frame_id):
    insign = win * frame
    spec = np.fft.fft(insign, nFFT, axis=0)

    #==========  Howling Detection Stage =====================#   
    ptpr_idx 
= pyHowling.ptpr(spec[:Slen], 10) papr_idx, papr = pyHowling.papr(spec[:Slen], 10) pnpr_idx = pyHowling.pnpr(spec[:Slen], 15) intersec_idx = np.intersect1d(ptpr_idx, np.intersect1d(papr_idx,pnpr_idx)) #print("papr:",papr_idx) #print("pnpr:",pnpr_idx) #print("intersection:", intersec_idx) for idx in intersec_idx: candidates[idx][frame_id] = 1 ipmp = pyHowling.ipmp(candidates, frame_id) #print("ipmp:",ipmp) result = pyHowling.screening(spec, ipmp) #print("result:", result) return result

 

三 總結   該演算法從 效果來看,效果還是比較不錯的,但是有一個維度難以把握,就是閾值的設定,這個是和實際環境有關係的,需要根據實際環境除錯,這個也決定了演算法的準確度。