Matlab-study-4

初阶绘图

plot()

plot(cos(0:pi/20:2*pi));

说明:
pi/20:设置每次增加的数值,或者叫做步长,相当于从0怎么增加到到2pi呢?就是每次都加一个pi/20,即0+pi/20+pi/20+pi/20……这样一直加到2pi就停止了

语法
plot(X,Y)
plot(X,Y,LineSpec)
plot(X1,Y1,…,Xn,Yn)
plot(X1,Y1,LineSpec1,…,Xn,Yn,LineSpecn)
plot(Y)
plot(Y,LineSpec)
plot(___,Name,Value)
plot(ax,___)
h = plot(___)

说明
示例

plot(X,Y) 创建 Y 中数据对 X 中对应值的二维线图。

如果 X 和 Y 都是向量,则它们的长度必须相同。plot 函数绘制 Y 对 X 的图。

如果 X 和 Y 均为矩阵,则它们的大小必须相同。plot 函数绘制 Y 的列对 X 的列的图。

如果 X 或 Y 中的一个是向量而另一个是矩阵,则矩阵的各维中必须有一维与向量的长度相等。如果矩阵的行数等于向量长度,则 plot 函数绘制矩阵中的每一列对向量的图。如果矩阵的列数等于向量长度,则该函数绘制矩阵中的每一行对向量的图。如果矩阵为方阵,则该函数绘制每一列对向量的图。

如果 X 或 Y 之一为标量,而另一个为标量或向量,则 plot 函数会绘制离散点。但是,要查看这些点,您必须指定标记符号,例如 plot(X,Y,‘o’)。

plot(X,Y,LineSpec) 设置线型、标记符号和颜色。

示例
plot(X1,Y1,…,Xn,Yn) 绘制多个 X、Y 对组的图,所有线条都使用相同的坐标区。

示例
plot(X1,Y1,LineSpec1,…,Xn,Yn,LineSpecn) 设置每个线条的线型、标记符号和颜色。您可以混用 X、Y、LineSpec 三元组和 X、Y 对组:例如,plot(X1,Y1,X2,Y2,LineSpec2,X3,Y3)。

示例
plot(Y) 创建 Y 中数据对每个值索引的二维线图。

如果 Y 是向量,x 轴的刻度范围是从 1 至 length(Y)。

如果 Y 是矩阵,则 plot 函数绘制 Y 中各列对其行号的图。x 轴的刻度范围是从 1 到 Y 的行数。

如果 Y 是复数,则 plot 函数绘制 Y 的虚部对 Y 的实部的图,使得 plot(Y) 等效于 plot(real(Y),imag(Y))。

plot(Y,LineSpec) 设置线型、标记符号和颜色。

示例
plot(___,Name,Value) 使用一个或多个 Name,Value 对组参数指定线条属性。有关属性列表,请参阅 Line 属性。可以将此选项与前面语法中的任何输入参数组合一起使用。名称-值对组设置将应用于绘制的所有线条。

示例
plot(ax,___) 将在由 ax 指定的坐标区中,而不是在当前坐标区 (gca) 中创建线条。选项 ax 可以位于前面的语法中的任何输入参数组合之前。

示例
h = plot(___) 返回由图形线条对象组成的列向量。在创建特定的图形线条后,可以使用 h 修改其属性。有关属性列表,请参阅 Line 属性。
说明
示例:

>> hold on
plot(cos(0:pi/20:2*pi),'x--r');
plot(sin(0:pi/20:2*pi),'d-.b');
hold off
>> 

结果

legend()

legend():在坐标区上添加图例
示例

x=0:0.5:4*pi;
y=sin(x); h=cos(x); w=1./(1+exp(-x));
g=(1/(2*pi*2)^0.5).*exp((-1.*(x-2*pi).^2)./(2*2^2));
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,g,'c^-');
legend('sin(x)','cos(x)','Sigmoid','Gauss function');

结果

其余

title()

xlabel()

ylabel()

zlabel()
举例:

x = 0:0.1:2*pi; y1 = sin(x); y2 = exp(-x);
plot(x, y1, '--*', x, y2, ':o');
xlabel('t = 0 to 2\pi');
ylabel('values of sin(t) and e^{-x}')
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');

示例

text() and annotation()

x = linspace(0,3); y = x.^2.*sin(x); plot(x,y);
line([2,2],[0,2^2*sin(2)]);
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(0.25,2.5,str,'Interpreter','latex');
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);

说明:

str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';

其中,\int:积分符号
t_{0}^{2}:下标是0,上标是2
x^2\:就是x的平方

text(0.25,2.5,str,'Interpreter','latex');

其中,(0.25,2.5)是(x,y)坐标,
str:要显示的内容
‘Interpreter’,‘latex’:固定语法,暂时不管

annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);

其中,‘arrow’:箭头
‘X’,[0.32,0.5]
‘Y’,[0.6,0.4]
示例

练习

t = linspace(1,2); 
f = t.^2;
g = sin(2*pi*t)
plot(t,f,'-k',t,g,':or');
xticks(1:0.2:2);
xlabel('Time(ms)');
ylabel('f(t)')
title('Mini assigniment #1');
legend({'f = t ^{2}','sin(2\pi t)'},'Location','northwest');

结果

图形调整

• Font
• Font size
• Line width
• Axis limit
• Tick position
• Tick label

示例

x = linspace(0, 2*pi, 1000); y = sin(x);
plot(x,y); set(gcf, 'Color', [1 1 1]);


set(gca, 'XLim', [0, 2*pi]);
set(gca, 'YLim', [-1.2, 1.2]);

set(gca, 'FontSize', 25);

