📄 lab_16.m
字号:
function lab_16(action)
%LAB_16 交互式数字信号处理演示实验
%自适应信号滤波
%
%实验目的:
%利用自适应LMS算法实现FIR最佳维纳滤波器
%观察影响自适应LMS算法收敛性、收敛速度以及失调量的各种因素,
%领会自适应信号处理方法的优缺点
%实现AR模型参数的自适应估计,了解自适应信号处理方法的应用
% possible actions:
% 'initialize'
% 'eval'
% 'next'
% 'prev'
% 'reset'
% 'info'
global hI h0 u aw step;
global promptStr;
if nargin<1
action='initialize';
end;
if strcmp(action,'initialize')
step=0; hI=-0.8; h0=0; u=0.03; aw=1;
%====================================
% Graphics initialization
figNumber=figure( ...
'NumberTitle','off', ...
'Name','自适应信号滤波',...
'Units','normalized');
axes( ...
'Units','normalized', ...
'Position',[0.08 0.43 0.62 0.48]);
%===================================
% Set up the Command Window
top=0.35;
left=0.05;
right=0.70;
bottom=0.05;
labelHt=0.05;
spacing=0.005;
promptStr=strvcat(' 自适应信号滤波', ...
' 设置参数,信号w的方差aw,w的样本个数L=100,',...
' 滤波器权系数hI,步长μ值,h(n) 的初始值h(0)',...
' 点击Next 开始实验');
% First, the Command Window frame
frmBorder=0.02;
frmPos=[left-frmBorder bottom-frmBorder ...
(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.35 0.35 0.5]);
% Then the text label
labelPos=[left top-labelHt (right-left) labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',[0.35 0.35 0.5], ...
'ForegroundColor',[1 1 0], ...
'Fontsize',10,...
'String','提 示 信 息');
% Then the editable text field
mcwPos=[left bottom (right-left) top-bottom-labelHt-spacing];
mcwHndl=uicontrol( ...
'Style','edit', ...
'HorizontalAlignment','left', ...
'Units','normalized', ...
'Max',10, ...
'BackgroundColor',[1 1 1], ...
'Position',mcwPos, ...
'ForegroundColor',[0 0.2 0.2],...
'Fontsize',10,...
'String',promptStr,...
'Tag','comdedit');
%====================================
% Information for all buttons
labelColor=[0.8 0.8 0.8];
top=0.95;
bottom=0.05;
left=0.77;
labelWid=0.05;
labelHt=0.045;
editWid=0.122;
editHt=0.05;
popbnWid=0.122;
popbnHt=0.05;
btnWid=0.175;
btnHt=0.07;
% Spacing between the label and the button for the same command
btnOffset=0.003;
% Spacing between the button and the next command's label
spacing=0.035;
%====================================
% The CONSOLE frame
frmBorder=0.02;
yPos=0.05-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
h=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.35 0.35 0.5]);
%===================================================
%The input aw popup button
btnNumber=1;
yLabelPos=top-(btnNumber-1)*(editHt+spacing);
labelList=' 0.01| 0.1| 0.3| 1.0| 10';
callbackStr='lab_16(''setpara1'');lab_16(''eval'')';
% Generic label information
labelPos=[left yLabelPos-editHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String','aw:');
% Generic popup button information
btnPos=[left+labelWid+btnOffset yLabelPos-editHt popbnWid popbnHt];
hndl1=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'value',4,...
'Tag','Wset',...
'Callback',callbackStr);
%===================================================
%The input u popup button
btnNumber=2;
yLabelPos=top-(btnNumber-1)*(editHt+spacing);
labelList=' 0.01| 0.03| 0.1| 0.5| 1.0';
callbackStr='lab_16(''setpara2'');lab_16(''eval'')';
% Generic label information
labelPos=[left yLabelPos-editHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String','u:');
% Generic popup button information
btnPos=[left+labelWid+btnOffset yLabelPos-editHt popbnWid popbnHt];
hndl1=uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList, ...
'value',2,...
'Tag','Uset',...
'Callback',callbackStr);
%===================================================
%The input hI editable text field
btnNumber=3;
yLabelPos=top-(btnNumber-1)*(editHt+spacing);
callbackStr='lab_16(''setpara3'');lab_16(''eval'')';
% Generic label information
labelPos=[left yLabelPos-editHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String','hI:',...
'Tag','Ilabel');
% Generic editable text field
btnPos=[left+labelWid+btnOffset yLabelPos-editHt editWid editHt];
hndl1=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',btnPos, ...
'BackgroundColor',[1 1 1],...
'String',-0.8, ...
'Tag','Iset',...
'Callback',callbackStr);
%===================================================
%The input h0 editable text field
btnNumber=4;
yLabelPos=top-(btnNumber-1)*(editHt+spacing);
callbackStr='lab_16(''setpara4'');lab_16(''eval'')';
% Generic label information
labelPos=[left yLabelPos-editHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String','h(0):',...
'Tag','Olabel');
% Generic editable text field
btnPos=[left+labelWid+btnOffset yLabelPos-editHt editWid editHt];
hndl1=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',btnPos, ...
'BackgroundColor',[1 1 1],...
'String',0, ...
'Tag','Oset',...
'Callback',callbackStr);
%====================================================
% The Next Step button
yPos=yLabelPos-editHt-spacing-btnHt;
labelStr='Next';
callbackStr='lab_16(''next'')';
% Generic button information
btnPos=[left yPos btnWid btnHt];
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Tag','nextbn',...
'Fontsize',10,...
'Callback',callbackStr);
%====================================================
% The Prev button
yPos=yPos-spacing-btnHt;
labelStr='Prev';
callbackStr='lab_16(''prev'')';
% Generic button information
btnPos=[left yPos btnWid btnHt];
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Tag','prevbn',...
'Enable','off', ...
'Fontsize',10,...
'Callback',callbackStr);
%====================================================
% The Reset button
yPos=yPos-spacing-btnHt;
labelStr='Reset';
callbackStr='lab_16(''reset'')';
% Generic button information
btnPos=[left yPos btnWid btnHt];
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Tag','resetbn',...
'Fontsize',10,...
'Callback',callbackStr);
%===========================================
% The info button.
uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom+btnHt+spacing btnWid btnHt], ...
'String','Info', ...
'Fontsize',10,...
'Callback','lab_16(''info'')');
% The close button.
uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom btnWid btnHt], ...
'String','Close', ...
'Fontsize',10,...
'Callback','close(gcf)');
% Now uncover the figure
set(figNumber,'Visible','on');
elseif strcmp(action,'setpara1')
Wmap=[0.01,0.1,0.3,1.0,10];
hndl=findobj(gcbf,'Tag','Wset');
value=get(hndl,'value');
aw=Wmap(value);
elseif strcmp(action,'setpara2')
Umap=[0.01,0.03,0.1,0.5,1.0];
hndl=findobj(gcbf,'Tag','Uset');
value=get(hndl,'value');
u=Umap(value);
elseif strcmp(action,'setpara3')
Hnd1=findobj(gcbf,'Tag','Iset');
hI=str2num(get(Hnd1,'string'));
if isempty(hI)
set(Hnd1,'string','');
end
elseif strcmp(action,'setpara4')
Hnd1=findobj(gcbf,'Tag','Oset');
h0=str2num(get(Hnd1,'string'));
if isempty(h0)
set(Hnd1,'string','');
end
elseif strcmp(action,'eval')
if isempty(hI)|isempty(h0)
errordlg('请输入正确的参数!','error');
else
lab_16s(step,aw,u,hI,h0)
end
elseif strcmp(action,'next')
step=step+1;
lab_16s(step,aw,u,hI,h0)
elseif strcmp(action,'prev')
step=step-1;
lab_16s(step,aw,u,hI,h0)
elseif strcmp(action,'reset')
step=0; hI=-0.8; h0=0; u=0.03; aw=1;
cla reset;
promptStr=strvcat(' 自适应信号滤波', ...
' 设置参数,信号w的方差aw,w的样本个数L=100,',...
' 滤波器权系数hI,步长μ值,h(n) 的初始值h(0)',...
' 点击Next 开始实验');
Hnd1=findobj(gcbf,'Tag','comdedit');
set(Hnd1,'String',promptStr);
hndl=findobj(gcbf,'Tag','nextbn');
set(hndl,'Enable','on');
hndl=findobj(gcbf,'Tag','prevbn');
set(hndl,'Enable','off');
hndl=findobj(gcbf,'Tag','Wset');
set(hndl,'value',4);
hndl=findobj(gcbf,'Tag','Uset');
set(hndl,'value',2);
Hnd1=findobj(gcbf,'Tag','Iset');
set(Hnd1,'string',-0.8);
Hnd1=findobj(gcbf,'Tag','Oset');
set(Hnd1,'string',0);
hndl=findobj(gcbf,'Tag','Ilabel');
set(hndl,'string','hI:');
hndl=findobj(gcbf,'Tag','Olabel');
set(hndl,'string','h(0):');
elseif strcmp(action,'info')
helpwin(mfilename);
end % if strcmp(action, ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -