Differentiating a triangle wave - Page 1
Forum section: electronics / beginners

author: Analog Kid
author_rank: Super Contributor
timestamp: September 11, 2025, 11:12:19 pm
content: Motivated by the other thread here about generating triangle waves, I took my first venture into signal differentiation. Wanted to see how it worked IRL as opposed to textbooks.I used my ICL8038 to generate a ~7KHz triangle wave. Ran it through a simple differentiator. 'Scoped both the triangle and diff waves to see what they looked like:Seemed to work pretty well. (The fuzzy bottom trace is due to my funky o'scope lead setup which is definitely not kosher. Funny thing is theothertrace, the triangle wave, was nice and clean but was also using a funky lead.)So now I really get how this works; the differentiated signal is the instantaneous slope (ΔV) of the triangle wave. Just like in calculus class. Kewl.Someone on that other thread pointed out that the slope of the diff curve indicates the linearity of the triangle wave, which makes sense. My question is, other than determining this visually, which you can see would be very iffy in this case, is there some way to determine the linearity quantitatively?After thinking about this it seemed to me that maybe one could cook up a circuit that wouldTrigger on the start of a rising triangle cycleMeasure the differentiated voltage at that start time and store it with a sample-and-holdTrigger at the peak of the triangle cycleMeasure the differentiated voltage at that peakCompare the two voltagesIf they were the same or close to the same, one could say that the triangle wave was pretty linear, right?.(The motivation for all this is a pipe dream of creating a usable triangle wave for a class D amp using discretes.)

author: ledtester
author_rank: Super Contributor
timestamp: September 12, 2025, 12:04:15 am
content: Quote from: Analog Kid on September 11, 2025, 11:12:19 pmIt would probably be easier to digitize the wave with a digital scope or the ADC of a micro and do all math on a computer.You could then do a lot more... like look at the Fourier transform, look at the linearity of each ramp, look for consistency of the wave's characteristics across multiple periods, etc.

author: BillyO
author_rank: Super Contributor
timestamp: September 12, 2025, 12:09:29 am
content: Two points would not be enough.As an example, there could be a non-linearity on the triangle that caused the derivative to dip int eh middle (or peak) the settle back to the beginning voltage.The best route would be to take many samples of the triangle waveform and compare them to an ideal waveform. This could easily be done with a modern digital scope to record and export the waveform. An alternative method which I have used before is the employ an ADC and acquire the waveform directly into a PC then analyze each point mathematically.Edit: Looks like ledtester has the same ideas. However I would dispense wit any FFT and just compare to an idealized triangle which can be done with simple math.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 12, 2025, 12:53:00 am
content: I like the ADC idea.Never played with one before.Any recommendations for a n00b in this area?I'm thinking: maybe a simple USB interface? (can't think how else to get data into a PC)16 bits? minimal external components needed?

author: BillyO
author_rank: Super Contributor
timestamp: September 12, 2025, 01:14:55 am
content: What frequencies are you looking at? The stuff I did in the past were pretty low (audio range) so $$$ were not required. There are also pretty fast ADCs in modern MCUs, but that's a bit out of my experience.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 12, 2025, 01:17:20 am
content: Let's say audio+. Up to 100KHz would be nice but not required.

author: BillyO
author_rank: Super Contributor
timestamp: September 12, 2025, 01:35:55 am
content: Well, if circa 20kHz or so is okay, I'd recommend a decent audio card or USB audio interface (Audiobox, Focusrite). Beyond that, custom interfacing and coding are the main challenges. But if you can get by with a commercial card or USB interface, then free software like Audacity will allow you to capture and store the waveform, then even use MS Excel to compare the captured waveform to an ideal triangle.Of course, as suggest by ledtester, there are some pretty slick MCUs out there today that could probably get you up to 100kHz if you are a decent C/C++ coder to do the initial acquisition.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 12, 2025, 02:01:35 am
content: Thanks.Probly getting a bit ahead of myself here, but I have used my sound card as input source.I program (Win32) in assembly language.Recently wrote a program to record WAV data using the sound card, so I know how to look at data using the Waveform Audio API.

author: radiolistener
author_rank: Super Contributor
timestamp: September 12, 2025, 05:26:20 am
content: If you just want to check the linearity of a triangle waveform you don’t need to write your own recording and analysis code in assembly language. Simply record the signal with standard software like Audacity, save it as a WAV file, and then analyze it in Octave. That will be much faster and easier than writing custom Win32 assembly code.

