MATLAB一阶系统二阶系统伯德图和奈氏图
时间: 2023-10-09 16:10:09 浏览: 268
MATLAB可以用系统工具箱中的函数来绘制伯德图和奈氏图。这里简要介绍一下如何使用MATLAB绘制一阶和二阶系统的伯德图和奈氏图。
一阶系统
伯德图:
```matlab
num = 1;
den = [1 1];
G = tf(num, den);
bode(G);
grid on;
```
奈氏图:
```matlab
num = 1;
den = [1 1];
G = tf(num, den);
nyquist(G);
grid on;
```
二阶系统
伯德图:
```matlab
num = 1;
den = [1 0.2 1];
G = tf(num, den);
bode(G);
grid on;
```
奈氏图:
```matlab
num = 1;
den = [1 0.2 1];
G = tf(num, den);
nyquist(G);
grid on;
```
需要注意的是,这里的num和den分别是系统的分子和分母多项式系数,可以根据具体的系统进行修改。
相关问题
MATLAB一阶系统二阶系统伯德图和奈氏图通过gui实现
可以使用MATLAB中的GUI开发工具来实现一阶系统和二阶系统的伯德图和奈氏图,下面是一个简单的实现示例:
首先,创建一个GUI窗口,可以使用MATLAB的GUIDE工具进行创建,将窗口分为两个部分,一部分用于输入系统参数,另一部分用于显示伯德图和奈氏图。
在输入部分,可以添加编辑框或下拉菜单等控件,用于用户输入系统参数,如系统的阻尼比、自然频率等。
在显示部分,可以添加绘图区域,用于绘制伯德图和奈氏图。使用MATLAB的绘图函数,如bode、nyquist等,可以方便地绘制伯德图和奈氏图。
下面是一个简单的示例代码:
```
function varargout = system_gui(varargin)
% SYSTEM_GUI MATLAB code for system_gui.fig
% SYSTEM_GUI, by itself, creates a new SYSTEM_GUI or raises the existing
% singleton*.
%
% H = SYSTEM_GUI returns the handle to a new SYSTEM_GUI or the handle to
% the existing singleton*.
%
% SYSTEM_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SYSTEM_GUI.M with the given input arguments.
%
% SYSTEM_GUI('Property','Value',...) creates a new SYSTEM_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before system_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to system_gui_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 system_gui
% Last Modified by GUIDE v2.5 23-Jun-2021 17:37:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @system_gui_OpeningFcn, ...
'gui_OutputFcn', @system_gui_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 system_gui is made visible.
function system_gui_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 system_gui (see VARARGIN)
% Choose default command line output for system_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes system_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = system_gui_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 plot_button.
function plot_button_Callback(hObject, eventdata, handles)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% read input values
zeta = str2double(get(handles.zeta_edit, 'String'));
wn = str2double(get(handles.wn_edit, 'String'));
% calculate system parameters
wd = wn * sqrt(1 - zeta^2);
tau = 1 / (zeta*wn);
sys = tf(wn^2, [1, 2*zeta*wn, wn^2]);
% plot bode diagram
axes(handles.bode_axes);
bode(sys);
% plot nyquist diagram
axes(handles.nyquist_axes);
nyquist(sys);
function zeta_edit_Callback(hObject, eventdata, handles)
% hObject handle to zeta_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function zeta_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to zeta_edit (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 wn_edit_Callback(hObject, eventdata, handles)
% hObject handle to wn_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function wn_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to wn_edit (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 clear_button.
function clear_button_Callback(hObject, eventdata, handles)
% hObject handle to clear_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% clear plots
axes(handles.bode_axes);
cla;
axes(handles.nyquist_axes);
cla;
% --- Executes on button press in exit_button.
function exit_button_Callback(hObject, eventdata, handles)
% hObject handle to exit_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% close the GUI window
close(handles.figure1);
```
这个示例代码可以实现通过GUI界面输入系统参数,绘制一阶系统和二阶系统的伯德图和奈氏图。
阅读全文