Problem in generating PWM pulses for DC-DC converter

2 ビュー (過去 30 日間)
Rajkiran Singh
Rajkiran Singh 2013 年 10 月 3 日
回答済み: Sabin 2024 年 1 月 23 日
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));

コミュニティ

カテゴリ

Help Center および File ExchangePulse width modulation (PWM) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by