How to plot the magnitude and phase of this Fourier Transform frequency response
8 views (last 30 days)
Show older comments
Hello ,
I want to write code in MATLAB to get the same plot please. I've tried to learn how to get this plot but I didn't find anything.

I have 3 inductors 478 µH. but I couldn't get the plot looking same.
This is the code that I have created with some help of chat GPT :
%% 1) Define the frequency range for analysis
f = logspace(1, 5, 500); % Frequency in Hz
w = 2*pi*f; % Angular frequency
% Given Parameters
Lb = 478e-6; % Phase inductance in H (Lb1 = Lb2 = Lb3)
Cb = 880e-6; % Output capacitance in F
R = 0.1; % Example ESR or sense resistor
% Control Gains (Placeholder values, adjust for your system)
K_v_gain = 1; % Voltage gain
K_i_gain = 1; % Current gain
K_i_fltr = 1; % Current filter gain
G_d = 1; % Duty cycle transfer function
%% 2) Define s-domain variable and transfer functions
s = tf('s');
Zi = R + s*Lb; % Impedance of the inductor
% Corrected Current Loop Transfer Function (Hp-i)
Hp_i = 3 * (1 / K_v_gain) * K_i_gain * K_i_fltr * G_d * (1 / Zi);
%% 3) Bode plot of the modeled open-loop gain
figure('Name','Modeled Open Loop Gain','NumberTitle','off');
bode(Hp_i, {2*pi*10, 2*pi*1e5}); % Bode plot from 10 Hz to 100 kHz
grid on;
title('Current Open-Loop Gain (Modeled)');
%% 4) Compare with measured data (if available)
% Replace with actual measured data if available
freq_meas = [10, 100, 1e3, 10e3, 100e3]; % Hz (example)
mag_meas_dB = [-5, -2, 0, -3, -10]; % dB (example)
phase_meas_deg= [ 0, -30, -60, -90, -120]; % deg (example)
% Extract the model’s magnitude and phase at the same measured frequencies
[mag_model, phase_model] = bode(Hp_i, 2*pi*freq_meas);
% Convert the magnitude (which is dimensionless) to dB
mag_model_dB = 20*log10(squeeze(mag_model));
phase_model_deg = squeeze(phase_model);
%% 5) Plot measured vs. modeled (Magnitude & Phase)
figure('Name','Open Loop Gain Comparison','NumberTitle','off');
subplot(2,1,1); % Magnitude subplot
semilogx(freq_meas, mag_meas_dB, 'bo-', 'LineWidth',1.5, 'MarkerSize',6);
hold on;
semilogx(freq_meas, mag_model_dB, 'rx--', 'LineWidth',1.5, 'MarkerSize',6);
grid on; xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)');
legend('Measured','Modeled','Location','Best');
title('Current Open-Loop Gain: Magnitude');
subplot(2,1,2); % Phase subplot
semilogx(freq_meas, phase_meas_deg, 'bo-', 'LineWidth',1.5, 'MarkerSize',6);
hold on;
semilogx(freq_meas, phase_model_deg, 'rx--', 'LineWidth',1.5, 'MarkerSize',6);
grid on; xlabel('Frequency (Hz)'); ylabel('Phase (deg)');
legend('Measured','Modeled','Location','Best');
title('Current Open-Loop Gain: Phase');
[EDIT] formatted code as code and ran it.
0 Comments
Accepted Answer
Mathieu NOE
on 20 Feb 2025
hello
well the code seems to work and the model plot (in red) looks good / in match with your publication
maybe the K -gains) must be also adjusted
simply the experimental values used in the code are off - you may need to put he right data here
%% 1) Define the frequency range for analysis
f = logspace(1, 5, 500); % Frequency in Hz
w = 2*pi*f; % Angular frequency
% Given Parameters
Lb = 478e-6; % Phase inductance in H (Lb1 = Lb2 = Lb3)
Cb = 880e-6; % Output capacitance in F
R = 0.1; % Example ESR or sense resistor
% Control Gains (Placeholder values, adjust for your system)
K_v_gain = 1; % Voltage gain
K_i_gain = 1; % Current gain
K_i_fltr = 1; % Current filter gain
G_d = 1; % Duty cycle transfer function
%% 2) Define s-domain variable and transfer functions
s = tf('s');
Zi = R + s*Lb; % Impedance of the inductor
% Corrected Current Loop Transfer Function (Hp-i)
Hp_i = 3 * (1 / K_v_gain) * K_i_gain * K_i_fltr * G_d * (1 / Zi);
%% 3) Bode plot of the modeled open-loop gain
figure('Name','Modeled Open Loop Gain','NumberTitle','off');
bode(Hp_i, {2*pi*10, 2*pi*1e5}); % Bode plot from 10 Hz to 100 kHz
grid on;
title('Current Open-Loop Gain (Modeled)');
%% 4) Compare with measured data (if available)
% Replace with actual measured data if available
freq_meas = [10, 100, 1e3, 10e3, 100e3]; % Hz (example)
mag_meas_dB = [-5, -2, 0, -3, -10]; % dB (example)
phase_meas_deg= [ 0, -30, -60, -90, -120]; % deg (example)
% Extract the model’s magnitude and phase at the same measured frequencies
[mag_model, phase_model] = bode(Hp_i, 2*pi*freq_meas);
% Convert the magnitude (which is dimensionless) to dB
mag_model_dB = 20*log10(squeeze(mag_model));
phase_model_deg = squeeze(phase_model);
%% 5) Plot measured vs. modeled (Magnitude & Phase)
figure('Name','Open Loop Gain Comparison','NumberTitle','off');
subplot(2,1,1); % Magnitude subplot
semilogx(freq_meas, mag_meas_dB, 'bo-', 'LineWidth',1.5, 'MarkerSize',6);
hold on;
semilogx(freq_meas, mag_model_dB, 'rx--', 'LineWidth',1.5, 'MarkerSize',6);
grid on; xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)');
legend('Measured','Modeled','Location','Best');
title('Current Open-Loop Gain: Magnitude');
subplot(2,1,2); % Phase subplot
semilogx(freq_meas, phase_meas_deg, 'bo-', 'LineWidth',1.5, 'MarkerSize',6);
hold on;
semilogx(freq_meas, phase_model_deg, 'rx--', 'LineWidth',1.5, 'MarkerSize',6);
grid on; xlabel('Frequency (Hz)'); ylabel('Phase (deg)');
legend('Measured','Modeled','Location','Best');
title('Current Open-Loop Gain: Phase');
0 Comments
More Answers (0)
Communities
More Answers in the Power Electronics Control
See Also
Categories
Find more on Classical Control Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


