Stuck with a SynthEdit project?

Tag: Distortion

Rectifier module.

This module flips negative voltages to positive, whilst leaving positive voltages unchanged. Behaves exactly as a “real world” bridge (full wave) rectifier.

Plugs.
Left Hand Side:

Signal in:- (Voltage) Input signal (AC)

Right Hand Side:
Signal Out:- (Voltage) Output signal

Example below: (The fixed voltages are just used to provide offset for the scope “Beams” for clarity)

This is a “Full Wave” rectifier, which passes the positive cycle, and flips the negative half over to become positive, suppose we just want a half wave rectifier? That is one that passes the positive cycles, and blocks the negative?

To create a Half wave rectifier that can output either a positive or negative output we can use the structure below. The comparator only passes an output signal when the input signal is positive by using the comparator to “gate” the Level Adj module. Inverter 2 is added to “flip” the polarity from +ve output pulses to -ve output pulses.

Creating a Voltage Controlled Waveshaper in SynthEdit.

Having some control over the waveshaper (although not over the actual transfer curve in the module) is possible in as far as the depth of the shaping effect, and the polarity of the shaping effect can be voltage controlled using a few stock modules, and one extra from Elena Novaretti’s module packs at www.elenadesign.eu, the ED Range Clipper which limits the amount by which the control voltages can be varied- this is used to prevent the control voltage exceeding the normal range for the waveshaper and causing unpredictable results.
The Intensity (or depth) of the effect can be varied between 0 V (minimum shaping) and 10 V (maximum shaping). This is then fed to the X-Mix module directly to Input B, and through an Inverter2 module to Input A. This allows us to effectively change the polarity of the waveform, which is then added to the Input audio at the final Level Adj module.
Of course you’re not limited to just using the Waveshaper3 module, you could just as easily use the Waveshaper2 module and use a formula for the transfer curve.

Voltage controlled waveshaper diagram

So far this is the best I have been able to come up with, but I’m as always going to keep experimenting so “watch this space” for updates on this technique

SynthEdit Waveshaper2b

This one is available in both SynthEdit V1.4 and V1.5
However there is a GUI module you can use to display the transfer curve from your formula which is only available in V1.5.

Waveshaper 2B in SynthEdit 1.4

This gives us a text box for entering our formula, with no means of displaying the Transfer Function curve.

Waveshaper2B in SynthEdit 1.4

Waveshaper 2B in SynthEdit 1.5

Whereas in V1.5 we have an additional module Waveshaper 2B GUI, which allows us to display the curve. Now the only real difference between Waveshaper 2 and 2B is that we can have a separate text box for entering our formula which can be resized for longer formulae, and by using a third party Text Entry module (such as the ED or DAM modules) can be customized to give control over font and background colours.

Waveshaper2B in SynthEdit 1.5

So with a little work we can have a demo that shows the input signal, the formula, which can be edited, the resulting curve, and the resulting output waveform.

Waveshaper2B demo in Syn
thEdit 1.5
Panel view of the Waveshaper demo

SynthEdit Waveshaper 3

This is a purely graphical waveshaper. It’s still a DSP module, so there is no need for any conversion between GUI and DSP data.
Although there is the Waveshaper2 or 2B, if you’re not mathematically inclined, or want to allow your plugin users to change the waveshaper’s function then this is by far the easiest solution. It’s very intuitive, you just click on a node (one of the small green squares) and drag it till you get the result you want. You can see below how dragging the nodes changes the output waveform.

Effect of moving nodes on the transfer curve

You just need to be aware that moving the centre node (0,0) can cause some issues with clicking and unwanted DC offset voltages (for audio you could put a high-pass filter set to about 50Hz cut-off pitch to filter out the DC component), when dealing with LFO’s or modulation envelopes you really do want to avoid moving the 0,0 node.
Another advantage is that as your plug-in users are unable to enter values into the waveshaper, they can’t cause the output to exceed the default +/- 5 Volts for Audio voltages.
The best way to learn this module is to connect it up and try dragging the nodes to see what the result is.

A test setup for the Waveshaper 3 module

SynthEdit Waveshaper 2

A Wave-Shaper distorts or modifies the input voltage depending on the transfer function that you specify. They can be used as a distortion unit, soft clipper, waveform modifier or control voltage transfer function (e.g. velocity response curve), they are to say the least, versatile.

Waveshaping is also a popular synthesis technique that turns simple sounds such as a sine wave into more harmonically complex sounds.
A guitar fuzz box is an example of a very basic waveshaper. The unamplified electric guitar sound is fairly close to a sine wave. But the fuzz box works by amplifying it to the point where the input clips the peaks of the signal in an amplifier designed to clip at moderate signal levels. A signal that is clipped has many more high frequency harmonics added to its spectrum. Sounds that have passed through any type of waveshaper will have a lot more high frequency harmonics, which gives them a “richer” sound.

Table based Waveshaping.

As you can probably imagine doing all these calculations in real time at audio frequencies is going to be a lot of work for the computer. So we generally pre-calculate these polynomials and put the results in a table. Then when we are Waveshaping sounds, we just take the value of the audio input and use it to look up the answer in the table. In the world of computer programming this is called optimization, and it greatly reduces the load on your CPU.
One big advantage of using a table is that regardless of how complex the original equations were, it always takes the same amount of time to look up the answer. You can even draw a function by hand without using an equation and use that hand-drawn function as your transfer function.

The SynthEdit Waveshaper2 module.

A simple waveshaper transfer function

The Waveshaper 2 module is just an in-out module, where you specify the transfer function either in the text box on the module, or in the module’s properties panel. Changing the formula will also change the curve in display that represents the transfer function

Changing the waveshaper transfer function formula-the effect

Note:
Input Levels: The input voltage is internally clipped at +/- 5 Volts, while it won’t do any harm to exceed these values, the results won’t bear any relation to the expected results from the formula.
Output Levels: These may be higher or lower than the default SynthEdit level of +/- 5 Volts depending on the transfer function specified. We can adjust the formula to compensate for this, we just change the multiplier at the beginning of the transfer function (shown in bold): Output = 5*sin(x/PI)

A simple Waveshaping Formula.

A waveshaper in DSP form can be described as a function that takes the original input signal x, and applies a mathematical formula to the input thus producing a new output signal y. This function is called the transfer function. A simple example in SynthEdit is shown below:

Showing the effect of the Waveshaper basic formula on a sine wave

Here we use a simple equation: Output = 5*sin(x/PI), the important part (the transfer function) is shown in bold. we merely multiply the results of the transfer function by 5 to restore the output to its normal SynthEdit +/- 5 volts peak to peak audio level.
In order to change the shape of the function (and not just make it bigger or smaller), the function must be nonlinear, which means it has exponents greater than 1, or functions (this is where we use sines, cosines, exponentials, logarithms, etc.). You can use almost any function you want as a waveshaper. But the most useful ones output zero when the input is zero (that’s because you usually don’t want any output when there is no input-this will result in unwanted clicking noises).

Showing the effect of changing the Waveshaper formula to 5 * sin((x*1.2)/PI)

If we change the equation slightly to: 5 * sin((x*1.2)/PI) the bold section is the change we insert, then the output goes from having the peaks flattened out, to a small amount of foldback, the greater the number we use to multiply x, the greater the waveform is folded back on itself- see below where it’s increased to x*1.8

Showing how the formula affects the Waveshaper output

Increasing the Input voltage:
What happens if we exceed the usual SynthEdit audio levels? Well with the most basic function we used in the first example you might possibly think you’ll get a result like we had in the last example where it starts to fold back, but it doesn’t it just goes into “hard clipping”. To demonstrate I put an amplifier between the signal source and the waveshaper with a gain of *3- you can see the result below.

Increasing the input above +/- 5V does not produce the expected results from the Waveshaper

And if we take the function that gave us the foldback:- 5 * sin((x*1.8)/PI),
and increase the input above the default level, then the following happens:

Increasing the waveshaper input above +/- 5V does produce some strange results