set(gca, 'XTick', 0:pi/2:2*pi);
set(gca, 'XTickLabel', 0:90:360);


set(gca, 'FontName', 'Tex');
set(gca, 'XTickLabel', {'0', '\pi/2', '\pi', '3\pi/2', '2\pi'})


set(h, 'LineStyle', '-.','LineWidth', 7.0, 'Color', 'g');

delete(h)

在这里插入图片描述
改进1
坐标修改
改进2-续
坐标修改
改进3-续
改进
改进4-续
改进
改进5-续
改进

额外说明:

handle:句柄/指针/代号
get()
set()

说明
Marker

x=rand(20,1); set(gca, 'FontSize', 18);
plot(x,'-md','LineWidth', 2, 'MarkerEdgeColor', 'k',...
'MarkerFaceColor', 'g', 'MarkerSize', 10);
xlim([1, 20]);

在这里插入图片描述

练习2.改进之前的图形

要求
要求
代码

t = linspace(1,2); 
f = t.^2;
g = sin(2*pi*t);
hold on;
h1 = plot(t,f,'-k');
h2 = plot(t,g,':or');
set(h1,'LineWidth',4);
set(h2,'LineWidth',1,'MarkerFaceColor','b');
xticks(1:0.2:2);
xlabel('Time(ms)');
ylabel('f(t)')
title('Mini assigniment #1');
set(gca, 'FontSize', 15);
set(gca, 'FontName', 'Tex');
set(gca, 'YTickLabel', {'-1', '0', '1', '2', '3','4'});
legend({'f = t ^{2}','sin(2\pi t)'},'Location','northwest');
hold off;

改进后的图形

绘制多个图形

subplot
示例:

t = 0:0.1:2*pi; x = 3*cos(t); y = sin(t);
subplot(2, 2, 1); plot(x, y); axis normal
subplot(2, 2, 2); plot(x, y); axis square
subplot(2, 2, 3); plot(x, y); axis equal
subplot(2, 2, 4); plot(x, y); axis equal tight

示例

在这里插入图片描述

绘图常用函数

函数

存储已绘制的图像

saveas(gcf,'<filename>','<formattype>');

存储

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 设计sigma-delta转换器是一个复杂的过程,需要经过多个步骤。以下是在MATLAB / Simulink中设计sigma-delta转换器的一般过程: 1. 确定系统规格:首先,确定sigma-delta转换器的采样率、精度要求和输入输出范围等系统规格。 2. 模型建立:使用Simulink建立sigma-delta转换器的模型。该模型包括一个Σ(summing)节点、一个Δ(differential)节点和一个比较器节点。使用研究成果相关的数学模型,可以更准确地描述转换器的行为。 3. 参数选择:选择适当的参数来满足系统规格。包括选择合适的阶数和过采样率。过采样率越高,转换器的性能越好,但同时也会增加计算的复杂性和系统复杂度。 4. 仿真验证:使用Simulink对模型进行仿真验证。这可以帮助我们了解系统的性能如何受到不同参数选取的影响。 5. 优化调整:根据仿真结果,对转换器的参数和结构进行优化调整。例如,可以调整Σ节点和Δ节点之间的连接方式,或者优化误差补偿电路的设计。 6. 输出结果:根据优化后的模型,输出设计好的sigma-delta转换器的结果。这可以包括模型中各个节点和参数的数值值。 此外,在设计sigma-delta转换器的过程中,还需要考虑一些其他的因素,如抗噪声能力、计算要求、电路复杂度和成本等。根据具体的需求和约束条件,可以对上述过程进行调整和扩展,以获得最佳的设计结果。 总而言之,设计sigma-delta转换器需要经历模型建立、参数选择、仿真验证、优化调整和输出结果等多个步骤。通过这些步骤,可以获得一个满足系统要求的优化转换器设计。 ### 回答2: Sigma-delta (ΣΔ) converters are commonly used in analog-to-digital (ADC) and digital-to-analog (DAC) applications. They are known for their outstanding performance in terms of resolution, noise shaping, and dynamic range. To design a Sigma-delta converter in MATLAB/Simulink, we can follow the following steps: 1. Specify the converter's specifications: Determine the required resolution, sampling frequency, and input signal bandwidth to meet the desired performance requirements. 2. Model the Sigma-delta modulator: Create a Simulink model to represent the Sigma-delta modulator. This can be done by using Simulink blocks such as Adders, Delays, and Comparators. 3. Define the Analog-to-Digital Converter (ADC): Add the ADC block to the Simulink model and configure its parameters, such as the number of bits, input range, and sampling frequency. 4. Implement the digital decimation filter: Insert a digital decimation filter after the ADC block to remove out-of-band noise and further improve the overall performance. The decimation filter can be modeled using filter blocks in Simulink. 5. Evaluate the performance: Simulate the Simulink model with different input signals and study the system's response. Analyze the output waveform, signal-to-noise ratio (SNR), and other performance metrics to assess the design's effectiveness. 6. Optimize the design: Based on the performance analysis, make design adjustments to enhance the overall system's performance. This can involve modifying filter parameters, changing the modulator architecture, or adjusting the decimation filter design. 7. Verify the design: Validate the design by testing it with various input signals and comparing the simulation results with the desired specifications. 8. Implement the design: Once the design is finalized, the Sigma-delta converter can be implemented in hardware using appropriate components. In summary, to design a Sigma-delta converter in MATLAB/Simulink, we start by specifying the converter's specifications, modeling the modulator and ADC in Simulink, adding a digital decimation filter, evaluating the performance, optimizing the design, verifying the design, and finally implementing it in hardware.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Max_J999

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

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

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

打赏作者

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

抵扣说明:

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

余额充值