Soft and hard clipping together?

Started by PBE6, March 24, 2014, 04:45:42 PM

Previous topic - Next topic

composition4

#40
Quote from: PRR on October 31, 2014, 04:58:48 PM
You usually put a resistor (~~1K) between the opamp and the diodes. Otherwise the diodes must clamp the full ~~30mA which the opamp can supply. Power supply demand goes way up. The clipping is quite abrupt.

Then I'd mix with ~~5K resistors. The passive mixer will work OK.

Sorry yeah, both of those things... Forgot resistor after opamps and didn't change the resistor values from default... Quick n dirty ;)

Anyway my thoughts are that it'd probably sound just like any other clipping with diodes, but if someone has a spare half hour to breadboard it, go ahead! Obviously you had, say 4 stages, you would want the input signal to reach a peak amplitude of 2.8V at least (4x0.7V) so maybe have an adjustable gain stage that allows you to adjust the input signal level to get the maximum effect of the clipping diodes

PBE6

Quote from: electrip on October 31, 2014, 05:47:51 PM
Quote from: PBE6 on October 30, 2014, 01:51:38 PM
Haven't gone back to try this in a while, but I was just noodling around on Excel and made some pretty pictures I thought I would share.
This is what soft clipping followed by hard clipping looks like (theoretically):

[ommitted pics]

(In all of the above, the blue dashed line is the input signal, the green dashed line is after soft clipping and the red solid line is after soft & hard clipping)

Will have to find out what these sound like and take some actual readings tonight.

Those waveforms don't look 'right'.
Whats the math behind it (formula)?

electrip

Original signal is just a sine wave.

Soft clipping is:
• v(clip) = v(in) {v(in) < v(diode)}
• v(clip) = v(in) + v(diode) {v(in) > v(diode)}

Hard clipping is:
• v(clip) = v(in) {v(in) < v(diode)}
• v(clip) = v(diode) {v(in) > v(diode)}

teemuk

#42
Quotesomething like that with 5 or 6 stages

Build it.  :icon_wink:


Anyway, the depicted circuit is simply going to "average" the clipping: The clipping threshold is always less than that of the "longest" diode string and more than that of the "shortest". The outcome is practically equivalent to plain diode clipping but with different forward voltage. If all clipping devices have the same characteristic curve the tranfer function of the circuit won't even change drastically.

As is, IMO, it's a complex circuit to gain practically nothing. An approach where you average between a hard characteristic curve and soft characteristic curve (instead of different Vf's) might make a little more sense but even then the result is just the average of them: Not quite soft clipping but not quite hard either. (I think you folks have an answer there how the waveform should end up looking like). In practice you can usually achieve the same characteristic by easier means as well, like simply varying series resistance of the clipping diode strings.

But it's a wortwhile experience to build it and discover that despite all complexity it isn't really performing in a groundbreakingly different manner from any other diode clipping scheme.

An interesting thing, BTW, happens to waveforms when you sum LP, BP, and HP clipped signals in similar parallel arrangement: The clipped waveforms do not have the traditional "tops clipped off" -look but start to resemble more the shape of Mesoamerican pyramids.

ashcat_lt

#43
Quote from: PBE6 on November 01, 2014, 03:29:40 AM
Original signal is just a sine wave.

Soft clipping is:
• v(clip) = v(in) {v(in) < v(diode)}
• v(clip) = v(in) + v(diode) {v(in) > v(diode)}
That ain't right dude.  It will almost work if you change the first one to be v(clip) = gain*v(in){gain*v(in)<v(diode)} and the second condition to {gain*v(in)...}   In this type of circuit, if there's no gain, then there's no clipping at all, period.  There shouldn't be that big infinite slope step where the diodes "turn on".  

Quote
Hard clipping is:
• v(clip) = v(in) {v(in) < v(diode)}
• v(clip) = v(diode) {v(in) > v(diode)}

Both of these, of course, are for ideal  diodes that actually act like switches.  Real diodes don't, but I guess it's close enough for the basic thing you're trying to show.

If you want to get a lot closer, use the hyperbolic tangent (scaled for the Vf of the diode) on the gained up input signal for the hard clipping, and then add the original (unity gain) signal to that for the soft clipping.

PBE6

The gain in my simulation is 1. The signal strength (2 V) happens to be above the diode threshold, so there is clipping. I could adjust the equations to require a gain input instead of signal strength, but it accomplishes exactly the same thing so why bother? A practical distortion pedal would include a gain control as you say, as real world guitar signals are often on the order of 0.1 V and would not clip unless boosted.

With regard to the infinite slope step, you're right that would not happen in real life. However, if you measure the output of a Tubescreamer-style clipping stage it's really not that far off (visually speaking):
 
http://www.bteaudio.com/articles/TSS/TSS.html

In answer your second comment, yes my simulation uses ideal diodes. When I have some time it would be fun to implement a better diode model to get a more realistic curve (especially if I ever figure out how to do Fourier analysis on the Excel output to estimate the harmonic content of the clipped signal), but ideal diodes are fine for showing the general behavior of signals clipped soft then hard. I will give the hyperbolic tangent method a try.

ashcat_lt

Nope.  The only way the TS-style soft clipper works is if there is actually gain when the diodes are "off".  Otherwise, it's  just plain unity gain.  Fine, it goes over the Vf of the diode...and it's still unity gain, so no change.

The steep slope you  see on the bottom of that new image is the effect of the gain on the input signal.   In your pictures, there is a section around 0 which is a lesser slope (equal to that of the original curve) then a sudden infinite step up when it hits the Vf of the diode.  It is completely different.  Your thing for soft clipping is nowhere near correct.  Sorry.

PBE6

Ah! Just ran through a simple calculation, yes you're right it doesn't work without a voltage divider in the feedback loop.

I'll try a diode different model when I get a chance.

ashcat_lt

Like I've said a couple times, "soft clipping" is almost exactly the same thing as adding the "hard clipped" signal (after gain) to the unity gain original signal.  Definitely close enough for what you're trying to do. 

teemuk

^ This. And if you think about it, push-pull circuit's clipping distortion is also largely combined of clean signal (from one half) summing up with clipped signal (from the other half).

PBE6

I finally got a chance to redo my soft clipping model and do some experiments on the breadboard with the scope and the guitar. Here are a few musings - pretty pictures to follow! :)

Based on the previous discussion, I decided to try a more realistic diode model and ended up choosing the Shockley diode equation:

http://en.m.wikipedia.org/wiki/Diode#Shockley_diode_equation

This model has a theoretical basis and gave good results, but required me to use a brute force numerical solution to find vD. However, now that I have my Excel sheet set up to do that it will be straightforward to try other diode models (like the hyperbolic tangent model mentioned previously in this thread) and see how they compare.

In a Tubescreamer-style gain stage with diodes in the feedback loop, the current flowing out of the ground resistor is equal to the current flowing through the diode plus the current flowing through the feedback resistor (omitting the capacitors for simplicity):

iG = iD + iF

v-/Rg = iD + (vout - v-)/Rf

The voltage (vout - v-) is simply the voltage across the diode vD. Also, the opamp will apply gain to keep both inputs equal, so v- = v+ = vin. Subbing these into the above equation gives:

vin/Rg = iD + vD/Rf

Tubescreamer gain is controlled by varying Rf. High values of Rf force more current through the diode while low values of Rf steal current away from it. In the extremes, Rf = 0 bypasses the diode completely creating a unity gain buffer while Rf = infinity  forces all the current through the diode giving maximum distortion. Interestingly enough, this second case can be achieved by removing Rf from the circuit altogether! This result surprised me, but was verified on a bench circuit. It seems that as long as current can flow out of the feedback loop through Rg, the diode will conduct (one caveat - if there is no capacitor in the grounding path, Rg must be connected to Vref instead of ground or the circuit becomes a buffer).

One other interesting thing about this equation is that iG = vin/Rg sets the total current for the feedback loop. Decreasing the absolute value of Rg will increase the amount of current flowing through the diode,  pushing it further up the conduction curve. This will result in slightly more volume and distortion due to the small rise in vD, but will also affect the quality of distortion by changing the shape of the diode conduction knee. This effect is fairly subtle, but it is interesting to hear the difference between two circuits with the same gain ratio settings (1 + Rf/Rg) but vastly different values of Rg.

A fun experiment to try is to remove Rf and use a pot for Rg (connecting it to Vref if there's no ground cap). Removing Rf keeps the distortion maxed out, allowing you to audition different values for Rg while keeping the gain fairly constant.

(At very low Rg settings the waveform changes from the familiar bullet-shaped Tubescreamer output to a type of slanted square wave which seems to be the opamp clipping..but at Rg = 0 even weirder things start to happen! The output becomes gated, keeping silent as long as the input is below a certain level and then lurching to life when the input crosses the threshold. Weird and broken sounding, but cool in its own unique way.)

Back to the equation. Subbing in the Shockley diode model gives:

vin = Rg*{Is*(exp(vD/(n*vT))-1) + vD/Rf}

Where:
Is = 1 x 10^(-12) A
n ~= 1.2 or 1.3
vT = 0.026 V

(These values gave good results for Si diodes)

Solving this equation for vD is non-trivial, but it does succumb to numerical methods. Using the fact that (vout - v-) = vD as above, we have:

vout = v- + vD

Again the opamp keeps both inputs the same, so v- = v+ = vin. Therefore we have:

vout = vin + vD.

So, knowing the input vin we can solve for vD and then add them together to find vout.

(An alternative method would be to calculate the diode resistance, use that to calculate Rf||Rd, then use that to find the gain, but this method didn't agree with scope observations except at high gain settings. This could be because of precision limitations with my calculation method, or because Rd = vD/iD is the incorrect formula for diode resistance in this case, or because this method doesn't deal with diode voltage drop properly - but in any event the equation above is much simpler to work with and gives good results.)

As noted previously in this thread, this equation shows that a Tubescreamer mixes the clean signal and the diode distortion together in a 1-to-1 ratio. A very similar effect can be achieved (in a more complicated, but perhaps more flexible way) by blending the output of a clipping-diodes-to-ground-style pedal with the original clean tone. I made a simple prototype based on this concept using individual volume controls for the clean and dirty signals, and the results were encouraging but I think its primary use would be to dial in a bit of clean bass in a bass distortion effect.

PBE6

Here are some of my results.

Input 0.25 V
Rf 20k
Rg 10k
Gain 3




Input 0.25 V
Rf 1M
Rg 10k
Gain 101




Input 1 V
Rf 20k
Rg 10k
Gain 3




As you can see, there is better agreement for higher input signals and high gain settings. Adjusting n for each input signal amplitude (1 V vs 0.25 V) seems to help. At this point I'm not sure if the issue is error in the general reasoning, calculation resolution (vD is only calculated to the nearest 10mV), or inherent limitations of the Shockley equation for small currents, but I'm happy with the performance for larger signals.

PBE6

Oops! Just found a glitch in my spreadsheet, the input signal was accidentally referenced to "n" instead of "amplitude". Much better numerical agreement now all around.



PBE6

I've been was messing around with my spreadsheet again - I added a hard clipping simulation (diodes to ground), upgraded my approximation method from brute force to a binary search, and added a crude harmonic content calculation. Here are some further musings..

In a Dist+ style circuit, the signal is first amplified by a non-inverting opamp (or similar) gain stage before passing through a limiting resistor and finally being clipped by a pair of diodes to ground. This circuit can be modified by adding a series variable resistor between the diodes and ground to create a "saturation" control.

The current through the limiting resistor is equal to the current flowing through the diodes-ground resistor combination plus the current flowing through the load. Summing these currents, we have:

(vin - vout)/Rin = iD + vout/RL

This equation shows that the smaller the input resistor, the more current will be available to flow through the diodes (even down to 0 ohms which maxes out the opamp current, although possibly at the expense of stability). Also, the higher the load resistance the more current will be forced to flow through the diodes. Both of these effects will push the diode current further along the conduction curve, modestly altering the harmonic content of the distortion and providing slightly more output voltage. (As will be shown below, the effect of the saturation control is much greater.)

The current flowing through the diode is simply iD, which gives rise to a diode voltage vD. The current through the ground resistor is equal to the current through the diode, which gives rise to a voltage drop of iD*Rg across the ground resistor. The output voltage is then:

vout = vD + iD*Rg

Although it's not immediately apparent by looking at this equation, the addition of resistance to the diode path limits the amount of current flowing through it. The diode current is always iD because that's how it's defined, but in order to have the same current flow through the diode/resistor combination as just the diode alone, the voltage must increase. When Rg = 0, the above simplifies to vout = vD. As Rg increases, less current flows and the diode has a smaller and smaller effect, causing vout to approach vin (provided RL is large enough not to form a significant voltage divider with Rin - which actually isn't the case with the MXR Dist+!). The effect of the saturation control is therefore very similar to a blend control. Contrast this with the Tubescreamer, where the original signal is always present with a gain of 1x and the gain control adds more and more distortion to it.

