[edit] Summary
Cyril BUTTAY
Principle of the intersective pulse width modulation (PWM). This figure has been made using gnuplot 4.0 and the following code:
# This file is used to generate a plot that explains the
# principle of the intersective pwm
# graph configuration
set terminal postscript eps enhanced "Times-Roman" 24 color solid
set encoding iso_8859_15
unset title
set line style 1 lt 3 lw 3 pt 0 ps 0
set line style 2 lt 2 lw 3 pt 0 ps 0
set line style 3 lt 4 lw 3 pt 0 ps 0
set border 15 lt 7 lw 4
set grid xtics ytics
set xlabel ""
set samples 10000
set format x ""
set bmargin 0
set tmargin 0
# equation of the sawtooth signal
sawsignal(x) = x-floor(x)
#equation of the sine signal
freq=0.05
sinesignal(x) = 0.5+0.499*sin(freq*x*(2*pi))
#equation of the resulting pwm signal
pwmsignal(x)=sawsignal(x)>=sinesignal(x)?0:1
#equation of the n-th intersection between sinesignal and
# sawsignal (used to plot the tics on the x axis)
#the following points are generated by the python file pwm.py
set xtics (0 , 0.592539223108 ,\
1 , 1.76298640357 ,\
2 , 2.89455246531 ,\
3 , 3.97426347018 ,\
4 , 5.0 ,\
5 , 5.97664892031 ,\
6 , 6.9124388806 ,\
7 , 7.81668786014 ,\
8 , 8.69875361032 ,\
9 , 9.56769737702 ,\
10 , 10.432302623 ,\
11 , 11.3012463897 ,\
12 , 12.1833121399 ,\
13 , 13.0875611194 ,\
14 , 14.0233510797 ,\
15 , 15.0 ,\
16 , 16.0257365298 ,\
17 , 17.1054475347 ,\
18 , 18.2370135964 ,\
19 , 19.4074607769)
set ytics ("0" 0, "1" 1)
set output "pwm.eps"
set multiplot
set ylabel "source signals"
set origin 0,0.54
set size 1,0.45
plot [0:19][-0.25:1.25] sawsignal(x) ls 1 title '',\
sinesignal(x) ls 2 title ''
set ylabel "PWM signal"
set xlabel "Time"
set origin 0,0.09
plot [0:19][-0.25:1.25] pwmsignal(x) ls 3 title ''
unset multiplot
The list of points used to define the tics along the x axis has been generated by the following python code:
#!/usr/bin/python
#this file generates a list of points used as ticks
# to draw the grid in the gnuplot file pwm.plt
from scipy import *
freq= 0.05
n=20
for i in range(n):
def f(x):
return sin(freq*x*2*pi)-2*x+1+2*i
print i,",", optimize.fsolve(f,0), ",\\"
the eps figure generated by gnuplot has been converted in png by the following command:
convert -density 300 pwm.eps pwm.png
The codes described above are given to the public domain.
[edit] Licensing
I, the copyright holder of this work, hereby publish it under the following licenses:
You may select the license of your choice.
|
Click on a date/time to view the file as it appeared at that time.
The following pages on the English Wikipedia link to this file (pages on other projects are not listed):