I am currently working on a set of .wav files which, unfortunately, do not have the same sampling rate - I need to resample them for the purpose of feeding them to a neural net.
So - using Sox I resampled every file - with the command:

sox -v 0.99 filein -G -r 192000 fileout

However, having a look at the resampled files: enter image description here,
the frequency range has changed. Which is confusing me. I have put several hours into finding out why this is happening but i can't seem to find the reason.
Can somebody explain?

EDIT1: Just realized that this example is misleading as I am referring to the change in maximum Frequency, (the y-labels)


1 Answer 1


Uniformly sampled pulse code modulation (PCM) audio such as WAV files only encodes frequencies up to the Nyquist frequency, which is half the sampling frequency. So for a sampling frequency of 500 kHz you can have frequencies up to 250 kHz, and for a sampling frequency of 192 kHz you can have frequencies up to 96 kHz. This is reflected in the range of the Y labels.

  • $\begingroup$ Well, that's awkward, I've read about this but I thought, it is possible to have higher frequencies than the Nyquist frequency but they aren't displayed well. $\endgroup$
    – soultice
    Apr 11, 2016 at 13:07
  • $\begingroup$ May I add to this question above: is it possible to resample a file and keep the 'shape' of the frequency the same? In other words, if I am upsampling to a higher samplerate, is it possible to stretch the frequency so that my spectrogramm will look exactly the same although the samplerate has changed? $\endgroup$
    – soultice
    Apr 11, 2016 at 13:13
  • $\begingroup$ Does sox -r 192000 filein fileout do what you want? It should spoof that the original file is already sampled at 192 kHz so it needs no resampling. Be aware that also time will be stretched. If that is not what you want, try something like breakfastquay.com/rubberband $\endgroup$ Apr 11, 2016 at 13:26
  • $\begingroup$ What I tried right now was reading the file in python with librosa lib, which gives a split of samples/samplerate. Now if I keep the samples the same but change the samplerate to a higher/lower one, I seem to get the result I wanted, at least visually. I will try your solution as well. Thanks! $\endgroup$
    – soultice
    Apr 11, 2016 at 14:41
  • $\begingroup$ Seems to be approximately the same result. I guess this needs more tinkering on my side until I fully understand all of that. $\endgroup$
    – soultice
    Apr 11, 2016 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.