【預測模型】基於matlab GUI一步線性+weiner濾波預測【含Matlab原始碼 942期】
阿新 • • 發佈:2021-06-20
一、簡介
基於matlab GUI一步線性+weiner濾波預測
二、原始碼
function varargout = WeinerFilter(varargin) % WEINERFILTER M-file for WeinerFilter.fig % WEINERFILTER, by itself, creates a new WEINERFILTER or raises the existing % singleton*. % % H = WEINERFILTER returns the handle to a new WEINERFILTER or the handle to % the existing singleton*. % % WEINERFILTER('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in WEINERFILTER.M with the given input arguments. % % WEINERFILTER('Property','Value',...) creates a new WEINERFILTER or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before WeinerFilter_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to WeinerFilter_OpeningFcn via varargin. % % *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 WeinerFilter % Last Modified by GUIDE v2.5 28-May-2021 16:23:34 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @WeinerFilter_OpeningFcn, ... 'gui_OutputFcn', @WeinerFilter_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 WeinerFilter is made visible. function WeinerFilter_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 command line arguments to WeinerFilter (see VARARGIN) % Choose default command line output for WeinerFilter handles.output = hObject; % Update handles structure guidata(hObject, handles); set(handles.listSignal,'string', ... '1-|2-AR過程的訊號|3-兩個正弦訊號疊加+N|4-單一正弦訊號|5-SAR_Line'); % UIWAIT makes WeinerFilter wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = WeinerFilter_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 btnWiener. function btnWiener_Callback(hObject, eventdata, handles) % hObject handle to btnWiener (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %獲取資料 pInfo = getappdata(handles.figure1,'mydata'); x=pInfo.pData; s=pInfo.pDataS; M=length(x); N=str2num(get(handles.edLengthFilter,'string')); fNoiseM=str2num(get(handles.edNoiseM,'string')); % 指定輸出 axes(handles.axesOut); %自相關矩陣 %自相關矩陣R Re=zeros(1,M); for i=1:N for j=1:M if j+i-1<=M Re(1,i)=x(1,j)*x(1,j+i-1)'/(M-i+1)+Re(1,i); end end end R=zeros(N,N); for i=1:N for j=i:N if(i==j) R(i,i)=Re(1,1); else R(i,j)=Re(1,j-i+1); R(j,i)=conj(R(i,j)); end end end %互相關矩陣 r r=zeros(1,N); for i=1:N for j=1:M if j-i+1>0 r(1,i)=x(1,j)*s(1,j-i+1)'/(M-i+1)+r(1,i); end end end Wopt=inv(R)*r'; %最優抽頭權向量 X=zeros(1,M); %濾波器輸出 for n1=1:M if n1<N for i=0:n1-1 X(1,n1)=Wopt(i+1,1)*x(1,n1-i)+X(1,n1); end else for i=0:N-1 X(1,n1)=Wopt(i+1,1)*x(n1-i)+X(1,n1); end end end % %%去延遲 % for j=1:M % if(j>=M-iDelay-iDelay) % XX(1,j)=0; % else % XX(1,j)=X(1,j+iDelay+iDelay); % end % end hold off plot(s,'.-k','linewidth',2);hold on plot(x,'.-b'); hold on plot(X,'*-r','linewidth',2); hold off legend('原訊號','噪聲訊號','濾波訊號') %% % --- Executes on selection change in listSignal. function listSignal_Callback(hObject, eventdata, handles) % hObject handle to listSignal (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 listSignal contents as cell array % contents{get(hObject,'Value')} returns selected item from listSignal % --- Executes during object creation, after setting all properties. function listSignal_CreateFcn(hObject, eventdata, handles) % hObject handle to listSignal (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox 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 function edLengthSignal_Callback(hObject, eventdata, handles) % hObject handle to edLengthSignal (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edLengthSignal as text % str2double(get(hObject,'String')) returns contents of edLengthSignal as a double % --- Executes during object creation, after setting all properties. function edLengthSignal_CreateFcn(hObject, eventdata, handles) % hObject handle to edLengthSignal (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit 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