how to downsample a audio having sampling rate 44100 Hz to 2000Hz in matlab? This is the program i used but it showing error. how to rectify it?
Afficher commentaires plus anciens
[x, fs1] = audioread('audio8.wav');
ts1=1/fs1;
N1=length(x);
Tmax1=(N1-1)*ts1;
t1=(0:ts1:Tmax1);
figure;
plot(t1,x),xlabel('Time'),title('Original audio');
[y,fs2]=downsqample(x,20,441);
ts2=1/fs2;
N2=length(y);
Tmax2=(N2-1)*ts2;
t2=(0:ts2:Tmax2);
figure;
plot(t2,y),xlabel('Time'),title('downsampled audio');
2 commentaires
madhan ravi
le 23 Oct 2018
What’s the error message paste everything in red here
SUCHITHRA K S
le 23 Oct 2018
Réponses (1)
madhan ravi
le 23 Oct 2018
Modifié(e) : madhan ravi
le 23 Oct 2018
0 votes
Should be downsample but you wrote it as downsqample
17 commentaires
madhan ravi
le 23 Oct 2018
downsample only should have one output but you have two that’s causing the error
SUCHITHRA K S
le 23 Oct 2018
madhan ravi
le 23 Oct 2018
[y,fs2]=downsample(x,20,441);
Should be
y=downsample(x,20,441);
SUCHITHRA K S
le 23 Oct 2018
SUCHITHRA K S
le 23 Oct 2018
madhan ravi
le 23 Oct 2018
I don’t have any experience in audio sampling but what I am sure that downsample() should have only one output
SUCHITHRA K S
le 23 Oct 2018
Walter Roberson
le 23 Oct 2018
For those inputs you probably want resample not downsample.
resample does permit two outputs but the second is not fs2. Your fs2 should be 20/441*fs1
SUCHITHRA K S
le 23 Oct 2018
Modifié(e) : Walter Roberson
le 23 Oct 2018
Walter Roberson
le 23 Oct 2018
Read the documentation for downsample:
downsample(X,N) downsamples input signal X by keeping every
N-th sample starting with the first. If X is a matrix, the
downsampling is done along the columns of X.
downsample(X,N,PHASE) specifies an optional sample offset.
PHASE must be an integer in the range [0, N-1].
I believe that what you want to do instead is to rate convert 44100 Hz to 22000 Hz, which is a ratio of 22 out of 441 . To do that you would use resample not downsample
SUCHITHRA K S
le 24 Oct 2018
Walter Roberson
le 24 Oct 2018
Your audio contains multiple channels, which is fine for resample(). However spectrogram can only process one channel.
SUCHITHRA K S
le 24 Oct 2018
Walter Roberson
le 24 Oct 2018
Modifié(e) : Walter Roberson
le 27 Jan 2021
nchan = size(y,2);
for chan = 1 : nchan
subplot(1, nchan, chan)
spectrogram(y(:,chan), 256, [], 25, 2000, 'yaxis');
title( sprintf('spectrogram of channel #%d', chan) );
end
SUCHITHRA K S
le 27 Oct 2018
madhan ravi
le 27 Oct 2018
Modifié(e) : madhan ravi
le 27 Oct 2018
Thank you sir Walter . @Suchithra you can appreciate the persons time by accepting the answer and also it indicates the question is solved
atek
le 27 Jan 2021
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!