TalkBass Forums Mathematical description of a compressor

Supporting Membership
Thank You

Latest Supporting Member
#1
07-03-2012, 09:38 AM
 Registered User Join Date: Jul 2012 Location: France
Mathematical description of a compressor

This my first post on TalkBass,
In order to have a better understanding of what really does a compressor, I’d like to have a simple mathematical description. the following :
Let’s assume that the input level of the bass is “s_in” and “s_out” the output level of the comp.
First, “s_in” is gained so: “s1 = gain + s_in”,
then this signal is compressed so : “s2 = 1/r * s1 + t * (1 – 1/r)” assuming a linear law with “r” ratio and “t” threshold
Finally the signal is outputted so “s_out = output + s2” with “output” the output level.

What do you think about that, is it correct?

Obviously, it is really simple but I think it can help to understand. Moreover, it’s just a “level” approach, there is a lack of “time” approach especially with attack and release times.

Thanks for the contribution,
#2
07-03-2012, 10:33 AM
 Registered User Join Date: Jan 2010 Location: Denmark
First of all you need to tell if s_in and s_out are in db or volts. (I'm assuming in db, or the s1 = gain + s_in would just result in a bias). There is something wrong in your equations too... I build a mathematical compressor "simulation" in TI-interactive once. I can post it if you like, but I think a flow diagram would be more useful... (I can draw up one later, if you want, or you can google it)
#3
07-03-2012, 12:15 PM
 Registered User Join Date: Dec 2010 Location: Zaragoza, Spain
I think a sine wave representation would be better (at least for my way of thinking).
__________________
Quote:
 Originally Posted by Sharko Do your research before your market your product so that you don't, oh, I don't know, accidentally put nazi insignias on it.
#4
07-03-2012, 12:19 PM
 Registered User Join Date: Jul 2012 Location: France
I assumed that s_in and s_out are in dB.
I'm very interested in your simulation and a flow diagram too if you have.
#5
07-03-2012, 12:22 PM
 Registered User Join Date: Jul 2012 Location: France
Of course, a sine wave can fed up this kind of simulation
#6
07-03-2012, 12:40 PM
 Registered User Exar went out of business, so... Join Date: Oct 2005 Location: PDX, OR
IF (IN >T) THEN ((IN -T) /R) +T +MG = OUT

IN = input signal
MG = makeup gain (final gain stage)
OUT = output

This won't literally apply to all compressors, due to the actual electronic behavior of their circuit design, but it covers the general idea.
__________________
Compressor, preamp, and EQ FAQ <--read first!
Compressor reviews / My blog / Twitter / >> Instrument cable reviews <<
Exar's business is on hold for now. I will still help previous customers.
#7
07-03-2012, 01:48 PM
 Registered User Join Date: Jul 2008
The settled gain reduction of a compressor is only one aspect of a compressor. The dynamic behavior of its attack and release account for a lot of the "sound" of a compressor. Different compressor models can handle this task very differently resulting in very different sounds, even though the gain reduction ends up with the same volume.

Here's a link to a simple representation of what a compressor does to a signal.

http://stash.reaper.fm/oldsb/108050/...ompression.JPG
#8
07-03-2012, 01:58 PM
 Registered User Join Date: Jul 2012 Location: France
Quote:
 Originally Posted by bongomania IF (IN >T) THEN ((IN -T) /R) +T +MG = OUT IN = input signal MG = makeup gain (final gain stage) OUT = output This won't literally apply to all compressors, due to the actual electronic behavior of their circuit design, but it covers the general idea.
Thanks, it seems to be similar but much more clear !
#9
07-03-2012, 02:04 PM
 Registered User Join Date: Jul 2012 Location: France
Quote:
 Originally Posted by Baer The settled gain reduction of a compressor is only one aspect of a compressor. The dynamic behavior of its attack and release account for a lot of the "sound" of a compressor. Different compressor models can handle this task very differently resulting in very different sounds, even though the gain reduction ends up with the same volume. Here's a link to a simple representation of what a compressor does to a signal. http://stash.reaper.fm/oldsb/108050/...ompression.JPG
Clear scheme, I really have to take it into account, especially by inputting sine wave, as mentioned before
#10
07-03-2012, 03:31 PM
 Registered User Join Date: Jul 2011
Quote:
 Originally Posted by Baer Here's a link to a simple representation of what a compressor does to a signal. http://stash.reaper.fm/oldsb/108050/...ompression.JPG
Is that image correct? I always thought that the attack time determined how long after reaching the threshold that the compressor should start working. In other words, that the signal would continue to be unaffected by the compressor during the attack time, and that the "sharpness" of the knee of the compressor decided how fast it reached full compression ratio after that.

Anyone with better knowledge, please enlighten me!

Cheers,
Kalle
#11
07-03-2012, 03:47 PM
 Registered User Join Date: Nov 2007
Yeah that diagram is throwing me for a loop! Someone please elaborate. The release time part is not what I thought all these years
#12
07-03-2012, 03:48 PM
 Registered User Join Date: Sep 2011
Sharpness of the "knee" determines how the compressor acts around the threshold level. A hard knee will attenuate any signal that's over the threshold with the full ratio that the compressor is set to. A soft knee will transition more gradually, meaning that a sound that's just barely over the threshold will effectively be compressed at a gentler ratio than a sound that is much louder than the threshold. (Hopefully that made some kind of sense )

The graphic is accurate in terms of how attack and release works.

EDIT: found an image on wikipedia that illustrates hard knee vs. soft knee:

EDIT #2: In fact, this whole article should be of interest to anyone who'd like to learn the basics of compressors. There's a whole section on attack/release as well.

Last edited by Knettgummi : 07-03-2012 at 03:57 PM.
#13
07-03-2012, 04:59 PM
 Registered User Join Date: Jul 2008
The diagram is correct. It is actually from a series of compressor plugin tests that I ran when I started using Reaper many years ago. The input was an actual audio file fed through a compressor. The compressed output was the actual output audio wave, it is not made up.

To explain the diagram, the input is simply a sine wave that starts at a low level, increases to a higher level, and then returns to the low level. The compressor threshold is set between the two levels. When the level increases, the compressor kicks in and starts decreasing the level at a rate dependent on two things: the attack time and the ratio. The attack time is the time over which the reduction will occur.

The release does confuse people, but here's what's happening. Once the compressor kicks in, the high level input is compressed and levels out at its compressed level (the second half of the middle section). When the input signal reaches the point where its higher level (the middle section) returns to its low level (the end section), the compressor is still on so the low level signal is, at first, still compressed. The compressor recognizes the input level is now below the threshold and starts to back off on the compression. The release time is the amount of time it takes for the compression to go from fully compressed to zero (signal no longer compressed).
#14
07-03-2012, 06:00 PM
 I promised myself I would stop buying pedals Join Date: Feb 2000 Location: Perth, Australia
I think that image confuses some people because you don't get that sort of input signal with a plucked instrument. There's no decay. And when a note stops on a bass, there's usually no signal stil present underneath.
__________________
#15
07-03-2012, 06:19 PM
 Registered User Designer/Owner of FEA Labs Join Date: Apr 2009 Location: Syracuse, NY
The one thing that the diagram and the info on wiki are missing is that they are showing the total attack and release times in a linear function. They are good general representations of the basic compressor function. But, most analog compressors specify attack and release times based off of a single RC time constant and the attack and release responses actually follow a curve.

T=RC ( T= Tau or time constant, R=Resistance, C= Capacitance)

1T is approximately 63% of fully charged or 37% when discharged. For an RC circuit to reach a fully charged or discharged state takes 5T , or 5 time constants.

As stated above, there are also many, many ways to change the compression characteristics for a particular response or sound… hard knee vs. soft knee, frequency modified thresholds, program dependent attack and release, ripple multiplication and parallel blending are a just few things that distinguish one compressor from another. So, if you are trying to model a “real” compressor the mathematics can become mind boggling.

-Frank
__________________
www.fealabs.com
#16
07-03-2012, 10:48 PM
 Registered User Join Date: Jan 2010 Location: Denmark
This is what I have:
Out(db) = db*ln(10) + 20*ln( (gain* (max(thresholdr, (10)^( (db)/(20) )))^(1/(ratio)) )/(max(thresholdr, (10)^( (db)/(20) ))) ))(ln(10)
Where Out is the output gain in dbv and db is the average inputgain in dbv.

I tried to incorporate threshold, but didn't get any good results, but hey, I just started designing compressors. And I still have to decide on a goo gain stage (Noise, distortion, linearity and so-forth)

This was done by converting form dbv to volts, then sending the signal trough a 1/x gainstage (I couldn't find a good way to do ratio, except for a power-function)

After reading through this topic, I realize, that It might be better to convert the input to a log-scale, perform math, the apply gain... Hmm I'll give it a shot after I get some sleep...

@Frank:
If you have any information on designing compressors, you are willing to share, or links one should check out feel free to post, or PM me I would appreciate it.
#17
07-03-2012, 11:20 PM
 Registered User Join Date: Nov 2007
Quote:
 Originally Posted by alec I think that image confuses some people because you don't get that sort of input signal with a plucked instrument. There's no decay. And when a note stops on a bass, there's usually no signal stil present underneath.
I think that's what threw me off.

But all said and told, best thread ever

#18
07-04-2012, 12:30 AM
 Registered User Designer/Owner of FEA Labs Join Date: Apr 2009 Location: Syracuse, NY
Quote:
 Originally Posted by Skrogh @Frank: If you have any information on designing compressors, you are willing to share, or links one should check out feel free to post, or PM me I would appreciate it.
The first thing that I can tell you about designing a compressor is… don’t do it… you may become quickly obsessed, forget to shower for days and will need therapy.

I started with dual-band compressors because I liked the Trace Elliot SMX and Rane DC-24. But my biggest love was for optical compressors, so I combined a dual-band concept with optical comps.

A good source for compressor design beyond the comp schematics that you can find, is manufacturer application notes. THAT corp has loads of great information on VCA designs. Silonex has optical application notes for a comp and limiter on their site. The optical compressor design that they have on their site is nice… but I absolutely hated the limiter.

It really helps with the process if you have good circuit emulation software and a way to build component models that are not available for the library.

When I see you at the compressor group therapy sessions I will tell you about my bad compressor experiences.

-Frank
__________________
www.fealabs.com
#19
07-04-2012, 12:52 AM
 Registered User Exar went out of business, so... Join Date: Oct 2005 Location: PDX, OR
Quote:
 Originally Posted by boomertech When I see you at the compressor group therapy sessions I will tell you about my bad compressor experiences.
...And about the weirdos that will harass you with unrealistic demands and complaints about noises nobody else can hear.
__________________
Compressor, preamp, and EQ FAQ <--read first!
Compressor reviews / My blog / Twitter / >> Instrument cable reviews <<
Exar's business is on hold for now. I will still help previous customers.
#20
07-04-2012, 03:12 AM
 Registered User Join Date: Sep 2011
Quote:
 Originally Posted by boomertech As stated above, there are also many, many ways to change the compression characteristics for a particular response or sound… hard knee vs. soft knee, frequency modified thresholds, program dependent attack and release, ripple multiplication and parallel blending are a just few things that distinguish one compressor from another. So, if you are trying to model a “real” compressor the mathematics can become mind boggling. -Frank
This is a very good point. And relates to something I was thinking about as well but forgot to put in my previous post: creating a basic mathematical model of a compressor can be helpful (at least to some people) in order to understand how the effect works, and thereby making it easier to achieve desired results when using it. Actually modeling a good compressor (whether it's based on a mathematical model or not) is much more complicated -- take it from Frank, who has first hand experience.

There's a reason for why there are a thousand different compressors on the market, and not one end-all, mathematically perfect model. In many cases, what distinguishes classic analog circuits from modern, digital models are the imperfections and less predictable qualities.

That being said, it's certainly a very interesting effect to explore, and there's a whole bunch of research material to be found on the web for those who want to spend a couple of years tearing their hair out.

I'd personally recommend getting into something like CSound or Max/MSP. Learning these kinds of DSP environments is a very rewarding way to gain a greater understanding of how effects and sound processing works.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are Off Refbacks are Off

All times are GMT -6. The time now is 06:25 PM.