%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%
% Script file for PWM generation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear;
fs = 1000; % Frequency of samples
fc = 25; % Frequency of error or message signal
t = 0:1/fs:10; % Array of time
Saw = sawtooth((fc/2)*2*pi*t);
Message = Saw/2+ range(Saw)./4;
figure(1)
plot(t,Message);
position_signal = sind(t*360); % Position signal in degrees
s11 = one
s(size(position_signal));
s11 = sign(diff(position_signal));% Comparision of signals
PWM_signal = zeros(size(position_signal)); %PWM Signal
for n = 1:length(position_signal)
if Message(n)>abs(position_signal(n))&& s11(n)>0
PWM_signal(n)=1;
elseif Message(n)>abs(position_signal(n))&&s11(n)<0
PWM_signal(n) = =-1;
end
end
figure(2)
plot(t,position_signal,'g-')
hold on
plot(t,PWM_signal,'k--')
title('\fontsize{20}\color{black}\bfPWM pulse generation by MATLAB coding')
axis off
% Script file for PWM generation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear;
fs = 1000; % Frequency of samples
fc = 25; % Frequency of error or message signal
t = 0:1/fs:10; % Array of time
Saw = sawtooth((fc/2)*2*pi*t);
Message = Saw/2+ range(Saw)./4;
figure(1)
plot(t,Message);
position_signal = sind(t*360); % Position signal in degrees
s11 = one
s(size(position_signal));
s11 = sign(diff(position_signal));% Comparision of signals
for n = 1:length(position_signal)
if Message(n)>abs(position_signal(n))&& s11(n)>0
PWM_signal(n)=1;
elseif Message(n)>abs(position_signal(n))&&s11(n)<0
PWM_signal(n) = =-1;
end
end
figure(2)
plot(t,position_signal,'g-')
hold on
plot(t,PWM_signal,'k--')
title('\fontsize{20}\color{black}\bfPWM pulse generation by MATLAB coding')
axis off
No comments:
Post a Comment