• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

How to convert between harmonic distortions and compression parameters?

Fluffy

Addicted to Fun and Learning
Joined
Sep 14, 2019
Messages
856
Likes
1,425
As I understand it, the effect of compression can be translated to adding odd order harmonics. Therefore, I wonder if it's possible to convert back. Meaning, taking a harmonic distortion profile, and using the relative strength of the harmonics to reconstruct what compression parameters can lead to it. I'm talking about the basic parameters – threshold, ratio, maybe knee.
 

hyperplanar

Senior Member
Joined
Jan 31, 2020
Messages
301
Likes
581
Location
Los Angeles
The distortion produced by a compressor will vary with time based on the attack and release. Unless you're describing something more like a waveshaper.
 

andreasmaaan

Master Contributor
Forum Donor
Joined
Jun 19, 2018
Messages
6,652
Likes
9,403
I don't have a solution Fluffy, but just to clarify, when you say:
taking a harmonic distortion profile, and using the relative strength of the harmonics to reconstruct what compression parameters can lead to it.

are you talking about reconstructing the uncompressed waveform, or merely analysing the compressed waveform to determine what compression settings were used?
 
OP
Fluffy

Fluffy

Addicted to Fun and Learning
Joined
Sep 14, 2019
Messages
856
Likes
1,425
I don't have a solution Fluffy, but just to clarify, when you say:


are you talking about reconstructing the uncompressed waveform, or merely analysing the compressed waveform to determine what compression settings were used?
I'm talking about analyzing the compressed waveform. Note, I don't mean analyzing complex music signals, just analyzing tones is fine. I hope to find a way to visualize how much compression could have resulted in a given harmonic distortion pattern.
 

hyperplanar

Senior Member
Joined
Jan 31, 2020
Messages
301
Likes
581
Location
Los Angeles
So let's say we are talking about 0 ms attack and release.
So a waveshaper then, because there is no state in its function. :)

If the original signal in question is known then it should be simple to deconvolve the distorted signal and obtain the transfer function. In other words, compare the shape of the original waveform to the distorted one in the time domain. The math is beyond me though.

The wiki article has a section relating the effect of polynomial transfer functions on a sinusoidal signal: https://en.wikipedia.org/wiki/Waveshaper#Polynomials
 

Hayabusa

Addicted to Fun and Learning
Joined
Oct 12, 2019
Messages
823
Likes
569
Location
Abu Dhabi
As I understand it, the effect of compression can be translated to adding odd order harmonics. Therefore, I wonder if it's possible to convert back. Meaning, taking a harmonic distortion profile, and using the relative strength of the harmonics to reconstruct what compression parameters can lead to it. I'm talking about the basic parameters – threshold, ratio, maybe knee.
only if you would know the amplitude and phase of the harmonics you can reconstruct the time domain waveform. an iFFT would work then
 
OP
Fluffy

Fluffy

Addicted to Fun and Learning
Joined
Sep 14, 2019
Messages
856
Likes
1,425
I'm specifically not interested in the original waveform and its reconstruction. I'm just interested in extracting the compression parameters that would lead to the resulting distortion of the waveform. if reconstructing the waveform is part of the solution, that's fine, but that's not the end result in want.
 

andreasmaaan

Master Contributor
Forum Donor
Joined
Jun 19, 2018
Messages
6,652
Likes
9,403
I'm talking about analyzing the compressed waveform. Note, I don't mean analyzing complex music signals, just analyzing tones is fine. I hope to find a way to visualize how much compression could have resulted in a given harmonic distortion pattern.

A slightly hacky approach, but if you're just thinking in terms of simple signals like sine waves, what I would do would be to take an uncompressed sine wave and then apply compression to it, while using a spectrum analyser to monitor the output.

Once the output matches your original compressed waveform, you can infer the setting used.

There is ofc a more elegant mathematical solution, but I'm not sure what it is.
 

Hayabusa

Addicted to Fun and Learning
Joined
Oct 12, 2019
Messages
823
Likes
569
Location
Abu Dhabi
I'm specifically not interested in the original waveform and its reconstruction. I'm just interested in extracting the compression parameters that would lead to the resulting distortion of the waveform. if reconstructing the waveform is part of the solution, that's fine, but that's not the end result in want.

Can you tell what you mean by compression in this context?
 
OP
Fluffy

Fluffy

Addicted to Fun and Learning
Joined
Sep 14, 2019
Messages
856
Likes
1,425
A slightly hacky approach, but if you're just thinking in terms of simple signals like sine waves, what I would do would be to take an uncompressed sine wave and then apply compression to it, while using a spectrum analyser to monitor the output.

Once the output matches your original compressed waveform, you can infer the setting used.

There is ofc a more elegant mathematical solution, but I'm not sure what it is.
That’s the brute force approach. But I don't think that would work with distortion patterns of any random amplifier, let's say. They usually don't only have odd order harmonics and they come in all different magnitudes, so tracking down approximate compression settings would be very time consuming. I wondered if there is a computational approach.
Can you tell what you mean by compression in this context?
I mean a compression effect, like something you'll find in a DAW. Once you get the hang of it, it's easy to understand what a "-10 db threshold, 1:3 ratio" compression would do to a signal. I want to try to translate the harmonic distortion characteristics of let's say, and amp or a dac or even headphones, to a (relatively) simple compression settings, for easier visualizations purposes. You can use that for, say, understanding how harmonic distortion represents effects on dynamics.
 

andreasmaaan

Master Contributor
Forum Donor
Joined
Jun 19, 2018
Messages
6,652
Likes
9,403
That’s the brute force approach. But I don't think that would work with distortion patterns of any random amplifier, let's say.

