0
$\begingroup$

Why does halving a floating point time series (audio) cause the noise shown in the spectogram to change?

From having a look, all the steps from getting the first half of X, stft() and amplitude_to_db() output the same values except in the last two frames closest to the halving point (which is expected but not expected to change specshow?).

So why does the graph show an increase in noise throughout the data?

Here is my code to create the two graphs:

audio_file = './nonvoice_snippets_stepvoices/t15_14steps.wav'
X, sample_rate = librosa.load(audio_file)


import matplotlib.pyplot as plt
import librosa.display
plt.figure(figsize=(15, 10))
D = librosa.amplitude_to_db(librosa.stft(X), ref=np.max)
plt.subplot(4, 2, 1)
librosa.display.specshow(D, y_axis='linear')
plt.colorbar(format='%+2.0f dB')
plt.title(audio_file)

X

#lets get the first half of that.
half = len(X)/2
half_X = X[:half]

plt.figure(figsize=(15, 10))
D = librosa.amplitude_to_db(librosa.stft(half_X), ref=np.max)
plt.subplot(4, 2, 1)
librosa.display.specshow(D, y_axis='linear')
plt.colorbar(format='%+2.0f dB')
plt.title(audio_file)

half_x

And the reason why I'm asking this is because I plan to get the Sum of absolute differences (SAD) for use in a Weiner filter to remove the noise you can see in both files. I figured that the first half of the file was a better representation of the noise in the file to get my SAD from but I need to know that this increase in noise won't cause unexpected effects.

Thanks community for being so helpful.

$\endgroup$
0
$\begingroup$

...why does the graph show an increase in noise throughout the data?

It does not. The graph is a depiction. You should focus on the numbers themselves.

Your silence segment includes at last three relatively loud spikes.

Spikes are sharp and brief transitions of the amplitude in the time domain. The bandwidth of a spike is inversely proportional to its duration. That is, the shorter the pulse, the more sinusoids it takes to synthesize it. A quick way to show this is via the Discrete Fourier Transform of the sinc pulse.

Spikes and more generally impulse-like waveforms, manifest themselves in a spectrogram as vertical "line" structures. There are three, relatively clear vertical "lines" in your spectrogram towards the end of the first plot.

The point is that the spike is a sharp transition that stands out from its surrounding samples (in the time domain) and causes relatively large sums in the frequency domain.

This is what is picked up by your normalisation by np.max and is made worse by your choice of y_axis='linear'.

If you try to depict this sequence of numbers x=[8,3,6,4,7,6,120,5,3,6,5,3,2] then the visualisation algorithm will assign the colour at the top of the color map to 120. Effectively, you would get one really bright value which would "swallow" all the rest. If you were to depict the same sequence of numbers but instead of 120 you substituted with 6.5, then you would observe a much more "colourful" output.

This is what is happening in this case. When you plot the whole file, you include the pulses that "skew" your visualisation (but not the underlying numbers) but this is not happening when you simply use the first half of the recording.

To deal with this, you can either use a simple logarithmic transform like log(1+x) or simply switch your scale to logarithmic (i.e. Decibel).

Both will have the same effect: Large values will remain large but small values will be "boosted". This does not distort the number. It simply changes the way the number is presented.

This looks like the beginning of a vinyl recording which includes a bit of hiss along with the occasional pop, because of depositions on the record (?)

Hope this helps.

$\endgroup$
  • $\begingroup$ Thanks a lot for the well thought out answer. Not a vinyl, it's a recording from my phone :P $\endgroup$ – Finn Maunsell Feb 7 '18 at 23:47
  • $\begingroup$ @FinnMaunsell Thanks for letting me know, glad to hear it was helpful, all the best with your project. $\endgroup$ – A_A Feb 8 '18 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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