author: MrAl
author_rank: Super Contributor
timestamp: September 12, 2025, 05:40:43 am
content: Quote from: Analog Kid on September 11, 2025, 11:12:19 pmHello there,An easy way to test the linearity is to take three samples: one near the start of the ramp v1, one near the middle of the ramp v2, and one near the end of the ramp v3. You can then do some easy math.k12=v1-v2k23=v2-v3k13=(v1-v3)/2For an ideal ramp, these would all be the same k12=k23=k13. If they are different, we could look at:k1223=k12-k23k2313=k23-k13k1213=(k12-k13)/2and then maybe take the average of the absolute values of these three results. That would give us a degree of nonlinearity.You could increase the number of samples to get a better estimate.You might also use oversampling to get more stable and better estimates of the samples themselves.There are other ways like calculating the Fourier amplitudes for various frequencies such as the fundamental, second, third, fourth, fifth, etc. You could then figure out how you want to interpret those results in order to classify the nonlinearity of the ramp. For example, total percent THD over the first 21 harmonics.When you use a differentiator circuit you have to be aware of the noise that will be introduced into the signal. They are known to be noisy so some means to decrease that noise is always a good idea. Perhaps a higher frequency low pass filter for a starting point. In general though, you don't want to use a differentiator circuit if you don't have to.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 23, 2025, 06:03:05 pm
content: I finished writing a small tool to analyze the triangle-wave output of my ICL8038. Made it easier by simply recording a short sample to a .wav file, then opening the file and comparing the samples to the "ideal" waveform. Pretty easy (another of my utilities written in x86 assembly language under Win32).I came up with a pretty piss-poor figure: 3% linearity. (Wave was somewhere in the sub-KHz area.) Far from the manufacturer's claimed sub-0.1% figure. Which was disappointing, as initially the wave lookedso goodon my 'scope.Oh well. I'll have to check some other frequencies. Not too disappointed, though, as I was certainly not expecting lab-quality results from that li'l chip. And it's probably good enough for my limited purposes anyhow.Oh, and no need for differentiation here.

author: gf
author_rank: Super Contributor
timestamp: September 23, 2025, 06:33:49 pm
content: Do you have enough bandwidth and sample rate?Keep in mind that in order to reproduce a triangle wave to within 0.1% accuracy, you need to retain more than the 31st harmonic.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 23, 2025, 07:21:13 pm
content: Quote from: gf on September 23, 2025, 06:33:49 pmI think so; sound card w/44.1KHz sample rate, and I'm guessing ~20KHz bandwidth (wave frequency was less than 1KHz).What do you think?Since the triangle wave is a constant-rate ramp, I wouldn't expect much distortion from the sound card. But who knows?One always needs better test gear ...Here's the wave viewed in Sound Forge:The "ideal" wave is drawn in red.

author: gf
author_rank: Super Contributor
timestamp: September 23, 2025, 08:34:39 pm
content: Quote from: Analog Kid on September 23, 2025, 07:21:13 pmThe first attachment shows an approximation of 1kHz with the first 19 harmonics (assuming a flat bandwidth up to 20 kHz). There is of course noticeable distortion near the corner points. 500 Hz with 39 harmonics (2nd attachment) is clearly better.QuoteA decent sound card should be pretty linear.Can't you plot the captured waveform for visual assessment?

author: gf
author_rank: Super Contributor
timestamp: September 23, 2025, 08:44:49 pm
content: Quote from: Analog Kid on September 23, 2025, 07:21:13 pmLooks like it was a bit high-pass filtered. DC blocker with non-negligible cutoff-frequency?

author: Analog Kid
author_rank: Super Contributor
timestamp: September 23, 2025, 08:52:18 pm
content: Quote from: gf on September 23, 2025, 08:44:49 pmDunno. It went through a LM324 follower. I couldn't connect it directly because my attenuator (potentiometer) on my sound card input overloaded the ICL8038 to the point that it clipped the wave.Could the op amp be the problem? No capacitors or filters in the signal path.

author: gf
author_rank: Super Contributor
timestamp: September 23, 2025, 09:05:51 pm
content: Quote from: Analog Kid on September 23, 2025, 08:52:18 pmI don't think so.QuoteAt least the sound card input is likely AC coupled.What exactly was the triangle frequency here?Added an example for 500 Hz triangle and 100 Hz highpass-cutoff.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 23, 2025, 10:37:23 pm
content: Thanks for your interest in this.I'm going to shelve this temporarily as I have other fish to fry as they say.Will revisit this soon, and run some more tests.

author: Zero999
author_rank: Super Contributor
timestamp: September 24, 2025, 08:18:52 pm
content: If you want to try an op-amp, then put the resistor in the feedback loop. You'll need to add a capacitor to limit the AC gain, in order to eliminate oscillation.

