6

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!

2
  • 1
    I am not a matlab expert, but I'm sure it depends on what you are trying to accomplish. You might want to explain why you are downsampling and then upsampling back to where you started. The only thing you can hope to accomplish this way is to degrade your signal. Commented Jul 22, 2013 at 21:13
  • 1
    The reason I'm doing this is I am testing the robustness of my audio watermark to resampling. Commented Jul 22, 2013 at 21:22

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Or to make it explicit if anyone else is reading your code, you can use y = resample(x,22050,44100); and x2 = resample(y,44100,22050);
Thanks, I have added a comment to clarify that
Since the downsampling is exactly half the rate, you could also just do y = x(1:2:end)
@DavidK That's not a good idea. It causes aliasing. You need to lowpass filter prior to that -- which is what resample does
Readers dealing with speech signals might want to also consider this Q&A, which deals with the interpolation setting that should be used with resample. TL;DR interpft is probably more appropriate for this use case than any of the settings of resample.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.