数字信号处理之 matlab gui 设计 系统函数

题目分析:

本题要求设计一个图形用户界面(GUI),用户可以通过该界面输入一个任意系统函数(通常是连续时间线性时不变系统的传递函数),然后GUI能够自动分析并显示该系统的一些关键信息,包括:

  1. 系统频率响应中的幅度响应和相位响应:幅度响应描述了系统对不同频率信号的增益,而相位响应则描述了系统对不同频率信号的相位偏移。这些信息对于理解系统的频域特性至关重要。
  2. 系统零极点的分布:系统的零点和极点对于分析其稳定性和动态特性非常重要。零点影响系统的暂态响应,而极点则决定系统的稳定性。在复平面上绘制零点和极点图(极零图)可以帮助用户直观地理解系统的行为。
  3. 系统的稳定性判定:稳定性是系统设计的关键要求之一。系统是否稳定取决于其极点的位置。如果所有极点都位于复平面的左半平面,则系统是稳定的。GUI需要能够自动检测并显示系统的稳定性状态。

设计思路:

采用freqz函数将系数矩阵转化为系统函数H,abs(H)即为幅度,angle(H)即为角度,接着将频率从db转到hz,用plot画出频率幅度响应以及相位响应。用pole与zero函数算出该系统函数的零极点分布后,调用zplane函数将零极点分布的图画出来,而判断系统稳定性只需判断该系统函数的极点是否都在y轴左半平面即可

运行结果

代码

function varargout = untitled(varargin)
% UNTITLED MATLAB code 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('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled
 
% Last Modified by GUIDE v2.5 12-Jun-2024 18:41:39
 
% 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   command line arguments to untitled (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;
 
 
 
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 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)
eval("b=["+get(handles.edit1,'String')+"]")
eval("a=["+get(handles.edit2,'String')+"]")
 
 
[H,W]=freqz(b,a);%W:Ä£Äâ½ÇƵÂÊ£¬H:Ä£ÄâÂ˲¨Æ÷µÄϵͳº¯Êý
mag=abs(H);%·ù¶È
pha=angle(H);%Ïàλ
db=20*log10((mag+eps)/max(mag));%ת»»Îª·Ö±´
f=W/(2*pi);%½«Ä£Äâ½ÇƵÂÊתΪHz
axes(handles.axes1)
plot(f,db);
title('·ùƵÇúÏß');xlabel('ƵÂÊ£¨Hz£©');ylabel('·ù¶È£¨dB£©');
axes(handles.axes3)
plot(f,pha);
title('ÏàƵÇúÏß');xlabel('ƵÂÊ£¨Hz£©');ylabel('Ïà루rad£©');
axes(handles.axes4)
sys=tf(b,a)
p = pole(sys); % ¼ÆË㼫µã  
z = zero(sys); % ¼ÆËãÁãµã 
zplane(z,p)
title('Á㼫µã·Ö²¼');
is_stable = all(real(p) < 0); % Èç¹ûËùÓм«µãµÄʵ²¿¶¼Ð¡ÓÚ0£¬ÔòϵͳÎȶ¨  
  
% ÏÔʾ½á¹û  
if is_stable  
    set(handles.text5,'String',"ϵͳÊÇÎȶ¨µÄ")
else  
    set(handles.text5,'String',"ϵͳ²»ÊÇÎȶ¨µÄ")
end  

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨痕_777

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值