How to change the default x-axis unit in a Bode diagram to Hertz?

410 views (last 30 days)
Rad/s is nice for mechanical people, but I'm an EE, and I much prefer Hertz. It should be something simple, but I can't find it in the help.
  1 Comment
dpb
dpb on 22 Sep 2018
Don't believe there is a way in the base routine; it's built entirely around rad/timeunits per the system object.
You could write a wrapper routine to convert frequency units and update the plot labels.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 22 Sep 2018
Use bodeplot (link) instead of bode.
It gives you that option, and the documentation specifically mentions that.
  4 Comments
marcel hendrix
marcel hendrix on 22 Sep 2018
I've put the below function in my userpath . It'll do for now.
% a new bode() command that has Hz as default
function h = bodef(x)
P = bodeoptions; P.FreqUnits = 'Hz';
h = bodeplot(x,P);
Star Strider
Star Strider on 22 Sep 2018
Edited: Star Strider on 22 Sep 2018
That is what I would do.
I defer to bodeplot because it allows some customization. I use and plot the bode outputs only if I want other options.
EDIT
I add that this was my original recommendation!

Sign in to comment.

More Answers (2)

Dimitris Kalogiros
Dimitris Kalogiros on 22 Sep 2018
clc;close all; clc
% test system
s=tf('s');
H=(s-1)/((s-3)*(s-2))
% bode
[mag,phase,wout] = bode(H);
%plot results, with frequency expressed at Hz
figure;
subplot(2,1,1);
semilogx(wout(:,1)/(2*pi), 20*log10(squeeze(mag)), '-b'); zoom on; grid on;
title('magnitude'); xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)');
subplot(2,1,2);
semilogx(wout(:,1)/(2*pi), squeeze(phase), '-r'); zoom on; grid on;
title('Phase'); xlabel('Frequecy (Hz)'); ylabel('Phase (deg)');
  1 Comment
Charl
Charl on 15 Mar 2024
Edited: Charl on 15 Mar 2024
This is the correct answer. Some of the others simply change the label to Hz without rescaling.

Sign in to comment.


Tjeerd Ickenroth
Tjeerd Ickenroth on 31 May 2023
Type 'ltiview' in your command window. The Linear System Analyzer will pop up. Click on: File --> Toolbox Preferences... --> Units --> Frequency: Hz
  3 Comments
Tjeerd Ickenroth
Tjeerd Ickenroth on 31 May 2023
You need to change it once in the GUI and you always obtain bode plots in Hz. The setting remains even when you restart Matlab.
marcel hendrix
marcel hendrix on 31 May 2023
And what when I share my function/script with others? Or use different (older) versions of MATLAB?

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!