【问题标题】:How to Calculate the transfer function and plot it after making fourier transform in frequency domain in terms of magnitude and phase?如何在幅度和相位方面在频域进行傅立叶变换后计算传递函数并绘制它?
【发布时间】:2018-12-02 16:14:17
【问题描述】:

在对两个信号进行傅里叶变换后,我无法根据幅度和相位绘制传递函数。

首先,我使用 excel xlxs 读取要在时域和频域中绘制的列,然后计算传递函数,一切顺利。

但是对于幅度和相位,我很难绘制它们。我厌倦了绘制它们,但这完全不正确。有人可以帮我解决这个问题吗?

这里是代码和excel 文件。

solarcell1 = xlsread('solarcell.xlsx','A2:C100005');
t=solarcell1(:,1);
N=length(t);
Channel1V = solarcell1(:,2);
Channel2V = solarcell1(:,3);
sig1=Channel1V;
sig2=Channel2V;
fs=1/((solarcell1(3)-solarcell1(2))*1e-3);
FA1=fs/length(sig1);
FA2=fs/length(sig2);
frange1=-fs/2:FA1:fs/2-FA1;
frange2=-fs/2:FA2:fs/2-FA2;
subplot(3,2,1);
plot(t,sig1);
hold on
plot(t,sig2);
title('Input and Output of Solar cell');
xlabel('Time');ylabel('Amplitude');
subplot(3,2,2);
plot(t,sig2);
title('Output');
xlabel('Time');ylabel('Amplitude');
z1=fftshift(fft(sig1))/length(t);
subplot(3,2,3);
plot(frange1,abs(z1));
title('Input');
xlabel('Freq.');ylabel('Amplitude');
z2=fftshift(fft(sig2))/length(t);
subplot(3,2,4);
plot(frange2,abs(z2));
title('Output');
xlabel('Freq.');ylabel('Amplitude');
TFC=z2./z1;
magnitude=20*log(abs(TFC));
phase=atan2(imag(TFC),real(TFC));
subplot(3,2,5);
bode(frange1(1002:N),magnitude(1002:N));
title('Magnitude');
xlabel('Freq.');ylabel('Magnitude');
subplot(3,2,6);
semilogx(frange1(1002:N),phase(1002:N));
title('Phase');
xlabel('Freq.');ylabel('Phase');

【问题讨论】:

    标签: matlab fft


    【解决方案1】:

    我可以在您提供的代码中看到三个问题。

    首先,您对bode 的使用不正确。这个函数接受一个dynamic model system 作为参数,你给了两个向量frange1(1002:N)magnitude(1002:N)。目前,我建议您直接使用plot

    subplot(3,2,5);
    plot(frange1(1002:N),magnitude(1002:N));
    title('Magnitude');
    xlabel('Freq.');ylabel('Magnitude');
    

    那么,当 x 轴为负值时,使用 semilogx 也是有风险的。对于frange1=-fs/2:FA1:fs/2-FA1;,您不应该要求semilogx。目前,我建议plot

    最后,我建议你使用unwrap 来绘制相位。

    subplot(3,2,6);
    plot(frange1(1002:N),unwrap(phase(1002:N)));
    title('Phase');
    xlabel('Freq.');ylabel('Phase');
    

    它绘制:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      相关资源
      最近更新 更多