author: TimFox
author_rank: Super Contributor
timestamp: September 24, 2025, 10:34:54 pm
content: In your simulation, the triangle wave is ideal.However, the added capacitor C2, necessary to avoid oscillation, causes the non-ideal rounding of the square-wave transitions, so the square wave is not a goofy measure of the linearity of the triangle waveform.

author: David Hess
author_rank: Super Contributor
timestamp: September 24, 2025, 10:52:29 pm
content: The method I commonly see to test linearity of a triangle wave is to digitize it and check the histogram, which also works for sine waves. This of course assumes that your digitizer has better linearity than the signal. An ultra-linear triangle wave, or low distortion sine wave, can be used to test digitizer linearity using the histogram.

author: BillyO
author_rank: Super Contributor
timestamp: September 25, 2025, 02:11:04 am
content: Quote from: Analog Kid on September 23, 2025, 07:21:13 pmLinearity is low because the lines between peaks are curved and this is not a good metric for testing the fidelity of the waveform. However, that does not mean the waveform sucks. It looks pretty good. I'd bet that if you did a FFT analysis on it you'd find it's fairly good. You could do an FFT on the signal in question, or use some statistical analysis software to compare it with ideal WRT deviation. But just eyeballing it, it's not bad.Here's the wave viewed in Sound Forge:

author: Analog Kid
author_rank: Super Contributor
timestamp: September 25, 2025, 03:40:16 am
content: Quote from: BillyO on September 25, 2025, 02:11:04 amYou're right, it doesn't look bad.I was more concerned about the linearity value I got: 3%*vs. the manufacturer's claimed <0.1%.Considering the source--a relatively cheap chip with just a few externals--it's pretty good.So what do you think: would this be at all suitable to drive a class D amplifier? I'd think that application would rely on high linearity to work well (minimal distortion).I'm planning on packaging this up into another of my tin-based pieces of test equipment. Nice to have a square/sine/triangle generator on the bench.*The formula I used was max.deviation / wave height * 100.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: September 25, 2025, 03:56:28 am
content: Quote from: Analog Kid on September 25, 2025, 03:40:16 amYou might try it under the test conditions specified. A 100k resistive load. The test conditions also define supply voltages and other resistances. It would be a bit disappointing if the performance dropped that much with other operating conditions that seem quite reasonable.

author: MrAl
author_rank: Super Contributor
timestamp: September 25, 2025, 08:10:06 am
content: Just to note, when we charge and discharge a capacitor with a constant current source, we get a perfect triangle.If we do not use a constant current source and just a resistor from a voltage source, we still get a good triangle if we only let the capacitor charge up to a fraction of the voltage of the voltage source. That's because during the first time constant it is almost a triangle already, and if we go 1/10^th of that, we get a pretty clean triangle. You can check it with Fourier to make sure it meets your needs.

