Extract data from a bode plot.

How do I extract an Excel table from the Bode of this transfer function:
format long;
s = tf('s');
HLM = ((2.524e-06)*s^3 + 37.11*s^2 + 37.6*s)/((2.704e-07)*s^3 + 1.767*s^2 + 41.36*s + 80);
Finf = 1e-3; %Hz
Fsup = 1e9; %Hz
options = bodeoptions;
options.FreqUnits = 'Hz';
Wmin = 2*pi*Finf;
Wmax = 2*pi*Fsup;
bode(HLM,{Wmin,Wmax}, options);
The bode was plotted in Hz, degrees, and from 1mHz to 1GHz.

Answers (1)

s = tf('s');
HLM = ((2.524e-06)*s^3 + 37.11*s^2 + 37.6*s)/((2.704e-07)*s^3 + 1.767*s^2 + 41.36*s + 80);
Finf = 1e-3; %Hz
Fsup = 1e9; %Hz
options = bodeoptions;
options.FreqUnits = 'Hz';
Wmin = 2*pi*Finf;
Wmax = 2*pi*Fsup;
figure
bode(HLM,{Wmin,Wmax}, options) % Plot With Options
[mag,phase,wout] = bode(HLM,{Wmin,Wmax}); % Return Calculated Data
mag = squeeze(mag);
phase = squeeze(phase);
fout = wout/(2*pi); % Convert To 'Hz'
BodeTable = table(fout,mag,phase)
BodeTable = 154×3 table
fout mag phase _________ _________ ______ 0.001 0.0029531 90.169 0.0011669 0.0034461 90.197 0.0013617 0.0040213 90.23 0.001589 0.0046926 90.269 0.0018542 0.0054759 90.314 0.0021637 0.00639 90.366 0.0025248 0.0074568 90.427 0.0029463 0.0087018 90.498 0.0034381 0.010155 90.582 0.0040119 0.01185 90.679 0.0046816 0.01383 90.792 0.005463 0.01614 90.924 0.0063748 0.018837 91.077 0.0074389 0.021986 91.257 0.0086806 0.025663 91.466 0.010129 0.029959 91.71
Then use writetable to create the Excel file.
EDIT — (10 May 2022 at 22:06)
Initially forgot that frequency vector was to be in Hz. Corrected.
.

4 Comments

Right, thank you, how do I get more points? It's getting only 154, I would like to get 1000 or 10000, is it possible?
It is. You can supply the ‘w’ argument to provide as many points (radian frequency values) as you want (although there may be practical limits). See the documentation section on Bode Plot at Specified Frequencies .
whiting the bode options?
The frequency vector is an argument to the bode function (here ‘wv’) not the bodeoptions structure —
s = tf('s');
HLM = ((2.524e-06)*s^3 + 37.11*s^2 + 37.6*s)/((2.704e-07)*s^3 + 1.767*s^2 + 41.36*s + 80);
Finf = 1e-3; %Hz
Fsup = 1e9; %Hz
options = bodeoptions;
options.FreqUnits = 'Hz';
Wmin = 2*pi*Finf;
Wmax = 2*pi*Fsup;
wv = logspace(-3, 9, 1000)*2*pi; % Vector Of 500 Radian Frequencies (Logarithmically Scaled)
figure
bode(HLM, wv, options) % Plot With Options
[mag,phase,wout] = bode(HLM, wv); % Return Calculated Data
mag = squeeze(mag);
phase = squeeze(phase);
fout = wout/(2*pi); % Convert To 'Hz'
BodeTable = table(fout,mag,phase)
BodeTable = 1000×3 table
fout mag phase _________ _________ ______ 0.001 0.0029531 90.169 0.001028 0.003036 90.174 0.0010569 0.0031211 90.179 0.0010865 0.0032086 90.184 0.001117 0.0032986 90.189 0.0011483 0.0033911 90.194 0.0011805 0.0034863 90.2 0.0012136 0.003584 90.205 0.0012477 0.0036845 90.211 0.0012826 0.0037879 90.217 0.0013186 0.0038941 90.223 0.0013556 0.0040033 90.229 0.0013936 0.0041156 90.236 0.0014327 0.004231 90.242 0.0014729 0.0043497 90.249 0.0015142 0.0044717 90.256
As requested, it produces a 1000-element frequency vector, and transfer function results at those values. (The plot does not appear to me to be different from the plot with the default frequencies, except for the higher frequency resolution.)
.

Sign in to comment.

Products

Release

R2016b

Asked:

on 10 May 2022

Commented:

on 11 May 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!