Author Topic: Generating sine with triangle and multiplier  (Read 2417 times)

0 Members and 1 Guest are viewing this topic.

Offline MrWifiHifiTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: sk
Generating sine with triangle and multiplier
« on: July 09, 2025, 11:06:52 pm »
Hi

I would like to ask. Wherever I have come across generating a sine from a triangle so far, it has always been done through some non-linearity. Whether diodes or transistors were used for this. But I wondered if it would be possible to use an analog multiplier to generate a sine from a triangle. The option would be to use a multiplier to generate the x^2 function that would be used for this. I am also attaching a link to the simulation in Falstad. For now, it's just a concept. I assume, however, that cosine could also be made with it, which would expand the possible uses.

https://tinyurl.com/ymoe5b4w

I will be grateful in advance for any useful insights.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 4222
  • Country: us
Re: Generating sine with triangle and multiplier
« Reply #1 on: July 10, 2025, 01:46:45 am »
One reason is cost... analog multipliers are a lot more expensive than diodes and transistors.

Are you approximating sin(x) with x*(pi-x) on the interval [0,pi]?

Here's my go at computing the THD...

For the sine terms one has:

Code: [Select]
[ integrate(x*(pi-x)*sin(n*x), (x, 0, pi)) for n in range(1,12) ]

[4, 0, 4/27, 0, 4/125, 0, 4/343, 0, 4/729, 0, 4/1331, ...]

or b_n = 4/n^3 for odd n and zero otherwise.

The cosine terms are all zero.

The THD comes out to:

$$
\text{THD} = \sqrt{ \sum_{n=1}^{\infty} \frac{1}{(2n+1)^{6}} } = 0.038...
$$

So about 3.8%.

At 7:26 in this video is a simple A/B comparison in an audio application between a pure sine wave and the quadratic approximation:

Fast and Simple Approximation of Sine Function
https://youtu.be/1xlCVBIF_ig?t=7m26s
 
The following users thanked this post: Someone

Online David Hess

  • Super Contributor
  • ***
  • Posts: 19232
  • Country: us
  • DavidH
Re: Generating sine with triangle and multiplier
« Reply #2 on: July 10, 2025, 04:25:58 am »
National Semiconductor application note AN-263, included below, shows several sine wave generation techniques, including logarithmic.

Burr-Brown's "Function Circuits - Design and Applications" has several examples of analog multipliers used for sine shaping:

https://bitsavers.trailing-edge.com/components/burrBrown/Burr_Brown_Function_Circuits_1976.pdf
« Last Edit: July 10, 2025, 04:27:50 am by David Hess »
 
The following users thanked this post: RoGeorge, MathWizard

Offline MathWizard

  • Super Contributor
  • ***
  • Posts: 2545
  • Country: ca
Re: Generating sine with triangle and multiplier
« Reply #3 on: July 10, 2025, 04:38:47 am »
If x is in radians, x*(pi-x)/2.47 would at least give sin(pi/2)=1

         
deg   x   (x*(pi-x)/2.4674)   sinx
0   0.00   0.00   0.00
10   0.17   0.21   0.17
20   0.35   0.40   0.34
30   0.52   0.56   0.50
40   0.70   0.69   0.64
50   0.87   0.80   0.77
60   1.05   0.89   0.87
70   1.22   0.95   0.94
80   1.40   0.99   0.98
90   1.57   1.0000   1.00
100   1.75   0.99   0.98
110   1.92   0.95   0.94
120   2.09   0.89   0.87
130   2.27   0.80   0.77
140   2.44   0.69   0.64
150   2.62   0.56   0.50
160   2.79   0.40   0.34
170   2.97   0.21   0.17
180   3.14   0.00   0.00   
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 3181
  • Country: gb
  • Recovering Electrical Engineer
Re: Generating sine with triangle and multiplier
« Reply #4 on: July 11, 2025, 07:32:38 am »
 
The following users thanked this post: RoGeorge

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 4222
  • Country: us
Re: Generating sine with triangle and multiplier
« Reply #5 on: July 12, 2025, 12:32:36 am »
Here's a recent youtube video on a squaring circuit:

Squaring Function Circuit Design Explained with Temperature Compensation -- Engineering Prof.


The guy has another video on a square-root circuit:

Accurate Analog Square Root Circuit with Temp Compensation Explained -- Engineering Prof.
https://youtu.be/tjzYZ4FlUtE
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3382
  • Country: au
Re: Generating sine with triangle and multiplier
« Reply #6 on: July 12, 2025, 01:19:02 am »
The option would be to use a multiplier to generate the x^2 function that would be used for this.

Yes, but x^2 is only one of many terms for a cosine polynomial, so it will be approximate.

There are log-shapers that try to do a bit better, and you can buy matched NPNs easily today.

