1. Please take 30 seconds to register your free account to remove most ads, post topics, make friends, earn reward points at our store, and more!  

Mathematical description of a compressor

Discussion in 'Effects [BG]' started by Pierrick, Jul 3, 2012.


  1. Pierrick

    Pierrick

    Jul 3, 2012
    France
    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. Skrogh

    Skrogh

    Jan 28, 2010
    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. I think a sine wave representation would be better (at least for my way of thinking).
     
  4. Pierrick

    Pierrick

    Jul 3, 2012
    France
    Thank you for your answer,
    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. Pierrick

    Pierrick

    Jul 3, 2012
    France
    Of course, a sine wave can fed up this kind of simulation
     
  6. bongomania

    bongomania Gold Supporting Member Commercial User

    Oct 17, 2005
    PDX, OR
    owner, OVNIFX and OVNILabs
    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.
     
  7. Baer

    Baer

    Jul 8, 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/Basic Compression.JPG
     
  8. Pierrick

    Pierrick

    Jul 3, 2012
    France
    Thanks, it seems to be similar but much more clear !
     
  9. Pierrick

    Pierrick

    Jul 3, 2012
    France
    Clear scheme, I really have to take it into account, especially by inputting sine wave, as mentioned before
     
  10. 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. ryansalmond

    ryansalmond

    Nov 21, 2007
    Canada
    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. Knettgummi

    Knettgummi

    Sep 28, 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 :p)

    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:
    [​IMG]

    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.
     
  13. Baer

    Baer

    Jul 8, 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. alec

    alec

    Feb 13, 2000
    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. boomertech

    boomertech Frank Appleton Commercial User

    Apr 8, 2009
    Syracuse, NY
    Designer/Owner of FEA Labs
    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
     
  16. Skrogh

    Skrogh

    Jan 28, 2010
    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. ryansalmond

    ryansalmond

    Nov 21, 2007
    Canada
    I think that's what threw me off.

    But all said and told, best thread ever:bassist:

    Thanks to everyone for replying
     
  18. boomertech

    boomertech Frank Appleton Commercial User

    Apr 8, 2009
    Syracuse, NY
    Designer/Owner of FEA Labs
    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.:D

    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
     
  19. bongomania

    bongomania Gold Supporting Member Commercial User

    Oct 17, 2005
    PDX, OR
    owner, OVNIFX and OVNILabs
    ...And about the weirdos that will harass you with unrealistic demands and complaints about noises nobody else can hear. ;) :p
     
  20. Knettgummi

    Knettgummi

    Sep 28, 2011
    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. :p

    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.