Posted on 1 Comment

Learn MATLAB Episode #13: Sound Processing Exercises

Let’s cover a few sound processing exercises in MATLAB!

So in this matlab video we’re going to do some exercises related to sound processing. So the first exercise we’re going to do is try and reverse the audio file, please pause this video and see if you can figure out how to do it yourself first. Ok, so, if you search on Google how to reverse a signal you see two functions that pop up, there’s fliplr and flipud. So now if we look at the sound file that we opened earlier, hello world from the last lecture, we see that it’s about 85,000 x 2. So this tells us that the samples are along the rows and each column is the left and right channel. Therefore, we want to use flipud not fliplr, because if you fliplr it’s just going to reverse the two channels, but if you flipldd it’s going to reverse the signal. So, let’s do that. So you see the shape is the same. If I plot d2 it’s not apparently obvious but this is the reverse of the signal that we had before. So now I want you to play this signal. Ok, so, I want to play this signal for you guys, but I have to save it first so that I can put it into the video editor that I’m using. I’m going to skip ahead a little bit and talk about the function audiowrite. So this is analogous to audioread, you pass in the data, and then you pass in the sampling rate. Ok, so, matlab does not support mp3 in audiowrite for some reason even though you can read mp3’s, let’s try mp4. Ok, so, now I’m going to read this file, I’m going to get the sampling rate also, going to play this back. So, that was hello world backwards. So the next thing I want to do is I want to speed up the sound waves so it plays twice as fast. I’m going to give you guys a minute to think about that, and so please pause this video and then come back once you think you’ve figured it out. Ok, so, the process of speeding up a sound wave is called downsampling. So we’re going to use an integer number like 2 so that it’s a little bit easier. So conceptually what you want to do is you basically want to drop every other sample of the original signal. There is some other algorithms and functions you could apply that theoretically might give you a better sound, but just to take every other sample is the simplest way. And so if you search for this earlier there is a method called downsample in matlab, ok. And so notice that we check the size of d4 the signal is half the length that it was before because we took every other sample. Now I want you to play this back with the original sampling rate. And so now it sounds like a chipmunk because it’s going twice as fast, and the pitch has increased. So if you think about a sine wave that doubles it’s frequency that’s the exact same thing that’s happening here. And now the next exercise I want you to do is theoretically maybe a little bit more complicated, but I think you guys can get it. So now that I have this downsampled version of hello world that’s playing every other sample of the original, how do I get it to play at the original speed so that it’s not high-pitched? I’m gonna give you guys a minute to think about that, so please pause this video and then come back once you think you’ve figured it out. Ok, so, the solution to this what we want to do is we want to play at half the sampling rate. “Hello world” and so this sounds pretty much like the original, you probably can’t tell that there’s some information loss, this has to do with a thing called compression. So if you ever study multimedia and you look into this field further you will learn more about that.

1 thought on “Learn MATLAB Episode #13: Sound Processing Exercises

  1. I’m not that much of a online reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your site to come back later on. Cheers

Comments are closed.