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!
- 1I 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.Bjorn Roche– Bjorn Roche2013-07-22 21:13:12 +00:00Commented Jul 22, 2013 at 21:13
- 1The reason I'm doing this is I am testing the robustness of my audio watermark to resampling.Math244– Math2442013-07-22 21:22:07 +00:00Commented Jul 22, 2013 at 21:22
Add a comment |
1 Answer
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.
5 Comments
Hugh Nolan
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);Luis Mendo
Thanks, I have added a comment to clarify that
David K
Since the downsampling is exactly half the rate, you could also just do
y = x(1:2:end)Luis Mendo
@DavidK That's not a good idea. It causes aliasing. You need to lowpass filter prior to that -- which is what resample does