Article - Disclaimer - About |
7. Matlab7.1 DownloadYou can download the matlab code that implements the phase vocoder described in the previous sections. ![]() 7.2 InstallationIn order to use this code, you need to unzip the following files in the folder of your choice:
7.3 ExecutionHere are the steps to shift the pitch of a wave file. 7.3.1 Launch MatlabWell this one is kinda trivial ;) 7.3.2 Change the current directoryYou need to set the current directory to the directory where you extracted the matlab files from the zip file above. You can do this with the following menu:
Figure 7.1: How to change the Matlab current directory 7.3.3 Load a wave file into a vectorThe next step consists in loading the content of a wave file (*.wav) into Matlab. As far as I know, you cannot load directly from the mp3 format. If you want to use a mp3 file, you first need to convert it to the wave format and then load it with Matlab. To do so, you can type the following command in the Matlab command window.
The audio signal is loaded in the vector named x and the sampling rate is loaded in the variable Fs (this can be useful if you ignore the sampling rate used for recording the sound initially). If you have a mono signal, x will be a matrix with a single column. However, if you have a stereo signal, x will be a matrix with two columns. You can either pitch shift each left and right channel individually or average them together and use the result as the input vector. You can use the following commands to reorganise your signals:
7.3.4 Shift the pitchYou can then shift your signal by calling the pitchShift function. Here, you need to specify the vector which contains the signal to be shifted, the sampling rate, the frame size in samples and the hop size in samples. We will assume that the samppling rate of the audio wave file was 48000 samples/sec, such that Fs = 48000. For this reason, as explained previously, we choose a frame size of 1024 samples for optimal results. Since we want an overlap of 75%, we set the hop size to 256. Finally, let's say we want to shift the pitch up by two steps. We want the resulting signal to be stored in a vector named y. We need to write the following command:
7.3.5 Listen to the resultThat's it! The signal is now pitch shifted. But it would be nice to listen to it. In order to do so, use the following command. By the way, always reduce the volume of your speaker when you perform some audio tests with Matlab. If for some reason the operation went wrong and the power of the resulting signal is two high, you could blast your ears (happened to me a few times... then I learned my lesson).
7.4 Complete codeHere is the content of the Matlab files, which you can download in section 7.1. pitchShift.m
createFrames.m
fusionFrames.m
Copyright © 2009-2025 François Grondin. All Rights Reserved. |