author: gf
author_rank: Super Contributor
timestamp: September 25, 2025, 08:32:00 am
content: Quote from: Analog Kid on September 25, 2025, 03:40:16 amHmm, unlikely that the chip misses the specs by that much.I think it is a measurement error, possibly (or even llikely) due to the low-frequency limit of the sound card.QuoteThe blue curve? For open loop PWM, not really. A closed feedback loop can improve linearity, though.[ But as said above, be skeptical; don't consider the blue curve as if it were the ground truth. ]Quote from: MrAl on September 25, 2025, 08:10:06 amThe ICL8038 does that, according to the block diagram in the datasheet.

author: TimFox
author_rank: Super Contributor
timestamp: September 25, 2025, 02:48:36 pm
content: Quote from: MrAl on September 25, 2025, 08:10:06 amCharging and discharging capacitor with a current source: the practical accuracy of this method depends on the finite output resistance of the current source and the input resistance of the buffer amplifier that follows. A possible improvement is to wire the capacitor as feedback around a high input impedance op amp driven through a finite resistor from a switched voltage source.

author: David Hess
author_rank: Super Contributor
timestamp: September 25, 2025, 04:58:21 pm
content: Quote from: TimFox on September 25, 2025, 02:48:36 pmAn operational integrator has its own set of limitations, especially since bandwidth is limited by the requirement for unity gain stability.Fast accurate integrators use switched current sources to drive a capacitor, with the currents switched after the current sources allowing high impedance and low charge injection. You can find these types of designs in old but fast discrete function generators.

author: Zero999
author_rank: Super Contributor
timestamp: September 25, 2025, 05:57:55 pm
content: Quote from: TimFox on September 24, 2025, 10:34:54 pmYou'll get the same problem doing it the digital way, because the anti-aliasing filter will have the same effect.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 25, 2025, 06:28:58 pm
content: Quote from: CatalinaWOW on September 25, 2025, 03:56:28 amWell, since I ran it into an opamp follower I figured that the extremely high input impedance wouldn't unduly load the triangle-wave output. Are you saying that I should put a 100K resistor as a load? I can try that.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: September 25, 2025, 10:20:08 pm
content: Quote from: Analog Kid on September 25, 2025, 06:28:58 pmYour "schematic" shows an RC filter attached to the chip. It is unclear whether your follower precedes or follows the filter. Either way you are providing a different load than specified in the test conditions. In tracking down the discrepancy I would start with identically matching the test setup where they specified the performance. If it is good under that condition you can start tracking what things effect linearity. If not, you have to suspect either a bad chip (manufacturing defect, bad clone or perhaps damaged, ESD) or just a manufacturer whose marketing department has run wild.

author: TimFox
author_rank: Super Contributor
timestamp: September 25, 2025, 10:23:11 pm
content: When coupling non-sinusoidal waveforms through a C-R filter or similar, the slight phase error introduced at frequencies far from the fundamental frequency, where the amplitude error is negligible, can make a noticeable difference to the wave's shape.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 25, 2025, 10:40:02 pm
content: Quote from: CatalinaWOW on September 25, 2025, 10:20:08 pmSorry, my bad.The setup I used to record the wave has no differentiating filter; I abandoned that approach after reading replies here.I just connected the ICL8038 straight to the LM324.Should have been clear about that earlier.

author: Terry Bites
author_rank: Super Contributor
timestamp: September 26, 2025, 04:30:12 pm
content: A small value resistor is needed between the capacitor and the ninv input for stability.

author: MrAl
author_rank: Super Contributor
timestamp: September 26, 2025, 07:35:47 pm
content: Quote from: TimFox on September 25, 2025, 02:48:36 pmIt was a theoretical statement. The more practical was shown after that where we do not charge the capacitor much and use that relatively straight slope. Of course the required accuracy always depends on the application not on general principles.

author: MrAl
author_rank: Super Contributor
timestamp: September 26, 2025, 07:38:30 pm
content: Quote from: David Hess on September 25, 2025, 04:58:21 pmHi,As I was saying in another post, It was a theoretical statement. The more practical was shown after that where we do not charge the capacitor much and use that relatively straight slope.Of course the required accuracy always depends on the application not on general principles. For a certain battery charger design the brief capacitor charge method was more than good enough, and for that all we need is a resistor and a low current rectangular wave drive.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 26, 2025, 07:47:30 pm
content: Just a note to all: I amnotusing a differentiator at this point. No capacitor. So no need to comment on that any more.At this point I'm analyzing the triangle wave directly.Further research forthcoming from Analog Kid Laboratories, GmbH.

author: MrAl
author_rank: Super Contributor
timestamp: September 27, 2025, 07:42:22 am
content: Hi again,It might be interesting to look into integration methods. When you integrate a ramp you get an exponential t^2 which can probably be arranged (with some more support circuitry) to generate a near sine wave. It gets pretty close to a sine wave (see attachment).In the attachment, the blue and red waves are combined to create the near cosine wave which is green. The blue and red waves are derived from the integration of the triangle which creates t^2 type waves. The THD is not bad so it would be good for some things.Ignore the dashed parts of the red and blue waves they are just artifacts from making the drawing using the waves shown in the upper right hand corner, and %pi is just pi (3.14159...).

author: Analog Kid
author_rank: Super Contributor
timestamp: September 27, 2025, 07:53:20 am
content: Here's how the 8038 converts triangle to sine waves:What do you think of that?

author: MariuszD
author_rank: Regular Contributor
timestamp: September 27, 2025, 12:59:06 pm
content: Instead of a capacitor Cext, you can connect a potentiometer and a high-resolution milliammeter. It is possible to statically measure the output resistance of current sources and calculate non-linearities in the waveform.

author: MrAl
author_rank: Super Contributor
timestamp: September 27, 2025, 06:41:50 pm
content: Quote from: Analog Kid on September 27, 2025, 07:53:20 amThat uses analog wave shaping using transistors. It's an old chip too, obsolete I think. There was a higher speed version out too for a while but that one is gone too some years back. There's also a diode version.The sine output is not that good though not something you'd want to use for fine audio testing.

author: ledtester
author_rank: Super Contributor
timestamp: September 27, 2025, 07:27:04 pm
content: Quote from: Analog Kid on September 27, 2025, 07:53:20 amWithin the last month the YouTube channel "Kludges from Kevin's Cave" has started a video series on the diode ladder sine shaper circuit that appeared in AoE.He does a good job explaining the analysis of the circuit.Links:The Diode-Ladder Sine Shaper - Introductionhttps://youtu.be/LhjyPiGYvoIThe Delta-Wye Equivalencehttps://youtu.be/U4_WVE8NHMADiode Ladder Sine Shaper part 2https://youtu.be/HmLgc34ZESAYou can skip to 21:00 in the last video to see him test and fine tune the circuit.

author: Zero999
author_rank: Super Contributor
timestamp: September 27, 2025, 09:03:49 pm
content: Quote from: Analog Kid on September 27, 2025, 07:53:20 amHere's another sine wave shaper circuit built with diodes. I've built before and it works well enough.

author: David Hess
author_rank: Super Contributor
timestamp: September 27, 2025, 10:03:28 pm
content: There are many sine shaping techniques, including using logarithms, multipliers, and a differential pair.https://www.eevblog.com/forum/projects/generating-sine-with-triangle-and-multiplier/msg5972899/#msg5972899The best seem to achieve between 0.1% and 0.25% distortion, which is good enough for some audio work.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 27, 2025, 10:23:53 pm
content: Quote from: David Hess on September 27, 2025, 10:03:28 pmHow do those conversion methods compare with generating a sine wave in the first place, like with a good Wien bridge oscillator?

author: David Hess
author_rank: Super Contributor
timestamp: September 28, 2025, 02:00:15 am
content: Quote from: Analog Kid on September 27, 2025, 10:23:53 pmThey do not compare. The best Wien bridge oscillators can produce sine waves with parts per billion distortion, which is what is needed to test the performance of 20+ bit ADCs. These are better than the best DACs.There are at least 2 designs for these super Wien bridge oscillators out there. Linear Technology did one of them. Most applications do not require this kind of performance.

author: MrAl
author_rank: Super Contributor
timestamp: September 28, 2025, 12:27:18 pm
content: We seem to be missing some replies from this thread all of a sudden.Is someone deleting replies?

author: Zero999
author_rank: Super Contributor
timestamp: September 28, 2025, 10:06:36 pm
content: I built a Wien bridge oscillator awhile ago. Here's the schematic.I constructed it on a breadboard, which I know isn't the best way, but I thought I'd try it, keeping it as small as possible.I went for 400kHz, which is quite high for this type of oscillator.R1 and R2, form a potential divider with an output impedance equivalent to their values in parallel, to the non-inverting input, so a resistance of 820/2 = 410R.R3 = 390R.For simplicity, consider R to be 400R, which should be near enough.C = 1nF.f = 1/(2π*400*10-9) = 400kHz.Note: the C1 and C3 are connected to +V, to avoid the risk of the TL071 going into phase inversion (when the functions of the +- inputs exchange, due to the common mode range limits being exceeded). If you're using a different op-amp say one which works with its inputs down to the negative supply, you'll be better off connecting them to 0V. It makes no difference, once the circuit is running, as both rails can be considered to be ground, at AC, since the power supply should have a low impedance C4 AC couples them together, for good measure.At first I used the TL071, but the frequency was much lower than it should be, at 220kHz, which was also a little distorted, which is evident from the fact that the peaks are asymmetrical, even though the oscilloscope is set to AC coupled. Probably because it didn't have enough gain at that frequency and the slew rate was also too low.So I switched it for the AD817 and the frequency was 454kHz, which was a little high and I put down the to the old stock ceramic capacitors I used, which had degraded, giving a slightly lower capacitance than expected.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 28, 2025, 10:17:00 pm
content: Kewl.Any idea what the THD% of your successful rig was?

author: TimFox
author_rank: Super Contributor
timestamp: September 28, 2025, 10:24:28 pm
content: Which dielectric do the tuning capacitors C1 and C2 use?If you are shooting for very low THD, they should be NP0/C0G ceramic or film (polypropylene or polystyrene).

author: David Hess
author_rank: Super Contributor
timestamp: September 29, 2025, 12:24:55 am
content: Quote from: Analog Kid on September 28, 2025, 10:17:00 pm0.003% is possible with the simple lamp design at lower frequencies. Then another factor of 10 improvement can be made by adding another operational amplifier for common mode suppression.

author: TimFox
author_rank: Super Contributor
timestamp: September 29, 2025, 01:05:36 am
content: Decades ago, I read a paper in the Hewlett-Packard journal where the ultimate limit to the distortion in the bulb-stabilized Wien-bridge oscillator was the temperature-induced variation in the filament resistance.This causes second-harmonic distortion.They suggested evacuating the bulb, but I don’t think they tried it.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 29, 2025, 01:18:33 am
content: Couple things:1. Let's say a guy wanted to build himself a nice sine-wave generator based on that circuit just a few posts back.Let's further say that he'd want to be able to select from several frequencies, say something on the order of a few Hz up to a couple hundred KHz. Not necessarily continuously-variable over the full range, although some adjustment here would be nice; several fixed frequencies would be adequate.How would that guy go about selecting R and C values to make this work with that circuit?I assume that there are some tradeoffs and limitations that need to be taken into account, but I have no idea what those might be.2. It's always struck me as odd that all the good Wien bridge circuits use a lowly light bulb as the variable-resistance element.Is it possible to build such an oscillator without a light bulb?Isn't the bulb's function just to get oscillations started? or does it have some kind of stabilizing role during operation?

author: TimFox
author_rank: Super Contributor
timestamp: September 29, 2025, 02:08:09 am
content: 2. Thermistors (PTC or NTC) have been used for stabilization, in similar manner to the low-power incandescent bulb. The amplitude stabilizes where the thermal resistance gives the 1/3 ratio referred to below.1. Discrete value networks are common for Wien-bridge or bridged-Tee oscillators. For wide range discrete oscillators, the capacitors are typically switched by factors of ten and the resistors over a decade.For the Wien-bridge, normally the tuning resistors are equal and the capacitors are equal, so the frequency is 1/(2pi R C). The response of the RC branch at that frequency is 1/3, so the resistive branch (including stabilizer) must also be 1/3.The range of resistors in the tuning branch could be 10 k to 100 k to cover a decade.You can choose a few values from the full set needed for a wide range.

author: MrAl
author_rank: Super Contributor
timestamp: September 29, 2025, 05:51:19 am
content: Quote from: Analog Kid on September 29, 2025, 01:18:33 amHi there,The function of the bulb is to automatically adjust the gain of the circuit. That's because the frequency domain function has to sit right on the jw axis. Too little gain and it drifts into the left half plane which means an overdamped response where oscillations cease, too much gain and it drifts into the right half plane where it becomes instable with the amplitude constantly increasing which eventually leads to the output pinning to one of the power supply rails. It has to be a nonlinear function so that it can ease off if the amplitude decreases and become more significant if the amplitude increases. To keep the oscillations a perfect sine, the gain has to be a specific value, exactly. It's not possible to design a circuit that has an exact gain, and the exact value may have to change slightly during environmental changes, so the gain has to be automatically adjusted on the fly.There are other ways to do it such as with diodes, but because a light bulb has a filament, its resistance changes due not to instantaneous changes in the circuit, but to average changes, which makes it react slowly. This means the gain adjusts itself slowly which does not cause much distortion in the output wave. A diode would tend to clip the output, and even though it would only be slight it would be enough to cause distortion. With the bulb, we can look at it like an ordinary resistor that is linear for a time, and linear elements do not cause distortion because they cannot create new frequencies. Over time this resistance changes very slowly so the distortion is very minimal over many cycles with each cycle changing very, very little.Other ways to do it involve and FET, AGC circuit, microcontroller adjustment, which can provide really good stability. Last is probably the thermistor which would have a warmup time. It also has to have a slow response. Perhaps one made by Murata like a barium titanate PTC type.It is interesting to analyze one of these circuits and find that the gain has to be EXACT or it flies off to one side of the complex plane jw axis and will not come back without some sort of adjustment to the gain. If the gain has to be 3 then it has to be 3.000000000000000000000000Since that cannot be done in any circuit, the gain has to be automatically adjusted. This keeps the average at exactly 3. It will drift from maybe 2.999999 to 3.000001 which means the wave amplitudes will increase slightly and decrease slightly as the circuit runs over time.

author: Zero999
author_rank: Super Contributor
timestamp: September 29, 2025, 08:41:12 am
content: Quote from: Analog Kid on September 28, 2025, 10:17:00 pmProbably not very good. I didn't perfom any tests on THD, but the traces don't look that good.Quote from: TimFox on September 28, 2025, 10:24:28 pmOrdinary Z5U. Yes, there are much better options. This was just a proof of concept.Quote from: Analog Kid on September 29, 2025, 01:18:33 amIt's fairly easy to make it adjustable. A dual gang potentiometer could be used for the frequency determining resistors. In my circuit the biasing potential divider is used as one of the resistors, which would need to be changed, but that's fairly easy.

author: David Hess
author_rank: Super Contributor
timestamp: September 29, 2025, 11:19:12 am
content: Quote from: TimFox on September 29, 2025, 01:05:36 amThat is right, but the distortion from the bulb increases as the frequency decreases. Several bulbs can be used in series to reduce the distortion.Quote from: MrAl on September 29, 2025, 05:51:19 amThe Linear Technology parts per billion design uses an operational transconductance amplifier as the variable gain element. CdS photocells work very well but have limited availability.

author: TimFox
author_rank: Super Contributor
timestamp: September 29, 2025, 02:40:13 pm
content: Besides their notorious non-linearity, ordinary Z5U ceramic capacitors have broad tolerance compared with good film or C0G/NP0 ceramics.The increase in distortion at low frequencies with bulb stabilization is due to their finite thermal time constant, so the resistance varies during the low-frequency cycle, but if that time constant is increased, the settling time of the stabilization increases.

author: David Hess
author_rank: Super Contributor
timestamp: September 29, 2025, 03:38:17 pm
content: Here are the pages from Jim Williams' application note which discuss lamp operation at low frequencies.

author: TimFox
author_rank: Super Contributor
timestamp: September 29, 2025, 04:07:25 pm
content: Quote from: MrAl on September 29, 2025, 05:51:19 amElaborating on that discussion of stabilization requirements, the exact ratio of 1:3 assumes exactly equal Rs and Cs in the reactive legs of the bridge, so the actual stabilization network has to adjust to the real component ratios, that will change as the values change when tuning to a different frequency.

author: Zero999
author_rank: Super Contributor
timestamp: September 29, 2025, 05:10:16 pm
content: I suspect the open-loop gain of the op-amp is a greater factor, than the matching of R and C. If it were just component tolerances, then adding a trimmer to one of the gain resistors would work, but it can't, since the open-loop's open loop gain is far too unstable.

author: TimFox
author_rank: Super Contributor
timestamp: September 29, 2025, 06:14:44 pm
content: Quote from: Zero999 on September 29, 2025, 05:10:16 pmIn a practical oscillator, the matching will change a bit as the unit is re-tuned.Assuming a perfect ratio of 1:3 in the Wien bridge's reactive branch, the closed-loop gain of the op amp and the resistive branch must be 3 V/V: that allows one to predict the effect of the finite open-loop gain of the op amp, which is really good at low frequencies but falls off at higher frequencies.Discretely-tuned oscillators typically have 0.1% tolerance in the switched resistors and < 1% tolerance in the range-setting capacitors.

author: MrAl
author_rank: Super Contributor
timestamp: September 29, 2025, 09:53:43 pm
content: Quote from: TimFox on September 29, 2025, 04:07:25 pmHello there,I probably should not have quoted the 3.000 value because that just happens to work with the values we normally see like R2=R1 and C2=C1. What I really meant though was that IF (and only IF) we need a gain of 3, then we need exactly a gain of 3 in theory. That means 3.00000000000000000000000000 with unending zeros. However, to better illustrate the point, if we need a gain of 3.5 then we need exactly a gain of 3.5 like: 3.5000000000000000000000 with unending zeros. Likewise, if we need a gain of 4 then we need 4.000000000000 with unending zeros, and if we need a gain of 103 then we need 103.0000000000000000 with unending zeros.This is all in theory, but the point is that whatever the gain needs to be to maintain oscillations that is exactly what we need and any variation will mean it does not work. So we need automatic gain correction of some kind.What I did not do yet was analyze what happens if the required gain varies too far from 3.0, does that introduce problems or not. That would be with component values we do not normally see. I don't have time right now to look too much more into this though maybe later or tomorrow.

author: MrAl
author_rank: Super Contributor
timestamp: September 29, 2025, 09:59:06 pm
content: Quote from: Zero999 on September 29, 2025, 05:10:16 pmActually it is both, and more precisely, anything that can change the gain which includes the impedance ratios between the two feedback components and the two grounded components. Those components set the required gain. If the open loop gain of the op amp changes that could cause slight changes in the overall gain too so that would mean another adjustment, but I think that would be very small. The open loop gain sets the error in the closed loop gain. We could look into this more carefully with a more detailed analysis.

author: TimFox
author_rank: Super Contributor
timestamp: September 29, 2025, 10:05:53 pm
content: Besides the magnitude of the op amp gain, the closed-loop phase shift of the amp and the resistive leg of the Wien bridge will depend on frequency.At reasonable audio frequencies, the open-loop phase shift is close to 90o, and the loop gain (open-loop times feedback fraction) reduces that to a closed-loop phase shift.Oscillation occurs when the total phase shift, including the reactive leg, is zero: theQfactor relating phase shift to frequency difference is much lower for R-C Wien-bridge and twin-Tee circuits than for L-C or crystal resonators.If required, this can all be analyzed algebraically or with Spice, since it's inherently a linear circuit question.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 29, 2025, 11:48:41 pm
content: Thinking of adapting @Zero999's circuit here to provide multiple frequencies:Following @TimFox's suggestions for R values (10K-100K), and suitable C values, this should work OK, right?Would there be any "forbidden" combinations of R and C? Meaning ones that gave less-than-optimum performance, as in greater distortion? (I'm reminded of the time I flew with a friend in his Mooney, and he pointed out that the red-marked zones on the engine tachometer were speeds that you should avoid due to harmonic imbalance and vibration.)I guess if there were any such combinations I could just avoid using them.I'm doing this same sort of thing with my ICL8038 to give me a frequency range.

author: TimFox
author_rank: Super Contributor
timestamp: September 30, 2025, 03:12:40 am
content: Quote from: Analog Kid on September 29, 2025, 11:48:41 pmNo "forbidden" combinations come to mind: if you keep the R values reasonable for the op amp (e.g. 10k to 100k), the corresponding capacitor values will work.Since precision capacitors are more expensive than precision resistors, if you only need a few frequencies you might be able to use fewer capacitors, but I don't recommend more than 10:1 ratio on the resistors, although that can be done carefully. A typical Heathkit-quality generator might have two decade knobs for the R's and one 4-position range switch for the C's. (To get linear frequency dependence, the decade resistor knobs are wired in parallel for each R.)Note: I think your polarized power capacitor is in the wrong place. Personally, I like to use split supplies for this type of circuit.

author: Zero999
author_rank: Super Contributor
timestamp: September 30, 2025, 07:03:27 am
content: Quote from: TimFox on September 30, 2025, 03:12:40 amWhy? Whether the capacitor is connected to the positive or negative rail is somewhat arbitrary. It depends on which rail the AC signal is referenced to. I chose +V in my circuit, because I origionally used the TL071 and wanted to ensure the input voltages didn't go to the negative rail, causing phase-inversion, when power was applied.If you're going to reference the AC signal to the negative rail, then put the capacitor between the potential divider and the negative.

author: David Hess
author_rank: Super Contributor
timestamp: September 30, 2025, 09:32:08 am
content: I have not tested this circuit for distortion, but frequency can also be controlled by a single resistance, as shown below.

author: MrAl
author_rank: Super Contributor
timestamp: September 30, 2025, 02:02:04 pm
content: Quote from: TimFox on September 30, 2025, 03:12:40 amHi again,We could get 'forbidden' combinations that would not be unusual. This would happen when the gain is not exactly equal to the required gain for oscillations as mentioned before.To be more exact, it looks like we have to satisfy this:C2*R2*R3+C1*R1*R3-C2*R1*R4=0With the values C1 and R1 the set in parallel and C2 and R2 the set in series, and R4 the feedback resistor and R3 the bulb.If the left side is greater than zero oscillations will start but then die down.If the left side is less than zero the oscillations will increase indefinitely if we have an op amp that can put out an infinite voltage. With a clamped output such as with a real-life op amp, we probably get square waves.Just to note as per other replies, with the open loop gain of the op amp being other than infinite, the analysis gets a lot more complicated.

author: TimFox
author_rank: Super Contributor
timestamp: September 30, 2025, 02:39:26 pm
content: So long as the two Rs and two Cs in the reactive branch are equal, the gain determined by the amplifier and the two resistors in the resistive branch will always be 3 for stable oscillation.With a cold bulb (or equivalent), the gain must be >3 initially for startup, but reduce to the correct value as the bulb warms up. The bulb or other stabilization circuit must have sufficient range to compensate for small deviations due to component tolerance and amplifier gain/phase.No “forbidden” values, but the maximum frequency depends on the amplifier’s capability.

author: MrAl
author_rank: Super Contributor
timestamp: October 01, 2025, 07:49:47 pm
content: Quote from: TimFox on September 30, 2025, 02:39:26 pmHi,Yeah it gets interesting, and sometimes the gain would have to be much higher if the R and C values vary enough.Now as far as the minimum gain is, that would be the absolute minimum gain we could use for any values. It think that is 1 from this:G=R2/R1+C1/C2+1or if we force C2=C1 then it looks like 2 from the same:G=R2/R1+C1/C2+1G=R2/R1+1+1and with very a high value for R1 thenG=2

author: TimFox
author_rank: Super Contributor
timestamp: October 01, 2025, 09:17:02 pm
content: But normally, R2 = R1 to within tolerance in a Wien-bridge oscillator.This assumes C2 = C1 (again, typical application) and their tolerance is probably wider than that of the two resistors in the reactive arm of the bridge.

author: MrAl
author_rank: Super Contributor
timestamp: October 02, 2025, 07:09:34 am
content: Quote from: TimFox on October 01, 2025, 09:17:02 pmHi again,Well in my little investigation I did not want to assume anything, and that means we gain intuition for any component values, and that of course means anything more typical could be covered easily.