How to generate waveforms in MATLAB from pre-calculated converter values?
44 views (last 30 days)
Show older comments
Hello everyone,
I am working on a buck converter and I have already calculated the key values analytically (such as inductor current ripple, maximum/minimum current, and capacitor voltage change per switching interval).
What I am trying to do now is generate the corresponding waveforms in MATLAB (for example, inductor current and capacitor voltage vs. time) using these calculated values.
I am not using Simulink, and I am completely new to MATLAB.
Specifically, I would like to understand:
- How to convert my calculated values (e.g., current slopes, ripple magnitudes, switching times) into time-domain waveforms in MATLAB?
I am not looking for a full circuit simulation—just a way to plot waveforms based on known equations and switching intervals.
Any guidance, examples, or recommended approach would be greatly appreciated.
Thank you!
0 Comments
Accepted Answer
Sabin
on 8 Jan 2026 at 11:01
If you only want to visualize the steady-state periodic waveforms of a buck converter, using only analytical calculations, you can do something similar to this:
% Parameters
Vin = 12; Vout = 5; L = 10e-6; C = 100e-6;
Iload = 2; fs = 100e3; Ts = 1/fs;
D = Vout / Vin; % Duty Cycle
% Calculated values
delta_IL = (Vin - Vout) * D * Ts / L; % Inductor ripple
IL_avg = Iload;
IL_max = IL_avg + delta_IL/2;
IL_min = IL_avg - delta_IL/2;
delta_VC = delta_IL / (8 * fs * C); % Capacitor voltage ripple
VC_avg = Vout;
VC_max = VC_avg + delta_VC/2;
VC_min = VC_avg - delta_VC/2;
% Number of cycles
num_cycles = 2;
% Time vector for multiple cycles
N = 1000 * num_cycles; % 1000 points per cycle
t = linspace(0, num_cycles*Ts, N);
% Inductor current waveform for multiple cycles
IL = zeros(size(t));
for k = 1:N
% Time within current cycle
t_in_cycle = mod(t(k), Ts);
if t_in_cycle < D*Ts
% ON interval: current rises
IL(k) = IL_min + (IL_max - IL_min)/(D*Ts) * t_in_cycle;
else
% OFF interval: current falls
IL(k) = IL_max - (IL_max - IL_min)/((1-D)*Ts) * (t_in_cycle - D*Ts);
end
end
% Capacitor voltage waveform (approximate, triangle)
VC = VC_min + (VC_max - VC_min) * (IL - IL_min) / (IL_max - IL_min);
% Plotting
figure;
subplot(2,1,1);
plot(t*1e6, IL, 'b', 'LineWidth', 2);
xlabel('Time (\mus)');
ylabel('Inductor Current (A)');
title('Inductor Current');
grid on;
ylim([IL_min-0.2, IL_max+0.2]);
subplot(2,1,2);
plot(t*1e6, VC, 'r', 'LineWidth', 2);
xlabel('Time (\mus)');
ylabel('Capacitor Voltage (V)');
title('Capacitor Voltage');
grid on;
ylim([VC_min-0.01, VC_max+0.01]);
More Answers (0)
See Also
Categories
Find more on Sources 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!