幅频特性曲线分析及使用WPF绘制

2024-08-24 18:44

本文主要是介绍幅频特性曲线分析及使用WPF绘制,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 1、一阶惯性环节的幅频特性曲线分析及绘制
  • 2、二阶系统的幅频特性曲线分析及绘制
  • 3、一般的系统
  • 4、上位机代码实现
    • 4.1 一阶惯性系统
    • 4.2 二阶系统
  • 5、稳定裕度
    • 5.1 幅值裕度
    • 5.2 相角裕度
  • 参考

1、一阶惯性环节的幅频特性曲线分析及绘制

在这里插入图片描述
这里的a和b可以根据系统的不同修改,然后在0-50Hz内以1/10000的分辨率取点,可得对数幅频特性曲线(1/0.5s+1):
在这里插入图片描述
MATLAB脚本实现传递函数(1/0.5s+1)的伯德图绘制:

% 0.001 - 10^1.5  10000个点
w = logspace(-3,2,10000);
num = [0 1];
f = [0.5 1];
sys = tf(num,f);
P = bodeoptions;
% 横坐标为Hz
P.FreqUnits = 'Hz';
bode(sys,w,P)

在这里插入图片描述

2、二阶系统的幅频特性曲线分析及绘制

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
MATLAB脚本实现传递函数(2/(0.01s+1)(0.2s+1)的伯德图绘制:

% 0.001 - 10^1.5  10000个点
w = logspace(-3,2,10000);
num = [0 2];
f1 = [0.01 1];
f2 = [0.2 1];
den = conv(f1,f2);
sys = tf(num,den);
P = bodeoptions;
% 横坐标为Hz
P.FreqUnits = 'Hz';
bode(sys,w,P)

在这里插入图片描述

3、一般的系统

在这里插入图片描述

4、上位机代码实现

源码及Oxyplot源码下载地址: WPF实现bode图demo源码

4.1 一阶惯性系统

<Page x:Class="WPF_Demo_V2.View.LogChartPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WPF_Demo_V2.View"xmlns:oxyplot="http://oxyplot.org/wpf"mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"Title="LogChartPage"><Grid><Grid.RowDefinitions><RowDefinition/><RowDefinition/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="5*"/><ColumnDefinition/></Grid.ColumnDefinitions><oxyplot:PlotView Model="{Binding MyPlotModelUp}"/><oxyplot:PlotView Grid.Row="1"  Model="{Binding MyPlotModelDown}"/><StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="0.8*"/><ColumnDefinition/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions><TextBlock Text="a:" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Column="1" Text="{Binding A}" Margin="2"></TextBox><TextBlock Text="b:" Grid.Row="1" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="1" Grid.Column="1" Text="{Binding B}" Margin="2"></TextBox><TextBlock Text="X max:" Grid.Row="2" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="2" Grid.Column="1" Text="{Binding X_max}" Margin="2"></TextBox><TextBlock Text="factor:" Grid.Row="3" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Factor}" Margin="2" ToolTip="X_max/factor 为最小分辨率"></TextBox><TextBlock Text="Y1 min:" Grid.Row="4" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Y1_min}" Margin="2"></TextBox><TextBlock Text="Y1 max:" Grid.Row="5" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Y1_max}" Margin="2"></TextBox><TextBlock Text="Y2 min:" Grid.Row="6" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Y2_min}" Margin="2"></TextBox><TextBlock Text="Y2 max:" Grid.Row="7" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="7" Grid.Column="1" Text="{Binding Y2_max}" Margin="2"></TextBox><Button Grid.Row="8" Grid.ColumnSpan="2" Content="确定" Margin="20,2" Command="{Binding sureCommand}"/></Grid><Image Source="../Resource/Image/function.png"/></StackPanel></Grid>
</Page>
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WPF_Demo_V2.ViewModel
{partial class LogChartViewModel: ObservableObject{#region 全局变量//UInt32 LEN = 50;//UInt32 FACT = 10000;double[] Gain;double[] Phase;FunctionSeries upFunctionSeries=new FunctionSeries();FunctionSeries downFunctionSeries=new FunctionSeries();#endregion#region 构造函数public LogChartViewModel(){upFunctionSeries.Title = "Gain";downFunctionSeries.Title = "Phase";}#endregion#region 属性[ObservableProperty]public PlotModel _MyPlotModelUp;[ObservableProperty]public PlotModel _MyPlotModelDown;[ObservableProperty]public double _A = 0.5;[ObservableProperty]public double _B = 1;[ObservableProperty]public int _X_max = 50;[ObservableProperty]public int _Factor = 10000;[ObservableProperty]public double _Y1_max = 0;[ObservableProperty]public double _Y1_min = -50;[ObservableProperty]public double _Y2_max = 0;[ObservableProperty]public double _Y2_min = -90;#endregion#region 方法public PlotModel PlotModelInit(string xtitle,string ytitle,double ymin,double ymax){var plotModel = new PlotModel();//plotModel.Title = "Log Paper";var logarithmicAxis1 = new LogarithmicAxis();logarithmicAxis1.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139);logarithmicAxis1.MajorGridlineStyle = LineStyle.Solid;logarithmicAxis1.Maximum = X_max;logarithmicAxis1.Minimum = 1/ (double)Factor;logarithmicAxis1.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139);logarithmicAxis1.MinorGridlineStyle = LineStyle.Solid;logarithmicAxis1.Position = AxisPosition.Bottom;if (!string.IsNullOrEmpty(xtitle)) logarithmicAxis1.Title = xtitle;plotModel.Axes.Add(logarithmicAxis1);var linearAxis1 = new LinearAxis();linearAxis1.MajorGridlineStyle = LineStyle.Solid;linearAxis1.MinorGridlineStyle = LineStyle.Dot;linearAxis1.Maximum = ymax;linearAxis1.Minimum = ymin;linearAxis1.Title = ytitle;plotModel.Axes.Add(linearAxis1);return plotModel;}[RelayCommand]private void sure(){if(upFunctionSeries.Points.Count>0) upFunctionSeries.Points.Clear();if (downFunctionSeries.Points.Count > 0)downFunctionSeries.Points.Clear();if (MyPlotModelUp != null) {if (MyPlotModelUp.Series.Count > 0) MyPlotModelUp.Series.Clear();}if(MyPlotModelDown != null){if (MyPlotModelDown.Series.Count > 0) MyPlotModelDown.Series.Clear();}MyPlotModelUp = PlotModelInit("", "Magnitude[dB]", Y1_min, Y1_max);MyPlotModelDown = PlotModelInit("Frequency[Hz]", "Phase[deg]", Y2_min, Y2_max);Gain = new double[X_max * Factor];Phase = new double[X_max * Factor];for (int i = 0; i < X_max * Factor; i++){double temp_a = 2 * Math.PI * A * (i / (double)Factor);double temp_2 = Math.Pow(temp_a, 2) + Math.Pow(B, 2);double temp_sqrt = 1 / Math.Sqrt(temp_2);double temp = Math.Abs(temp_sqrt);Gain[i] = 20 * Math.Log10(temp);Phase[i] = -Math.Atan(temp_a / (double)B) / Math.PI * 180;upFunctionSeries.Points.Add(new DataPoint(i / (double)Factor, Gain[i]));downFunctionSeries.Points.Add(new DataPoint(i / (double)Factor, Phase[i]));}MyPlotModelUp.Series.Add(upFunctionSeries);MyPlotModelDown.Series.Add(downFunctionSeries);MyPlotModelUp.ResetAllAxes();MyPlotModelUp.InvalidatePlot(true);MyPlotModelDown.ResetAllAxes();MyPlotModelDown.InvalidatePlot(true);}#endregion}
}

4.2 二阶系统

<Page x:Class="WPF_Demo_V2.View.Log3ChartPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WPF_Demo_V2.View"xmlns:oxyplot="http://oxyplot.org/wpf"mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"Title="Log3ChartPage"><Grid><Grid.RowDefinitions><RowDefinition/><RowDefinition/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="5*"/><ColumnDefinition/></Grid.ColumnDefinitions><oxyplot:PlotView Model="{Binding MyPlotModelUp}"/><oxyplot:PlotView Grid.Row="1"  Model="{Binding MyPlotModelDown}"/><StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="0.8*"/><ColumnDefinition/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions><TextBlock Text="a:" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Column="1" Text="{Binding A}" Margin="2"></TextBox><TextBlock Text="b:" Grid.Row="1" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="1" Grid.Column="1" Text="{Binding B}" Margin="2"></TextBox><TextBlock Text="c:" Grid.Row="2" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="2" Grid.Column="1" Text="{Binding C}" Margin="2"></TextBox><TextBlock Text="X max:" Grid.Row="3" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="3" Grid.Column="1" Text="{Binding X_max}" Margin="2"></TextBox><TextBlock Text="factor:" Grid.Row="4" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Factor}" Margin="2" ToolTip="X_max/factor 为最小分辨率"></TextBox><TextBlock Text="Y1 min:" Grid.Row="5" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Y1_min}" Margin="2"></TextBox><TextBlock Text="Y1 max:" Grid.Row="6" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Y1_max}" Margin="2"></TextBox><TextBlock Text="Y2 min:" Grid.Row="7" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="7" Grid.Column="1" Text="{Binding Y2_min}" Margin="2"></TextBox><TextBlock Text="Y2 max:" Grid.Row="8" Foreground="White" HorizontalAlignment="Right"/><TextBox Grid.Row="8" Grid.Column="1" Text="{Binding Y2_max}" Margin="2"></TextBox><Button Grid.Row="9" Grid.ColumnSpan="2" Content="确定" Margin="20,2" Command="{Binding sureCommand}"/></Grid><Image Source="../Resource/Image/function.png"/></StackPanel></Grid>
</Page>
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WPF_Demo_V2.ViewModel
{partial class Log3ChartViewModel: ObservableObject{#region 全局变量//UInt32 LEN = 50;//UInt32 FACT = 10000;double[] Gain;double[] Phase;FunctionSeries upFunctionSeries = new FunctionSeries();FunctionSeries downFunctionSeries = new FunctionSeries();#endregion#region 构造函数public Log3ChartViewModel(){upFunctionSeries.Title = "Gain";downFunctionSeries.Title = "Phase";}#endregion#region 属性[ObservableProperty]public PlotModel _MyPlotModelUp;[ObservableProperty]public PlotModel _MyPlotModelDown;[ObservableProperty]public double _A = 0.5;[ObservableProperty]public double _B = 1;[ObservableProperty]public double _C = 1;[ObservableProperty]public int _X_max = 50;[ObservableProperty]public int _Factor = 10000;[ObservableProperty]public double _Y1_max = 0;[ObservableProperty]public double _Y1_min = -100;[ObservableProperty]public double _Y2_max = 100;[ObservableProperty]public double _Y2_min = -100;#endregion#region 方法public PlotModel PlotModelInit(string xtitle, string ytitle, double ymin, double ymax){var plotModel = new PlotModel();//plotModel.Title = "Log Paper";var logarithmicAxis1 = new LogarithmicAxis();logarithmicAxis1.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139);logarithmicAxis1.MajorGridlineStyle = LineStyle.Solid;logarithmicAxis1.Maximum = X_max;logarithmicAxis1.Minimum = 1 / (double)Factor;logarithmicAxis1.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139);logarithmicAxis1.MinorGridlineStyle = LineStyle.Solid;logarithmicAxis1.Position = AxisPosition.Bottom;if (!string.IsNullOrEmpty(xtitle)) logarithmicAxis1.Title = xtitle;plotModel.Axes.Add(logarithmicAxis1);var linearAxis1 = new LinearAxis();linearAxis1.MajorGridlineStyle = LineStyle.Solid;linearAxis1.MinorGridlineStyle = LineStyle.Dot;linearAxis1.Maximum = ymax;linearAxis1.Minimum = ymin;linearAxis1.Title = ytitle;plotModel.Axes.Add(linearAxis1);//var logarithmicAxis2 = new LogarithmicAxis();//logarithmicAxis2.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139);//logarithmicAxis2.MajorGridlineStyle = LineStyle.Solid;//logarithmicAxis2.Maximum = 180;//logarithmicAxis2.Minimum = -180;//logarithmicAxis2.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139);//logarithmicAxis2.MinorGridlineStyle = LineStyle.Solid;//logarithmicAxis2.Title = "Y";//plotModel.Axes.Add(logarithmicAxis2);return plotModel;}[RelayCommand]private void sure(){if (upFunctionSeries.Points.Count > 0) upFunctionSeries.Points.Clear();if (downFunctionSeries.Points.Count > 0) downFunctionSeries.Points.Clear();if (MyPlotModelUp != null){if (MyPlotModelUp.Series.Count > 0) MyPlotModelUp.Series.Clear();}if (MyPlotModelDown != null){if (MyPlotModelDown.Series.Count > 0) MyPlotModelDown.Series.Clear();}MyPlotModelUp = PlotModelInit("", "Magnitude[dB]", Y1_min, Y1_max);MyPlotModelDown = PlotModelInit("Frequency[Hz]", "Phase[deg]", Y2_min, Y2_max);Gain = new double[X_max * Factor];Phase = new double[X_max * Factor];double previousPhase = 0;for (int i = 0; i < X_max * Factor; i++){double w = 2 * Math.PI * (i / (double)Factor);double temp_a = 1 - A*B * Math.Pow(w, 2);double temp_b = (A+B)*w;double temp_2 = Math.Pow(temp_a, 2) + Math.Pow(temp_b, 2);double temp_sqrt = C / Math.Sqrt(temp_2);double temp = Math.Abs(temp_sqrt);Gain[i] = 20 * Math.Log10(temp);double currentPhaseA = Math.Atan(A * w) / Math.PI * 180;double currentPhaseB = Math.Atan(B * w) / Math.PI * 180;Phase[i] = 0-(currentPhaseA + currentPhaseB);upFunctionSeries.Points.Add(new DataPoint(i / (double)Factor, Gain[i]));downFunctionSeries.Points.Add(new DataPoint(i / (double)Factor, Phase[i]));}MyPlotModelUp.Series.Add(upFunctionSeries);MyPlotModelDown.Series.Add(downFunctionSeries);MyPlotModelUp.ResetAllAxes();MyPlotModelUp.InvalidatePlot(true);MyPlotModelDown.ResetAllAxes();MyPlotModelDown.InvalidatePlot(true);}#endregion}
}

5、稳定裕度

在这里插入图片描述

5.1 幅值裕度

在这里插入图片描述

5.2 相角裕度

在这里插入图片描述

参考

【1】第五章 线性系统的频域分析法:
https://buckyi.github.io/Note-Automation/%E7%BB%8F%E5%85%B8%E6%8E%A7%E5%88%B6%E7%90%86%E8%AE%BA/%E7%AC%AC05%E7%AB%A0%20%E7%BA%BF%E6%80%A7%E7%B3%BB%E7%BB%9F%E7%9A%84%E9%A2%91%E5%9F%9F%E5%88%86%E6%9E%90%E6%B3%95.html#33
【2】【自动控制原理】第5章 幅相频率特性曲线(奈氏图)及其绘制:
https://blog.csdn.net/persona5joker/article/details/140055111
【3】相角裕度与幅值裕度:
https://blog.csdn.net/qq_38972634/article/details/119787996
【4】【自动控制原理】第五章 奈奎斯特稳定判据,相角裕度和幅值裕度,对数频率特性及其绘制:
https://blog.csdn.net/persona5joker/article/details/140059710?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-4-140059710-blog-119787996.235v43pc_blog_bottom_relevance_base8&spm=1001.2101.3001.4242.3&utm_relevant_index=7
【5】自控理论 第6章 II 相对稳定性、伯德图和闭环频率响应
https://www.cnblogs.com/harold-lu/p/15740368.html

这篇关于幅频特性曲线分析及使用WPF绘制的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1103296

相关文章

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Python虚拟环境终极(含PyCharm的使用教程)

《Python虚拟环境终极(含PyCharm的使用教程)》:本文主要介绍Python虚拟环境终极(含PyCharm的使用教程),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录一、为什么需要虚拟环境?二、虚拟环境创建方式对比三、命令行创建虚拟环境(venv)3.1 基础命令3

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi

关于pandas的read_csv方法使用解读

《关于pandas的read_csv方法使用解读》:本文主要介绍关于pandas的read_csv方法使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录pandas的read_csv方法解读read_csv中的参数基本参数通用解析参数空值处理相关参数时间处理相关

使用Node.js制作图片上传服务的详细教程

《使用Node.js制作图片上传服务的详细教程》在现代Web应用开发中,图片上传是一项常见且重要的功能,借助Node.js强大的生态系统,我们可以轻松搭建高效的图片上传服务,本文将深入探讨如何使用No... 目录准备工作搭建 Express 服务器配置 multer 进行图片上传处理图片上传请求完整代码示例

SpringBoot条件注解核心作用与使用场景详解

《SpringBoot条件注解核心作用与使用场景详解》SpringBoot的条件注解为开发者提供了强大的动态配置能力,理解其原理和适用场景是构建灵活、可扩展应用的关键,本文将系统梳理所有常用的条件注... 目录引言一、条件注解的核心机制二、SpringBoot内置条件注解详解1、@ConditionalOn

Python中使用正则表达式精准匹配IP地址的案例

《Python中使用正则表达式精准匹配IP地址的案例》Python的正则表达式(re模块)是完成这个任务的利器,但你知道怎么写才能准确匹配各种合法的IP地址吗,今天我们就来详细探讨这个问题,感兴趣的朋... 目录为什么需要IP正则表达式?IP地址的基本结构基础正则表达式写法精确匹配0-255的数字验证IP地

使用Python实现全能手机虚拟键盘的示例代码

《使用Python实现全能手机虚拟键盘的示例代码》在数字化办公时代,你是否遇到过这样的场景:会议室投影电脑突然键盘失灵、躺在沙发上想远程控制书房电脑、或者需要给长辈远程协助操作?今天我要分享的Pyth... 目录一、项目概述:不止于键盘的远程控制方案1.1 创新价值1.2 技术栈全景二、需求实现步骤一、需求

Spring LDAP目录服务的使用示例

《SpringLDAP目录服务的使用示例》本文主要介绍了SpringLDAP目录服务的使用示例... 目录引言一、Spring LDAP基础二、LdapTemplate详解三、LDAP对象映射四、基本LDAP操作4.1 查询操作4.2 添加操作4.3 修改操作4.4 删除操作五、认证与授权六、高级特性与最佳