Downsample audio signal am I doing it right?

Hello,
I have an audio file and I want to perform Downsampling
form 44100 to 22050 / from 22050 to 11025 / from 11025 to 8000
Please find bellow my code.
[samples,fs] = audioread ('piano.wav');
audiowrite('piano.wav', samples,fs);
subplot (2,1,1)
plot(samples)
xlabel 'audio signal'
% processing second part downsampling
S1 = resample(fs,22050,44100); % downsample from 44100 to 22050
S2 = resample (S1,11025,22050); % downsample from 22050 to 11025
S3 = resample (S2,8000,11025); % doensample from 11025 to 8000

5 件のコメント

Walter Roberson
Walter Roberson 2018 年 12 月 4 日
Looks okay, except that there is no good reason for writing the file you just read from.
Also, you should be using a better x axis for the plot: it should be
x = (0:size(samples,1)-1)/fs;
plot(x, samples);
Isida Kaloshi
Isida Kaloshi 2018 年 12 月 4 日
Dear Mr Roberson,
Thank you very much for your fast reply and for your comment for the x axis.
Kind regards,
Hari Ijjada
Hari Ijjada 2019 年 9 月 6 日
After resampling the origanl samples how can i listen the resampled file ?
Henrik Gunnar Sundt
Henrik Gunnar Sundt 2020 年 6 月 18 日
You probably mean:
S1 = resample(samples,22050,44100);
not:
S1 = resample(fs,22050,44100);
Walter Roberson
Walter Roberson 2020 年 6 月 18 日
Good point, Henrik

サインインしてコメントする。

回答 (1 件)

Yash Bansod
Yash Bansod 2019 年 9 月 27 日

1 投票

I don't think that you are doing it rigt.
The following post describes the correct procedure: https://www.mathworks.com/help/signal/ug/changing-signal-sample-rate.html
To summerize:
% Code to read audio files
[y,Fs] = audioread(filename);
% code to resample audio
Fs_new = 16000;
[Numer, Denom] = rat(Fs_new/Fs);
y_new = resample(y, Numer, Denom);
% Code to play an already read audio file
sound(y, Fs);

カテゴリ

質問済み:

2018 年 12 月 4 日

コメント済み:

2020 年 6 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by