⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 all.m

📁 最小二乘法中的递推最小二乘法
💻 M
📖 第 1 页 / 共 2 页
字号:
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in ps_sl.
function ps_sl_Callback(hObject, eventdata, handles)
global glb_in glb_out u_m v_m y1 y2          %原始输入输出数据
global glb_lmd n            %系统阶数和参数
global N M a b c                        %参与运算的数据长度
global glb_theta                      %系统参数
[b1,a21,ef11]=DLS(N,n,glb_in,y1);      %系统一
[c1,a31,ef21]=GLS(N,n,glb_in,y1);
[b2,a22,ef12]=DLS(N,n,glb_in,y2);      %系统二
[c2,a32,ef22]=GLS(N,n,glb_in,y2); 
switch get(findobj(gcf,'Tag','rb_zls'),'Value')
    case 1   %整批算法
        s='请选择递推或广义二乘法';
        axes(handles.pic_all);
        cla;
    case 0   %递推算法
        if(get(findobj(gcf,'Tag','rb_dls'),'Value')==1)
        axes(handles.pic_all);
        cla;
        plot(ef11,'r');
        hold on;
        plot(ef12,'k');
        hold off;
        s=str2mat(...
            '递推算法的收敛过程',...
            '    红色曲线为模型一',...
            '    黑色曲线为模型二');
        else  %广义
        axes(handles.pic_all);
        cla;
        plot(ef21,'g');
        hold on;
        plot(ef22);
        hold off;
        s=str2mat(...
            '广义二乘算法的收敛过程',...
            '    绿色曲线为模型一',...
            '    蓝色曲线为模型二');
        end
end
set(findobj(gcf,'Tag','text_sy'),'String',s);

