And the secret, as you may guess, is found in the Fourier domain so

we plot the DFT spectrum of the music again on the scale.

So that's the top graph and you see that there is some spectral decay and

it varies the particular shape, which depends on this particular piece of music.

Then the first noise, which is certain dB signal to noise ratio noise,

has an, essentially, flat spectrum across all the spectrum.

Whereas the second noise, it's a clever noise, as you can see,

it has a shape that resembles the shape of the music.

And so when the music has all the Fourier energy, we can add some noise,

whereas the music has very energy, we put very little noise.

So that's called noise shaping So

we summarize this in this graph where the blue curve is the spectrum of the music,

the red curve is a spectrum of the noise exactly adapted to the music.

And the compression algorithm used in MP3s of course very complex.

But one of the key elements is to shape the errors and

actively as the Fourier spectrum changes, because, of course,

music evolves over time so the Fourier spectrum does not always look like this.

It changes all the time.

So you have to constantly adapt where you put the noise

as the Fourier spectrum of the music changes.

And so MP3 magically minimizes the loss of quality

by shaping the compression errors in a clever manner, and

this is done in something that is called the short time Fourier transform domain.

Which we don't explain now in detail, but

the idea is essentially a DFT that is local, so with small pieces of music,

you take a discrete Fourier transform You look at the spectrum of the music and

you put some noise exactly where it's not going to be heard.

This is a magic metronome,

this is what has made MP3 such a successful music compression algorithm.

By the way, this is called perceptual compression, and

this is an art, because you have to understand not only the mathematics,

but all the perceptual effects of the human hearing system.

And the people that derived the MP3 compression standard,

that's a lot of people are involved in this.

Have actually brought together all the qualities from mathematical analysis to

human perceptual knowledge to derive a very powerful algorithm.

By the way MP3 is not the only audio compression algorithm out there.

There are other ones.

But all the successful ones will have noise shaping

in the same style as what we have just seen for MP3.