# Why do MP3 files have a sample rate? (When they are just composed of sine waves)

I apologise if the title wasn't clear, but essentially, I am a little bit confused about MP3 files.

I was under the assumption (in MP3s) that a Fourier transform is used to split up the sound wave down to sine (or cosine) waves that have a phase difference, differing amplitudes, frequencies, etc. These varying sine waves would then be combined (apart from a few waves that don't make much change to the sound) to form a mostly accurate sound (lossy audio). But, why do MP3s then have a sample rate? There isn't any sampling going on here, if my understanding is correct.

Isn't a sample rate only for things like WAV files that chop up the sound wave (44100 times a second to be precise) get samples and then combine to form the sound (ensuring lossless audio)?

Digital sound files are not made up of sine waves - You may be thinking of FM or West Coast synthesis where sine waves are used to modulate other sine waves to generate more complex waveforms.

You will often see two different values associated with digital sound: the sample rate and the bit depth.

The bit depth determines the range of values available - on a CD this is 32,767 or 16 bit. At any given moment, a value somewhere between 0 and 32,767 is fed into the digital-to-analogue converter (DAC) to give a voltage that can be used to push a speaker cone in or out by a specific amount.

The sample rate determines how fast these values follow each other. Going back to CDs, a sample rate of 44.1kHz means that the values being fed to the DAC are being sent at a rate of 44,100 values per second.

Alternating between 0 and 32,767 at 44,100 times per second would result in a 44.1kHz square wave passing through the DAC.

Human hearing doesn't really work above around 18kHz-20kHz so we have twice the samples that we need - this helps to eliminate any issues with harmonics introduced by the digitisation process (similar to pixelation on a low res picture). You've probably heard this as a metallic or crunchy sound in low-quality digital audio.

The higher the sample rate and bit depth, the greater the fidelity of the recording/playback. There is a point, however, where the difference in quality becomes imperceptible to human hearing.

EDIT

I forgot to add that the different file formats (FLAC, MP3, WAV) etc. use different algorithms to calculate which sets of values they can skip without losing quality.

Removing unused values means that the resulting files can be smaller but the DAC needs to know what criteria were used in deciding which samples to remove so that it can calculate and insert an appropriate replacement value during playback.

• FLAC doesn’t skip values… it is a lossless compression. It typically tries to predict each sample depending of the previous ones and code in a little number the error. WAV is not compressed at all. (I mean LPCM which is the codec of 99.9% of WAV files). MP3 compress losing quality (depending of the specified bitrate). Jun 19 at 11:54

Yes, according to https://www.math.utah.edu/~gustafso/s2012/2270/web-projects/Guckert-audio-compression-svd-mdct-MP3.pdf there is a FFT involved in the MP3 compression.

However, the coding is tighly bound to the sample rate. The 1024 points FFT gives you 1024 frequency bins… then when decoding with a IFFT you will get back 1024 samples at the same sample rate of the original signal.

Since you have a frequency analysis you could add sine waves at an other sample rate, but you won’t be able to use IFFT then it would be quite slower.

I don't think MP3s use FFT rather than LPC analysis. At any rate, either form of analysis works tied to a particular sample rate, and after subtracting the approximate "predictive" (describable in terms of frequency parameters) part of the signal, the residue signal is still roughly characterised and encoded (the roughness of the characterisation means that stuff like the stereo location and some other subtle properties of "noise-heavy" signals such as cymbals are among the early victims of reproduction quality with MP3 compression losses).

The majority of the resulting encoding parameters end up pretty thoroughly tied into the sample rate. While in theory some parameters could be translated into different sample frequency, in practice the LPC parameters are to a large degree not transferred but derived from the output signal on both encoding and decoding sides, with just the residue signal being encoded. This requires both sides to work with the same numbers.

That doesn't really work with something with a numeric impact as thorough as a different sample rate would have.