Differences downsampling with seewave "resamp" function

16 views
Skip to first unread message

Florian Rabasco

unread,
Mar 27, 2023, 12:47:37 PM3/27/23
to seewave
Dear all,
I need to downsample wav files from 44 100 Hz to 4 000 Hz.
For this, I'm using the "resamp" function of seewave, and tell the function to divide my frequency by 11, as here :

for (i in 1:length(patterns)){
 
  path_wav_file<-paste(path,patterns[i], sep="")
  wav_file<-readWave((path_wav_file))
  g=wav_...@samp.rate    #To catch the sample rate of the wave files
  sample_4K<-resamp(sound, g=g/11, output = "Wave")
  savewav(sample_4K, filename = paste(path4kHz, "4kHz", patterns[i], sep=""))
}

A pair of mine with much more experience and specialized in acoustic studies use a personal code in Matlab,  as here :
for u = 1 : Nfile
u
Nfile
file_loc1 = liste(u,:)
cd(directory_data_initiale)
wavinfo = wavfinfo(file_loc1);
if length(wavinfo)>0
   [s,fe]=wavread(file_loc1);
   s_re = resample(s,a,b);
   ind = find(file_loc1=='.');
   fe_new = a*fe/b;
   file_loc2 = [file_loc1(1:ind-1) string_subscript '_' num2str(floor(fe_new)) 'virg' num2str(floor( (fe_new-floor(fe_new))*100))  'Hz' '.wav'];
   cd(directory_data_resample)
   wavwrite(s_re,a*fe/b,file_loc2);
   clear s s_re
end
end

However, when I open the spectrogram of each downsampling, with exactly the same characteristics, I get 2 different results. The Matlab one here : 4kHz_Sample_Matlab_spec.png seems to be less contaminated than the seewave one here :4kHz_sample_Seewave_spec.png
I would like to know why there is such a difference, and what should I change in my "resamp" function to get the same with the seewave function, please?
Thank you very much !

Best regards,
Florian Rabasco
Reply all
Reply to author
Forward
0 new messages