【語音去噪】基於matlab GUI LMS+RLS語音去噪【含Matlab原始碼 528期】
一、簡介
最小均方(LMS, Least Mean Squares)和 遞迴最小二乘(RLS, Recursive Least Squares)是兩種最基本的自適應濾波演算法。
1 LMS
LMS演算法是自適應濾波器中常用的一種演算法與維納演算法不同的是其系統的係數隨輸入序列而改變。維納演算法中擷取輸入序列自相關函式的一段構造系統的最佳係數。而LMS演算法則是對初始化的濾波器係數依據最小均方誤差準則進行不斷修正來實現的。因此理論上講LMS演算法的效能在同等條件下要優於維納。但是LMS是在初始值下逐步調整的,因此在系統穩定前,會有一段調整時間,調整時間受步長因子的控制,一定範圍內,步長因子越大,調整時間越小,步長因子的最大取值為R的跡。LMS採用平方誤差最小的原則代替均方誤差最小的原則,訊號基本關係如下:
2 RLS
引數遞推估計,每取得一次新的觀測資料後,就在前次估計結果的基礎上,利用新引入的觀測資料對前次估計的結果,根據遞推演算法進行修正,減少估計誤差,從而遞推地得出新的引數估計值。這樣,隨著新觀測資料的逐次引入,一次接一次地進行引數估計,直到引數估計值達到滿意的精確程度為止。
3 RLS演算法與LMS對比:
由於LMS演算法只是用以前各時刻的抽頭參量等作該時刻資料塊估計時的平方誤差均方最小的準則,而未用現時刻的抽頭參量等來對以往各時刻的資料塊作重新估計後的累計平方誤差最小的準則,所以 15 LMS演算法對非平穩訊號的適應性差。RLS演算法的基本思想是力圖使在每個時刻對所有已輸入訊號而言重估的平方誤差的加權和最小,這使得RLS演算法對非平穩訊號的適應性要好。與LMS演算法相比,RLS演算法採用時間平均,因此,所得出的最優濾波器依賴於用於計算平均值的樣本數,而LMS演算法是基於集平均而設計的,因此穩定環境下LMS演算法在不同計算條件下的結果是一致的。在效能方面,RLS的收斂速率比LMS要快得多,因此,RLS在收斂速率方面有很大優勢。 圖6分別為RLS演算法和LMS演算法在處理過程中的誤差曲線,它指出了在迭代過程中的誤差減少過程。由圖可見,RLS演算法在迭代過程中產生的誤差明顯小於LMS演算法。由此可見,RLS在提取訊號時,收斂速度快,估計精度高而且穩定性好,可以明顯抑制振動加速度收斂過程,故對非平穩訊號的適應性強,而LMS演算法收斂速度慢,估計精度低而且權係數估計值因瞬時梯度估計圍繞精確值波動較大,權噪聲大,不穩定。
lms濾波器是採用瞬時值對相關矩陣、梯度等進行估計的方法,而rls則是將目標函式固定為最小二乘意義下的指數加權和的形式。換句話說,lms演算法的最小化目標函式是瞬時誤差訊號的平方,而rls演算法最小化的目標函式是從0時刻到k時刻為之所有訊號在當前係數下的誤差訊號的加權平方和。由於都使用了當前時刻的係數,因此也可以說是後驗誤差的加權平方和。
二、原始碼
function varargout = untitled(varargin) %UNTITLED M-file for untitled.fig % UNTITLED, by itself, creates a new UNTITLED or raises the existing % singleton*. % % H = UNTITLED returns the handle to a new UNTITLED or the handle to % the existing singleton*. % % UNTITLED('Property','Value',...) creates a new UNTITLED using the % given property value pairs. Unrecognized properties are passed via % varargin to untitled_OpeningFcn. This calling syntax produces a % warning when there is an existing singleton*. % % UNTITLED('CALLBACK') and UNTITLED('CALLBACK',hObject,...) call the % local function named CALLBACK in UNTITLED.M with the given input % arguments. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help untitled % Last Modified by GUIDE v2.5 09-May-2006 17:38:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before untitled is made visible. function untitled_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin unrecognized PropertyName/PropertyValue pairs from the % command line (see VARARGIN) % Choose default command line output for untitled handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = untitled_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in select. function select_Callback(hObject, eventdata, handles) % hObject handle to select (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename, pathname] = ... uigetfile({'*.wav'},'File Selector'); if isequal(filename,0)|isequal(pathname,0) return; else str=[pathname,filename]; setappdata(handles.figure1,'str',str); [Y,FS]=wavread(str); %讀取聲音訊號 SigLength=length(Y); %計算訊號長度 t=(0:SigLength-1)/FS; axes(handles.axes1); plot(t,Y); set(gca,'YLim',[-1 1]); xlabel('t1:時間'); ylabel('Y(原音)'); title('原始語音訊號') end % --- Executes on button press in test2. function test2_Callback(hObject, eventdata, handles) % hObject handle to test2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) str2= getappdata(handles.figure1,'str'); [Y,FS,NBITS]=wavread(str2); %讀取聲音訊號 sound(Y); % --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 axes(handles.axes2); popup_sel_index = get(handles.popupmenu1, 'Value'); str2= getappdata(handles.figure1,'str'); [Y,FS]=wavread(str2); %讀取聲音訊號 SigLength=length(Y); %計算訊號長度 t=(0:SigLength-1)/FS; switch popup_sel_index case 1 case 2 x1=1/2*sin(2*pi*5000*t); xn=x1+0.02*x1.*randn(size(x1)); xn=xn'; xs=Y+xn; setappdata(handles.figure1,'xs',xs); plot(t,xs); set(gca,'YLim',[-2 2]); xlabel('t1:時間'); title('加噪後的語音訊號') spPower=sum(abs(Y( : )).^2)/length(Y( : )); noPower=sum(abs(xn( : )).^2)/length(xn( : )); spPower=10*log10(spPower); noPower=10*log10(noPower); SNR=spPower-noPower; set(handles.edit4,'string',num2str(SNR)); case 3 xn=sin(2*pi*120*t); xn=xn'; xs=Y+xn; setappdata(handles.figure1,'xs',xs); plot(t,xs); set(gca,'YLim',[-2 2]); xlabel('t1:時間'); title('加噪後的語音訊號') spPower=sum(abs(Y( : )).^2)/length(Y( : )); noPower=sum(abs(xn( : )).^2)/length(xn( : )); spPower=10*log10(spPower); noPower=10*log10(noPower); SNR=spPower-noPower; set(handles.edit4,'string',num2str(SNR)); case 4 xs=awgn(Y,10);%加入高斯白噪聲,信噪比隨機產生 setappdata(handles.figure1,'xs',xs); xn=xs-Y; plot(t,xs); set(gca,'YLim',[-2 2]); xlabel('t1:時間'); title('加噪後的語音訊號') spPower=sum(abs(Y( : )).^2)/length(Y( : )); noPower=sum(abs(xn( : )).^2)/length(xn( : )); spPower=10*log10(spPower); noPower=10*log10(noPower); SNR=spPower-noPower; set(handles.edit4,'string',num2str(SNR)) end % --- Executes on button press in test3. function test3_Callback(hObject, eventdata, handles) % hObject handle to test3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) xs1= getappdata(handles.figure1,'xs'); sound(xs1) % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423