I downsampled an audio file to a very low sampling rate, 48hz. This is because I stored some information in the file, that are not really audio information but the audio format was convenient to use. After we recorded the files, we realized we can strongly downsample the original file without losing audio information, because the maximum frequency present in the spectrum are around 20hz - hence we can safely downsample to 48hz.
In order to check that the downsample was sucessfull and did not loose relevant information, I plotted a librosa specshow, to see whether it looks correct. But when I do that I see a lot of higher frequencies that were not present in the specshow of the original file.
Here a few code lines, so you can see what I did and the two plots to compare:
- downsampling: I used the scipy resample function, but I got similar results with scipy decimate.
snd, sampling_rate = sf.read(file_name) number_of_samples = round(len(snd) * float(new_rate) / sampling_rate) new_snd_resample = scipy.signal.resample(snd, number_of_samples)
- specshow plotting:
snd = np.abs(librosa.stft(snd)) fig, ax = plt.subplots() img = librosa.display.specshow(librosa.amplitude_to_db(snd, ref=np.max), y_axis='hz', x_axis='time', ax=ax) plt.ylim([1,1000]) ax.set_title(name) fig.colorbar(img, ax=ax, format="%+2.0f dB") plt.show()
And here the two resulting plots:
- original file:
- downsampled:
Is this maybe a problem of specshow with such a low and unusual sampling rate data? How can I check the spectral content of the downsampled file otherwise?
When I open the downsampled files, the data looks the same as the original, so I think the downsample process was correct.