Skip to main content
Skip table of contents

Atan Wave Shaper

About This Guide

This Application Note explains the use of the Atan Wave Shaper module in the Audio Weaver Application.

The Atan Wave Shaper Module

The Atan Wave Shaper module can be found in Sound Design/Effects folder or by using the search window in the module browser. It is called “Wave Shaper Atan”.

Figure 1. Location in Module Browser

Transfer function

This module implements arctangent wave shaping. The arctangent is a part of a family of functions called sigmoid functions. Sigmoid functions produce S-shaped curves. The amplitude transfer function of a vacuum tube generally resembles a sigmoid, so this function can be used to mimic a tube amplifier.

The arctangent function y = arctan(k * x) has this curve family for varying values of x:

Figure 2. function y = arctan(k * x) for different values of k

A normalization factor has been added to restrict the output to the range of –1.0 to +1.0.

Figure 3. Normalized arctan function y(n) = arctan(k*x(n)) /arctan(k)

As k increases, the S-shaped curve emerges and adds gain (increased slope at the zero crossing). Low level signals are increasingly amplified, although the changes in gain tend towards zero as k increases.

Effect on the waveform and spectrum

Atan shaper example.awd

Figure 4. Baseline spectrum

Test signal = 500 Hz sine wave at 0 dB.

  • NumStages = 1

  • KPos = 0.1

  • KNeg = 0.1

  • InvStages = 0

Figure 5. Waveform (kPos = kNeg = 0.1)

Figure 6. Spectrum (kPos = kNeg = 0.1)

Input = 0 dB. Input and output are overlaid and are so close that it is difficult to see the difference.

  • NumStages = 1

  • KPos = 1.0

  • KNeg = 1.0

  • InvStages = 0

Figure 7. Waveform (kPos = kNeg = 1.0)

Figure 8. Spectrum (kPos = kNeg = 1.0)

  • NumStages = 1

  • KPos = 5.0

  • KNeg = 5.0

  • InvStages = 0

Figure 9. Waveform (kPos = kNeg = 5.0)

Figure 10. Spectrum (kPos = kNeg = 5.0)

Asymmetrical distortion

Asymmetrical distortion can be implemented easily by using two different k-values, one for positive input samples and the other for negative ones. This asymmetrical distortion is found in Class-A tube circuits. Note that unbalancing the waveshaper introduces even harmonics.

  • NumStages = 1

  • KPos = 3.0

  • KNeg = 1.0

  • InvStages = 0

Figure 11. Waveform (kPos = 3.0, kNeg = 1.0)

Figure 12. Spectrum (kPos = 3.0, kNeg = 1.0)

  • NumStages = 1

  • KPos = 5.0

  • KNeg = 1.0

  • InvStages = 0

Figure 13. Waveform (kPos = 5.0, kNeg = 1.0)

Figure 14. Spectrum (kPos = 5.0, kNeg = 1.0)

Multiple stages

Cascading multiple stages will result in more gain for low level signals. Ultimately, with high enough signal level, k and number of stages, the waveform will tend towards hard clipping. If you wish to distort even low-level signals, increase the value of k and/or the number of stages to get the desired result.

Figure 15. Effect of using multiple stages

Inter-stage inversion

In many electronic amplifiers the gain curves are inverted in between each stage. The resulting sound is quite different than simply cascading the modules without inversion. These differences are accentuated when kPos and kNeg have different values.

Figure 16. Interstage inversion when numStages is odd

When using inversion, setting numStages to an even number (2 or 4) eliminates much of the asymmetry, regardless of the settings of kPos and kNeg.

Figure 17. Interstage inversion when numStages is even

Using a lookup table

Calculating the arctan function in real time involves calling a function in a math library, which while very accurate, is also costly in CPU cycles. If you wish to conserve CPU cycles, you can try the “Use Table Lookup” option. This method pre-calculates a fixed number of values, which are stored in memory, and then interpolates between them as needed at run time. This uses relatively few CPU cycles.

Figure 18. useLookupTable selection in module inspector

The number of data points to use is set with the “tableSize” argument.

The memory heap to use is set by the “memHeap” argument.

Figure 19. Module arguments

Aliasing

Note that it is possible to cause aliasing with sufficiently high settings of k, numStages, and/or the input level. The peaks highlighted in yellow and magenta below are aliased. For an example of using oversampling to reduce aliasing artifacts, review the “guitar_distortion.awd” Audio Weaver layout in the Examples folder. The atan shaper can be used in place of the soft clipping module.

Figure 20. Aliasing

Module arguments

kMax

The maximum setting for kPos and kNeg, which multiply the input signal prior to the atan function to give a stronger distortion effect.

tableSize

The number of data points to use when useTableLookup = 1.

memHeap

The memory heap to use for the lookup table when useTableLookup = 1.

Module variables

numStages

Number of stages to cascade. More stages gives more distortion.

invStages

When set to 1, causes a phase inversion between multiple stages.

kPos

The multiplier for positive values of the input signal prior to hitting the arctan function.

kNeg

The multiplier for negative values of the input signal prior to hitting the arctan function.

useTableLookup

This setting trades run time CPU load for accuracy and static memory. When this setting is 0, the arctan function is calculated using a math library. When useTableLookup is 1, the value is interpolated from a prebuilt table.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.