 Here is an example of an audio file. Just a sample file. This illustrates the analog data in the time domain. So on the horizontal axis is time. So this is just a plot of a signal. Think of our signals from our first lectures. We plot the signal strength versus time. And in fact we have two plots here. So we have time along this axis. Zero seconds up to nine seconds. So it's nine seconds worth of audio. And the signal strength going up and down. We'll zoom in in a moment and we'll see it closer. This is an audio file which uses stereo. There are two channels left and right. And stereo just means that think of two separate audio tracks. And that's shown here. How big is the file if we save it? So let's say we recorded this nine seconds of audio. How are you going to calculate the file size when you save it to disk? What do you need to know? So I think this is the original analog audio. Analog data. How big is the file? Nine seconds of audio. Well, first you need to know what technique is used to encode the analog data into digital. So when we take the analog input, we save it as a file. Usually we select a file format which would imply the algorithm used to encode analog to digital, the codec. So when I save this, actually I export this in this case, and I can select the format here, there are different formats that some of you would have heard of. If you cannot see, there's WAVE, WAV, MP3, FLAC, AAC, AC3, WMA. These I think are formats or more specifically codecs used for encoding analog audio into digital. So when you play back music, you're usually using MP3 or one of the other codecs. Well, we want to use a codec which uses PCM, and commonly WAVE uses PCM. Not always, but it's common that when you save a file in WAVE format, WAV, the codec used is PCM, and it is the case in this one. And it says WAVE, Microsoft, because they standardised this format, signed 16-bit PCM. So when I save that file, or in this case exported, I get a file on the hard disk and we'll look at the moment the size. So the format of the file usually determines the codec used to encode that analog data into digital. This is using PCM. What else do we need to know? Well, when we save the file, it says 16-bit PCM, which means that there are 16 bits per sample. One sample is saved at a 16-bit value. With 16 bits, it means there's two to the power of 16 possible levels, or code numbers, about 65,000 levels in this case. The sampling rate, it's actually shown up here. The sampling rate, and it's common, we could have changed it, but the sampling rate in this case is 44,100. It's CD quality audio. So it's the same as a CD. 44,100 hertz. And it's in stereo, so we could calculate the file size. We did it yesterday for a CD. It's the same structure. What do we have? We have nine seconds of audio in this example. And the sampling rate of 44,100 hertz, which means 44,100 samples per second. And a sample size, that is, each sample is 16 bits. In other words, two to the power of 16 different levels. And it's in stereo. There are two tracks. So the data size in digital, well, we just calculate. We have, in one second, we have nine seconds worth. In one second, we have 44,100 samples. So four. So in one second, we have 44,100 samples. Each sample is 16 bits. And we have nine seconds worth. So that will tell us the number of bits for one track of audio. For nine seconds, this would give us the number of bits. But in fact, we have two tracks. We have left and right for stereo. So in fact, we multiply by two. Because each track, we must save those bits on the hard disk. So that's the total number of bits to represent this audio, which is, you'll get out your calculator, nine times 44,100 times 16 times two. That's the number of bits. And usually when we save on a disk, we use bytes. So let's just convert to bytes. So 1,587,600 bytes. So that's the amount of data we need to save on the disk. So we expect the file size to be at least that size. So when we save it in a WAV file, the file size should be around this. Let's check. Come back to that number. Where is it? I have it somewhere. The file size is 1,589,228 bytes. So the WAV file. 1,589. We calculated the data is 1,587. So the file is slightly larger than this. The file, the WAV file includes the data plus a few extra things to keep track of what type of data is inside here. So the format of what the data is. Think of it as like a header, some overhead to store there. So it's about 1.5 megabucks. What if I export it to a different file type or using a different codec? That was using WAV, which uses PCM. I haven't tried this, we'll see if it works. MP3. Save it as an MP3 file. And let's look at the size of the MP3. 145,000 bytes. The WAV file using PCM was 1.5 megabytes. The MP3 is about one-tenth of the size. So the same original analog audio, same original data, but we used a different codec. With WAV we used the PCM codec, the one that we've studied. But in the second case with MP3, it uses a different algorithm for converting the analog into digital. And in this case, it uses an algorithm such that the file size, the amount of data saved is much less. And that's the advantage of MP3. Same nine seconds of audio, but a smaller file to store it on disk. And much more easier to store many, a large amount of audio and also to transfer. So what's the difference? It's smaller, what's the problem with MP3? How does it get it smaller? With PCM we took samples and mapped each sample to 16 bits. With MP3 it's more complex and I don't even remember the details of the algorithm. But there's two things. To reduce the file size we can reduce the quality. So less samples and less bits per sample reduces the quality. So generally a smaller file size, a smaller quality. But it's not always true. What MP3 and other algorithms or other codecs do is that they look at the structure of the audio and the MP3 even removes some parts of the audio. So some of the frequencies which do not contribute much to the quality of the audio, it discards them. It throws them away. So when you play back the MP3 file you don't hear exactly the same as the original. Or you don't hear exactly the same as the WAI file because the MP3 codec discards some of the information. Why? Because it makes the file size smaller. That's a good thing. The problem is that the quality goes down a little bit. But in many cases your human ear will not be able to detect the differences. So that's the advantage of the MP3. Basically it compresses the data. So it compresses the data and discards some what it thinks is not useful data. So that the file is small but the quality may be less. So different codecs will produce different file sizes and will have an impact really on the quality. One last one. If we save it as one more export to... Actually I've done it before. I've also got in another format of FLAC. FLAC uses another codec and the file size is about half of the original WAV, the PCM encoded. So it's 770,000 bytes. The original was 1.5 megabytes. MP3, 145 kilobytes. FLAC, 772 kilobytes. So FLAC is in the middle. It's bigger than MP3 but smaller than the original PCM encoded WAV. FLAC is just used as a different algorithm. And the key part of FLAC and other similar algorithms is that it doesn't discard any of the audio. MP3 throws away some of the audio so when you play it back compared to the WAV file it will not be the same. But FLAC is what's called a lossless codec in that it compresses the audio it compresses the WAV file effectively but it doesn't discard any of the audio. So when you play it back you'll get exactly the same audio as when you play back the WAV file. So FLAC is what's called a lossless codec. No information is lost. It's just compressed. The same as you have a large text file you compress it using zip. When you decompress it you get the original text back. Nothing is lost. That's the same as FLAC. But with MP3 if you had a large text file you'd decompressed it with MP3 and you decompress you wouldn't get the original text back which is not so good for text files but for audio it is okay because their ears may not detect the differences. So many different codecs have trade-offs in terms of file size mainly the quality of the reproduction and also sometimes the time it takes to encode and decode to compress and decompress. As well as the support of those codecs in different pieces of software and in different pieces of hardware. Any questions to finish on PCM? We're not going to talk about the other codecs else is just about PCM but I think you've used many other codecs. Any questions before we finish this topic? It's hard to demonstrate in some time to think about but the same applies for video and other sources of analog data. Video, audio, data recorded from some sensor that records temperature for example that data or analog data we can apply a codec to convert it into digital. There's a few slides here that we didn't really use but they just summarise the steps used for PCM. So really if you can follow the examples we went through yesterday then that's all you need to understand about PCM. This just describes the steps that we used. This was the sampling theorem we should sample at two times the highest frequency component of the original input data. There are variations of PCM using what's called non-linear coding. In our case we divided the space into equal sized bands in this case from 0 up to 16 each row was the equal size. That's a linear coding but you can do other things like make it non-linear that is almost like a logarithmic scale. Here we have smaller bands and as we get to the larger amplitudes we get larger bands here but that's what we'll not cover non-linear coding. There's other modifications delta modulation, modifiers, PCM we will not cover that there's a couple of slides there. PCM think is the basic codec used for audio but there are many other codecs that try to improve upon the efficiency like compress the data more PCM doesn't compress anything and also maybe sacrifice some quality like MP3 does to reduce the file size. So that brings us to the end because the other topic we've covered before the midterm in the signal encoding techniques.