# generating sine wave

Discussion in 'The Projects Forum' started by elengr, Jun 28, 2011.

1. ### elengr Thread Starter New Member

Feb 5, 2011
15
0
I am working on pure sine wave inverter. My skills are of beginner level. Will integrating a triangular wave form a sine wave?

Apr 5, 2008
15,799
2,385
Hello,

Did you already think of SPWM (sinusoidal pulse width modulation) ?
Here is a page from the EDUCYPEDIA with several links on the subject:
SPWM

Bertus

3. ### wayneh Expert

Sep 9, 2010
12,375
3,226
Nope. Do the math. Integral of cosine is sine.

Mar 24, 2008
20,772
2,540
5. ### CDRIVE Senior Member

Jul 1, 2008
2,223
99
One of the function generators that Heathkit produced in the 70's produced a square, sine and triangle. All three were formed by the triangle osc.

Jul 7, 2009
1,585
141
A triangle wave is a collection of straight lines and the integral of a straight line is a quadratic. But Bill's right -- it's a pretty good fit to a sine wave. Here's some python/numpy/matplotlib code that generates the attached plot that shows you qualitatively what's going on:

Code ( (Unknown Language)):
1.
2. from __future__ import division
3. from pylab import *
4.
5. n, num_periods = 1000, 3
6. # Create square wave
7. y = zeros(n//2) + 1
8. y = concatenate((y, zeros(n//2) - 1))
9. # Show a few periods
10. y = concatenate([y]*num_periods)
11. # Plot
12. plot(y, label="Square wave")
13. y = cumsum(y)
14. y /= max(abs(y))/2
15. range = max(y) - min(y)
16. y -= range/2  # Center it symmetrically about the x axis
17. plot(y, label="Triangle wave")
18. y = cumsum(y)
19. y /= max(abs(y))
20. plot(y - 0.05, label="Integrated triangle wave (offset a bit)")
21. # Subtract from a sine and plot the difference
22. t = arange(0, 2*pi, 2*pi/n)
23. t = concatenate([t]*num_periods)
24. y1 = -sin(t)
25. plot(y, label="True sine")
26. diff = y - y1
27. plot(diff, label="Integrated triangle minus sine")
28. legend(loc="upper left")
29. ylim(-1.1, 2.2)
30. title("Integrated Triangle Wave")
31. grid(True)
32. show()
33.
Note I had to offset the integrated triangle wave a bit -- otherwise the two become nearly indistinguishable.

File size:
115.8 KB
Views:
545
7. ### wayneh Expert

Sep 9, 2010
12,375
3,226
Interesting, thanks. That's a lot better than I guessed.

Jul 7, 2009
1,585
141
What was interesting was that I was going to roast Bill for making such a dumb statement. But then I thought I should check it out first. After writing that script, I had a strange feeling of deja vu. Then it slowly dawned on me that two or three decades ago I remember being a bit of a disbeliever when someone else made the same comment and I had to see if it was true. I had forgotten all about it.

That, of course, is the canonical definition of experience: it lets you recognize that you just made the same dumb mistake again.

Apr 30, 2011
1,426
363
I ran across this very multiple diode clipper triangle to sine conversion a while back: http://www.falstad.com/circuit/e-sinediode.html. It made me smile because there's so many parts. I guess you could use Germanium diodes and even more stages to get a better approximation of a true sine wave.

10. ### wayneh Expert

Sep 9, 2010
12,375
3,226
Hah! What a concept; think first, flame second.

Your comments on experience ring true. More than once in my career I found myself working on something vaguely familiar. Digging into my files would uncover that I had solved the same thing 5-10 years earlier. Very oddly, it was often on the same date, just years earlier. It was almost as if my interests were seasonal. Anyway, a few experiences like that taught me the value of documenting your work, if not for others, for your future self. Ten years later, it reads like someone else wrote it, but it sure is helpful compared to nothing.

11. ### Wendy Moderator

Mar 24, 2008
20,772
2,540
Another way of looking at this is as a filter. A single integrator is a simple 1st order filter, two of them is a 2nd order filter. Add enough filtering anything becomes a sine wave.

The diode shaper is something else, it is fundamentally a logarithmic amplifier.

12. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,435
1,305
If your triangle wave has the top and bottom peaks clipped (with diodes or PSU limits etc) it requires even less filtering to get a "sine" output.

To Elengr, I have built inverters that produced a decent sinewave out of the transformer, but they always needed waveforms very UN sine like driving the power components...

It also depends a bit on the type and current of the load. Maybe you should say what the load is and why you need to make a sinewave inverter?

13. ### Audioguru New Member

Dec 20, 2007
9,411
896
An inverter is NEVER made from an amplified sine-wave because the amplifier is always linear and wastes a lot of power making lots of heat.
Instead a sine-wave inverter uses Pulse-Width-Modulation at a high frequency where the output Mosfets switch completely on and off at a high frequency then the high frequency is simply filtered away with an LC filter.
Since the Mosfets switch completely on and off then they do not waste much power and do not get hot.

elengr likes this.
14. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,435
1,305
Actually they are. It's not common these days and it has never been a good idea with high power inverters, but there are linear sine wave inverters out there AG.

The last one I made was for a small "antique" clock with a 60Hz AC mains synchronous motor.

15. ### elengr Thread Starter New Member

Feb 5, 2011
15
0

I want to use sine wave inverter in UPS so that I can run my computer in case of power failure.

16. ### kubeek AAC Fanatic!

Sep 20, 2005
4,687
805
A computer will run fine with square wave or anything in-between, as the voltage is rectified and filtered to make a steady DC voltage for the SMPS. The electromagnetic noise will be higher with the square wave, but it shouldn´t affect the computer.

17. ### Audioguru New Member

Dec 20, 2007
9,411
896
AC motor speed controls don't work properly from a square-wave.
Many electronic products also don't work properly from a square-wave because they rely on the 1.414 times higher peak voltage of a sine-wave.

18. ### elengr Thread Starter New Member

Feb 5, 2011
15
0

Can you please upload a schematic of integrator circuit which at least converts square wave into triangular wave?

19. ### Audioguru New Member

Dec 20, 2007
9,411
896
An old 741, LM358 or LM324 opamp makes a triangle wave by integration when you have a frequency that exceeds its very low slew rate.

I think an integrating opamp circuit makes a triangle wave when its input is a square wave.