MATLAB - Pitch Shifting an Audio Signal

user2817753 picture user2817753 · Nov 19, 2013 · Viewed 13k times · Source

My group is developing a simple MATLAB Graphical User Interface (GUI) that is supposed to record audio from a microphone - plugged in or built in to the computer - and play back the signal. So far we have that completed. Our GUI also can load a sample (a .wav file, etc..) and play it back using the same "Play" pushbutton on the GUI. We have a Play, Record, Load, and Save push button. Now for the pitch-shifting of loaded or recorded samples... We know we need a peak-picking algorithm to find the fundamental frequencies of the signals. We were then thinking that we could multiply each of those values by a constant to shift the pitch of all those frequencies. What we aim to do it use this algorithm and assign the separate shifts to different Pushbuttons or radiobuttons, in which we can load our sample, press the button and manipulate the pitch by doing so, then play it back. Will using a peak-picking algorithm sufficiently shift the pitch of our signals, or will the signal be screwed up during playback?

(THIS IS NOT REAL-TIME PROCESSING)

Answer

MZimmerman6 picture MZimmerman6 · Nov 19, 2013

As mentioned in my comments above, there are really two approaches you can use, Phase Vocoders or higher sampling rates. The first method, using a vocoder will maintain signal length while shifting the contained frequencies higher. I am not going to go through the algorithm on how to do this, but code is openly available for this from Columbia University - http://www.ee.columbia.edu/ln/labrosa/matlab/pvoc/

The second method is simply writing the *.wav file to a higher sampling rate.

say you have a 440 Hz signal you want to be 880 Hz, simply double the sampling rate.

so instead of say wavwrite(signal,fs,'file'), use wavwrite(signal,2*fs,'file')

This however, will shorten the length of the audio file by whatever factor you increased the sampling rate.

Overall I think the better and more impressive method is the vocoder, I would not recommend just blindly using the code from Columbia, but actually taking time to understand it and being able to explain the logic behind it all mathematically