Problem in generating PWM pulses for DC-DC converter

2 次查看(过去 30 天)
Below is the code that I used to generate the PWM pulse for dc-dc converter. There is an error in the codes. Basically I would like to generate the pwm pulses by comparing carrier signal with straight line. Anyone could enlighten me pls? thank you.
clc;
clear all;
close all;
F1=input('Carrier Sawtooth frequency=');
A=1;
t=0:0.00001:0.002;
c=A.*sawtooth(2*pi*F1*t);%Carrier sawtooth
subplot(3,1,1);
plot(t,c);
xlabel('time');
ylabel('Amplitude');
title('Carrier sawtooth wave');
grid on;
m=[0 1],[0.5 0.5];%Message amplitude must be less than Sawtooth
subplot(3,1,2);
plot(t,m);
xlabel('Time');
ylabel('Amplitude');
title('Message Signal');
grid on;
n=length(c);%Length of carrier sawtooth is stored to 'n'
for i=1:n%Comparing Message and Sawtooth amplitudes
if (m(i)>=c(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
subplot(3,1,3);
plot(t,pwm);
xlabel('Time');
ylabel('Amplitude');
title('plot of PWM');
axis([0 0.002 0 2]);%X-Axis varies from 0 to 1 & Y-Axis from 0 to 2
grid on;
  2 个评论
Walter Roberson
Walter Roberson 2013-10-3
What error message do you get where, or what difference do you observe between the desired and actual output ?
Rajkiran Singh
Rajkiran Singh 2013-10-3
Below line suppose to generate horizontal line but it's not plotting it. m=[0 1],[0.5 0.5];%Message amplitude must be less than Sawtooth

请先登录,再进行评论。

回答(1 个)

Sabin
Sabin 2024-1-23
This line of code is not doing what is intended:
m=[0 1],[0.5 0.5];%Message amplitude must be less than Sawtooth
to make it work replace it with something like (0.5 is the duty cycle):
m = 0.5*ones(1, length(t));

社区

更多回答在  Power Electronics Control

类别

Help CenterFile Exchange 中查找有关 Switches and Breakers 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by