【问题标题】:Plotting measured data along with Bode plot绘制测量数据和波特图
【发布时间】:2025-11-27 17:15:01
【问题描述】:

我正在上一门电路课,对于实验室,我们需要使用 MATLAB 做一些工作来绘制一些结果。我得到了以下代码,用于为我们正在设计的滤波器生成传递函数的波特图。我有点了解它是如何工作的,但我并不真正了解或在本课程之外使用 MATLAB。

clc;
close all
s=tf('s');
w=628*1000;
H=(1/(1 + 1.85*s/w + s^2/w^2))*(1/(1 + 0.77*s/w + s^2/w^2));
figure;
bode(H)

这工作得很好,但现在我需要根据 SAME 绘图轴上的数据绘制我在实验室测量的传递函数。我怎样才能将它们都绘制在一起。我将实验室数据作为增益频率对的列表。

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    试试bode(H),而不是:

    [mag,ph,w] = bode(H); % gets the data without generating the figure
    plot(w, mag, 'b'); % plots only the magnitudes
    
    freqs = data(:,1); % These 2 lines depend on how your data is formatted
    gains = data(:,2); % These 2 lines depend on how your data is formatted
    
    hold on % will add new content to the existing figure without erasing the previous content
    plot(freqs, gains, 'r');
    hold off 
    

    你也可以试试(灵感来自http://www.mathworks.com/help/ident/ref/bodeplot.html):

    h = bodeplot(H);
    setoptions(h,'FreqUnits','Hz','PhaseVisible','off'); % suppress the phase plot
    
    
    freqs = data(:,1); % These 2 lines depend on how your data is formatted
    gains = data(:,2); % These 2 lines depend on how your data is formatted
    
    hold on % will add new content to the existing figure without erasing the previous content
    plot(freqs, gains, 'r');
    hold off 
    

    【讨论】:

    • 这可行,但它将我的图添加到相图而不是幅度图。我怎样才能解决这个问题。 (如果我能摆脱它,我什至不在乎相位图。)
    • 我实际上是在做预兆之前通过绘制数据自己解决了最后一个问题。有点骇人听闻,但我只需要。感谢您解决了我的主要问题。