简体   繁体   中英

How to plot bode diagram of a signal using fft in MATLAB?

I want to plot bode diagram of the following system both using bode and fft :

%// System info
num=[0 1];   %// Numerator of z-transform of impulse response of system
den=[1 -0.8]; %// Denominator of z-transform of impulse response of system

I used dbode to plot bode method:

figure(6); dbode(num,den,1) %// 1 is sampling time Ts

As I want to do it from fft method, it gets wrong:

Ts=1;
Fs=1/Ts;
L=length(ym);
NFFT = 2^nextpow2(L); %// Next power of 2 from length of ym
H2=fft(ym,NFFT)./fft(u,NFFT); 
f=Fs/2*linspace(0,1,NFFT/2+1);
ww=f*2*pi;

figure(7)
semilogx(20*log10(abs(H2(1:NFFT/2+1))))

figure(10)
semilogx((180/pi)*angle(H2(1:NFFT/2+1)))

Bode diagram using bode :

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Any idea

Here is my data (u and ym)

I looked at your data and compared it with the theoretical transfer function in the time-domain and it isn't a bad fit if you ignore some of the data :

t = 1:length(u);
num=[0 1];   %// Numerator of z-transform of impulse response of system
den=[1 -0.8]; %// Denominator of z-transform of impulse response of system
H = tf(num,den,1)
[yy,tt,xx] = step(H,max(t));
plot(t-10,ym-2.2,tt,yy)

You'll notice that I have discarded the time values before 10 and shifted the response values down by about 2.2. This gives the following plot (in Octave):

在此处输入图片说明

I suggest you do the same thing when taking the FFT:

L = length(ym(t>=10));
NFFT = 2^nextpow2(L);
H2 = fft(ym(t>=10)-2.2,NFFT)./fft(u(t>=10),NFFT);
f=Fs/2*linspace(0,1,NFFT/2+1);ww=f*2*pi;
[mag,ph,w ] = bode(H);
semilogx(ww,20*log10(abs(H2(1:NFFT/2+1))),w,20*log10(abs(mag)))

在此处输入图片说明

The DC level of the transfer function is correct, but the poor FFT technique yields too much noise at (relatively) higher frequencies. tfestimate would be a better choice to estimate the transfer based on the measurement data (again remember to pre-process the data the same way as I have just done here). It is part of the Signal Processing Toolbox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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