function varargout = LS(varargin)
% LS MATLAB code for LS.fig
% LS, by itself, creates a new LS or raises the existing
% singleton*.
%
% H = LS returns the handle to a new LS or the handle to
% the existing singleton*.
%
% LS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LS.M with the given input arguments.
%
% LS('Property','Value',...) creates a new LS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before LS_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to LS_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 LS
% Last Modified by GUIDE v2.5 28-Apr-2013 10:23:30
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LS_OpeningFcn, ...
'gui_OutputFcn', @LS_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 LS is made visible.
function LS_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 LS (see VARARGIN)
% Choose default command line output for LS
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LS wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = LS_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% c=imread('公式3.jpg');
%
% axes(handles.axes1);
% image(c,'parent',handles.axes1);
% axis off;
a=[1 -1.5 0.7]'; b=[1 0.5]'; d=3; %对象参数
na=length(a)-1; nb=length(b)-1; %na、nb为A、B阶次
L=1000; %数据长度
uk=zeros(d+nb,1); %输入初值:uk(i)表示u(k-i)
yk=zeros(na,1); %输出初值
x1=1; x2=1; x3=1; x4=0; S=1; %移位寄存器初值、方波初值
xi=randn(L,1); %白噪声序列
theta=[a(2:na+1);b]; %对象参数真值
for k=1:L
phi(k,:)=[-yk;uk(d:d+nb)]'; %此处phi(k,:)为行向量,便于组成phi矩阵
y(k)=phi(k,:)*theta+xi(k); %采集输出数据
IM=xor(S,x4); %产生逆M序列
if IM==0
u(k)=-1;
else
u(k)=1;
end
S=not(S); M=xor(x3,x4); %产生M序列
%更新数据
x4=x3; x3=x2; x2=x1; x1=M;
for i=d+nb:-1:2
uk(i)=uk(i-1);
end
uk(1)=u(k);
for i=na:-1:2
yk(i)=yk(i-1);
end
yk(1)=y(k);
end
thetae=inv(phi'*phi)*phi'*y'; %计算参数估计值thetae
thetae=thetae';
s1=thetae(1);
s2=thetae(2);
s3=thetae(3);
s4=thetae(4);
set(handles.a1,'enable','on','string',s1);
set(handles.a2,'enable','on','string',s2);
set(handles.b0,'enable','on','string',s3);
set(handles.b1,'enable','on','string',s4);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
function a1_Callback(hObject, eventdata, handles)
% hObject handle to a1 (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 a1 as text
% str2double(get(hObject,'String')) returns contents of a1 as a double
% --- Executes during object creation, after setting all properties.
function a1_CreateFcn(hObject, eventdata, handles)
% hObject handle to a1 (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 a2_Callback(hObject, eventdata, handles)
% hObject handle to a2 (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 a2 as text
% str2double(get(hObject,'String')) returns contents of a2 as a double
% --- Executes during object creation, after setting all properties.
function a2_CreateFcn(hObject, eventdata, handles)
% hObject handle to a2 (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 b0_Callback(hObject, eventdata, handles)
% hObject handle to b0 (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 b0 as text
% str2double(get(hObject,'String')) returns contents of b0 as a double
% --- Executes during object creation, after setting all properties.
function b0_CreateFcn(hObject, eventdata, handles)
% hObject handle to b0 (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 b1_Callback(hObject, eventdata, handles)
% hObject handle to b1 (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 b1 as text
% str2double(get(hObject,'String')) returns contents of b1 as a double
% --- Executes during object creation, after setting all properties.
function b1_CreateFcn(hObject, eventdata, handles)
% hObject handle to b1 (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,'Backgr