It certainly is ;) It wasn't clear to me what you were trying to do, but now I think it is clearer.

You want to model the harmonic distortion profile of electronic components like amplifiers using a software compressor in a DAW, correct?

I don't think you'll be able to model even-order harmonics, nor harmonics that are out of phase with the fundamental, using a compressor.

Would that not be a problem, given your goal?
 

hyperplanar

Senior Member
Joined
Jan 31, 2020
Messages
301
Likes
581
Location
Los Angeles
They usually don't only have odd order harmonics and they come in all different magnitudes, so tracking down approximate compression settings would be very time consuming. I wondered if there is a computational approach.

I mean a compression effect, like something you'll find in a DAW. Once you get the hang of it, it's easy to understand what a "-10 db threshold, 1:3 ratio" compression would do to a signal. I want to try to translate the harmonic distortion characteristics of let's say, and amp or a dac or even headphones, to a (relatively) simple compression settings, for easier visualizations purposes. You can use that for, say, understanding how harmonic distortion represents effects on dynamics.

I don't think a compressor can provide you with the same distortion profile as an amplifier (assuming truly 0 ms attack and release, which is basically never the case in any compressor plugin by the way). There's way too many different transfer functions, or "shapes", that compressors can have, and there is no unambiguous definition of parameters like knee. Many compressors also show frequency-dependent behavior. Similar issues arise on the amplifier side—there are many types of distortion that can arise, based on topology and implementation.

If you want to model the static nonlinearities of a device such as an amplifier, the only way to do it is to pass a signal through it (such as a pure sine wave) and determine its transfer function based on the result.
 

JustAnandaDourEyedDude

Addicted to Fun and Learning
Joined
Apr 29, 2020
Messages
518
Likes
820
Location
USA
I mean a compression effect, like something you'll find in a DAW. Once you get the hang of it, it's easy to understand what a "-10 db threshold, 1:3 ratio" compression would do to a signal. I want to try to translate the harmonic distortion characteristics of let's say, and amp or a dac or even headphones, to a (relatively) simple compression settings, for easier visualizations purposes. You can use that for, say, understanding how harmonic distortion represents effects on dynamics.

Do you mean effects such as in the graphics in post #15 by Member pkane in the thread Simple Dynamic Compression & Expansion ? He/she mentions that symmetric transfer functions produce odd harmonics as distortion, while asymmetric and more complex ones would include further sorts of harmonics. A question: are those transfer functions in the frequency space (i.e. in the Fourier-transformed or Laplace-tranformed versions of the signal)?

In the same thread, in post #10, I describe a crude and elementary compression algorithm that produces neither new odd nor new even harmonics nor any other new frequencies. The harmonic distortion it produces lies entirely in the change of amplitude of each tone/frequency in the original signal. I am calling it a compression algorithm because it falls within my vague picture of what I see discussed as "compression" does. I think the algorithm I describe would probably correspond to a sort of laterally-inverted Z, with two sharp knees connected by a straight line slanted from bottom-left knee to top-right knee. I could be mistaken though; I am too lazy to think it through.

I think Member hyperplanar is right, though. I don't think compression transfer functions alone are able to mimic all the types of distortion that amplifiers, headphones, etc. are capable of producing.
 
Last edited:

hyperplanar

Senior Member
Joined
Jan 31, 2020
Messages
301
Likes
581
Location
Los Angeles
A question: are those transfer functions in the frequency space (i.e. in the Fourier-transformed or Laplace-tranformed versions of the signal)?

The transfer functions are in the time/amplitude domain. They are a mapping of an original signal's amplitude (at any given point in time) to the transformed signal's amplitude, where x is the amplitude of the original signal and y is the amplitude of the transformed signal.

A perfectly linear device is where the transfer function is simply y = x:
1590212819041.png


Or you can have something like tube saturation:
1590212904483.png


These graphs depict the full transfer function from -1 to 1 amplitude. Note how only the top part of the transfer function rounds off and the bottom is unchanged. So if you feed in a sine wave, only the positive peaks will be rounded off, while the negative peaks are untouched. This gives rise to even-order harmonic distortion.

In an actual device things are much more complicated because this transfer function can vary with respect to frequency and time.
 

Attachments

  • 1590212896822.png
    1590212896822.png
    84.3 KB · Views: 64

JustAnandaDourEyedDude

Addicted to Fun and Learning
Joined
Apr 29, 2020
Messages
518
Likes
820
Location
USA
The transfer functions are in the time/amplitude domain. They are a mapping of an original signal's amplitude (at any given point in time) to the transformed signal's amplitude, where x is the amplitude of the original signal and y is the amplitude of the transformed signal.

A perfectly linear device is where the transfer function is simply y = x:
Or you can have something like tube saturation:

These graphs depict the full transfer function from -1 to 1 amplitude. Note how only the top part of the transfer function rounds off and the bottom is unchanged. So if you feed in a sine wave, only the positive peaks will be rounded off, while the negative peaks are untouched. This gives rise to even-order harmonic distortion.

In an actual device things are much more complicated because this transfer function can vary with respect to frequency and time.

Thanks! That cleared things up for me a lot, because I am unfamiliar with DAWs and their software. No wonder those transfer functions introduce other frequencies as harmonic distortion due to changing of sine shape. The elementary compression I listed in the other thread is performed in the amplitude-frequency domain, and so requires a time-window's worth of a signal sample, unlike the instantaneous compressors you describe. However, my algorithm produces no spurious frequencies, as it does not alter a sine wave's shape but merely its amplitude. And its picture as a right-slanting S would be as a scaling factor for amplitudes in the amplitude-frequency domain, not in the amplitude-time domain that Member Fluffy is used to.
 
Top Bottom