Pulse width modulation
Copyright (C) 2022 Miodrag Bolic
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details <https://www.gnu.org/licenses/>.
% Changing the path from main_folder to a particular chapter
main_path=fileparts(which('Main_Content.mlx'));
%addpath(append(main_path,'/Chapter2'))
cd (append(main_path,'/Chapter3/Generating Signals'))
addpath(append(main_path,'/Service'))
SAVE_FLAG=0; % saving the figures in a file
PWM Signal generation
The code below shows a 10 Hz modulation waveform. The input signal is the sine wave with a frequency of 1 Hz. The code then generates the the output PWM signal.
% This code has been modified from Sourangsu Banerji, 2013 at
% https://www.mathworks.com/matlabcentral/fileexchange/42168-pulse-width-modulation
fc = 10; % the Frequency of Carrier Signal
fm = 1; % Frequency of the input signal
a = 1 ; %Amplitude of Modulation signal
b = 1; % Amplitude of the input signal
vc = a.*sawtooth(2*pi*fc*t);
% Representation of the Message Signal
% Representation of the Carrier Signal
legend('Input signal', 'Modulation Signal');
% Representation of the PWM Signal
% Add title to the Overall Plot
ha = axes ('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text (0.5, 1,'\bf Pulse Width Modulation ','HorizontalAlignment','center','VerticalAlignment', 'top')
exportgraphics(gcf,"Fig3.29.jpg", 'Resolution',600)