# How does MP3 work?

1. Dec 20, 2003

### arcnets

Hi all,
when you store music as a WAV file (CD quality), it will take ~10 MB per minute. If you compress to MP3, even with the highest quality, you will only get ~1 MB per minute.
I know that the file size is determined by amplitude resolution * sample rate. If you use 16 bit, 44 kHz, and stereo, that results in ~10 MB per minute as I said.
The Shannon theorem says that, in order to digitalize an analog signal with full quality, the sample rate must be at least twice the highest frequency. So you cannot throw away any high-frequency Fourier components, or the sound will be bad.
My question is: How can the MP3 compression give a sound almost as good as the original, while throwing away ~90% of the information?
Does anyone know a simple explanation?
Thanks...

2. Dec 21, 2003

### Greg Bernhardt

What MP3 codec does, is that it gets rid of parts of audio that you and I cannot hear.

3. Dec 21, 2003

### Carlos Hernandez

I can easily tell the difference between mpw and .wav. When you convert to mp3, the song loses much of its stereo sound/3-d quality. I compared same songs in both formatts and could tell the difference quite easily.

Carlos Hernandez

4. Dec 21, 2003

Carlos,
Were you using variable bitrate or constant bitrate ?

5. Dec 21, 2003

### Carlos Hernandez

Constant, I believe.

6. Dec 21, 2003

Some software programs may not allow the luxury of opting to encode using variable bitrate but you can obtain better sound quality with this method...just a thought.

7. Dec 21, 2003

### chroot

Staff Emeritus
Actually, Shannon's sampling theorem says nothing about quality. What it says is that to represent a signal of frequency f Hz at all, you must sample at or above 2f Hz. f, the highest frequency representable, is called the Nyquist frequency.

A sine wave digitized at almost exactly the Nyquist frequency will look nothing at all like the original sine wave. All Shannon's theorem says is that its fundamental power will still appear in a frequency-domain plot.

Now, mp3 is not a sampled data stream, so Shannon's theorem doesn't apply to it.

What mp3 basically does is compute a wavelet (or FFT, I can't remember which) transform on blocks of samples. The result is a set of Fourier coefficients. The mp3 algorithm then discards some of these coefficients which are not psychoacoustically important. Voila! You have compressed your data.

- Warren

8. Dec 21, 2003

### Carlos Hernandez

I was using the freeware CDex, they had both options available.

9. Dec 21, 2003

### chroot

Staff Emeritus
Note to Carlos: the quality of your encoding software matters. A lot.

- Warren

10. Dec 21, 2003

### Greg Bernhardt

Yeah for example 64kb encoding would sound pretty bad, but 192kb encoding sounds great.

11. Dec 21, 2003

### chroot

Staff Emeritus
Not just that -- different encoders, both running at 192kbps, will produce different results.

- Warren

12. Dec 21, 2003

### arcnets

What I'm referring to as 'almost as good as the original', is:
256 kBit/s, 44100 Hz, Stereo + Resample.
How does it know what you and I cannot hear? And does this imply that we cannot hear ~90% of the information that is in a soundwave?

13. Dec 21, 2003

### Carlos Hernandez

I encoded my .wav into 128, 160, 192, 256, and 320 kbps, and I've tried freeware like CDex, which is supposed to be high quality, but I've also tried high quality shareware, like media jukebox and MusicMatch Jukebox. No matter what the situation, I noticed that you end up loosing significant stereo/3-D sound from the original. And it's not just me, I found that other people also found the same results as I. I searched this on the internet, and others have said the same thing.

Carlos Hernandez

14. Dec 21, 2003

### chroot

Staff Emeritus
Try a real encoder, like LAME.

- Warren

15. Dec 21, 2003

### Carlos Hernandez

All the encoders I used had the Lame feature.

Perhaps I just have a better ear for music and can tell differences better. Or maybe not, who knows.

16. Dec 22, 2003

### Jimmy

http://www.modatic.net/audio/stereo_vs_jointstereo.php

If your having a problem with your separation, then it's probably the software you are using. The lame encoder that was mentioned is a command line program. It's one of the best encoders. It's free. If your not comfortable with using a command line interface, then you might not like using lame. There are many windows front-ends available but they generally don't use all the features that you get when using the CLI version. Some software may use the lame encoder (lame_enc.dll) but the functionality is usually crippled.

http://lame.sourceforge.net/

I think the info on the first page I linked to will solve your problem.

Last edited: Dec 22, 2003
17. Dec 22, 2003

### Guybrush Threepwood

one example is that when you have 2 frequencies f1 and f2 very close and the amplitude of f1 is smaller than the amplitude of f2 you cannot hear f1. But the exact parameters (when 2 frequencies are close or what amplitude difference is important is subject to psychoacoustics...).
So the mp3 encoder after computing the wavelet transform (or FFT, whetever....) can safely ignore some of the coeficients based on rules such as the above one.

18. Dec 22, 2003

### arcnets

Thanks Guybrush T.,
yes I understand. In the case that you mention, the result of the 2 waves superimposing, would be a very long-period, low amplitude modulation in volume, which is ignored by the ear.
Since the lowest audible frequency is ~20 Hz, the fourier transform will deliver sinus components of 20 Hz, 40 Hz, 60 Hz, and so on. And, of course, say, 10000 Hz and 10020 Hz are 'very close together'.

I have the following idea: Is it possible to construct (mathematically or otherwise) a WAV file that sounds *bad* with any MP3 compression? Because the wave is constructed so tricky that MP3 throws away just the components that are, in fact, important to our hearing?

Maybe a voice whispering some words, barely audible, in a lot of noise?

19. Dec 22, 2003

### NateTG

Actually, there are people who test various encoders using a bunch of different files. You can see what the results are for some pathological sounds like instantaneous pulses.

IIRC mp3 has problems with clicks and pops of some type more than anything else.

Here's a chapter of O'Reilley's book on mp3's. It might be more than what you wanted.

http://www.oreilly.com/catalog/mp3/chapter/ch02.html [Broken]

Last edited by a moderator: May 1, 2017
20. Dec 23, 2003

### arcnets

NateTG,
that's great. Thank you.