# What's this effect?

What would you get, if you would amplify a sound source in the following way:

Imagine a normalized sound sample, with peaks that reach the highest level. Say that the sound wave is between -1 and +1. If you take the square root value of each value between 0 and 1, you get a higher value. You kind of amplify the wave, but values near 1 get only little amplified:

``````x    sqrt(x)
============
0      0
0.2    0.45
0.4    0.63
0.6    0.77
0.8    0.89
1      1
``````

And the values from 0 to -1 would behave in same way. Is this a known and used effect? It looks like some kind of compressor without any threshold values. One could also think of the square root function as something raised to the power of 0.5. And changing the exponent to anything would change the compression or amplifying rate.

The values below the zero line need to be handled a little differently, because you can’t take the square root of a negative number. But I’ll try to bust out Matlab and see if I can’t write a quick program that will do this.

If I knew more about Nyquist I would probably be able to write a Nyquist program, but I haven’t taken the time to learn it yet.

My gut instinct says it will sound like distortion, we’ll find out later.

I did some testings already and I got some binary overflow distortion, but that’s probably because bad calculation. Through the distorted noise, I could hear something that sounded like the compression like amplifying I tried to do. And changing the root function to square function made it backward. The softer sounds almost disappeared, while only the strongest peaks remained.

Yes, the negative values are treated differently:

``````if (old >= 0) new = sqrt(old)
else new = -sqrt(-old)
``````

My guts say there should be no distortion. I must include visualisation of the sample to find out why it distorts. This effect is a bit like what gamma makes to images, namely changing the brightness without making all pixels above some brightness level completely white.

What I’ve done is the following:
I’ve used a 44.1 kHz 16 bit mono sample, unsigned.
Each sample is an integer in the range 0 and 65535.
32767 is the zero level.
Converting the old sample to a new goes:

``````1: float f;
2: f = old - 32767;          // make zero level really zero
3: f = f / 32768;            // make all values between -1 and +1
4: if (f >= 0) f = sqrt(f);  // do the effect
5: else f = -sqrt(-f);
6: f = f * 32768;            // expand the values to -32768 to 32767
7: f = f + 32767;            // do them unsigned (range 0 to 65535)
8: new = int(f);
``````

The third line might be the critical. I should divide with something bigger, like 32800, to ensure nothing goes above 1 or below -1.

It’s absolutely a form of distortion. Any constant non-linear change to an audio signal will result in distortion. This particular distortion is very fuzzy (aka very white-ish sounding), but I can see a use for it.

I think one problem you’re running into is that a Float is not accurate enough. I used Matlab to do mine, all the calculations were in Double precision (64-bit, I think).

I’ll try and upload the distorted clip:

And now the original for reference:

Still beats me why it is fuzzy. I can understand that an overdrive guitar gets fuzzy, because there will be abrupt clippings of the peaks in the sound wave. But as I see it, this effect doesn’t make cracks in the wave. Any part of the wave, that looks continuous, should look continuous after the effect, too. Yes, it’s distorted, but somehow I thought it wouldn’t sound fuzzy. Isn’t any compressed sound distorted?

This square root function is not compressed in the way that we normally talk about dynamic range compression (though the signal strength certainly increases). That kind of compression is a dynamically changing amplification factor that multiplies smaller portions of the audio to make it “look” about the same size as the louder portions. A Compressor doesn’t react to individual samples, it reacts to the “recent average.”

You asked if any Compressed sound would be distorted. Technically it is, but think of it this way: At it’s most basic, a Compressor is simply a fancy version of amplification. While it’s not technically a linear operation, the non-linearities occur at such a slow rate that only incredibly low frequencies (that we can’t hear) will be distorted. The only frequencies added to the signal will be subaudible.

But this square root stuff isn’t just multiplying the signal, it’s performing a more complicated operation to it. And it’s doing this in a constantly non-linear fashion. This is because it’s affecting each sample differently based on how big the individual sample is, NOT on how big the “recent average” is (like a Compressor would).

I guess the easy way to look at it would be this: If you take a sine wave and apply several iterations of this square root function, it will end up looking more and more like a square wave.

``````x     x^.5    x^.25  ...  x^.031
==============================
0      0       0           0
0.2    0.45    0.66        0.95
0.4    0.63    0.79        0.97
0.6    0.77    0.88        0.98
0.8    0.89    0.94        0.99
1      1       1           1
``````

From this, the ‘squareness’ of the distortion should be pretty evident. But what does that mean for the spectral content? It means that we’re adding odd harmonics to the signal, and we’re adding quite a few of them.

Take a look at the wikipedia article on distortion:
http://en.wikipedia.org/wiki/Distortion#Electronic_signals

Note forms 4 and 5 they have at that list right there. The transfer function for a square root (or whatever it is we should call this effect) will fall somewhere between those two extremes. It will look like number 4, but will have more of a “shelf” at the top, and the upward swing (near the zero crossing) will be much sharper.

What we audio people call “distortion” is basically the addition of musically related harmonics to a signal. You don’t need abrupt clipping to add harmonics to a sound. It’s true that that’s exactly what number 5 is doing, but number 4 is still a form of distortion despite making no abrupt changes.

The reason this might not sound as nice your run of the mill distortion pedal is probably due to the lack of any equalization to the signal. I’m sure with some tweaking it can sound great.

Does that make sense?