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

조회 수: 663 (최근 30일)
marcel hendrix
marcel hendrix 2018년 9월 22일
댓글: Meth Hai 2024년 7월 15일
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
dpb
dpb 2018년 9월 22일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2018년 9월 22일
Use bodeplot (link) instead of bode.
It gives you that option, and the documentation specifically mentions that.
  댓글 수: 4
marcel hendrix
marcel hendrix 2018년 9월 22일
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 2018년 9월 22일
편집: Star Strider 2018년 9월 22일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Tjeerd Ickenroth
Tjeerd Ickenroth 2023년 5월 31일
Type 'ltiview' in your command window. The Linear System Analyzer will pop up. Click on: File --> Toolbox Preferences... --> Units --> Frequency: Hz
  댓글 수: 3
Tjeerd Ickenroth
Tjeerd Ickenroth 2023년 5월 31일
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 2023년 5월 31일
And what when I share my function/script with others? Or use different (older) versions of MATLAB?

댓글을 달려면 로그인하십시오.


Dimitris Kalogiros
Dimitris Kalogiros 2018년 9월 22일
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)');
  댓글 수: 2
Charl
Charl 2024년 3월 15일
편집: Charl 2024년 3월 15일
This is the correct answer. Some of the others simply change the label to Hz without rescaling.
Meth Hai
Meth Hai 2024년 7월 15일
%%% G1 & and G2 is your TFs
[mag1, phase1, wout1] = bode(G1);
[mag2, phase2, wout2] = bode(G2);
% Convert angular frequency (rad/s) to frequency (Hz)
freq1 = wout1 / (2 * pi);
freq2 = wout2 / (2 * pi);
% Plot the magnitude response
figure;
subplot(2,1,1);
semilogx(freq1, 20*log10(squeeze(mag1)), '-b');
hold on;
semilogx(freq2, 20*log10(squeeze(mag2)), '-g');
grid on;
title('Magnitude');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
legend('G1', 'G2');
%%%%%%%%%%%%
% Plot the phase response
subplot(2,1,2);
semilogx(freq1, squeeze(phase1), '-r');
hold on;
semilogx(freq2, squeeze(phase2), '-m');
grid on;
title('Phase');
xlabel('Frequency (Hz)');
ylabel('Phase (deg)');
legend('G1', 'G2');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by