Resampling Audio in MATLAB

Math244 picture Math244 · Jul 22, 2013 · Viewed 11.3k times · Source

I have a wav file that has been imported into MATLAB and is sample at 44.1 kHz. I am trying to resample this audio file to 22.05 kHz and then restore it back to 44.1 kHz. However, I am confused on how to use the resample function in MATLAB and if that is even the function I should be using to do this. Any help would be greatly appreciated. Thank you!

Answer

Luis Mendo picture Luis Mendo · Jul 22, 2013

Yes, resample is your function. To downsample x from 44100 Hz to 22050 Hz:

y = resample(x,1,2);

(the "1" and "2" arguments define the resampling ratio: 22050/44100 = 1/2)

To upsample back to 44100 Hz:

x2 = resample(y,2,1);

Note that the resample function includes the necessary anti-aliasing (lowpass) filter.

As you probably know, the "recovered" signal x2 has lost the highest-frequency information that may have been present in x.