The reason for this is that the input of the Waveshaper modules in SynthEdit is internally limited to the default of 10 volts peak to peak, so when we reach the clipping voltage the waveform loses its sine wave like shape and is clipped. So to ensure correct operation we need to ensure that the input never exceeds +/-5 Volts (especially when using external audio sources). Likewise the result of the function must be scaled correctly to restore the default output of+/- 5 Volts audio that SynthEdit uses.

Need to convert a Sine wave to a Square wave?
Then this formula will do the job for you: 5*sgn(x/pi)

Converting a sine wave to a square wave with the Waveshaper

If we want to “pull” a sine wave into more pronounced peaks the following formula works well: 0.15 * sinh(x/1.2)

Producing a more exponential transfer curve from the waveshaper

Which also has a useful effect on Sawtooth and Triangle waves, so you can see how this can also be useful for manipulating envelopes and control voltages provided we pay close attention to the input and output voltage swings.

Effect of the new curve on a sawtooth
Effect of the new curve on a triangle wave

SynthEdit:- Aliasing and distortion.

Audio Aliasing is an effect which occurs when converting an analogue signal into a digital one with an insufficient sampling frequency.
The result of this effect is that the high-frequency components of that analogue signal will not be correctly interpreted, and the digital signal will not be an accurate copy of the analogue one.
Analogue to Digital conversion.
When analogue signals are digitised and turned into digital signals, the analogue signal is sampled at regularly occurring points in time, or in other words, the instantaneous amplitude of the analogue signal is recorded to create a digital copy of the analogue signal.
This happens very quickly in audio signals, for example, CD audio is sampled at 44.1 kHz (44,100 samples per second).
Aliasing occurs when a signal is sampled at an insufficient rate. Two audio signals can become indistinguishable from each other once they have been sampled and converted– they have become aliases of each other.

The Nyquist sampling theorem states that:
“To avoid aliasing, the sampling frequency must be at least twice that of the highest frequency which is to be represented“. If we use the example of CD audio, a sampling frequency of 44.1 kHz means that the highest frequency which can be represented without aliasing is 22.05 kHz. For CD audio this is sufficient as the upper limit of human hearing is around 15 to 20 kHz depending on the individual.

Aliasing can occur either because the anti-alias filter in the A-D converter (or in a sample-rate converter) doesn’t have a steep enough roll-off, or alternatively because the system has been overloaded. Distortion caused by overloading the input or conversion circuitry is the most common source of aliasing, because overloads result in the generation of multiple high-frequency harmonics within the digital system itself after the anti-aliasing filtering.
Sampling images.
The sampling process is similar to a form of amplitude modulation in which the input signal frequencies are added to, and subtracted from the sample-rate frequency. In radio terms, the sum products are called the upper sideband and the subtracted products are called the lower sideband. In digital circles they are just referred to as the ‘images‘.
Unwanted Effects.
These images play no part in the digital audio process — they are essentially just a side-effect of sampling. However they must be kept well above the wanted audio frequencies so that they can be removed easily without affecting the quality of the required audio signals. This is where all the can trouble begin. The upper image isn’t really a problem – that’s easily filtered out, but if the lower one is too low in frequency, it will mix with the audio we do want and because the frequencies are similar, this will create ‘aliases‘ that cannot be removed.
Unwanted guests you can’t get rid of.
This is what the aliases turn into… that guest at the party who causes bad feelings and will not leave. Once aliasing effects are there there is no way you can filter them out without causing even more audio degradation.

Spectrum of aliasing signal images

Note that, unlike an analogue system, in which the distortion products caused by overloads always follow a normal harmonic series, and can even give quite a pleasant sound, (consider tape saturation on an old reel to reel recorder, or soft clipping in a valve amplifier) overloading, or incorrect clock frequencies in a digital system aliasing result in the harmonic series being “folded back or mirrored” on itself to produce audible signals that are no longer harmonically related to the source (they are referred to as “Inharmonics”).
In this very basic example, we have ended up with aliases at 2kHz and 18kHz that have no obvious musical relationship to the 10kHz source. This is why overloading a digital system sounds so nasty in comparison to overloading an analogue system.