Showing posts with label aliasing. Show all posts
Showing posts with label aliasing. Show all posts

2015-03-26

Golden Eyes: Experiments with Audio - Part 7 (Squeezing Those Waves)

[ Catch up:  part 1, part 2, part 3, part 4, part 5, part 6 ]

I am back with more eye candy! This time we will squeeze and squash our waveforms for fun and profit, in other words we will compress them. This compression should not be confused with 'audio data compression to reduce size' like in a mp3 format.

The kick sample is a good candidate to demonstrate this effect. We have four tracks with different variations of compression applied to them. The final amplitudes have been roughly matched here for easy comparison (using the makeup gain):

Compression at work

Let's see all the binary comparisons to our original:

A1

A2

A3

A4

You can enlarge the images by clicking on them. If you have first looked for high or low frequency loss or addition, you would have seen that there isn't any. All the frequencies are accounted for. The only difference seems to be in the amplitude or volume of some parts. Let's also look at the comparison between A2 and A3 for the heck of it:

A2 & A3

The amplitudes in the beginning seem to be different though the final parts of the tracks look the same in amplitude. Notice also the timeline. The whole part takes about about 100 ms in time with the first low frequency wave spanning about 10 ms and the longest sinusoidal wave spanning 20 ms (which means the frequencies are 100 Hz and 50 Hz). The amplitude comparison would be really easier if we overlay them like this:

A1 (black) & Original (red)
 A1 looks almost the same except being somewhat quieter in the beginning.

A2 (black) & Original (red)

A2 looks similar but the second low frequency peak in the waveform seems quieter than the rest.

A3 (black) & Original (red)

When we come to A3, the differences become noticeable. It looks like it is quieter overall with larger attenuation for louder parts.

A4 (black) & Original (red)

A4 looks same as A3 in the beginning; however the attenuation is greater in the following section. Let's look at A2 vs A3 vs Original for a better understanding.

A2 (blue) & A3 (black) & Original (red)

The difference lies in the beginning where the amplitudes are greater. Is it a time-based effect, or amplitude-based, or both? Let's add A4:

A2 (blue) & A3 (black) & A4 (green) & Original (red)

A4 is same with A3 in the beginning but then it becomes quieter after some time. Finally, A1 is added:

A1 (orange) & A2 (blue) & A3 (black) & A4 (green) & Original (red)

A1, as we noticed before, only differs in the beginning and about the same in the following parts. So, what is happening here?

The answer is compression! It is both an amplitude-based and a time-based effect. The settings are like this:

  • A1: Maximizer (short attack, short release, practically infinite ratio)
  • A2: Compressor with 10:1 ratio, 50 ms attack, 3 ms release (long attack, short release)
  • A3: Compressor with 10:1 ratio, 5 ms attack, 3 ms release (short attack, short release)
  • A4: Compressor with 10:1 ratio, 5 ms attack, 50 ms release (short attack, long release)

Threshold point is the same for all. In short, maximizer tries to cut all the peaks above a certain threshold immediately to allow an increase in volume and compressors do the same but gradually using a time component for activation and deactivation. This is why A2 (with a slower attack) does not start compressing immediately at the beginning but gradually compresses for 50 milliseconds while A3 starts compressing the offending peaks almost immediately. Meanwhile A4 does not want to let go for a while, even after the offending peaks have been passed :).

The comparison would be easier on a repeating faster drum hits. Notice the timeline on the following example. Every labelled tick is 100 ms in time. Here the compression threshold is also lower.

Drum part compression comparison

 As we can see, maximizer (A1) tries to remove (gently) all the offending peaks to allow for a louder sound (after adding make-up gain) while removing transients (making the sound less 'punchy'). The compressor with a slower attack (A2) passes more of the transient 'attack' part of the beat while compressors with fast attacks (A3 & A4) leaves only the very beginning of the 'attack' sound. This makes the difference between a 'fatter' kick sound and a 'punchier' kick sound. A very-fast (or immediate) attack would make the sound even less punchier and perhaps 'duller'. Adequate use of compressors is a long topic and maybe best left for another article.

Let's compare them one by one (this time on black):

A1-maximizer (white) & Original (red)

Yep, the maximizer removes all of our precious transients (see loudness wars!).

A2 [long attack, short release] (white) & Original (red)

A long attack gently carves out the transients.

A3 [short attack, short release] (white) & Original (red)

A short attack leaves out only the immediate transients carving out the excess fat :).

A4 [long attack, long release] (white) & Original (red)

A long release means we also squeeze the quiet parts (sustain and release part of the drum hit). If there are above-threshold parts encountered during the release part of a compressor, these will be immediately compressed regardless of the attack settings since we are already activated at that time. Therefore, it is not a good idea to time the release longer than two consecutive attacks of our sample.

A2 [long attack] (white) & A3 [short attack] (blue) & Original (red)

Long attack vs. short attack in plain sight above. Let's see the 'difference' tracks also! These difference tracks show 'what' exactly carved out by the compression.

Differences with the original for the tracks A1, A2, A3, and A4
Many variations of compression can also be easily heard with an experienced ear. This post completes this series that was started as a curiosity.

Until next time....
Cagil

2015-03-13

Golden Eyes: Experiments with Audio - Part 6 (Nyquist said it first!)

[ Catch up:  part 1, part 2, part 3, part 4, part 5. ]

Hi again,

In this part, let's analyze (or eyenalyze?) another kind of degradation: the sample rate. So, consider the following:

Track G

This is a single snare hit from our sample collection. If you compare track G with the original, it is quite obvious that there are some fine details missing though the overall shape is there. Therefore there should be a process that strips the high frequencies (the fine details of the waveform). Let's look at the difference as usual:

It lost all the details!

The difference looks to be devoid of bass frequencies. Let's look closer:

It is like a summary of the original

Yes, the details are simply not there! The difference track only consists of higher frequencies. Now we overlay them:

Overlaid version

The blue processed line cannot keep up with the red original one. We can clearly see the highest frequency visible in this sample part by taking note of the time information from the top bar. The minimum distance between two positive peaks in the processed track looks like about 1/4th of a millisecond which corresponds to 4 kHz for a full wave period. Since at least two sampling points are needed to accurately represent a sinusoidal wave, this processed waveform must be sampled in 8 kHz or higher. Similarly, the red original waveform has about half the length of the processed one. Therefore that one must be at 16 kHz or higher.

Sample rate differences


In fact, the original is at 48 kHz sample rate. But the snare sound sample does not have sound components in the 16 kHz+ range (8 kHz frequency in audio). Therefore we only see the maximum we have in the data. The modified track was down-sampled to 8 kHz allowing only frequencies 4 kHz and lower to pass (effectively a low-pass filter). It is practically (but not exactly) the same thing using a low-pass EQ filter.

The down-sampled version usually will not correspond with the exact sampling point of the higher sample original version. The reason is that many down-sampling algorithms employ specific averaging and anti-aliasing techniques for a more accurate representation. When the original data have more fine details (higher frequencies) than that can be captured by the sample rate, then we may have an aliasing or moiré pattern effect. This is very interesting for our purposes and I will investigate that in a future part.

Using a 44.1 kHz ve can accurately represent 22.05 kHz frequencies which are at the upper limit of human hearing threshold. Sometimes it is advised to use higher sampling rates such as 48 kHz, 88.2 kHz (or even 192 kHz!) because of some concerns about digital processing artifacts in the very high frequency ranges. But theoretically (see Nyquist-Shannon Sampling Theorem) two samples are enough to represent a specific sinusoidal frequency.

That's all for this part. In the next one, I want to delve into audio compression magic!

Cagil

Continue with part 7.