简体   繁体   English

如何在Matlab中找到矩阵的波特图?

[英]How to find the bode plot of a matrix in matlab?

I'm trying to find the system transfer function of a set of input-output data using the FFT method. 我正在尝试使用FFT方法查找一组输入输出数据的系统传递函数。 The algorithm I'm following is as follows: 我要遵循的算法如下:

  1. Load the input data and output data into matlab. 将输入数据和输出数据加载到matlab中。
  2. FFT the input data and output data. 对输入数据和输出数据进行FFT。
  3. Divide the output FFT by the input FFT and take the magnitude. 将输出FFT除以输入FFT,然后取幅值。 Since the input for our example is a unit impulse, the input FFT is 1.0. 由于本例的输入为单位脉冲,因此输入FFT为1.0。
  4. Plot the result as a Bode' plot. 将结果绘制为波特图。
  5. Treat the resulting Bode' plot as a frequency response - which it really is - and use frequency response methods to fit a transfer function to the calculated Bode' plot. 将生成的Bode'图视为频率响应(实际上是频率响应),并使用频率响应方法将传递函数拟合到计算出的Bode'图。

My code is: 我的代码是:

load testdata.mat; // testdata is a 2 column matrix (1001x2 matrix)

input = fft(signal(:,1)); // FFT of input data (1001x1 complex matrix)

output = fft(signal(:,2)); // FFT of output data (1001x1 complex matrix)

fft_ratio = output/input; // (1001x1001 complex matrix)

fft_ratio_mag = abs(fft_ratio); // (1001x1001 matrix) except column 1, all other    columns have '0' data

bode(fft_ratio_mag(:,1))

I get the following error: 我收到以下错误:

Error using bode (line 84)
Not enough input arguments.

Please guide me how to go about steps 4 and 5 in the above algorithm. 请指导我如何执行上述算法中的第4步和第5步。

Use element-wise divide , not matrix divide, and plot using the plot function. 使用逐元素除法 ,而不是矩阵除法,并使用plot函数进行绘图。 To produce a plot similar to that shown in the bode function you can plot using semilogx but do the dB and degree conversions yourself: 要生成类似于bode 函数中所示的图,可以使用semilogx进行绘制,但自己进行dB和度转换:

fft_ratio = output ./ input % note the dot
subplot(2,1,1)
semilogx(20*log10(abs(fft_ratio)))
subplot(2,1,2)
semilogx(plot((180/pi)*angle(fft_ratio))

Generate the x-axis using however you like, I usually use normalized radian frequency from 0 to 1, which is just linspace(0,1,length(fft_ratio)) . 使用您喜欢的方式生成x轴,我通常使用从0到1的归一化弧度频率,即linspace(0,1,length(fft_ratio))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM