Showing posts with label Soft clip. Show all posts
Showing posts with label Soft clip. Show all posts

Friday, January 31, 2025

Filters clipping - current situation and solution

All three filters clip but some are more extreme than others.

Juno clipping

The Juno filter has a major flaw, it has an output gain stage that clips for anything above 2V out. It outputs 2V from 10V in, which means that all resonance is clipped if it exceeds the max input signal.

JP6 clipping

The JP6 filter clips in the output selector/gain stage, but also slightly internally

Moog clipping

The moog filter clips the least as it has a fairly good soft clipping built-in. The output gain op amp still clips at extremes.


Fixes

I've worked a lot to find the best solution the last few days, and as such has come up with the following approach:

Bus mixer changes

Reduce amplitude from the bus mixer into the filters from max 10V to max 5V. This requires two changes:

- Double the input resistors to the wet/dry amps in the bus mixer, halving the output of the summer

- When turning on serial instead of parallel filters, disable input from sum B. 

- SVF must still somehow have unity gain, if not, chaining input will be too low.

This alone has a huge effect on most clipping, giving double the headroom. 


Reduce the post filter gain

Moog filter

For the Moog filter, this is simply done by using half the CV. It can be done in software for the current version. This stops any leftover clipping in the Moog filter.

Juno filter

For the Juno filter, we add a resistor to the output. This will end up in series with the 18k resistor in the post juno filter gain stage, and reduce the gain. A 22k resistor reduces gain from 5.5 to 2.5. This takes away most of the clipping, though the filter still clips when the resonance oscillation has the same frequency as the input signal. It does however require modification of the juno filter board. This requires some other mechanism, like soft clipping the signal. More on that later.

JP6 filter

For the JP filter, we need to keep unity gain through the filter, so we do the gain reduction in the output mixer. It does not prevent any clipping but is required to keep max levels the same as for the juno and moog filter. This is the simplest solution for now. 

 

Reducing JP clipping

Unfortunately, the JP filter clips very slightly at highest resonance at the point where oscillation is in sync with the signal. This is not easily changed as it happens inside the filter circuit, but it is also the least serious clipping. I will leave it as is for now. It also goes away if reducing the max input slightly, but requires at least another 20% reduction. Perhaps this is best done in software for now.

To prevent other clipping, we have to change the output gain that happens around the output selector. This can be done in two ways: 

- Changing the voice card. This is the correct solution, and should be done for future versions of the card. Gain for all but the BP2 cell is 100/65 = 1.54, so quite a bit of clipping can be removed here. We still may have to add some kind of soft clipping, though. If soft clipping is added, we may choose to reduce the input by the needed 20% and increase the output gain instead to get around the initial clipping.

- Making a drop-in-replacement for the IC56 DG408 mux that halves the output by adding more input resistors. Unfortunately, the maximum BP2 output is 8.6V, and this is followed by a 1.67x gain stage (IC52A) which immediately clips. This cannot be remedied by the card. Instead, we need to reduce the BP2 gain stage to unity by adding an output resistor > 39k (to make the sum of 56k + 3.9k + x = 100k) to the JP6 BP2 output. It may be possible to do with existing JP6 filter cards or we can order new cards with this modification, and use the current version with new voice cards.


TL;DR - these are the needed fixes

- Double the signal input resistors on the wet/dry mixer on the bus mixer board

- (fix the gain error on the bus mixer board)

- Reduce output amp gain for Moog, JP6 and Sines to 50% (in software)

- Set a max resonance for all filters to keep self resonance oscillation amplitude as low as possible.

 

To save the current voice cards

- Add a 22k resistor to the juno output boards (for this version).

- Double the Moog resonance CV somehow, possibly by adding a parallel resistor to the CV input to double the current.

- Create a drop-in for the DG408 JP output selector that reduces gain (and possibly adds soft clipping?)


For new version

- Replace the 18k juno post filter gain input resistor with a 39k one (or rather, move the post filter gain onboard the Juno filter PCB).

- Add soft clipping to the juno filter

- Fix Moog resonance CV on the moog board

- Update the circuit around the JP filter output selector to prevent clipping. May have to add soft clipping.


PS: Self oscillation with a very high frequency (>20kH<) makes what sounds like digital noise. Not sure exactly what to do with it, maybe a lower frequency output LPF would be a good idea.

PPS: There are a lot of weird things happening that may be caused by the ground plane noise from the waveshaper. 

PPPS: Knocking on the breadboard makes resonance wobble. I hope this is just poor connections but fear that some of the ceramic caps are picking it up. We'll see.

Monday, May 25, 2020

Little Phatty overload is just soft clipping

From the time I studied the Little Phatty to build my moog filter, I have wondered if the LP does pre-filter distortion of the signal or if it uses feedback for its overload.

From the Little Phatty schematics it is clear that overload is just soft clipping, and the circuit is extremely similar to what I did for my distortion with in-feedback-loop OTA :-D


The LP:

There are a couple of differences: The moog circuit uses both inputs of the OTAs, and also the same CV (though inverted) for both increasing the amount of distortion and reducing (?) the output gain. A nice trick to keep output at the same level I assume.

The overload CV also controls gain/attenuation of the filter output it seems.

UPDATE: I missed something - in addition to the soft clipping, the output from the distortion is fed back to the audio mixer, thus the distortion also has feedback.

Tuesday, March 31, 2020

Distortion (continued)

After figuring out what was going on in the distortion circuit, I set out to make a nice switchable distortion for the XM8.

Matching hard and soft

Through some experimenting I came up with the following circuit. It has the same amplitude for the output of both soft and hard clipping. Distortion starts at around 10mV input and output is at 3-400mV. Combining these two involves having an additional cap and resistor in the feedback circuit, and the hard clipping circuit has to be attenuated, meaning we should either switch output attenuation or do this in a VCA later.



Matching hard and soft clipping at 20mV input



Various diodes

I tried simulating various diodes. It seems that all silicon diodes (wow, I just realised I've spelt it silicone elsewhere! Blush...) such as 1N4148, 1N914 and 1N4001 give about the same result in the simulation. An 1N34 germanium diode on the other hand clips MUCH softer:


Soft clipping with 1N34 germanium at 10mV

Soft clipping with 1N34 germanium at 50mV


Soft clipping with 1N4001 at 5mV

Soft clipping with 1N4001 at 10mV

Soft clipping with 1N4001 at 25mV

Soft clipping with 1N4001 at 50mV




Matching hard and soft (silicone) without varying amplification or attenuation

The following circuit gives similar amplitude on the output of both hard and soft clipping, without any changes in amplification or attenuation when switching between hard and soft.

I have simulated this with a 31k resistor but that may be changed to 33k without any issue. With a 33k resistor, low pass cutoff is at 26.7kHz with a 180pF feedback capacitor, 32kHz with 150pF.

The input should be at around 15mV when signal is 5V, which will not clip. Soft clipping starts at around 20mV and hard clipping slightly later. Output is around 7-800mV





I've simulated the circuit with two separate opamps but this may be build using only one and with a single SPDT-switch like the DG419:



PS: Connecting the point between each of the two diodes in the feedback circuit changes nothing. That means that we can actually get away with two diodes less, putting the switch at the bottom of the hard sync instead of top.

Here's a closer look at the effects of clipping at various inputs.

Matching clipping at 15mV input

Matching clipping at 30mV input

Matching clipping at 55mV input

These show the effect on only one type of clipping in 10mV steps from 15mV to 55mV: 

Input, 15mV to 55mV in 10mV steps

Hard clip, 15mV to 55mV in 10mV steps

Soft clip, 15mV to 55mV in 10mV steps




From the plots above it becomes quite clear that distortion changes very quickly in the beginning and slower later. It may be an idea to use an exponential VCA on the input to get a more even rate of change. This, the actual sound and whether or not the audible volume is similar between hard and soft clipping has to be tested in real life.

Filtering (again)


As explained in the previous post, there is more to the tube screamer distortion (of which this is a variation) than just clipping. It also does selective filtering/gain of the input through the use of two shelving filters, and the low pass filter even changes as gain/distortion is increased, rounding off the curve more at increased soft clipping distortion, see https://www.electrosmash.com/tube-screamer-analysis for more about this.

This change may bring more "life" to the distortion circuit as clipping does not stay static when increasing gain. In the circuit above, gain is done pre-clipping, so clipping just becomes "wider". It may be possible to put an OTA in the feedback circuit instead of the tube screamer's potentiometer and thus keep functionality similar to the TS. Again, this has to be tested in practice to see what sounds good.

And in any case, selecting a cap for LP filtering at a lower frequency than that in the TS should be tested.

Voltage controlled distortion using OTA in feedback


Now, this is pretty cool. Last night I thought about how to replace the variable resistor in the feedback circuit of the TS with an OTA. Today I experimented a little and came up with something that seems to work fairly well.

By controlling the OTA with a 0-2.5V CV, we decide how much current should come out of it, which is exactly what changing the resistance does. I was able to find component values that gives fairly good controllability - at 0V CV no current flows through the OTA, and all current in the feedback loop flows through the diodes, giving maximum distortion. At 2.5V CV enough flows through the OTA to turn off the diodes (at least it looks like it).

I am not sure if this is the exact same result as with a potentiometer. Nor am I sure if the filter calculations hold true and if low pass cutoff changes like it does with changing potentiometer resistance. But it is definitely something worth trying.

Changing the CV input resistor to 20k lets us use 0-5V CV btw.

Hard clipping works well too btw, but the OTA cannot be fully off as then no current will flow.

20m input, slight skewing due to 1nF cap in feedback
15mV input, no distortion when OTA CV is 2.5V

Hard clipping, 15mV input



Hard clipping circuit

Voltage controlled input attenuation

One can also control the input, and thus the distortion, using an OTA circuit. The following circuit will let the clipping circuit see an input of around 15mV when CV = 0 and 130mV when CV = 5. CV is offset by R2 to slightly turn on the OTA even in the absence of CV.

At 5V the output is 1.1V which is rather high, but I've chosen to have this as the max and intead limit max distortion in software.

OTA controls input amplitude
At 0V CV output from the OTA buffer is around 20mV and signal distorts slightly. Replace R6 with 3.9k resistor for less distortion if wanted.
At 5V CV output is 130mV and the circuit clips heavily. Output after clipping is around 1.1V




Further work:

Output VCA - output should be around 5V when input to circuit is 20mV (e.g. input is 5V), and it should be possible to amplify output to 150-200% to do max volume in software and allow higher max volume than 5V (inputs may be above 5V when mixing multiple waveforms and  oscillators).


For the XM8 I may also want to look into mixing of dry/wet signal, and inclusion of a bit crusher. (https://en.wikipedia.org/wiki/Bitcrusher, https://www.reddit.com/r/diypedals/comments/1zck7p/bitcrusher_schematics/) Looking into how the PT2399 works would also be of interest for the global FX. https://www.electrosmash.com/pt2399-analysis

Distortion (clipping)

Seems I can't stop working on my synth these days. There are two major parts missing from my synth voice cards: Digital playback and pre-filter distortion. I am not sure about the need for the last one, so I decided to build that first.

Googling distortion circuits I came across a resource that I have read long ago and forgotten about: Design your own distortion.

This page gives a great step by step introduction to two types of distortion: Hard and soft clipping. It also has some on filtering and tone control but it contains some errors (50nF cap in distortion does not give a lower frequency of 31Hz but 3.1kHz, the shown circuit will not give any distortion and indeed very little gain for frequences lower than 3.1kHz).

I decided to try simulating the circuit in LTSpice (with +/-15v supply lines) before breadboarding it, to get a feel of what it is doing.

Hard clipping

The hard clipping part of the circuit is easy. Two parallel diodes in reverse order from signal to ground after a buffer or similar that disconnects it from the input.

Hard clipping at around 750mV

What is going on? When the input signal, and thus the voltage across the diodes reaches the forward voltage drop of one of the diodes, it switches on, sinking the current to ground. This effectively cuts off the peaks of every wave cleanly. A fairly normal diode voltage drop is around 0.75V, meaning the signal is clipped at 0.75V. The amount of clipping is adjusted by attenuating the input (assuming a +/-5v input) to where you want the clipping to occur.

If one wants a higher clipping point it is also possible to connect diodes in series, going from 0.75V to 1.5V to 2.25V etc.

Hard clipping with series diodes, clips at around 1.5V


Soft clipping

This is slightly more involved. Soft clipping means that instead of brutally chopping off the wave tops, they are rounded off. Soft clipping can be achieved by placing two diodes in parallel / reverse order in the negative feedback loop of an op amp, parallel to the feedback resistor.

I first simulated inverting amplification instead of the non inverting "tube screamer" version on the web page because I could not get that one working due to the HP cutoff error in the article.



Here is what I think is going on, and why this is different to hard clipping:

When the voltage across the feedback resistor Rf is low, the diode will be turned off. Current only flows through Rf. Increasing the voltage (and thus current) gradually switches on the diode. Some of the current starts flowing through the diode while some still flows through the resistor.

Soft clipping currents - the original input current (red) is equal to the sum of the current through the resistor (blue) and diode (green). The diode only starts conducting after a while, but when it does almost all current goes through it.

Abiding to Ohms law, the opamp output voltage is still the current flowing through the resistor times the resistance, but as some of the current required to keep the two opamp inputs equal now flows through the diode, the output voltage is less than the input voltage (given a unity gain configuration where Rin = Rf).

As the input current increases, more and more current flows through the diode, and the amount of current flowing through the resistor flats out, cutting off the top of the input waves.



Another interesting thing to note is at what voltage the cut happens at is affected by the resistance of Rf. With a larger resistance, current starts flowing through the diode earlier (as its "resistance" is lower). Thus, the voltage across the resistor when it starts clipping is also lower, meaning the output is clipped more than with a lower value resistor.

Example values for a +/-1v input are clipped peaks at:

550mV for 1k,
450mV for 10k and
355mV for 100k.


A +/-5v input has peaks at 650mV and +/-15v peaks at 712mV (at 100k?)

Soft clipping with 1k resistor in feedback loop

Soft clipping with 10k resistor in feedback loop

Soft clipping with 100k resistor in feedback loop


Currents with 1k resistor, total current is 1mA

Currents with 10k resistor, total current is 100uA. A proportionally larger part of the input current goes through the diode (the diode "resistance" is still the same so it's easier for the current to go this way) and the output current is clipped earlier.

Currents with 100k resistor, total current is 10uA, an even larger part of the current goes through the diode


The non-inverting version probably works in the same way.

I first had issues getting the non-inverting circuit from Design your own distortion to work because of the HP cutoff error, but finally I found and was able to simulate a similar non-inverting circuit, this one:

https://electronics.stackexchange.com/questions/473989/need-help-designing-and-implementing-an-op-amp-based-distortion-circuit

Non inverting circuit, increased value of filter cap, meaning a lower high pass filter point distorts the wave.
The same circuit as above but without filter cap. The clipping part is more visible here.


The slight skewing is because of the cap in the feedback loop. Gain is (10k + 220) / 220 = 46

It also explains a very important thing: The guitar signal amplitude is 40mV, nothing near the 1-5V I've been experimenting with so far. Taking this into account I was able to simulate a +/-15v version of the original circuit, but WITHOUT the 50nF capacitor in series with the 1k input resistor on the positive terminal of the op amp, an the resistor connected to GND instead of the negative supply (in the original circuit it is connected to ground, but ground is the negative supply as this is a 9V circuit). See the filter section below for an explanation of why removing the 50nF cap was necessary (the cap value is simply wrong due to a calculation error in the article).

Further more, Rf must be much larger than 1k to get distortion, without this all the current flows through Rf and none through the diodes so no clipping happens. I've been working with 30k.

Working soft and hard clipping. The input (green) is multiplied by 31 to see how it matches (the non inverting opamp configuration here amplifies the input 31 times).

I have also simulated various types of diodes for the soft clipping circuit, more about this in a separate post.

Filtering

The webpage on top also talks a lot about filtering. The original article is about distortion for guitars and says that one should aim for keeping frequencies from 40Hz to 30kHz (NB: There is a serious error in the HP filter calculations in the article, see the end of this section). It may be different for a synth but that's a good starting point.

The article discusses high pass and low pass filtering in a non-inverting amplifier. The chosen circuit is often referred to as shelving filters elsewhere, it is not the most common circuit in examples on the web.

Shelving filters actually have two parts, the "normal" high or lowpass filter, and then a second part where it flattens out again at a lower or higher frequency with lower gain, but where the gain stays at this level instead of continuing to drop off, letting all frequencies below (for HP) or above (for LP) pass. - see http://www.linkwitzlab.com/filters.htm#5.

Here are the sub-circuits and formulas needed for calculating the 3dB points:

The full circuit (NB: Other component names than the original):


The second parts of the shelving filter: Both these have gain = 1. To find the frequencies, replace R1 in the HP formula with (R1 + R2), and R2 in the LP formula with (R1*R2) / (R1 + R2).

For example:

Given the values
R1 = 1kOhm
R2 = 10kOhm
C1 = 50nF
C2 = 470pF

For the HP filter:
HP filter frequency: 3.1kHz (Gain = 11)
Lower frequency: 290Hz (Gain = 1 for all freqs below this)

For the LP filter:
LP filter frequency: 33.9kHz  (Gain = 11)
higher frequency: 373kHz (Gain = 1 for all freqs above this)

PS: In the "Design your own distortion" article HP frequency capacitor selection calculation is wrong. 1 / (2 * PI * 1000 * 40) is not 0.039uF, it is 3.98uF. This explains my inability to get the distortion working without removing the cap during my simulation - I simulated using a 400Hz sine wave, this is well below the 3.1kHz HP cutoff, meaning it has unity gain and is not at all distorted.

In general, there is a lot of info about filtering missing from the "Design your own distortion" article. The Tube Screamer analysis at https://www.electrosmash.com/tube-screamer-analysis has a much better description, talking about how the filter frequencies are affected by changes in the gain of the distortion and how bass frequencies are passed undistorted (but also un-amplified).


When deciding on component values, one first chooses the gain, then calculate the necessary capacitors.

See also


https://www.premierguitar.com/articles/diode-stew-1
https://sound-au.com/articles/soft-clip.htm
https://anasounds.com/od-disto-fuzz-differences/
https://www.electrosmash.com/tube-screamer-analysis