https://till.com/articles/sineshaper/index.html
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 2318
Re: Generating sine with triangle and multiplier
« Reply #7 on: September 28, 2025, 11:54:38 am »
If x is in radians, x*(pi-x)/2.47 would at least give sin(pi/2)=1

         
deg   x   (x*(pi-x)/2.4674)   sinx
0   0.00   0.00   0.00
10   0.17   0.21   0.17
20   0.35   0.40   0.34
30   0.52   0.56   0.50
40   0.70   0.69   0.64
50   0.87   0.80   0.77
60   1.05   0.89   0.87
70   1.22   0.95   0.94
80   1.40   0.99   0.98
90   1.57   1.0000   1.00
100   1.75   0.99   0.98
110   1.92   0.95   0.94
120   2.09   0.89   0.87
130   2.27   0.80   0.77
140   2.44   0.69   0.64
150   2.62   0.56   0.50
160   2.79   0.40   0.34
170   2.97   0.21   0.17
180   3.14   0.00   0.00

That's the technique of generating a near sine with a squared time value.  This can be obtained from a triangle wave by integration.  There's a little more to it but that's the main idea.  The generated sine bulges a little at the sides but it's not bad.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 2318
Re: Generating sine with triangle and multiplier
« Reply #8 on: September 28, 2025, 12:00:48 pm »
You'll love this:
Nonlinear Circuits Handbook Analog Devices, 1976.
www.analog.com/media/en/training-seminars/design-handbooks/Nonlinear-Circuits-Handbook/Nonlinear-Circuits-Handbook-1976.zip

A browser flagged this as not being able to be downloaded securely, but when checked with several virus scanners they all say it's ok.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 2318
Re: Generating sine with triangle and multiplier
« Reply #9 on: September 28, 2025, 12:16:12 pm »
The option would be to use a multiplier to generate the x^2 function that would be used for this.

Yes, but x^2 is only one of many terms for a cosine polynomial, so it will be approximate.

There are log-shapers that try to do a bit better, and you can buy matched NPNs easily today.

https://till.com/articles/sineshaper/index.html

Hi,

Of course, but sometimes the idea is to get a simple circuit to do it not perfect accuracy.  If we wanted better we can add a 4th degree term (see attachment).
The image shows 2nd degree and 4th degree approximations.  The 2nd degree is not as accurate but is much easier to generate.
Blue: 2nd degree
Red: 4th degree
Green: exact cos()
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 2318
Re: Generating sine with triangle and multiplier
« Reply #10 on: September 28, 2025, 12:21:55 pm »
Hello again,

Since I worked in the industry designing and testing sine converters we had different ways to go about doing this.
One of the best we came up with was actually very simple.  Store some of the sine amplitudes in a ROM, then run the ROM from 0 to N.  The output is then filtered.
The result was a sine converter with less than 1 percent THD.  It was a significant improvement for the time.
It also had sub-cycle feedback to keep the THD this good even with nonlinear loads.  That was one of the other reasons for the sine generation.
 

Offline mtwieg

  • Super Contributor
  • ***
  • Posts: 1826
  • Country: us
Re: Generating sine with triangle and multiplier
« Reply #11 on: September 28, 2025, 01:51:56 pm »
This can be obtained from a triangle wave by integration.  There's a little more to it but that's the main idea.  The generated sine bulges a little at the sides but it's not bad.
Agreed, if you start with a triangle wave and you want to generate a sinewave using parabolas as an approximation, then simply integrating the triangle wave is far simpler than actually squaring it. However the output amplitude will be inversely proportional to the triangle wave frequency.

Long ago I had to make a function generator for a class project, and got around this issue by also making the triangle wave generator design such that its amplitude was proportional to frequency, which mostly eliminated this problem.

However, I still found that a triangle > sine converter made out of diodes/LEDs seemed to have lower distortion overall, and was even simpler.  :-//

Since I worked in the industry designing and testing sine converters we had different ways to go about doing this.
One of the best we came up with was actually very simple.  Store some of the sine amplitudes in a ROM, then run the ROM from 0 to N.  The output is then filtered.
The result was a sine converter with less than 1 percent THD.  It was a significant improvement for the time.
It also had sub-cycle feedback to keep the THD this good even with nonlinear loads.  That was one of the other reasons for the sine generation.
Sounds like you're describing direct digital synthesis.
« Last Edit: September 28, 2025, 01:54:27 pm by mtwieg »
 

Offline mawyatt

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: us
Re: Generating sine with triangle and multiplier
« Reply #12 on: September 28, 2025, 02:40:13 pm »
Way back in 80 when we were working with a Real Time SA based around Chirp-Z Transform this required a complex (Sine and Cosine) sweep multiplication of the input. This was done by using a custom very fast hybrid multiplying DAC and feeding the input to the DAC Reference, the DAC Digital input came from a ECL ROM that was cycled thru and swept for the Sine and Cosine coefficients which created the necessary swept Sine and Cosine multiplication for the CZT. Sort of a DDS type solution.

Best
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3382
  • Country: au
Re: Generating sine with triangle and multiplier
« Reply #13 on: September 28, 2025, 02:40:30 pm »
Store some of the sine amplitudes in a ROM, then run the ROM from 0 to N.  The output is then filtered.
The result was a sine converter with less than 1 percent THD.
What size rom ?
I would have expected a ROM to manage well under 1% THD?


Years ago we looked at PLD & MCU for sine generation, which stepped always the same in Y, but varied the X axis, so had much wider steps at the ‘flat’ tops. This also allowed fastest and even steps at 45’ slopes and did not waste any DAC steps.  FWIR, ~804 time units gave the best fit with 8b DAC.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->