Subbing the above expression for vout into the first equation and solving for vin, we have:

vin = iD*(Rin + Rg + Rin*Rg/RL) + vD*(1 + Rin/RL)

This form makes it easier to input into Excel, especially when using the Shockley diode equation:

iD = 1E-12*(exp(vD/(n*0.026))-1)

For this circuit, n = 1 seemed to give the best results, in contrast to the soft clipping simulation where n = 1.25 gave the best results.

Using the above equation, I was able to find vD for a given input vin using a binary search. This gave much better results than the previous method. Using the values of vD I was able to calculate iD*Rg, and adding them together gave vout. Here are some results:

Rin = 10k, Rg = 0





Rin = 10k, Rg = 10k





Rin = 1k, Rg = 0





Rin = 1k, Rg = 10k





I was quite happy with the agreement between the measured values and the predicted values - and even happier about the lack of spreadsheet goofs! :D

I also implemented a crude harmonic content calculation, which wasn't perfect but actually performed much better than expected. This involved setting up several columns of sine waves with integer multiples of the fundamental frequency and variable amplitudes. These were summed, and the absolute difference between the summed waveform and the predicted vout data points were calculated. These differences were summed into a total difference, and then I used Excel's Solver plug-in to minimize the total difference by varying the amplitudes. The result was a measure of the harmonic content of the distorted signal.

The results were encouraging. Given a single sinusoid input, hard clipping apparently produces odd harmonics only. A sample result is shown below for Rin = 10k, Rg = 10k (with noise hovering somewhere between -70 to -80 dB):

Measured

1 -4.3 dB
2 noise floor (NF)
3 -27.2 dB
4 NF
5 -36.9 dB
6 NF
7 -49.4 dB
8 NF
9 -60 dB

Predicted

1 -2.3 dB
2 NF
3 -24.6 dB
4 NF
5 -34.9 dB
6 NF
7 -49.5 dB
8 NF
9 NF

The model predicted values roughly 2-3 dB too high for many lower harmonics, and got a bit worse with higher harmonics, but this was still much closer than I expected. It also correctly predicted odd harmonics only, which was another pleasant surprise.

Some things I noticed were that increasing Rg increased the level overall and shifted the spectrum toward the lower harmonics (which makes sense, since it reduces clipping distortion by reducing the effect of the diode) and that lowering Rin increased the distortion and level overall (which also makes sense, since there is more current flowing through the diode), but also that lowering Rin shifted the spectrum slightly toward the lower harmonics (which makes less sense, since more current is available to flow through the diode - although it could be that this change moves the current to a different part of the conduction knee).

What use is any of this? Well, it suggests that you can make subtle alterations to the sound of your hard clipping circuit by varying Rin (say, with a 10k-100k trimpot) and you can make much larger alterations by adding a saturation control.

One suggestion would be to use a large Rin value to increase the higher harmonic content and use a similarly large Rg pot to reduce that higher harmonic content to taste. Another would be to use a small value of Rin (say 1k) to increase volume and decrease higher harmonic content, and use a similarly small Rg to blend and refine the sound even further.

The effect of changing Rin will be subtle, but it's worth trying if you have extra trimpots lying around. Adding a saturation control is a fun mod to make and may breathe new life into your hard clipping pedal.

drolo

Quote from: ashcat_lt on March 26, 2014, 12:39:33 PM
  I personally can't think of any popular designs that have diodes in the feedback path of an inverting opamp stage.
Marshall BluesBreaker / AnalogMan King of Tone :-)

PBE6

Interesting. This type of clipping circuit gives the following current balance:

vin/Rin = -vout*(1/Rf + iD/vD)

And since (v-) - vout = -vout = vD, we simply have vout = -vD.

This type of clipping is exactly the same as standard hard clipping*, except that the signal is inverted. Lowering Rin will provide slightly more diode current, while inserting a blocking resistor in series with the diodes will reduce diode current and act like a blend control.

I wonder what the advantage of using an inverting clipping stage is?

EDIT: *Wrong again! :( See below for a more thoughtful answer...

PBE6

Oops! I'm wrong, inverting clipping shares similarities with hard clipping but it's not the same. Did I mention..oops?

The current balance using a blocking resistor is as follows:

vin/Rin = (vD + iD*Rb)*(1/Rf + 1/(Rb + vD/iD)

When Rb = 0, this simplifies to the expression in the previous post. So far so good. What I didn't realize is that while hard clipping takes a signal and squishes the top without any additional gain, the inverting feedback configuration does apply gain. While the amplitude of a hard clipped signal must be less than or equal the input amplitude, the amplitude of this circuit's output is only bound by the voltage across the clipping path. This means that for small signals, the output can exceed the input. In practical terms this means the output can get much closer to being a square wave (albeit with a slightly rounded top) than hard clipping can:



(I inverted the input graph just to make it look nicer, in reality the input and output will have opposite polarities.)

That's all well and good. What I think is really interesting is that as the series resistance with the diodes is increased, the waveform changes from a gnarly oblong shape to a Tubescreamer shape to a pure gain shape!









Fascinating - while the ground resistor in the hard clipping lets you move from hard clipping to clean, the blocking resistor in this circuit lets you move from fuzz to Tubescreamer overdrive to simple boost! Adjusting the gain also allows you to move from fuzz to hard clipping - 4 sounds in 1!! I'm definitely going to have to build one of these :D

crb3

It's sounding to me like the difference between hard and soft clipping might be that soft clipping is actually log-conversion.

I vaguely recall seeing designs for speech-compression by multiple-diode-breakover log-conversion in old (pre-90's) issues of QST (or was it Ham Radio or 73 or CQ), back when I was first getting into ham radio. I did a quick search but turned up nothing on-topic in the first few screens. Pity; from what little I recall, the stages might have looked like Big Muff Pi stages.

I did glance at the log-conversion pages in Walter Jung's IC Op-Amp Cookbook, and there are some things to experiment with in there, using a transistor in an op-amp feedback loop to log-convert a unipolar voltage, which implies that symmetrical-about-ground conversion using a pair of transistors might be useful. I put this out for those with more time-to-play than I have at present. Maybe one of you even has the relevant QST.