MATLAB program for PWM signal generation

Program Code
% PWM Signal Generation
clc;
close all;
clear all;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
    if (m(i)>=s(i))
        pwm(i)=1;
    elseif (m(i)<=s(i))
        pwm(i)=0;
    end
end
plot(t,pwm,'-g',t,m,'--r',t,s,'--b');
grid on;
ylabel('Amplitude');
xlabel('Time index');
title('PWM Wave');
axis([0 1 -1.5 1.5]);



Output

_________________

7 comments:

  1. getting an error called Undefined function or variable
    'l'.
    please help
    i am new to matlab

    ReplyDelete
    Replies
    1. Respected sir
      Variable 'l' is not used in this program. You might have mistaken 1(one) or i as 'l'.

      Delete
  2. hello sir,
    me generate the PWM form the micro controller pin and me used MPLAB IDE v8.88 with Hi-Tech compiler............ then please send me some code for this project.

    ReplyDelete
    Replies
    1. Respected madam,
      May your project be a success. Wish you all success in your project.

      Delete
  3. Respected visitors of this blog,
    It would be nice if any of you send Ms. Pooja Mehta some code for her project as soon as possible or posted the code for the project here as a comment so that she can view it

    ReplyDelete
  4. i am getting an error pwm not defined ?? what to do plz help

    ReplyDelete
    Replies
    1. Respected Sir,
      Thank you very much for spending your precious time to visit this humble weblog.

      When I ran the program code I published in this page, I got output. The output I got is also given in this page under the caption 'Output'. So you please copy the entire program given here using the copy option and paste it to your computer using paste option. After that you please save and run the program in MATLAB.
      Please don't give the file name as pwm.
      After that kindly inform us about the output by posting a comment here. If you still face any problem in getting the correct output, then please inform us. We are always at your service.

      Thank you for being kind enough to visit this weblog. Thank you for asking me this question and thus giving me a chance to serve a honourable person like you.I am greatly obliged you for this. Wish you good health, success and happiness. May your friends and relatives also have good health, success and happiness.

      Waiting for you reply

      Delete

Please write your opinion about this MATLAB program here, only in English.

For sale

For sale
Indian currency Ten-rupee note in good condition. Issued by the Reserve Bank of India between 22 December 1992 and 21 December 1997. Serial number 52T332603 . Those interested to buy, please contact: Anju K, Email: tc9749@gmail.com . Address: 'Sreyas', House no.7/296, Pulliodi, Kathiroor village, Ponniam east PO, via Ponniam west, Thalassery, Kannur, Kerala - 670641, India.