How to plot Bode diagram from input and output data
137 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pritesh Shah
am 22 Feb. 2016
Bearbeitet: Arkadiy Turevskiy
am 19 Jun. 2024
I want to plot bode diagram from input and output data. Also, I should able to change frequency range and amplitude should be in dB.
Thank you,
0 Kommentare
Akzeptierte Antwort
Star Strider
am 22 Feb. 2016
Bearbeitet: Arkadiy Turevskiy
am 19 Jun. 2024
This should have been covered in your signal processing course. First, take the fft of your input and output data, the divide the Fourier transform of your output data by the Fourier transform of your input data to get the complex frequency transfer function. Use the abs function to calculate the amplitude, and the angle function (consider unwrap as well) to get the phase. I will let you explore the code to define the frequency range, and calculating the amplitude in dB.
If you want a transfer function representation, your likely best option is to use the invfreqz function to create a transfer function, then the freqz function to create the Bode plot. If your transfer function is relatively smooth, this will be a good approximation.
The impulse response is the inverse Fourier transform of the complex transfer function.
Update by Kishen Mahadevan at MathWorks on 6/19/2024
Please refer to the accepted answer here for code example- Is it possible that ploting bode diagram without transfer fuction? - MATLAB Answers - MATLAB Central (mathworks.com)
In addition to the suggested method, if you have System Identification Toolbox you can use the System Identification app or command line functionalities to automatically fit different models such as ARX, state-space, transfer function to your input-output data. Then use the identified system model 'sys' with the 'bode' function to plot the bode diagram using ‘bode(sys)’.
0 Kommentare
Weitere Antworten (2)
Naty Shemer
am 6 Feb. 2017
Hey, I have attempted what you've suggested to get the Bode plot right. Something' doesn't seems right with my bode plot. Any idea what I am doing wrong?
L=length(Cmd);
n = 2^nextpow2(L);
Fs=100;
f=Fs*(0:(n/2)-1)/n;
CmdFFT=fft(Cmd,n);
FdbckFFT=fft(Fdbck,n);
H=FdbckFFT./CmdFFT;
HH=H(1:end/2);
HMag=abs(HH);
HPh=(angle(HH));
figure;
ax1=subplot(2,1,1);
semilogx(f*2*pi,20*log10(HMag));
grid on
ax2=subplot(2,1,2);
semilogx(f*2*pi,HPh*57.3);
grid on
linkaxes([ax1 ax2],'x')
0 Kommentare
Hamidreza Hoshyarmanesh
am 21 Aug. 2019
This is a bit late responding this post, however I thought a quick response could be useful for those who might face the same problem in the future.
When calling semilogx(f*2*pi,HPh*57.3) to plot the phase digram, Matlab ignores the imaginary part of the HH (due to HMag=abs(HH);) and you will get zero as the output.
1 Kommentar
Sumit Swain
am 14 Apr. 2021
Consider having the input and output data from experiment in sine wave form. How to plot the bodeplot in matlab from the input and the output data?
Siehe auch
Kategorien
Mehr zu Analyze Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!