% hObject    handle to ps_sl (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in ps_wc.
function ps_wc_Callback(hObject, eventdata, handles)
global glb_in glb_out u_m v_m             %原始输入输出数据
global n glb_lmd                  %系统阶数和参数
global N M a b c                           %参与运算的数据长度
global glb_theta                    %系统参数
glb_theta;
ay=(glb_theta(1:2,1));
ayy=[1;ay];
by=glb_theta(3:5,1);
switch get(findobj(gcf,'Tag','mod_1'),'Value')
    case 1   %模型一
        y_mwc=filter(by',ayy',u_m)+glb_lmd*v_m;                               %白噪声   
        s=str2mat(...
    '左边两图显示模型一的预报误差',...
    '    红色曲线为系统生成的输出',...
    '    绿色曲线为预报的输出',...
    '',...
    '注:预报时使用的是最近一次辨识',...
    '        的结果');
    case 0   %模型二
        y_mwc=filter(by',ayy',u_m)+filter(c,a,glb_lmd*v_m);                    %有色噪声
        s=str2mat(...
    '左边两图显示模型二的预报误差',...
    '    红色曲线为系统生成的输出',...
    '    绿色曲线为预报的输出',...
    '',...
    '注:预报时使用的是最近一次辨识',...
    '        的结果');
end
y_mwc=y_mwc(1,1:N);
axes(handles.pic_all);
cla;
plot(glb_out,'r');
hold on;
plot(y_mwc,'g');
hold off;
set(findobj(gcf,'Tag','text_sy'),'String',s);
% hObject    handle to ps_wc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in ps_js.
function ps_js_Callback(hObject, eventdata, handles)
global glb_in glb_out N y1 y2           %原始输入输出数据
u=glb_in;
y=y1;
for n=1:10
theta_j=ZLS(N,n,u,y);
for i=n+1:N
        e_j(i-n)=y(i);
       for j=1:n
             e_j(i-n)=e_j(i-n)+theta_j(j)*y(i-j);
        end
        for k=(n+1):(2*n+1)
            e_j(i-n)=e_j(i-n)-theta_j(k)*u(i-k+n+1);
        end
end
J(n)=e_j*e_j';
end
axes(handles.pic_all);
cla;
plot(J);
s=str2mat(...
    '左图显示模型的阶次',...
    '横坐标表示模型的阶次变化',...
    '纵坐标为残差平方和的值',...
    '由最终陡峭下降准则,模型阶次为2');
set(findobj(gcf,'Tag','text_sy'),'String',s);

% hObject    handle to ps_js (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)





function text_Callback(hObject, eventdata, handles)
% hObject    handle to text_a (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 text_a as text_a
%        str2double(get(hObject,'String')) returns contents of text_a as a double


% --- Executes during object creation, after setting all properties.
function text_a_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text_a (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



function text_a_sy_Callback(hObject, eventdata, handles)
% hObject    handle to text_a_sy (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 text_a_sy as text_a
%        str2double(get(hObject,'String')) returns contents of text_a_sy as a double


% --- Executes during object creation, after setting all properties.
function text_a_sy_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text_a_sy (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



function text_a_cs_Callback(hObject, eventdata, handles)
% hObject    handle to text_a_cs (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 text_a_cs as text_a
%        str2double(get(hObject,'String')) returns contents of text_a_cs as a double





% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called




% --- Executes during object creation, after setting all properties.
function pic_in_CreateFcn(hObject, eventdata, handles)

% hObject    handle to pic_in (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate pic_in




% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in ps_gene.
function ps_gene_Callback(hObject, eventdata, handles)
global glb_in glb_out u_m v_m y1 y2          %原始输入输出数据
global glb_lmd n           %系统阶数和参数
global N M a b c                        %参与运算的数据长度
global glb_theta                      %系统参数
%获取系统的阶数
s=get(findobj(gcf,'Tag','ed_n'),'String');
n=str2double(s); 
%获取输入数据长度
s=get(findobj(gcf,'Tag','ed_N'),'String');
M=str2double(s);  
N=M/2;
%获取Lmd
s=get(findobj(gcf,'Tag','ed_lmd'),'String');
Lmd=str2double(s);  
glb_lmd=Lmd;
%产生输入
u_m=randn(1,M);
v_m=randn(1,M);
b=[0 1 -0.5];
a=[5 -2.5 3.5];
c=[1 0 0];
y1_m=filter(b,a,u_m)+Lmd*v_m;                   %有色噪声
y2_m=filter(b,a,u_m)+filter(c,a,Lmd*v_m);       %白噪声
glb_in=u_m(1,1:N);
y1=y1_m(1,1:N);
y2=y2_m(1,1:N);
switch get(findobj(gcf,'Tag','mod_1'),'Value')
    case 1   %模型一
        glb_out=y1;                                 %有色噪声      
        clour='r';
        s=str2mat('模型一的输入和输出');
    case 0   %模型二
        glb_out=y2;                                 %白噪声
        clour='g';
        s=str2mat('模型二的输入和输出');
end
%绘图
axes(handles.pic_in);
cla;
plot(glb_in);
axes(handles.pic_out);
cla;
plot(glb_out,clour);
set(findobj(gcf,'Tag','text_sy'),'String',s);
%axes(handles.pic_out);
%plot(glb_out,'g');
%cla;

% hObject    handle to ps_gene (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on button press in pb_do.
function pb_do_Callback(hObject, eventdata, handles)
global glb_in glb_out  y1 y2           %原始输入输出数据
global u_m v_m
global glb_lmd             %系统阶数和参数
global N M                          %参与运算的数据长度
global glb_theta                      %系统参数
s=get(findobj(gcf,'Tag','ed_n'),'String');
n=str2double(s);  
switch get(findobj(gcf,'Tag','mod_1'),'Value')
    case 1   %模型一
        glb_out=y1;                                 %有色噪声      
    case 0   %模型二
        glb_out=y2;                                 %白噪声
end
switch get(findobj(gcf,'Tag','rb_zls'),'Value')
    case 1   %整批算法
        glb_theta=ZLS(N,n,glb_in,glb_out);
    case 0   %递推算法
        if(get(findobj(gcf,'Tag','rb_dls'),'Value')==1)
        [b,glb_theta,ef]=DLS(N,n,glb_in,glb_out);
        else
         [b,glb_theta,ef]=GLS(N,n,glb_in,glb_out);
        end
end
sa=sprintf('a%d=%f,a%d=%f',0,glb_theta(1),1,glb_theta(2));
sb=sprintf('b%d=%f,b%d=%f,b%d=%f',0,glb_theta(3),1,glb_theta(4),2,glb_theta(5));
set(findobj(gcf,'Tag','text_a'),'String',sa);
set(findobj(gcf,'Tag','text_b'),'String',sb);
% hObject    handle to pb_do (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)





function text_a_Callback(hObject, eventdata, handles)
% hObject    handle to text_a (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 text_a as text
%        str2double(get(hObject,'String')) returns contents of text_a as a double





function text_b_Callback(hObject, eventdata, handles)
% hObject    handle to text_b (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 text_b as text
%        str2double(get(hObject,'String')) returns contents of text_b as a double


% --- Executes during object creation, after setting all properties.
function text_b_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text_b (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




% --- Executes on selection change in text_sy.
function text_sy_Callback(hObject, eventdata, handles)
% hObject    handle to text_sy (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 text_sy contents as cell array
%        contents{get(hObject,'Value')} returns selected item from text_sy


% --- Executes during object creation, after setting all properties.
function text_sy_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text_sy (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


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -