I'm not a math or electronics genius but I was wondering if anyone
could provide an equation that gives amplitude (voltage) as a function
of time and duty cycle for a square wave:
symbolically:
A (V) = f(t (sec),duty cycle (%))
perhaps also the function would include something about the initial
phase (phi)......
A simple equation that just gave back 1 or 0, as a function of time and
duty cycle would work good too....I presume any answer would involve a
trig function someway....
I have already tried searching the web for the answer and the closest I
found was this link:
http://www.dattalo.com/technical/theory/sqwave.html
However, I'm not sure exactly how LaPlace transforms figure into it, or
if any of these are usable equations for what I'm looking for.
Please help....if you can.
Thank you.
Google on "Fourier series" plus "square wave". Here's a nice piece
from Addison-Wesley:
http://www.aw-bc.com/ide/Media/JavaTools/srfoursq.html
If you're into electronics, you might want to study the use of
the Laplace transform in solving second-order ordinary
differential equations. It is especially handy when the equation
contains a discontinuous "forcing term", which it frequently
does in electronics.
LH
I assume you mean: Vave = VpD the average voltage equals the peak voltage
times the duty cycle. The duty cycle, D = Ton/(Ton + Toff) = Ton/(period) =
f Ton. The RMS voltage is more complicated.
Bob
I am not quite sure what your question is. The terms *step function* and
*Heavyside function* are sometimes used to represent pulses. Such a function
is merely H(t)=1 for t>0 and 0 for t<0. A pulse of width T would be
represwented by f(t)= H(t)-H(t-T). These are not the nice continuous
functions with smooth derivatives that old-time mathematicians like, but
they do have nice Laplace transforms.
Bill
I did the Google search you suggested and I came on this site:
http://mathworld.wolfram.com/SquareWave.html
At first glance, this website seems to answer my query but upon further
inspection it is not any good.
First, EXCEL has a problem raising negative numbers (in this case -1)
to a fractional exponent. So the first equation is no good.
Secondly, it does allow for varied duty cycle.
Thirdly, the other 2 formulas are not conducive to inclusion in
EXCEL......
Also, any "Fourier series" solution to my problem is also not conducive
to EXCEL since it requires summation of an infinite series.....
Also, I really don't care about the LaPlace transform of the equation
I'm looking for, just the actual equation itself.....
see the links I mentioned to get a better idea.
thank you...
The 'formula' for a PWM square wave is exactly what you think it ought to
be; something like:
T=period
p=percentage 'on' time
t=current time
O=output
Set t'=t mod T (this gets the time into the current period)
Set O=1 if t'>=p*T
else set O=0
Although this notation wouldn't please a mathematician, it can be 'prettied
up' such that it if perfectly legitimate. Excel knows the modulus operator
and if/then/else operators if you want to implement it.
The stuff about Fourier transforms relates to taking a square wave and
expressing it as a sum of some other set of 'fundamental' (aka, 'basis')
functions; sines and cosines turn out to be particularly useful in this
endeavor, but you can typically express any function as some (often
infinite) sum of some other set of basis functions so long as those basis
functions have certain special properties (e.g., if you like, you can
express sine in terms of bunch of square wave-like functions). There's lot
of math behind this that you can dig up if you're so inclined.
Here's a good web page with examples:
http://cnx.rice.edu/content/m0041/latest/ Note the equation at the bottom
of the page -- you could use that summation using, e.g., the first 5 terms
and then checking to see if the result is greater than or less than 0, but
this is a lot more effort than just using the definition of a PWM square
wave directly.
---Joel Kolstad
What don't you like about IF/THEN/ELSE?
In your case, you can cheat a little and use various rounding functions such
as TRUNC or perhaps CEILING/FLOOR... but realize that all you're doing is
shifting the conditional statement to being 'hidden' (Excel does it
internally) rather than your doing it explicitly.
There is no finite series closed-form expression in terms of "familiar"
functions that I'm aware of for a square wave. Even if you have an infinite
number of terms, there's still an error in the approximation of ~9%, if I
recall correctly, due to something called the Gibbs phoenomenom. You might
be able to remove it with another infinite series that represents an ideal
brick wall filter, however, but this is really starting to get silly...
In signals and systems work, it's common to get around most of these
functions by _defining_ a function called, e.g., "rect" that defines a
single rectangular pulse of a given duration.
---Joel Kolstad
Here's my retort:
>What don't you like about IF/THEN/ELSE?
Hard to explain, but basically I want to do further operations on the
equation which makes the use of IF/THEN/ELSE problematic...
>There is no finite series closed-form expression in terms of
"familiar"
>functions that I'm aware of for a square wave.
See Formula 1 of the following link:
http://mathworld.wolfram.com/SquareWave.html
Problems with this formula are 1.) that EXCEL will not allow (-1) to be
raised to a fractional exponent and 2.) duty cycle is not accounted
for...
I've read everybodies repy and your answers to them and clearly you don't
know what you are asking for and neither do we. If you don't know what you
are asking, why are you asking it? PWM signals are used to drive motors,
vary voltages, powers or currents in power supplies, class D amplifiers,
motor controllers and the like. The relationships I gave you above are what
you need if you are working on a power supply or amplifier and want to
relate the output to the duty cycle. You responded with some quip about sine
waves? Clearly you don't understand what I told you and I have no clue what
you are asking. Instead of chasing URL's, try to state your problem in
english, maybe we can help. The URL you refer to is highly mathematical and
forms the underlying basis for harmonic cancellation to suppress harmonics
from PWM signals.Is this what you want to put into practice? It seems like a
big jump from your original question.
Bob
> I've read everybodies repy and your answers to them and clearly you
> don't know what you are asking for and neither do we. If you don't
> know what you are asking, why are you asking it?
Simply stated, I want a mathematical equation which shows
voltage/amplitude of a square wave (+1 or -1) as a function of time,
frequency/period, and duty cycle. However, this equation must be
"neat" - no conditional statements (like "IF"), or piecewise statements
(like Heaviside), or infinite series (like Fourier). The desire for a
"neat" equation is for easy incorporating and manipulating in EXCEL.
If this is not clear enough, then please let me know.
> PWM signals are used to drive motors, vary voltages, powers or
> currents in power supplies, class D amplifiers, motor controllers
> and the like. The relationships I gave you above are what you need
> if you are working on a power supply or amplifier and want to relate
> the output to the duty cycle. You responded with some quip about sine
> waves?
My "quip" about sine waves was in response to your misinterpreting my
question as referring to RMS/sine waves as opposed to square waves. You
had stated:
>> I assume you mean: Vave = VpD the average voltage equals the peak
>> voltage times the duty cycle. The duty cycle, D = Ton/(Ton + Toff) =
>> Ton/(period) = f Ton. The RMS voltage is more complicated.
>> Bob
Here is my "quip" back to you, making it clear I was talking about
square waves, not sine waves...I was not confounding the issue, just
clearing it up:
>> No...I'm not talking about sine waves but square waves....also,
>> I'm not talking about Vave but Vinst (e.g.. +1 and -1, or Vhi and
>> Vlo or Vhi and 0)...I want to know what Vinst is at any time (time)
>> for a given frequency/period, amplitude and duty cycle.....
> Clearly you don't understand what I told you and I have no clue what
> you are asking.
I think I do on both accounts. You had responded to me using the
concepts of RMS, sine waves, and Vave, whereas I am interested in
square waves and Vinst. I think the record shows your reply was
off-target, albeit well-intentioned.
> Instead of chasing URL's, try to state your problem in
> english, maybe we can help.
See above.
> The URL you refer to is highly mathematical and
> forms the underlying basis for harmonic cancellation to suppress
> harmonics from PWM signals. Is this what you want to put into
> practice? It seems like a big jump from your original question.
> Bob
Here is the URL again:
http://mathworld.wolfram.com/SquareWave.html
I agree this URL eventually becomes "highly mathematical" but Eaquation
1 is not. Do you believe Equation 1 is "highly mathematical"? If so,
how so? As previously stated, the formula would work great if 1.)
EXCEL allowed rasing a negative number to a fractional exponent and 2.)
duty cycle was included.
"jack" <mathgu...@yahoo.com> wrote in message
news:1113290792....@o13g2000cwo.googlegroups.com...
> Hard to explain, but basically I want to do further operations on the
> equation which makes the use of IF/THEN/ELSE problematic...
OK...
>>There is no finite series closed-form expression in terms of
> "familiar"
>>functions that I'm aware of for a square wave.
>
> See Formula 1 of the following link:
>
> http://mathworld.wolfram.com/SquareWave.html
OK, equation (1) is certainly simple enough. :-) Equation (2) is probably
your best bet for implementation in Excel; it has the "signum" functin
(SIGN).
> Problems with this formula are 1.) that EXCEL will not allow (-1) to be
> raised to a fractional exponent and 2.) duty cycle is not accounted
> for...
With equation (2), let's see... you could account for duty cycling by
subtracting two sine waves that are out of phase with one another and taking
the SIGN of the result. The amount that they're out of phase will determine
the duty cycle (albeit non-linearly) -- 0 degrees out of phase is 0% PWM,
180 degrees out of phase is 100% PWM.
---Joel
You're right that equation 2 will "work" in EXCEL although it is still
not really mathematically "pure" or very "elegant".
However, I challenge you to try to get Equation 1 to work in EXCEL.
Raising a negative number to a fractional exponent causes an error in
EXCEL. Try it. I agree Equation 1 would be great if it worked in
EXCEL. :-(
>Raising a negative number to a fractional exponent causes an error in
>EXCEL. Try it.
A negative number to a fractional exponent is a complex number. Excel
2003 understands them, but I've never used that feature. Earlier
versions (e.g. Excel 97) didn't understand them.
I think it is irresponsible to allow accountants to use a spreadsheet
that can cope with imaginary numbers. (;-)
--
Regards, John Woodgate, OOO - Own Opinions Only.
There are two sides to every question, except
'What is a Moebius strip?'
http://www.jmwa.demon.co.uk Also see http://www.isce.org.uk
"jack" <mathgu...@yahoo.com> wrote in message
news:1113330784.6...@g14g2000cwa.googlegroups.com...
> You're right that equation 2 will "work" in EXCEL although it is still
> not really mathematically "pure" or very "elegant".
I suppose that's in the eye of the beholder?
> However, I challenge you to try to get Equation 1 to work in EXCEL.
> Raising a negative number to a fractional exponent causes an error in
> EXCEL. Try it.
Yeah, I see that you're right. This isn't too surprising, though, in that
typically raising negative numbers to fractional exponents ends up with an
imaginary result, and Excel doesn't support complex numbers 'natively' (it
can be done with them with the Analysis ToolPak, but it's still a little
clunky). In fact, looking at equation (1) on the MathWorld site, I believe
you have to look strictly at the real part of the result to get the output
(the square wave) that you're after (and just discard the imaginary part).
The Windows calculator, regular scientific calculators without native
complex number support, and many other applications that you might try to
use with eqn (1) will fail... those guys over at MathWorld aren't bothered
by this because their product, Mathematica, pretty much never fails. :-)
(Mathematica will produce results from expressions that almost any
'everyday' calculator like Excel will barf at, since Mathematica 'knows'
many extensions of 'familiar' functions that make them 'work' in uncommon
domains that high-powered math guys are familiar with... for instance, the
factorial function can be extended to produce results even when its argument
is negative or fractional, even though for the vast majority of people this
is unexpected behavior.)
An implementation using equation (2) is going to be a lot more efficient
than one using eqn (1). An implementation using a boring 'if/then/else'
approach is going to be the most efficient of all. Often the most 'elegant'
mathematical expressions are the most inefficient if you perform the
'straightforward' implementation; this is understandable in that by
'elegant' one oftens means they're trying to hide lots of ugly details in a
few nice, all-powerful functions -- which are inherently slow to evaluate.
---Joel
> Hi,
>
> I'm not a math or electronics genius but I was wondering if anyone could
> provide an equation that gives amplitude (voltage) as a function of time
> and duty cycle for a square wave:
>
> symbolically:
>
> A (V) = f(t (sec),duty cycle (%))
>
Do you even know what a "square wave" is?
Do you have any idea at all why asking for an "equation that gives voltage"
is stupider than a joke?
You'd better ask your teacher for remedial instruction on the difference
between "pressure" and "flow". Or maybe the difference between
"measuring" and "fantasizing".
Good Luck!
Rich
> O.K., fair enough....let me respond by point:
>
>> I've read everybodies repy and your answers to them and clearly you
>> don't know what you are asking for and neither do we. If you don't know
>> what you are asking, why are you asking it?
>
> Simply stated, I want a mathematical equation which shows
> voltage/amplitude of a square wave (+1 or -1) as a function of time,
> frequency/period, and duty cycle. However, this equation must be "neat" -
> no conditional statements (like "IF"), or piecewise statements (like
> Heaviside), or infinite series (like Fourier). The desire for a "neat"
> equation is for easy incorporating and manipulating in EXCEL.
This is the problem. Your problem statement doesn't make any sense.
There Is NO Equation that can give you voltage based on any of those
other parameters.
You cannot write an equation that derives height from speed. They're
orthogonal.
You really need to go back to your fundamentals and learn the difference
between things like voltage, resistance, power, frequency, and so on.
Good Luck!
Rich
Life is truly tough. It is made up of a series of trick problems. solve them
for yourself. Don't ask others to do it for you, especially if you pay no
attention to the replies.
Bill
> Yeah, I see that you're right. This isn't too surprising,
> though, in that typically raising negative numbers to fractional
> exponents ends up with an imaginary result,
John Woodgate (in his previous reply) makes the same point about
negative numbers and fractional exponents....however this isn't always
true, is it? X^(1/2) is a no-no for negative numbers (i.e. imaginary
result) but X^(1/3) is O.K. for negative numbers (real result). EXCEL
treats both of these these correctly (error for X^(1/2) and real number
for X^(1/3)). But EXCEL chokes on X^(2/3) for a negative number - this
should be O.K. (real number result) for negative numbers....right?
> An implementation using equation (2) is going to be a lot more
> efficient than one using eqn (1). An implementation using a
> boring 'if/then/else' approach is going to be the most efficient
> of all. Often the most 'elegant' mathematical expressions are
> the most inefficient if you perform the 'straightforward'
> implementation; this is understandable in that by 'elegant' one
> oftens means they're trying to hide lots of ugly details in a
> few nice, all-powerful functions -- which are inherently slow to
> evaluate.
I will probably go with Equation 2, although how to incorporate duty
cycle into the equation is still perplexing me.
It's just a shame that a seemingly straightforward periodic function as
a square wave (+1,-1,+1,-1,.....) could not be expressed as a
straightforward function. If they can fake putting a man on the moon,
why can't they figure this one out?
Well- if you know duty D and period T, then at any time t, the function
is +1 if FRACT(t/T)<=D and -1 if FRACT(t/T)>D. If you have an offset,
to, then use t-to for t in the above. How hard is that? Excel doesn't
allow logic coefficients in expressions?
>> Simply stated, I want a mathematical equation which shows
>> voltage/amplitude of a square wave (+1 or -1) as a function of time,
>> frequency/period, and duty cycle.
Then you said:
> This is the problem. Your problem statement doesn't make any sense.
> There Is NO Equation that can give you voltage based on any of those
> other parameters.
I assume you are being a hyper-stickler because I did not explicitly
include a reference (Vo) voltage in my problem statement. Would you be
O.K. if I had said instead:
>> Simply stated, I want a mathematical equation which shows
>> voltage/amplitude of a square wave (+1 or -1) as a function of time,
>> frequency/period, duty cycle, AND REFERENCE VOLTAGE (Vo).
I think everyone else understood this as a given, which did not need to
be explicitly stated.
If this still doesn't satisfy you, then just do a Google search for
"voltage as a function of time" +"edu" and you will get a ga-zillion
hits showing how voltage can be expressed as a time function. Random
example from Bucknell Univ.:
http://www.facstaff.bucknell.edu/mastascu/eLessonsHTML/Signal/Signal2.htm
> You cannot write an equation that derives height from speed. They're
> orthogonal.
No, you're orthogonal.
> You really need to go back to your fundamentals and learn the
> difference between things like voltage, resistance, power,
> frequency, and so on.
Rather, I think you need to go back to Kindergarten and learn how not
to be a ball-breaker over something that is obvious.
In my original post I clearly indicated that I had done a fair amount
of due diligence and wasn't asking without having done some homework
already. The assumption in my original post was that there must be a
straigtforward answer and since high-powered math-oriented folk
frequent such internet groups, it might be a good place to ask....this
should be an easy question IF the answer is indeed straightforward.
Also, I did pay attention to the replies and patiently explained why
responses were off-target or not what I was looking for. Check out my
responses, I paid attention to all the replies and I always explained
myself.
> Do you have any idea at all why asking for
> an "equation that gives voltage"is
> stupider than a joke?
Suggest you contact each of the authors (all somehow associated with
educational institutions) of the approximately 745 web pages that show
up when you Google the terms +"voltage equation" +"edu" and tell them
they are "stupider than a joke"....
Google Search:
http://www.google.com/search?hl=en&lr=&q=%2Bedu+%2B%22voltage+equation%22+
Semi-random example page...this doesn't exactly look "stupider than a
joke"...does it?
Assuming your square wave oscillates from some voltage V+ to V- at some
frequency and duty cycle, here's a simple equation that will work. You *can*
implement an IF statement in Excel very easily. Here's the equation:
Given:
t = time in seconds
f = frequency in Hertz
d = duty cycle expessed as a decimal (e.g. 35% = 0.35)
IF = tf - INT(tf) < d/f THEN V(t,f,d) = V+ ELSE V(t,f,d) = V-
The INT function in Excel returns the whole number portion and drops the
decimal part.
tf - INT(tf) gives the fraction of the last wave completed after t seconds.
d/f gives the fraction of a cycle where the voltage is V+. If the first
fraction is less than the second, the voltage is V+. Otherwise it's V-.
Hopes this helps.
Allen
"jack" <mathgu...@yahoo.com> wrote in message
news:1113319474....@g14g2000cwa.googlegroups.com...
>result) but X^(1/3) is O.K. for negative numbers (real result).
Maybe. Some would say (-1)^(1/3) = (-1/2) + i sqrt(3)/2.
>But EXCEL chokes on X^(2/3) for a negative number - this
>should be O.K. (real number result) for negative numbers....right?
Maybe. Some would say that -- with the exception of integer n , perhaps --
the right definition of X^n is exp( n log(X) ), which forces such
people to add "... for positive X only."
>It's just a shame that a seemingly straightforward periodic function as
>a square wave (+1,-1,+1,-1,.....) could not be expressed as a
>straightforward function. If they can fake putting a man on the moon,
>why can't they figure this one out?
Oh, we can fake this too. What you want is the straightforward function
f(x) = squarewave(x). You got a problem with that? Most mathematicians
would probably accept that answer. (Maybe after a beer or two.)
You could also opt for f(x) = sin(x) / |sin(x)| or f(x) = (-1)^floor(x) .
Much depends on what you're trying to accomplish. (You might already
have said; I haven't been paying attention, sorry.)
dave
I don't have a formula, but I do have a simple approach:
If all you want is to know whether the signal (Vinst) is
hi or low at any given instant, it is a simple divide and compare.
From the frequency and duty cycle you compute total time
for the cycle, and determine the "on time" from the duty cycle.
Assume your pulse is positive going at time Tsubzero:
Divide Tsubn by total time. If there is no remainder, the ampltude
is at Tsubzero amplitude - high. If there is a remainder, and the
remainder is greater than the "on time" the signal is low.
If the remainder is less than or equal to the "on time" , the signal is
high.
If your signal is negative going instead of positive going at
Tsubzero, it still works, but you have to invert the highs
and lows in the description.
Ed