How can I change sampling frequency when I use audiowrite function?

19 views (last 30 days)
Hi, I have an mp3 file that I upload to matlab using audioread function, which gives me an audio signal which is stored in a 25392x1 matrix with the sampling frequency of 22050 which is stored in a variable called 'Fs'. I am trying to save this audio signal in a 'mp4' format using the audiowrite function. When I try using the variable Fs or 22050 is gives the error following error:
Error using audiowrite (line 203)
Unsupported SampleRate value.
Error in audio_signal (line 90)
audiowrite('reconstructed_computer_male.mp4', a, 22050);
Intresting thing is, when I put in Fs*2 or 44100, the function works just fine. The problem with that is the mp4 file that is saved is not an accurate representation of the audio signal because it is twice as fast as it should be. I checked the type of the variable which is double in both cases but only one of the cases work. How can I save this audio signal with the right sampling frequency, which is 22050?

Accepted Answer

Star Strider
Star Strider on 9 Jul 2020
From the audowrite documentation for Fs:
‘When writing to .m4a or .mp4 files on Windows platforms, audiowrite supports only samples rates of 44100 and 48000’
Consider using the Signal Processing Toolbox resample funciton to resample it to one of those frequencies.
.

More Answers (0)

Categories

Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!